so not having much luck with the updated libraries, the tilemap code i'm using compiles ok with no errors, but when i run it the emulator freezes
i'm still trying a few things so hopefully i can get this to work
Arduino: 1.6.7 (Windows 7), Board: "Arduino Duemilanove or Diecimila, ATmega328"
C:\Users\duhjoker\Desktop\ESMERELDA3\ESMERELDA3.ino: In function 'void loop()':
ESMERELDA3:60: error: 'i' was not declared in this scope
for(i=0; i < gb.display.numcolision + 1; i++)
^
ESMERELDA3:62: error: 'player' was not declared in this scope
if(gb.collideRectRect(player.posx,player.posy,8,8,gb.display.solid[i].x,gb.display.solid[i].y,8,8))
^
exit status 1
'i' was not declared in this scope
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
const byte tilemap[] PROGMEM = {14,8,
6,6,
3,3,3,3,3,3,6,6,3,3,3,3,3,3,
3,3,3,5,3,6,6,6,3,3,3,3,3,3,
3,3,6,6,6,6,6,6,6,3,3,3,3,3,
3,6,6,6,6,6,6,6,6,6,3,3,3,3,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,
3,3,6,6,6,6,6,6,6,6,6,6,3,3,
3,3,6,6,6,6,6,6,6,6,6,6,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3};
const byte bush_bottom[] PROGMEM = {B01001000,B00110000,B01011000,B00000000,B00000000, B00000000 };
const byte bush_top[] PROGMEM = {B00000000, B00000000, B00000000, B00110000,B01001000,B10110100 };
const byte bush[] PROGMEM = {B0010000, B01001000, B10110100, B01001000, B00110000, B01011000 };
const byte rock_terrain[] PROGMEM = {B01011000, B10100100, B00010100, B10100000, B10000100, B01011000 } ;
const byte turtle_rock[] PROGMEM = {B00000000, B01110000, B00101000, B01001000, B01110000, B00000000 };
const byte port_noir[] PROGMEM = {B11111100, B11111100, B11111100, B11111100, B11111100,B11111100 };
const byte port_blanc[] PROGMEM = {B00000000, B00000000, B00000000, B00000000, B00000000, B00000000 } ;
const byte *spritesheet[] = {bush_bottom,bush_top,bush,rock_terrain,turtle_rock,port_noir,port_blanc};
const byte sever_front_1[] PROGMEM = {6,6,0x78,0x0,0x0,0x30,0x0,0xcc,};
const byte sever_front_2[] PROGMEM = {6,6,0x84,0x48,0x78,0x84,0x78,0x0,};
const byte sever_right_1[] PROGMEM = {6,6,0x78,0x80,0xc8,0xb4,0x0,0xcc,};
const byte sever_right_2[] PROGMEM = {6,6,0x4,0x58,0x30,0x0,0x78,0x0,};
const byte sever_rear_1[] PROGMEM = {6,6,0X78,0X78,0X0,0X30,0X0,0XCC,};
const byte sever_rear_2[] PROGMEM = {6,6,0x84,0x0,0x78,0x84,0x78,0x0,};
const byte sever_left_1[] PROGMEM = {6,6,0x78,0x4,0x4c,0xb4,0x0,0xcc,};
const byte sever_left_2[] PROGMEM = {6,6,0x80,0x68,0x30,0x0,0x78,0x0,};
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 );
for(i=0; i < gb.display.numcolision + 1; i++)
{
if(gb.collideRectRect(player.posx,player.posy,8,8,gb.display.solid[i].x,gb.display.solid[i].y,8,8))
{
if(gb.display.solid[i].spritecol == port_blanc); //Do nothing because it's floor
else if(gb.display.solid[i].spritecol == port_noir);
else if(gb.display.solid[i].spritecol == rock_terrain);
else if(gb.display.solid[i].spritecol == turtle_rock);
else if(gb.display.solid[i].spritecol == bush);
else if(gb.display.solid[i].spritecol == bush_bottom);
else if(gb.display.solid[i].spritecol == bush_top);
}
}
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_direction = 1;
player_y = player_y - 1;}
if(player_y <= 0){
player_y = 0;}
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_direction = 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_direction = 3;
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_direction = 4;
player_x = player_x - 1;}
if(player_x <= -2){
player_x = -2;}
////////////PLAYER DIRECTION/////////////
if (player_direction == 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);
}
}
else if (player_direction == 2){
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);
}
}
else if (player_direction == 3){
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);
}
}
else if (player_direction == 4){
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);
}
}
else { 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.collideRectRect(player_x,player_y,8,8,gb.display.solid[i].x,gb.display.solid[i].y,8,8))
int i;
gb.display.drawTilemap(x,y,tilemap,spritesheet);
#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 = {6,6,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
};
const byte rock[] PROGMEM = {6,6,
0x58,
0xA4,
0x14,
0xA0,
0x84,
0x58,
};
const byte *spritesheet[] = {blank,rock};
const byte player[] PROGMEM = {6,6,
0x78,
0x48,
0x78,
0xFC,
0x78,
0x48,
};
const byte up[] PROGMEM = {6,6,
0x30,
0x78,
0xB4,
0x30,
0x30,
0x30,
};
const byte down[] PROGMEM = {6,6,
0x30,
0x30,
0x30,
0xB4,
0x78,
0x30,
};
const byte right[] PROGMEM = {6,6,
0x10,
0x8,
0xFC,
0xFC,
0x8,
0x10,
};
const byte left[] PROGMEM = {6,6,
0x20,
0x40,
0xFC,
0xFC,
0x40,
0x20,
};
int player_x = 15;
int player_y = 15;
int player_direction = 0;
int x=0,y=0;
int i;
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,0,0,6,6); // 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);
}
//////collision test
for(i=0; i < gb.display.numcolision + 1; i++)
{
if(gb.collideRectRect(player_x,player_y,6,6,gb.display.solid[i].x,gb.display.solid[i].y,6,6))
{
if(gb.display.solid[i].spritecol == blank); //Do nothing because it's floor
else if(gb.display.solid[i].spritecol == rock)gb.popup(F("rock"),10);
}
}
}
}
gb.display.drawTilemap(x,y,tilemap,spritesheet,0,0,6,6);
Sorunome wrote:Now, what are those mysterious last four parameters? If defined the tilmap will ONLY be rendered in that area! Be sure to note that x/y is actually relative to drawX/drawY.
That means that something like gb.display.drawTilemap(x,y,tilemap,spritesheet,0,0,LCDWIDTH,LCDHEIGHT-8); for example would always leave the lower 8 pixels of the screen free, so you could, for example, draw some stats there!
Add this library to Arduino IDE ( just Delete/Remove a Gamebuino from Libraries Folder and add this librarie from the Link)... So you can try to compile this code (this is a game in which I was working a long time ago... haha):
http://www.4shared.com/rar/CrbeXgMcce/G ... er123.html
#include <Gamebuino.h>
#include <SPI.h>
#define goup 0
#define godown 1
#define goleft 2
#define goright 3
#define solido 1
#define passway 2
#define underpass 3
#define cavepass 4
#define world 0
#define House 1
//#define forest 2
#define theend 3
#define cavepass1 4
#define cavepass2 5
Gamebuino gb;
const byte plb1[] PROGMEM = {8,8,0x70,0x88,0xD8,0x88,0x70,0xA8,0x70,0xD8,};
const byte plb2[] PROGMEM = {8,8,0x70,0x88,0xD8,0x88,0x70,0xA8,0x70,0xD0,};
const byte plb3[] PROGMEM = {8,8,0x70,0x88,0xD8,0x88,0x70,0xA8,0x70,0x58,};
const byte plc1[] PROGMEM = {8,8,0x70,0x88,0x88,0x88,0x70,0xA8,0x70,0xD8,};
const byte plc2[] PROGMEM = {8,8,0x70,0x88,0x88,0x88,0x70,0xA8,0x70,0xD0,};
const byte plc3[] PROGMEM = {8,8,0x70,0x88,0x88,0x88,0x70,0xA8,0x70,0x58,};
const byte pll1[] PROGMEM = {8,8,0x70,0x88,0x98,0x88,0x70,0xA8,0x70,0xD8,};
const byte pll2[] PROGMEM = {8,8,0x70,0x88,0x98,0x88,0x70,0xA8,0x70,0x58,};
const byte pll3[] PROGMEM = {8,8,0x70,0x88,0x98,0x88,0x70,0xA8,0x70,0xD0,};
const byte harbor[] PROGMEM = {11,6,
8,8,
4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4,
4, 4, 3, 3,14, 3,14, 3, 3, 3,14,
4, 3, 3, 3, 3, 3, 3,14,14,14, 0,
3, 3, 3, 3, 3, 3,14, 0, 1, 1, 3,
3, 3, 3, 3, 3,14, 0, 3, 3, 3, 3,
14,14,14,14,14, 0, 3, 3, 3, 3, 3 } ;
const byte forest[] PROGMEM = {11,6,
8,8,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4,
4, 4, 3, 3, 4, 3, 4, 3, 3, 4, 4,
4, 4, 3, 3, 3, 4, 3, 3, 3, 4, 4,
4, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4,
4, 4, 4, 4, 3, 3, 3, 4, 4, 4, 4 } ;
const byte tilemap[] PROGMEM = {30,30,
8,8,
12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
12,12,12,12,12,12,12,12,12,11,11,11,11,12,12,11,11,12,11,11,12,12,11,12,11,12,12,11,13,11,
12,12,12,12,12,12,12,12,11, 3, 3, 3, 3,11,11, 3, 3,11, 3, 3,11,11, 4,11, 4,11,11,14, 3,14,
11,11,11,13,11,11,11,11, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3,
3, 3,14, 3,14, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,14, 4, 4, 4, 4,14, 3, 3, 3,10, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3,14, 4, 4, 4,14, 3,14, 4, 4, 4, 4,14, 3,14, 4, 3, 3, 3, 3, 3, 3,
14, 3, 3, 3, 3, 3, 3, 3,14, 4, 4,14,14, 3, 3, 3,14,14, 3, 4, 4,14, 4, 4, 4, 4, 3, 3, 3, 3,
4,14, 3,14,14,14,14,14, 4, 4, 3, 3, 3, 3, 4, 3, 3, 3, 3,14, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3,
4, 4,14, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3,14, 4, 4, 4, 4, 4, 4, 4, 4, 3,
4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 4, 3, 3,14, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4,14, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4,14, 3,14, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 4, 4, 4, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4,14, 3,14,14, 3,14, 4, 4, 4, 3, 3, 3, 4, 3, 3, 3, 3, 4, 4, 4, 4, 4, 9, 4, 4, 4, 4, 4,
4, 4, 4,14, 4, 4,14, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4,14, 3,14,14, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 4,14, 3, 3, 3,14, 4, 4, 4,
4, 4, 3, 4, 4, 4, 4, 4, 3, 3, 3, 4, 3, 3, 3, 3, 4, 4, 4,14,14,14, 3, 3, 3, 3, 4, 4, 4, 4,
9, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
9, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4,
4, 4, 3, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3,14, 4,
4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 6, 5, 7, 3, 3, 3,14, 4,
4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 6, 5, 5, 5, 7, 3, 3,14, 4,
4, 4, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 4, 4, 3, 3, 3,14, 5, 8, 5,14, 3, 3, 4, 4,
4, 3, 3,14, 3, 3, 3, 3, 3, 3, 3,10, 3, 3, 3, 3, 3, 3, 3, 3, 3,14,14, 3,14,14, 3, 4, 4, 4,
4, 3,14, 4,14, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4,
4, 3, 4,10, 3, 3, 3, 3, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4,
4, 3,14, 4,14, 3, 3, 3, 3, 4, 4, 4, 4, 4, 3, 3, 3, 3,14,14,14,14,14,14,14,14,14,14,14, 3,
4, 4, 3,14, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3,14,14, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 9, 0, 3, 3, 2, 2, 3, 3, 3, 3, 3, 2, 2, 3 } ;
const byte agua3[] PROGMEM = {
B00000011,
B00000100,
B00011000,
B00100000,
B01000000,
B01000000,
B10000000,
B10000000 } ;
const byte agua2[] PROGMEM = {
B10011001,
B01101111,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000 } ;
const byte agua1[] PROGMEM = {
B00000000,
B00000000,
B00100010,
B01010101,
B10001000,
B00000000,
B00000000,
B00000000 } ;
const byte voidtile[] PROGMEM = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000 } ;
const byte arvore[] PROGMEM = {
B00010000,
B00101000,
B01000100,
B10000010,
B10000010,
B01101100,
B00101000,
B01010100 } ;
const byte tijolo[] PROGMEM = {
B11111111,
B10101001,
B10101111,
B11111111,
B10010001,
B11111111,
B10000101,
B11111111 } ;
const byte telha[] PROGMEM = {
B00000001,
B00000011,
B00000111,
B00001111,
B00011111,
B00111111,
B01111111,
B11111111 } ;
const byte telha2[] PROGMEM = {
B00000000,
B10000000,
B11000000,
B11100000,
B11110000,
B11111000,
B11111100,
B11111110 } ;
const byte porta[] PROGMEM = {
B11111111,
B11100111,
B11000011,
B10000001,
B10000001,
B10000001,
B10000001,
B10000001 } ;
const byte grass1[] PROGMEM = {
B00000000,
B01000100,
B00100010,
B00011001,
B01000000,
B00000100,
B00100010,
B00000000 } ;
const byte Grave1[] PROGMEM = {
B11111111,
B01000010,
B01011010,
B01011010,
B01011010,
B01011010,
B01000010,
B11111111 } ;
const byte BaseM1[] PROGMEM = {
B10000001,
B10001001,
B10000011,
B10100001,
B10001001,
B10000001,
B01000010,
B00111100 } ;
const byte M2[] PROGMEM = {
B10010001,
B10000001,
B11000101,
B10000001,
B10101001,
B10000001,
B10000101,
B10100001 } ;
const byte cave1[] PROGMEM = {
B10000001,
B10000001,
B10011001,
B10111101,
B10111101,
B10111101,
B01111110,
B00000000 } ;
const byte flor[] PROGMEM = {
B00000000,
B00000000,
B00001000,
B00000000,
B00000000,
B01000000,
B00000010,
B00000000 } ;
const byte *spritesheet[] = { agua3,agua2,agua1,voidtile,arvore,tijolo,telha,telha2,porta,grass1,Grave1,BaseM1,M2,cave1,flor } ;
const byte logo[] PROGMEM = {32,30,
0x60,0x0,0x0,0x0,
0x3C,0xF,0x70,0x0,
0x1F,0xBC,0xC,0x0,
0xF,0xFF,0xFA,0x0,
0x3,0xFF,0x35,0x0,
0x1,0xFF,0xBF,0x80,
0x0,0xFF,0xFF,0x80,
0x0,0xFF,0xFF,0x80,
0x0,0xFF,0xFF,0x0,
0x0,0xFF,0xFE,0x0,
0x0,0xFF,0xFE,0x0,
0x0,0x7F,0xFE,0x0,
0x0,0x7F,0xFE,0x0,
0x0,0x33,0xBA,0x0,
0x0,0x33,0x18,0x0,
0x0,0x31,0x0,0x0,
0x0,0x0,0x4,0x0,
0x0,0x20,0x18,0x0,
0x0,0x20,0x30,0x0,
0x0,0x16,0x70,0x0,
0x0,0xC,0xF0,0x0,
0x0,0x37,0xF0,0x0,
0x0,0x3F,0xFF,0x0,
0x0,0x7F,0xFF,0x0,
0x1,0xFF,0xFF,0xC0,
0x3,0xFF,0xFF,0xE0,
0xF,0xFF,0xFF,0xF0,
0x1F,0xFF,0xFF,0xF8,
0x3F,0xFF,0xFF,0xFC,
0x7F,0xFF,0xFF,0xFC,
};
typedef struct{
int posx=42;
int posy=24;
int tilex=0;
int tiley=0;
byte flip = NOFLIP;
const byte *bitmap = plb1;
} character;
character player;
int camerax = -144 ;
int cameray = -172 ;
byte cenary=0;
void setup() {
Serial.begin(9600);
gb.begin();
gb.titleScreen(F("LIS"),logo);
gb.setFrameRate(16);
}
void loop()
{
if(cenary == world)
{
if(gb.update()){
walk();
render();
}
}
if(cenary == House){
if(gb.update()){
}
}
if(cenary == cavepass1){
if(gb.update()){
}
}
}
void walk()
{
byte direc = godown;
bool flagwalk = false;
if(gb.buttons.pressed(BTN_B)){Serial.println(camerax);Serial.println(cameray);}
if(gb.buttons.repeat(BTN_UP,1)){direc = goup;player.posy--;flagwalk = true;player.flip = NOFLIP;if(colisiontest() == solido)player.posy++;}
else if(gb.buttons.released(BTN_UP))direc = goup;
if(gb.buttons.repeat(BTN_DOWN,1)){direc = godown; player.posy++;flagwalk = true;player.flip = NOFLIP;if(colisiontest() == solido)player.posy--;}
else if(gb.buttons.released(BTN_DOWN))direc = godown;
if(gb.buttons.repeat(BTN_LEFT,1)){direc = goleft; player.posx--;flagwalk = true; player.flip = FLIPH;if(colisiontest() == solido)player.posx++;}
else if(gb.buttons.released(BTN_LEFT))direc = goleft;
if(gb.buttons.repeat(BTN_RIGHT,1)){direc = goright; player.posx++ ;flagwalk = true;player.flip = NOFLIP;if(colisiontest() == solido)player.posx--;}
else if(gb.buttons.released(BTN_RIGHT))direc = goright;
if(flagwalk)
{
if(direc==goup){
if(gb.frameCount % 6 >= 0 && gb.frameCount % 6 < 2){player.bitmap = plc1 ;}
else if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = plc2;}
else if(gb.frameCount % 6 >= 4 && gb.frameCount % 6 <= 6){player.bitmap = plc3;}
}
else if(direc==godown){
if(gb.frameCount % 6 >= 0 && gb.frameCount % 6 < 2){player.bitmap = plb1;}
else if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = plb2;}
else if(gb.frameCount % 6 >= 4 && gb.frameCount % 6 <= 6){player.bitmap = plb3;}
}
else if(direc==goleft){
if(gb.frameCount % 6 >= 0 && gb.frameCount % 6 < 2){player.bitmap = pll1;}
else if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = pll2;}
else if(gb.frameCount % 6 >= 4 && gb.frameCount % 6 < 6){player.bitmap =pll3 ;}
}
else if(direc==goright){
if(gb.frameCount % 6 >= 0 && gb.frameCount % 6 < 2){player.bitmap = pll1;}
else if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = pll2;}
else if(gb.frameCount % 6 >= 4 && gb.frameCount % 6 <= 6){player.bitmap = pll3;}
}
}
if(player.posx > 79)player.posx = 79;
else if(player.posx < 0)player.posx = 0;
if(player.posy > 40)player.posy = 40;
else if(player.posy < 0)player.posy = 0;
}
void render()
{
if(player.posx > 54 && camerax < 0 && camerax > -156){player.posx = 54;camerax--;}
else if(player.posx < 30 && camerax < 0 && camerax > -156){player.posx = 30;camerax++;}
else if(player.posx > 54 && camerax <= 0 && camerax >= -156)camerax--;
else if(player.posx < 30 && camerax <= 0 && camerax >= -156)camerax++;
if(player.posy > 28 && cameray < 0 && cameray > -192){player.posy = 28;cameray--;}
else if(player.posy < 20 && cameray < 0 && cameray > -192){player.posy = 20;cameray++;}
else if(player.posy > 28 && cameray <= 0 && cameray >= -192)cameray--;
else if(player.posy < 20 && cameray <= 0 && cameray >= -192)cameray++;
if(camerax > 0)camerax=0;
else if(camerax < -156) camerax = -156;
if(cameray > 0)cameray=0;
else if(cameray < -192) cameray = -192;
gb.display.drawTilemap(camerax,cameray,tilemap,spritesheet);
gb.display.drawBitmap(player.posx,player.posy,player.bitmap,NOROT,player.flip);
if(gb.buttons.repeat(BTN_B,1))
{
gb.display.print("CPU Load: ");
gb.display.print(gb.getCpuLoad());
gb.display.cursorX = 0;
}
}
byte colisiontest()
{
byte i=0;
for(i=0; i < gb.display.numcolision + 1; i++)
{
if(gb.collideRectRect(player.posx,player.posy,5,8,gb.display.solid[i].x,gb.display.solid[i].y,8,8))
{
//if(gb.display.solid[i].spritecol == voidtile); //Do nothing because it's floor
if(gb.display.solid[i].spritecol == porta) return passway;
else if(gb.display.solid[i].spritecol == Grave1) return underpass;
else if(gb.display.solid[i].spritecol == cave1) return cavepass;
if(gb.display.solid[i].spritecol == arvore) return solido;
else if(gb.display.solid[i].spritecol == agua2) return solido;
else if(gb.display.solid[i].spritecol == agua3) return solido;
else if(gb.display.solid[i].spritecol == tijolo) return solido;
else if(gb.display.solid[i].spritecol == telha) return solido;
else if(gb.display.solid[i].spritecol == telha2) return solido;
else if(gb.display.solid[i].spritecol == BaseM1) return solido;
else if(gb.display.solid[i].spritecol == M2) return solido;
}
}
return 0;
}
Return to Programming Questions
Users browsing this forum: No registered users and 4 guests