Understanding the language, error messages, etc.
by naed » Mon Aug 01, 2016 8:21 am
Duhjoker wrote:Oh OK!!! Thank you!!!
Looks simple enough I'll make a copy of the current build and play with it. Also don't they need the vertical coordinates Or the VX VY on a couple?
not for the screen boundaries as you'll only hit the top of the screen if your pressing up, that's why the boundaries are set to stop you going out of the top of the screen when going upwards
-
naed
-
- Posts: 140
- Joined: Tue May 31, 2016 3:18 pm
by Duhjoker » Mon Aug 01, 2016 8:31 am
That makes since.
I've been looking around for how to set the orientation after a button press but coming up short. I found a couple commands that I thought might work but can't find any reference or threads mentioning them. I'm wondering if it might need a new set of commands to add to the regular movement commands.
Maybe an else/if statement or a command after the button release like gb.display.bitmap after the button release command
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
by Duhjoker » Mon Aug 01, 2016 8:52 am
How about
- Code: Select all
if(gb.buttons.released(BTN_UP))
gb.display.drawBitmap(player_x,player_y,spriteId);
Would i need to code another groupset with the if.(gb.button.released etc like with the buttons pressed or would i put one command under each direction?
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
by naed » Mon Aug 01, 2016 7:45 pm
What about
- Code: Select all
gb.buttons.released
Description
Function used to know when a given button is released.
EDIT
Lol your previous post didn't show for me but we're thinking the same thing
-
naed
-
- Posts: 140
- Joined: Tue May 31, 2016 3:18 pm
by Duhjoker » Mon Aug 01, 2016 8:24 pm
Awesome!!!!
Ok so no if and it works? Do I use this command at one for each set of button punches or do I create a separate list below the buttons pressed code.
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
by Duhjoker » Mon Aug 01, 2016 11:30 pm
All right I tried to implement the button release command to lock its orientation. Its working kind of. It now stays locked on sever_rear. Also the whole room bitmap screen is flickering like the sprite and it wasn't before and the character now moves supper fast.
- Code: Select all
//imports the SPI library (needed to communicate with Gamebuino's screen)
#include <SPI.h>
//imports the Gamebuino library
#include <Gamebuino.h>
//creates a Gamebuino object named gb
Gamebuino gb;
const byte room_1[] PROGMEM = {88,48,
0x59,0x65,0x96,0x59,0x60,0x00,0x59,0x65,0x96,0x59,0x60
,0xa6,0x9a,0x69,0xa6,0x90,0x00,0xa6,0x9a,0x69,0xa6,0x90
,0x14,0x51,0x45,0x14,0x50,0x00,0x14,0x51,0x45,0x14,0x50
,0xa2,0x8a,0x28,0xa2,0x80,0x00,0xa2,0x8a,0x28,0xa2,0x80
,0x86,0x18,0x61,0x86,0x10,0x00,0x86,0x18,0x61,0x86,0x10
,0x59,0x65,0x96,0x59,0x60,0x00,0x59,0x65,0x96,0x59,0x60
,0x59,0x65,0x80,0x58,0x00,0x00,0x00,0x00,0x00,0x59,0x60
,0xa6,0x9a,0x40,0xa4,0x00,0x00,0x00,0x00,0x00,0xa6,0x90
,0x14,0x51,0x40,0x14,0x00,0x00,0x00,0x00,0x00,0x14,0x50
,0xa2,0x8a,0x00,0xa0,0x00,0x00,0x00,0x00,0x00,0xa2,0x80
,0x86,0x18,0x40,0x84,0x00,0x00,0x00,0x00,0x00,0x86,0x10
,0x59,0x65,0x80,0x58,0x00,0x00,0x00,0x00,0x00,0x59,0x60
,0x59,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x59,0x60
,0xa6,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa6,0x90
,0x14,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x50
,0xa2,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa2,0x80
,0x86,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x86,0x10
,0x59,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x59,0x60
,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x59,0x60
,0xa4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa6,0x90
,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x50
,0xa0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa2,0x80
,0x84,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x86,0x10
,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x59,0x60
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x59,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x59,0x60
,0xa6,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa6,0x90
,0x14,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x50
,0xa2,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa2,0x80
,0x86,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x86,0x10
,0x59,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x59,0x60
,0x59,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x59,0x60
,0xa6,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa6,0x90
,0x14,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x50
,0xa2,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xa2,0x80
,0x86,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x86,0x10
,0x59,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x59,0x60
,0x59,0x65,0x96,0x59,0x65,0x96,0x59,0x65,0x96,0x59,0x60
,0xa6,0x9a,0x69,0xa6,0x9a,0x69,0xa6,0x9a,0x69,0xa6,0x90
,0x14,0x51,0x45,0x14,0x51,0x45,0x14,0x51,0x45,0x14,0x50
,0xa2,0x8a,0x28,0xa2,0x8a,0x28,0xa2,0x8a,0x28,0xa2,0x80
,0x86,0x18,0x61,0x86,0x18,0x61,0x86,0x18,0x61,0x86,0x10
,0x59,0x65,0x96,0x59,0x65,0x96,0x59,0x65,0x96,0x59,0x60,};
const byte sever_front_1[] PROGMEM = {8,6,0x78,0x0,0x0,0x30,0x0,0xcc,};
const byte sever_front_2[] PROGMEM = {8,6,0x84,0x48,0x78,0x84,0x78,0x0,};
const byte sever_left_1[] PROGMEM = {8,6,0x78,0x80,0xc8,0xb4,0x0,0xcc,};
const byte sever_left_2[] PROGMEM = {8,6,0x4,0x58,0x30,0x0,0x78,0x0,};
const byte sever_rear_1[] PROGMEM = {8,6,0X78,0X78,0X0,0X30,0X0,0XCC,};
const byte sever_rear_2[] PROGMEM = {8,6,0x84,0x0,0x78,0x84,0x78,0x0,};
const byte sever_right_1[] PROGMEM = {8,6,0x78,0x4,0x4c,0xb4,0x0,0xcc,};
const byte sever_right_2[] PROGMEM = {8,6,0x80,0x68,0x30,0x0,0x78,0x0,};
int player_x = 15;
int player_y = 15;
// the setup routine runs once when Gamebuino starts up
void setup(){
// initialize the Gamebuino object
gb.begin();
//display the main menu:
gb.titleScreen(F("Myth of ESmerelda"));
gb.setFrameRate(80);
}
// the loop routine runs over and over again forever
void loop(){
//updates the gamebuino (the display, the sound, the auto backlight... everything)
//returns true when it's time to render a new frame (20 times/second)
if(gb.update()){
//prints Hello World! on the screen
gb.display.drawBitmap(0,0,room_1);
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,sever_front_1);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_front_2);
}
if(gb.buttons.repeat(BTN_UP,1)){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,sever_rear_1);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_rear_2);
}
player_y = player_y - 1;}
if(player_y <= 0){
player_y = 0;}
}
gb.buttons.released(BTN_UP);{ ////////added for orientation
gb.display.setColor(BLACK);{ ////////added for orientation
gb.display.drawBitmap(player_x,player_y,sever_rear_1); ////////added for orientation
}
gb.display.setColor(GRAY);{ ////////added for orientation
gb.display.drawBitmap(player_x,player_y,sever_rear_2); ////////added for orientation
}
}
if(gb.buttons.repeat(BTN_DOWN,1)){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,sever_front_1);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_front_2);
}
player_y = player_y + 1;}
if(player_y >= 40){
player_y = 40;}
if(gb.buttons.repeat(BTN_RIGHT,1)){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,sever_right_1);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_right_2);
}
player_x = player_x + 1;}
if(player_x >= 77){
player_x = 77;}
if(gb.buttons.repeat(BTN_LEFT,1)){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,sever_left_1);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_left_2);
}
player_x = player_x - 1;}
if(player_x <= -2){
player_x = -2;}
}
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
by naed » Mon Aug 01, 2016 11:45 pm
you could try this, i didn't get good results from the button release way, so just came up with another way (probably not the best way but it certainly works)
i'll post the whole code here and you can take a look
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
//map followed by tilesprites
const byte
tilemap[] PROGMEM = {14,8,
6,6,
1,1,1,1,1,1,0,0,1,1,1,1,1,1,
1,1,1,0,1,0,0,0,0,0,0,0,1,1,
1,1,0,0,0,0,0,0,0,0,0,0,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,1,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,0,0,0,0,0,0,0,0,0,0,1,1,
1,1,0,0,0,0,0,0,0,0,0,0,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1};
const byte blank[] PROGMEM = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000 } ;
const byte rock[] PROGMEM = {
B01011000,
B10100100,
B00010100,
B10100000,
B10000100,
B01011000 } ;
const byte *spritesheet[] = { blank, rock };
const byte player[] PROGMEM = {8,6,
B111111,
B010010,
B011110,
B101101,
B011110,
B110011,};
const byte up[] PROGMEM = {8,6,
B001100,
B011110,
B101101,
B001100,
B001100,
B001100,};
const byte down[] PROGMEM = {8,6,
B001100,
B001100,
B001100,
B101101,
B011110,
B001100,};
const byte right[] PROGMEM = {8,6,
B000100,
B000010,
B111111,
B111111,
B000010,
B000100,};
const byte left[] PROGMEM = {8,6,
B001000,
B010000,
B111111,
B111111,
B010000,
B001000,};
int player_x = 15;
int player_y = 15;
int player_direction = 0;
int x=0,y=0;
void setup() {
gb.begin();
gb.titleScreen(F("test"));
gb.display.persistence = false;
}
void loop() {
if(gb.update()){
if (gb.buttons.repeat(BTN_RIGHT,1));
if (gb.buttons.repeat(BTN_LEFT,1));
if (gb.buttons.repeat(BTN_DOWN,1));
if (gb.buttons.repeat(BTN_UP,1));
gb.display.drawTilemap(x,y,tilemap,spritesheet); // draw the tilemap
// gb.display.cursorY = 12; gb.display.println( x );gb.display.println( y );
if(gb.buttons.repeat(BTN_UP,1)){
gb.display.drawBitmap(player_x,player_y,up);
player_direction = 1;
player_y = player_y - 1;}
if(player_y <= 0){
player_y = 0;}
if(gb.buttons.repeat(BTN_DOWN,1)){
gb.display.drawBitmap(player_x,player_y,down);
player_direction = 2;
player_y = player_y + 1;}
if(player_y >= 40){
player_y = 40;}
if(gb.buttons.repeat(BTN_RIGHT,1)){
gb.display.drawBitmap(player_x,player_y,right);
player_direction = 3;
player_x = player_x + 1;}
if(player_x >= 77){
player_x = 77;}
if(gb.buttons.repeat(BTN_LEFT,1)){
gb.display.drawBitmap(player_x,player_y,left);
player_direction = 4;
player_x = player_x - 1;}
if(player_x <= -2){
player_x = -2;}
////////PLAYER DIRECTION//////////////
if (player_direction == 1){
gb.display.drawBitmap(player_x,player_y,up);
}
else if (player_direction == 2){
gb.display.drawBitmap(player_x,player_y,down);
}
else if (player_direction == 3){
gb.display.drawBitmap(player_x,player_y,right);
}
else if (player_direction == 4){
gb.display.drawBitmap(player_x,player_y,left);
}
else { gb.display.drawBitmap(player_x,player_y,down);
}
}
}
-
naed
-
- Posts: 140
- Joined: Tue May 31, 2016 3:18 pm
by Duhjoker » Tue Aug 02, 2016 1:37 am
Hmmmm I get an error on drawTilemap. It says no member named tileMap. I guess I need to find the library for it.
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
by Duhjoker » Tue Aug 02, 2016 2:22 am
Went through all my posts after remembering what sorunome said about the Tilemap routine and found the updated library that includes the tilemap parts. The link to this repository is not included in the wiki so make sure you use this library when using the tilemap command.
https://github.com/Sorunome/Gamebuino/tree/tilemapperJust simply remove the old library and replace it with the update.
Any way after updating the example compiles just haven't had a chance to look at it on the simbuino app yet.
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
by Duhjoker » Tue Aug 02, 2016 2:57 am
Awesome thank you gonna play with it now and create a new build.
Did you mean to comment out // the last line of the commands under void loop?
Ok starting at the first set of button commands i see you have added "player_direction = 1;". And then below at the player direction part you have "if (player_direction == 1) {..etc...
So in the buttons pressed code we are naming the player direction and assigning it an integer and the using that integer to tell where the sprite will face when button released in player direction?
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
Return to Programming Questions
Who is online
Users browsing this forum: No registered users and 2 guests