Hi, am a noob at programing and I need to make a player controller program for my game but I have a problem when I use the UP DOWN LEFT RIGHT keys instead of my bitmap moving around on the x and y it rotates around like a mad man I know its a silly question but pls help.
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
int player_x = LCDHEIGHT/2;
int player_y = LCDWIDTH/2;
int playervx = 1;
int playervy = 1;
const byte Knight[] PROGMEM = {16,15,
B00000111,B00001000,
B00000111,B00001000,
B00000111,B00001000,
B00011111,B11001000,
B00101111,B10111100,
B00101101,B10011000,
B00101111,B10001000,
B00001111,B10000000,
B00001111,B10000000,
B00001000,B01000000,
B00001000,B00100000,
B00001000,B00100000,
B00000000,B00000000,
B00000000,B00000000,
B00000000,B00000000,
};
void setup() {
gb.begin();
gb.titleScreen(F("collidePointRect"));
}
void loop() {
if(gb.update()) {
if(gb.buttons.pressed(BTN_C)) {
gb.titleScreen(F("Bitmap example"));
}
if(gb.buttons.repeat(BTN_RIGHT,1)){
player_x = player_x - playervx;
}
if(gb.buttons.repeat(BTN_LEFT,1)) {
player_x = player_x + playervx;
}
if(gb.buttons.repeat(BTN_UP,1)) {
player_y = player_y - playervy;
}
if(gb.buttons.repeat(BTN_DOWN,1)){
player_y = player_y + playervy;
}
gb.display.drawBitmap(20, 20, Knight, player_x, player_y);
}
}