Page 1 of 1

Question about drawBitmap

PostPosted: Mon Jan 19, 2015 1:55 pm
by GlueMen
hey guys im new to the gamebuino but i want to programm a game like PokéMon :P
but for now i got a question why i get an error in my script while compiling

Code: Select all
 #include <Backlight.h>
#include <Battery.h>
#include <Buttons.h>
#include <Display.h>
#include <Gamebuino.h>
#include <Sound.h>
#include <SPI.h>
Gamebuino gb;

int trainer_x = LCDWIDTH/2;
int trainer_y = LCDHEIGHT/2;
int trainer_vx = 2;
int trainer_vy = 2;
int trainer_inv = 6;


const byte PROGMEM trainerup[] =
{
  16,16,
  B111111111111111,
  B111111111111111,
  B111111111111111,
  B111111111111111,
  B111111111111111,
  B111111111111111,
  B000000000000000,
  B000000000000000,
  B000000000000000,
  B000000000000000,
  B000000000000000,
  B000000000000000,
  B000000000000000,
  B000000000000000,
  B000000000000000,
  B000000000000000,

};
const byte PROGMEM trainerdown[] =
{
  16,16,
  B0000000000000000,
  B0000000000000000,
  B0000000000000000,
  B0000000000000000,
  B0000000000000000,
  B0000000000000000,
  B0000000000000000,
  B0000000000000000,
  B0000000000000000,
  B0000000000000000,
  B1111111111111111,
  B1111111111111111,
  B1111111111111111,
  B1111111111111111,
  B1111111111111111,
  B1111111111111111,
};



void setup(){
                                                        // put your setup code here, to run once:
  gb.begin();
  gb.titleScreen(F("PokeMon"));
}

void loop(){
                                                        // put your main code here, to run repeatedly:
  if(gb.update()){
   
                                                        //HIER STEURERRUNG
    if(gb.buttons.repeat(BTN_LEFT,1)){
    trainer_x = trainer_x - trainer_vx;
    }
  if(gb.buttons.repeat(BTN_RIGHT,1)){
    trainer_x = trainer_x + trainer_vx;
    }
  if(gb.buttons.repeat(BTN_UP,1)){
    trainer_y = trainer_y - trainer_vy;
    gb.display.drawBitmap(trainer_x,trainer_y,trainerup);
    }
  if(gb.buttons.repeat(BTN_DOWN,1)){
    trainer_y = trainer_y + trainer_vy;
    gb.display.drawBitmap(trainer_x,trainer_y,trainerdown);
    }
  if(trainer_x < 0){
    trainer_x = 0;
    }
  if((trainer_x + 7) > LCDWIDTH){
    trainer_x = LCDWIDTH - 7;
    }
  if(trainer_y < 0){
    trainer_y = 0;
    }
  if((trainer_y + 8) > LCDHEIGHT){
    trainer_y = LCDHEIGHT - 8;
    }
                                                         //HIER POKE INVENTAR

   
  }
}


i got a error for the imagines where i try to make them look in the direktion im walking
and im gonna make some new trainer models with bitmap later dont worrie ;)

sorry for that bad english im a german one

Re: Question about drawBitmap

PostPosted: Tue Jan 20, 2015 2:22 pm
by Jolly
Hey, can you post the error message, too?

And there's already some Pokemon-like game planned (Buinomon).
Maybe you can use the information from the Buinomon-Threads instead of doing everything yourself: viewtopic.php?f=10&t=550&hilit=buinomon

Of course I don't want to discourage you from your own project, I just wanted to show you that there's already something in that direction. ;)

Re: Question about drawBitmap

PostPosted: Tue Jan 20, 2015 6:51 pm
by Marcus
Hello GlueMen,

nice to see more RPG games :-)

being new to Gamebuino myself, I ran into similar troubles when first attempting to make my characters look in different directions and cycle through the animation.

First of all, the first of your sprite data is just 15 characters long, not 16 as defined.
Second, a byte can only be 8 bit long. ;-)

Example:
Code: Select all
const byte Bild1[] PROGMEM = {16,16,
B00000000,B00000000,
B00000000,B00000000,
B00000100,B01000000,
B00000100,B01000000,
B00000100,B01000000,
B00000000,B00000000,
B00000000,B00000000,
B00000000,B00000000,
B00000000,B00000000,
B00000000,B00000000,
B00010000,B00110000,
B00011000,B01100000,
B00001111,B10000000,
B00000000,B00000000,
B00000000,B00000000,
B00000000,B00000000,
};


Helpful tool: Bitmap Encoder, see http://gamebuino.com/wiki/index.php?title=Download

Re: Question about drawBitmap

PostPosted: Wed Jan 21, 2015 5:05 pm
by GlueMen
thank you guys it helped me verymuch^^
but i got an other question now:P
how can i script is that the character is looking in the direktion im walking to and after it its looking that way also right now i got this but its not what i want

Code: Select all
  if(gb.buttons.pressed(BTN_C)){
    gb.titleScreen(F("PokeMon"));
  } 
  if(gb.buttons.repeat(BTN_LEFT,1)){
    trainer_x = trainer_x - trainer_vx;
    gb.display.drawBitmap(trainer_x,trainer_y,trainerleft);
    }
  if(gb.buttons.repeat(BTN_RIGHT,1)){
    trainer_x = trainer_x + trainer_vx;
    gb.display.drawBitmap(trainer_x,trainer_y,trainerright);
    }
  if(gb.buttons.repeat(BTN_UP,1)){
    trainer_y = trainer_y - trainer_vy;
    gb.display.drawBitmap(trainer_x,trainer_y,trainerup);
    }
  if(gb.buttons.repeat(BTN_DOWN,1)){
    trainer_y = trainer_y + trainer_vy;
    gb.display.drawBitmap(trainer_x,trainer_y,trainerdown);
    }

right now the char is just showing of if one or more buttons are pressed and if i press more than one buttons also more chars display

Re: Question about drawBitmap

PostPosted: Wed Jan 21, 2015 5:27 pm
by Marcus
You could either use "else if" or use a variable to memorize what direction was pressed first and disable further input until the key is released again.

Re: Question about drawBitmap

PostPosted: Wed Jan 21, 2015 7:19 pm
by GlueMen
have you got an example for me its very hard for me to do this without some little helps it dont need to be an working example for my script so you could give me a script what you are working on where it is working
so that i can see how it works i already tried with while but then broke the comlpete game and i also tried with if button ... botton... and button... are pushed dont show the basic

(i was trieng to do it that if i dont press a button the char is looking down and if i push a button its justone picture but then the pictures are overlayed :lol: ) im sooo bad at scripting right now