Understanding the language, error messages, etc.
by Sushi » Tue Oct 07, 2014 11:01 am
I've just created my first simple game, but the bitmap I've put it gets cut in half when I load the program:
- Code: Select all
#include <Gamebuino.h>
#include <SPI.h>
Gamebuino gb;
byte PROGMEM player[] =
{
5,5,
B00100,
B00000,
B11111,
B01010,
B10001,
};
float thing_x = LCDWIDTH/2;
float thing_y = LCDHEIGHT/2;
float thing_vx = 1;
float thing_vy = 1;
float thing_size = 5;
void setup(){
gb.begin();
gb.titleScreen(F("SimpleTest"));
gb.popup(F(":3"), 20);
}
int count = 0;
void loop(){
if(gb.update()){
gb.display.println(thing_vx);
gb.display.println(thing_vy);
gb.display.drawBitmap(thing_x, thing_y, player);
if(thing_x < 0){
thing_vx = -thing_vx;
}
if(thing_x + thing_size > LCDWIDTH){
thing_vx = -thing_vx;
}
if(thing_y < 0){
thing_vy = -thing_vy;
}
if(thing_y + thing_size > LCDHEIGHT){
thing_vy = -thing_vy;
}
if(gb.buttons.repeat(BTN_UP,2)){
thing_vy = thing_vy - 1;
}
if(gb.buttons.repeat(BTN_DOWN,2)){
thing_vy = thing_vy + 1;
}
if(gb.buttons.repeat(BTN_RIGHT,2)){
thing_vx = thing_vx + 1;
}
if(gb.buttons.repeat(BTN_LEFT,2)){
thing_vx = thing_vx - 1;
}
thing_x = thing_x + thing_vx;
thing_y = thing_y + thing_vy;
}
if (count++ % 5 == 0) {
thing_vx = thing_vx * 0.999;
thing_vy = thing_vy * 0.999;
}
}
Last edited by
Sushi on Wed Oct 08, 2014 10:00 pm, edited 1 time in total.
-
Sushi
-
- Posts: 52
- Joined: Tue Oct 07, 2014 12:12 am
by rodot » Tue Oct 07, 2014 3:12 pm
Hello Sushi, and welcome!
It's because bitmap's width have to be a multiple of 8 (and the height can have any value). So if you change your code to that it works fine :
- Code: Select all
byte PROGMEM player[] =
{
8,5,
B00100000,
B00000000,
B11111000,
B01010000,
B10001000,
};
-
rodot
- Site Admin
-
- Posts: 1290
- Joined: Mon Nov 19, 2012 11:54 pm
- Location: France
-
by Sushi » Tue Oct 07, 2014 9:28 pm
Thanks r0d0t! It works fine now
-
Sushi
-
- Posts: 52
- Joined: Tue Oct 07, 2014 12:12 am
Return to Programming Questions
Who is online
Users browsing this forum: No registered users and 73 guests