Bitmap movement kinda working pls help

Advice on general approaches or feasibility and discussions about game design

Bitmap movement kinda working pls help

Postby Willballs2you » Fri May 13, 2016 4:13 am

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);
}
}
Willballs2you
 
Posts: 5
Joined: Fri May 13, 2016 4:03 am

Re: Bitmap movement kinda working pls help

Postby Sutchig » Fri May 13, 2016 4:45 am

you should use
Code: Select all
gb.display.drawBitmap(x,y,bitmap,rotation,flip)


in your sketch this could be
Code: Select all
gb.display.drawBitmap(player_x, player_y, Knight, NOROT , NOFLIP);


see http://gamebuino.com/wiki/index.php?title=Reference
and http://gamebuino.com/wiki/index.php?tit ... drawBitmap
Sutchig
 
Posts: 67
Joined: Sat May 23, 2015 3:48 pm

Re: Bitmap movement kinda working pls help

Postby Willballs2you » Fri May 13, 2016 2:44 pm

It works! Thank you so much for helping me and the quick reply!
Willballs2you
 
Posts: 5
Joined: Fri May 13, 2016 4:03 am

Re: Bitmap movement kinda working pls help

Postby Willballs2you » Fri May 13, 2016 4:01 pm

I have two more questions the first one is how to make a bitmap despawn? 2nd how do I make the camera follow the player?
Willballs2you
 
Posts: 5
Joined: Fri May 13, 2016 4:03 am

Re: Bitmap movement kinda working pls help

Postby Sutchig » Sat May 14, 2016 7:50 pm

i dont know what you mean by despawn?

camera:
there are different ways.
the simplest could be:
you have world-coordinates: player_x/y, camera_x/y
at the beginning they are all at 0:
Code: Select all
int player_x = 0;
int player_y = 0;
int camera_x =0;
int camera_y =0;


at drawBitmap you add LCDWIDTH/2 and LCDHEIGHT/2 to center your view and add your player minus camera coordinates. (screen coordinates)
Code: Select all
gb.display.drawBitmap(LCDWIDTH/2+player_x-camera_x, player_y, Knight, 0,0);


to follow with camera your player, you could simply test, if the difference between them is above a threshold:
Code: Select all
if (camera_x>player_x+10) camera_x--;

^^this has to be before drawBitmap and repeated for three other directions ;)
Sutchig
 
Posts: 67
Joined: Sat May 23, 2015 3:48 pm


Return to Project Guidance & Game development

Who is online

Users browsing this forum: No registered users and 30 guests