Yea you would have to overlay two up tilemaps.
Hmmmm ok.
naed wrote:
got it to work
- Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
const byte tilemap[] PROGMEM = {17,11,
8,8,
2, 2, 2, 2, 2, 2, 2,19, 8, 8, 3,18,18,18,18,18, 2,
2, 2, 2, 2, 2, 2, 2,19, 8, 8,27,27,27,27,27,27,20,
2, 2, 2, 2, 2, 2, 2,19, 8, 8,26,26,26,26,26,26,20,
2, 2, 2, 2, 2, 2,18, 4, 8, 8,25,26,26,26,26,26,20,
2, 2, 2, 2, 2, 4, 8, 8, 8, 8, 8,26,26,26,26,26,20,
2, 2, 2, 2, 4, 8, 8, 8, 8, 8, 8,26,26,26,26,26,20, /////////112x64 pix res
18,18,18, 4, 8, 8, 8, 8, 8, 8, 8, 8,25,25,25,25, 3,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
21,21, 6, 8, 8, 8,22,23,24, 8, 8, 8, 8, 8, 5,21,21,
2, 2,19, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,20, 2, 2,
2, 2, 2,21,21,21,21,21,21,21,21,21,21,21, 2, 2, 2,};
const byte bush[] PROGMEM = {B00101100,B01010010,B10001001,B01000010,B10010001,B01001010,B00100100,B01111110,};
const byte port_noir[] PROGMEM = {B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,};
const byte rock_terrain_master[] PROGMEM = {B00000010,B00010000,B01000000,B00000010,B00010000,B00001000,B01000001,B00000100,};
const byte rock_valley_ne[] PROGMEM = {B10100000,B11001001,B01110000,B00001100,B00000101,B00000100,B00000110,B00000011,};
const byte rock_valley_nw[] PROGMEM = {B00000101,B10010011,B00001110,B00110000,B10100000,B00100000,B01100000,B11000000,};
const byte rock_valley_se[] PROGMEM = {B00000011,B00000110,B00000100,B00000101,B00001100,B01110000,B11001001,B10100000,};
const byte rock_valley_sw[] PROGMEM = {B11000000,B01100000,B00100000,B10100000,B00110000,B00001110,B10010011,B00000101,};
const byte turtle_rock[] PROGMEM = {B01101100,B10110010,B11010001,B01010101,B01010010,B10011001,B10000001,B11111110,};
const byte void_tile[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte water_left_bottom[] PROGMEM = {B10001111,B10000000,B11110000,B10000000,B10001111,B10000000,B11110000,B11111111,};
const byte water_left_middle[] PROGMEM = {B10001111,B10000000,B11110000,B10000000,B10001111,B10000000,B11110000,B10000000,};
const byte water_left_top[] PROGMEM = {B11111111,B10000000,B11110000,B10001111,B10000000,B10000000,B11110000,B10000000,};
const byte water_right_bottom[] PROGMEM = {B1110001,B00000001,B0000111,B00000001,B11110001,B00000001,B00001111,B11111111,};
const byte water_right_middle[] PROGMEM = {B11110001,B00000001,B00001111,B00000001,B11110001,B00000001,B00001111,B00000001,};
const byte water_right_top[] PROGMEM = {B11111111,B00000001,B00001111,B00000001,B11110001,B00000001,B00001111,B00000001,};
const byte water_middle_bottom[] PROGMEM = {B11110000,B00000000,B00001111,B00000000,B11110000,B00000000,B00001111,B11111111,};
const byte water_middle_middle[] PROGMEM = {B11110000,B00000000,B00001111,B00000000,B11110000,B00000000,B00001111,B00000000,};
const byte water_middle_top[] PROGMEM = {B11111111,B00000000,B11110000,B00000000,B00001111,B00000000,B11110000,B00000000,};
const byte rock_s[] PROGMEM = {B00010010,B00000000,B01001000,B00000100,B00100001,B10001100,B01110010,B10000001,};
const byte rock_e[] PROGMEM = {B00000101,B00100010,B00001010,B10000010,B00100100,B00010100,B10000010,B00001001,};
const byte rock_n[] PROGMEM = {B10000001,B01110010,B10001100,B00100001,B00000100,B01001000,B00000000,B00010010,};
const byte rock_w[] PROGMEM = {B10100000,B01000100,B01010000,B01000001,B00100100,B00101000,B01000001,B10010000,};
const byte bush_left[] PROGMEM = {B00111011,B01000100,B10100000,B10010100,B01000010,B10000000,B10001000,B01110111,};
const byte bush_middle[] PROGMEM = {B10111101,B01000010,B00001000,B10000100,B00010000,B00100001,B10001000,B01110111,};
const byte bush_right[] PROGMEM = {B11011100,B00100010,B00000101,B00101001,B01000010,B00000001,B00010001,B11101110,};
const byte tree_base[] PROGMEM = {B01010100,B01000100,B10100010,B10001010,B10000010,B01101100,B00101000,B00101000,};
const byte tree_repeat[] PROGMEM = {B01010100,B01000100,B10000010,B10010010,B10101010,B01101100,B00101000,B01000100,};
const byte tree_top[] PROGMEM = {B00000000,B00000000,B00000000,B00010000,B00101000,B00101000,B00101000,B01000100,};
const byte *spritesheet[] = {bush, //0
port_noir, //1
rock_terrain_master, //2
rock_valley_ne, //3
rock_valley_nw, //4
rock_valley_se, //5
rock_valley_sw, //6
turtle_rock, //7
void_tile, //8
water_left_bottom, //9
water_left_middle, //10
water_left_top, //11
water_right_bottom, //12
water_right_middle, //13
water_right_top, //14
water_middle_bottom, //15
water_middle_middle, //16
water_middle_top, //17
rock_s, //18
rock_e, //19
rock_w, //20
rock_n, //21
bush_left, //22
bush_middle, //23
bush_right, //24
tree_base, //25
tree_repeat, //26
tree_top}; //27
const byte backblack[] PROGMEM = {8,8,0x7E,0x42,0x42,0x3C,0x7E,0x3C,0x3C,0x24,};
const byte backgrey[] PROGMEM = {8,8,0x1,0x1,0x1,0xC1,0x81,0xC0,0x40,0x0,};
const byte frontblack[] PROGMEM = {8,8,0x7E,0x66,0x42,0x38,0x78,0x38,0x3C,0x24,};
const byte frontgrey[] PROGMEM = {8,8,0x80,0x80,0x80,0x87,0x87,0x7,0x2,0x0,};
const byte leftblack[] PROGMEM = {8,8,0x3E,0x32,0x22,0x1C,0x1C,0x1C,0x1C,0x14,};
const byte leftgrey[] PROGMEM = {8,8,0x0,0x0,0x0,0x60,0x60,0x60,0x40,0x0,};
const byte rightblack[] PROGMEM = {8,8,0x7C,0x4C,0x44,0x38,0x3C,0x38,0x38,0x28,};
const byte rightgrey[] PROGMEM = {8,8,0x2,0x2,0x2,0x2,0x2,0x0,0x0,0x0,};
int player_x = 70; //cant get these to center
int player_y = 40; //cant get these to center
int player_direction = 0;
int x,y; ///if 0 player spite will not move, -50,50 no tilemap
//////CAMERA//////
int camerax = -20 ;
int cameray = -20 ;
int xmax = -68;
void setup() {
gb.begin();
gb.titleScreen(F("test"));
gb.setFrameRate(62); ////////for sprite
gb.display.persistence = false;
}
/////////PLAYER_MOVEMENT\\\\\\\\\
void loop() {
if(gb.update()){
if (gb.buttons.repeat(BTN_RIGHT,1));{x--;}
if (gb.buttons.repeat(BTN_LEFT,1));{x++;}
if (gb.buttons.repeat(BTN_DOWN,1));{y--;}
if (gb.buttons.repeat(BTN_UP,1));{y++;}
if(player_x > 59 && camerax < 0 && camerax > -52){player_x = 59;camerax--;}
//value 59 equals player position on right when camera will start to follow
//value 0 and -52 equals camera boundary positions
else if(player_x < 15 && camerax < 0 && camerax > -52){player_x = 15;camerax++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -52 equals camera boundary positions
else if(player_x > 59 && camerax <= 0 && camerax >= -52)camerax--;
else if(player_x < 15 && camerax <= 0 && camerax >= -52)camerax++;
if(player_y > 28 && cameray < 0 && cameray > -40){player_y = 28;cameray--;}
//value 28 equals player position on right when camera will start to follow
//value 0 and -40 equals camera boundary positions
else if(player_y < 15 && cameray < 0 && cameray > -40){player_y = 15;cameray++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -40 equals camera boundary positions
else if(player_y > 28 && cameray <= 0 && cameray >= -40)cameray--;
else if(player_y < 15 && cameray <= 0 && cameray >= -40)cameray++;
if(camerax > 0)camerax= 0;
else if(camerax < -52) camerax = -52;
//value 0 and -52 equals camera boundary positions
if(cameray > 0)cameray= 0;
else if(cameray < -40) cameray = -40;
//value 0 and -40 equals camera boundary positions
gb.display.drawTilemap(camerax,cameray,tilemap,spritesheet); // draw the tilemap
// gb.display.cursorY = 12; gb.display.println( player_x );gb.display.println( player_y );
if(gb.buttons.repeat(BTN_UP,1)){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,backblack);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,backgrey);
}
player_direction = 1;
player_y = player_y - 1;
if(checkcolision())player_y++; // ADD by Summoner123 - If have colision on the new position regreat one Pixel
}
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,frontblack);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,frontgrey);
}
player_direction = 2;
player_y = player_y + 1;
if(checkcolision())player_y--; // ADD by Summoner123 - If have colision on the new position regreat one Pixel
}
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,rightblack);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,rightgrey);
}
player_direction = 3;
player_x = player_x + 1;
if(checkcolision())player_x--; // ADD by Summoner123 - If have colision on the new position regreat one Pixel
}
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,leftblack);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,leftgrey);
}
player_direction = 4;
player_x = player_x - 1;
if(checkcolision())player_x++; // ADD by Summoner123 - If have colision on the new position regreat one Pixel
}
if(player_x <= -2){
player_x = -2;}
////////////PLAYER DIRECTION/////////////
if (player_direction == 1){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,backblack);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,backgrey);
}
}
else if (player_direction == 2){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,frontblack);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,frontgrey);
}
}
else if (player_direction == 3){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,rightblack);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,rightgrey);
}
}
else if (player_direction == 4){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,leftblack);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,leftgrey);
}
}
else { gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,frontblack);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,frontgrey);
}
}
}
}
bool checkcolision() // Transformed it into a function
{
uint16_t i;
for(i=0; i < gb.display.numcolision + 1; i++)
{
if(gb.collideRectRect(player_x,player_y,8,8,gb.display.solid[i].x,gb.display.solid[i].y,8,8))///changed player_x,y back to 8
{
// if(gb.display.solid[i].spritecol == void_tile); //Do nothing because it's floor - This line not needed
if(gb.display.solid[i].spritecol == bush) return true;
else if(gb.display.solid[i].spritecol == port_noir) return true;
else if(gb.display.solid[i].spritecol == rock_terrain_master) {gb.popup(F(" ""Rock"" "),1); return true;} //Return True if character have touched the wall
else if(gb.display.solid[i].spritecol == rock_valley_ne) return true;
else if(gb.display.solid[i].spritecol == rock_valley_nw) return true;
else if(gb.display.solid[i].spritecol == rock_valley_se) return true;
else if(gb.display.solid[i].spritecol == rock_valley_sw) return true;
else if(gb.display.solid[i].spritecol == turtle_rock) return true;
else if(gb.display.solid[i].spritecol == water_left_bottom) return true;
else if(gb.display.solid[i].spritecol == water_left_middle) return true;
else if(gb.display.solid[i].spritecol == water_left_top) return true;
else if(gb.display.solid[i].spritecol == water_right_bottom) return true;
else if(gb.display.solid[i].spritecol == water_right_middle) return true;
else if(gb.display.solid[i].spritecol == water_right_top) return true;
else if(gb.display.solid[i].spritecol == water_middle_bottom) return true;
else if(gb.display.solid[i].spritecol == water_middle_middle) return true;
else if(gb.display.solid[i].spritecol == water_middle_top) return true;
else if(gb.display.solid[i].spritecol == rock_n) return true;
else if(gb.display.solid[i].spritecol == rock_e) return true;
else if(gb.display.solid[i].spritecol == rock_s) return true;
else if(gb.display.solid[i].spritecol == rock_w) return true;
else if(gb.display.solid[i].spritecol == bush_left) {gb.popup(F(" ""A bush!!"" "),1); return true;}
else if(gb.display.solid[i].spritecol == bush_middle) {gb.popup(F(" ""A bush!!"" "),1); return true;}
else if(gb.display.solid[i].spritecol == bush_right) {gb.popup(F(" ""A bush!!"" "),1); return true;}
else if(gb.display.solid[i].spritecol == tree_base) return true;
else if(gb.display.solid[i].spritecol == tree_repeat) return true;
else if(gb.display.solid[i].spritecol == tree_top) return true;
}
}
return false; // Return false if don't touch anything
}
I changed the sprites in this one as i was playing around ( and also the tilemap size) but you should be able to just take this code and copy it into your project if you need to - i've commented it the best i can to explain
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;
const byte room_1_1[] PROGMEM = {15,9,
8,8,
2,2,2,2,2,2,2,8,8,2,2,2,2,2,2,
2,2,2,2,2,1,4,8,8,2,2,2,2,2,2,
2,2,2,2,4,8,8,8,8,2,2,2,2,2,2,
2,2,2,4,8,8,8,8,8,2,2,2,2,2,2,
2,2,4,8,8,8,8,8,8,3,2,2,2,2,2,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
2,2,8,8,8,8,8,8,8,8,8,8,8,2,2,
2,2,8,8,8,8,8,8,8,8,8,8,8,2,2,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2};
const byte room_1_2[] PROGMEM = {15,9,
8,8,
2,0,8,0,8,0,8,8,8,0,8,0,8,0,2,
2,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
4,8,8,8,8,0,8,8,8,0,8,0,8,0,8,
8,0,8,0,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,0,8,8,8,0,8,0,8,0,8,
8,0,8,0,8,8,8,8,8,8,8,8,8,8,8,
6,8,8,8,8,0,8,8,8,0,8,0,8,0,8,
2,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
2,0,0,0,0,0,0,0,0,0,0,0,0,0,2};
const byte room_1_3[] PROGMEM = {15,9,
8,8,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,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8,8,8,8,8,8,8,8,8,8,8,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16};
const byte room_1_7[] PROGMEM = {15,9,
8,8,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16};
const byte room_1_8[] PROGMEM = {15,9,
8,8,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,
8,8,3,2,4,3,4,3,4,3,2,4,3,2,2,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16};
const byte room_1_9[] PROGMEM = {15,9,
8,8,
2,2,2,2,2,2,2,8,8,8,10,16,16,16,16,
4,3,2,4,3,2,4,8,8,8,10,16,16,16,16,
8,8,8,8,8,8,8,8,8,8,10,16,16,16,16,
8,8,8,8,8,8,8,8,8,8,10,16,16,16,16,
8,8,8,8,8,8,8,8,8,8,10,16,16,16,16,
17,17,17,17,17,17,17,17,17,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,16,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8,8,8,8,8,8,8,8,8,2,
8,8,8,8,0,8,8,8,8,8,8,8,0,8,2,
2,8,8,8,8,8,8,8,5,2,6,8,8,8,2,
2,6,8,8,8,8,8,5,2,2,2,6,8,5,2,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2};
const byte room_3_9[] PROGMEM = {15,9,
8,8,
2,2,2,2,2,2,8,8,8,8,10,16,16,16,16,
2,2,2,2,2,4,8,8,8,8,10,16,16,16,16,
2,2,2,2,4,8,8,8,8,8,10,16,16,16,16,
2,2,2,4,8,8,8,8,8,8,10,16,16,16,16,
2,2,2,8,8,8,8,8,8,8,10,16,16,16,16,
2,2,2,8,8,8,8,8,8,8,10,16,16,16,16,
2,2,2,6,8,8,8,8,8,8,10,16,16,16,16,
2,2,2,2,6,8,8,8,8,8,10,16,16,16,16,
2,2,2,2,2,8,8,8,8,8,10,16,16,16,16};
const byte room_4_1[] PROGMEM = {15,9,
8,8,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
const byte room_4_2[] PROGMEM = {15,9,
8,8,
16,16,16,16,16,16,13,8,8,8,0,0,0,0,0,
16,16,16,16,16,16,13,8,8,8,8,8,8,0,0,
16,16,16,16,16,16,13,8,8,8,8,8,8,0,0,
15,15,15,15,15,15,12,8,8,8,8,8,8,0,0,
8,8,8,8,8,8,8,8,8,8,8,8,8,0,0,
8,8,8,8,8,8,8,8,8,8,8,8,8,0,0,
8,8,8,8,8,8,8,8,8,8,8,8,8,0,0,
0,8,8,8,8,8,8,8,8,8,8,8,8,0,0,
0,0,0,0,0,0,0,8,8,8,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8,8,8,8,10,16,16,16,16,
2,2,2,6,8,8,8,8,8,8,10,16,16,16,16,
2,2,2,2,6,8,8,8,8,8,10,16,16,16,16,
2,2,2,2,2,8,8,8,8,8,10,16,16,16,16};
const byte bush[] PROGMEM = {B00101100,B01010010,B10001001,B01000010,B10010001,B01001010,B00100100,B01111110,};
const byte port_noir[] PROGMEM = {B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,};
const byte rock_terrain_master[] PROGMEM = {B01001101,B10100100,B10010001,B01001010,B10010000,B01100101,B10001001,B01011010,};
const byte rock_valley_ne[] PROGMEM = {B10101010,B10010101,B01000100,B00101001,B00110010,B00001010,B00000100,B00000011,};
const byte rock_valley_nw[] PROGMEM = {B01010101,B10101001,B00100010,B10010100,B01001100,B01010000,B00100000,B11000000,};
const byte rock_valley_se[] PROGMEM = {B00000011,B00000100,B0011001,B00010010,B00101001,B01000110,B10110001,B10001010,};
const byte rock_valley_sw[] PROGMEM = {B11000000,B00100000,B10011000,B01001000,B10010100,B01100010,B10001101,B01010001,};
const byte turtle_rock[] PROGMEM = {B01101100,B10110010,B11010001,B01010101,B01010010,B10011001,B10000001,B11111110,};
const byte void_tile[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte water_left_bottom[] PROGMEM = {B10001111,B10000000,B11110000,B10000000,B10001111,B10000000,B11110000,B11111111,};
const byte water_left_middle[] PROGMEM = {B10001111,B10000000,B11110000,B10000000,B10001111,B10000000,B11110000,B10000000,};
const byte water_left_top[] PROGMEM = {B11111111,B10000000,B11110000,B10001111,B10000000,B10000000,B11110000,B10000000,};
const byte water_right_bottom[] PROGMEM = {B1110001,B00000001,B0000111,B00000001,B11110001,B00000001,B00001111,B11111111,};
const byte water_right_middle[] PROGMEM = {B11110001,B00000001,B00001111,B00000001,B11110001,B00000001,B00001111,B00000001,};
const byte water_right_top[] PROGMEM = {B11111111,B00000001,B00001111,B00000001,B11110001,B00000001,B00001111,B00000001,};
const byte water_middle_bottom[] PROGMEM = {B11110000,B00000000,B00001111,B00000000,B11110000,B00000000,B00001111,B11111111,};
const byte water_middle_middle[] PROGMEM = {B11110000,B00000000,B00001111,B00000000,B11110000,B00000000,B00001111,B00000000,};
const byte water_middle_top[] PROGMEM = {B11111111,B00000000,B11110000,B00000000,B00001111,B00000000,B11110000,B00000000,};
const byte steps[] PROGMEM = {B10000001,B01111110,B10000001,B01111110,B10000001,B01111110,B10000001,B01111110,};
const byte dead_tree[] PROGMEM = {B10101001,B01010110,B01001001,B10101010,B01011010,B00111100,B00011000,B00011000,};
const byte dungeon_left_bottom[] = {B11111111,B10001111,B01001111,B11111111,B10001111,B01001111,B11111111,B10001111,};
const byte dungeon_left_top[] = {B00010001,B00101110,B00101010,B00101110,B01000000,B01000001,B10010010,B10001000,};
const byte dungeon_right_bottom[] = {B11111111,B11110001,B11110010,B11111111,B11110001,B11110010,B11111111,B11110001,};
const byte dungeon_right_top[] = {B10001000,B01110100,B01010100,B01110100,B00000010,B10000010,B01001001,B00010001,};
const byte statue[] = {B10111010,B11000110,B01101100,B11101110,B11111110,B11111110,B01101100,B01101100,};
const byte bridge[] = {B01110111,B10001000,B10101010,B10001000,B10001000,B10101010,B10001000,B01110111,};
const byte grave_marker[] PROGMEM = {B00011000,B00111100,B01100110,B0100010,B01100110,B01100110,B00111100,B11111111,};
const byte dungeon_middle[] = {B10000001,B01000010,B00111100,B00000000,B00000000,B10011001,B00011000,B01000010,};
const byte sand[] PROGMEM = {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,};
const byte *spritesheet[] = {bush, port_noir, rock_terrain_master, rock_valley_ne,
rock_valley_nw, rock_valley_se, rock_valley_sw, turtle_rock, void_tile, water_left_bottom,
water_left_middle, water_left_top, water_right_bottom, water_right_middle, water_right_top,
water_middle_bottom, water_middle_middle, water_middle_top, steps, dead_tree, dungeon_left_bottom,
dungeon_left_top, dungeon_right_bottom, dungeon_right_top, statue, bridge, grave_marker, dungeon_middle,};
const byte sever_front_black[] PROGMEM = {8,8,0x39,0x7d,0x01,0x01,0xfe,0x01,0x7c,0x46};
const byte sever_front_grey[] PROGMEM = {8,8,0x82,0x82,0xd6,0x7c,0x01,0xa8,0x00,0x00,};
const byte sever_left_black[] PROGMEM = {8,8,0x9f,0xbe,0x80,0x82,0x7f,0x00,0x3e,0x62,};
const byte sever_left_grey[] PROGMEM = {8,8,0x00,0x00,0x17,0x3c,0x00,0x95,0x00,0x00,};
const byte sever_rear_black[] PROGMEM = {8,8,0x9c,0xbe,0xbe,0x80,0x7f,0x88,0x3e,0x62,};
const byte sever_rear_grey[] PROGMEM = {8,8,0x41,0x41,0x7f,0x3e,0x80,0x15,0x00,0x00,};
const byte sever_right_black[] PROGMEM = {8,8,0xf9,0x7d,0x01,0x41,0xfe,0x00,0x7c,0x46,};
const byte sever_right_grey[] PROGMEM = {8,8,0x00,0x00,0xe8,0x3c,0x00,0xa9,0x00,0x00,};
int player_x = 70;
int player_y = 40;
int player_direction = 0;
int x=0,y=0;
int camerax = -20 ;
int cameray = -10 ;
int xmax = -68;
void setup() {
gb.begin();
gb.titleScreen(F("test"));
gb.setFrameRate(62);
gb.display.persistence = false;
}
/////////PLAYER_MOVEMENT\\\\\\\\\
void loop() {
if(gb.update()){
if (gb.buttons.repeat(BTN_RIGHT,1));//{x--;}
if (gb.buttons.repeat(BTN_LEFT,1));//{x++;}
if (gb.buttons.repeat(BTN_DOWN,1));//{y--;}
if (gb.buttons.repeat(BTN_UP,1));//{y++;}
//////camera controls
if(player_x > 59 && camerax < 0 && camerax > -52){player_x = 59;camerax--;}
//value 59 equals player position on right when camera will start to follow
//value 0 and -52 equals camera boundary positions
else if(player_x < 15 && camerax < 0 && camerax > -52){player_x = 15;camerax++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -52 equals camera boundary positions
else if(player_x > 59 && camerax <= 0 && camerax >= -52)camerax--;
else if(player_x < 15 && camerax <= 0 && camerax >= -52)camerax++;
if(player_y > 28 && cameray < 0 && cameray > -40){player_y = 28;cameray--;}
//value 28 equals player position on right when camera will start to follow
//value 0 and -40 equals camera boundary positions
else if(player_y < 15 && cameray < 0 && cameray > -40){player_y = 15;cameray++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -40 equals camera boundary positions
else if(player_y > 28 && cameray <= 0 && cameray >= -40)cameray--;
else if(player_y < 15 && cameray <= 0 && cameray >= -40)cameray++;
if(camerax > 0)camerax= 0;
else if(camerax < -52) camerax = -52;
//value 0 and -52 equals camera boundary positions
if(cameray > 0)cameray= 0;
else if(cameray < -40) cameray = -40;
//value 0 and -40 equals camera boundary positions
gb.display.drawTilemap(camerax,cameray,room_1_1,spritesheet);
if(gb.buttons.repeat(BTN_UP,1)){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,sever_rear_black);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_rear_grey);
}
player_direction = 1;
player_y = player_y - 1;
if(checkcolision())player_y++; // ADD by Summoner123 - If have colision on the new position regreat one Pixel
}
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_black);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_front_grey);
}
player_direction = 2;
player_y = player_y + 1;
if(checkcolision())player_y--; // ADD by Summoner123 - If have colision on the new position regreat one Pixel
}
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_black);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_right_grey);
}
player_direction = 3;
player_x = player_x + 1;
if(checkcolision())player_x--; // ADD by Summoner123 - If have colision on the new position regreat one Pixel
}
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_black);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_left_grey);
}
player_direction = 4;
player_x = player_x - 1;
if(checkcolision())player_x++; // ADD by Summoner123 - If have colision on the new position regreat one Pixel
}
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_black);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_rear_grey);
}
}
else if (player_direction == 2){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,sever_front_black);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_front_grey);
}
}
else if (player_direction == 3){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,sever_left_black);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_left_grey);
}
}
else if (player_direction == 4){
gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,sever_right_black);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_right_grey);
}
}
else { gb.display.setColor(BLACK);{
gb.display.drawBitmap(player_x,player_y,sever_front_black);
}
gb.display.setColor(GRAY);{
gb.display.drawBitmap(player_x,player_y,sever_front_grey);
}
}
}
}
bool checkcolision() // Transformed it into a function
{
uint16_t i;
for(i=0; i < gb.display.numcolision + 1; i++)
{
if(gb.collideRectRect(player_x,player_y,8,8,gb.display.solid[i].x,gb.display.solid[i].y,8,8))
{
if(gb.display.solid[i].spritecol == void_tile); //Do nothing because it's floor - This line not needed
if(gb.display.solid[i].spritecol == bush)return true;
else if(gb.display.solid[i].spritecol == port_noir)return true;
else if(gb.display.solid[i].spritecol == rock_terrain_master)return true;//{gb.popup(F(" ""Rock"" "),1); return true;} //Return True if character have touched the wall
else if(gb.display.solid[i].spritecol == rock_valley_ne)return true;
else if(gb.display.solid[i].spritecol == rock_valley_nw)return true;
else if(gb.display.solid[i].spritecol == rock_valley_se)return true;
else if(gb.display.solid[i].spritecol == rock_valley_sw)return true;
else if(gb.display.solid[i].spritecol == turtle_rock)return true;
else if(gb.display.solid[i].spritecol == water_left_bottom)return true;
else if(gb.display.solid[i].spritecol == water_left_middle)return true;
else if(gb.display.solid[i].spritecol == water_left_top)return true;
else if(gb.display.solid[i].spritecol == water_right_bottom)return true;
else if(gb.display.solid[i].spritecol == water_right_middle)return true;
else if(gb.display.solid[i].spritecol == water_right_top)return true;
else if(gb.display.solid[i].spritecol == water_middle_bottom)return true;
else if(gb.display.solid[i].spritecol == water_middle_middle)return true;
else if(gb.display.solid[i].spritecol == water_middle_top)return true;
else if(gb.display.solid[i].spritecol == steps)return true;
else if(gb.display.solid[i].spritecol == dead_tree)return true;
else if(gb.display.solid[i].spritecol == dungeon_left_bottom)return true;
else if(gb.display.solid[i].spritecol == dungeon_left_top)return true;
else if(gb.display.solid[i].spritecol == dungeon_right_bottom)return true;
else if(gb.display.solid[i].spritecol == dungeon_right_top)return true;
else if(gb.display.solid[i].spritecol == statue)return true;
else if(gb.display.solid[i].spritecol == bridge)return true;
}
}
return false; // Return false if don't touch anything
}
// palette[0] = 0;
palette[1] = BLACK;
palette[2] = BLUE;
palette[3] = BROWN;
palette[4] = DARKGREEN;
palette[5] = GREY;
palette[6] = PINK;
palette[7] = RED;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
palette[8] = LIGHTBROWN;
palette[9] = GREEN;
palette[a]= DARKGREY;
palette[b] = LIGHTGREY;
palette[c] = YELLOW;
palette[d] = PURPLE;
palette[e] = WHITE;
palette[f] = NAVY;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
const byte paul_front[] = {
0x00,0x00,0x03,0x37,0x73,0x30,0x00,0x00,
0x00,0x00,0x37,0x33,0x33,0x73,0x00,0x00,
0x00,0x03,0x73,0x37,0x73,0x37,0x30,0x00,
0x00,0x73,0x76,0x63,0x36,0x67,0x37,0x00,
0x00,0x37,0x66,0x66,0x66,0x66,0x73,0x00,
0x01,0x63,0x63,0x36,0x63,0x36,0x36,0x10,
0x01,0x66,0x66,0x26,0x62,0x66,0x66,0x10,
0x00,0x11,0x66,0x26,0x62,0x66,0x11,0x00,
0x00,0x11,0x16,0x66,0x66,0x61,0x11,0x00,
0x01,0x66,0x11,0x66,0x66,0x11,0x66,0x10,
0x01,0x66,0x11,0x11,0x11,0x11,0x66,0x10,
0x00,0x11,0x12,0x21,0x12,0x21,0x11,0x00,
0x00,0x01,0x51,0x15,0x51,0x15,0x10,0x00,
0x00,0x01,0x52,0x21,0x12,0x25,0x10,0x00,
0x00,0x00,0x22,0x10,0x01,0x22,0x00,0x00,
0x00,0x00,0x11,0x10,0x01,0x11,0x00,0x00};
#include <GrafxT3.h>
#include <SPIN.h>
#include "SPI.h"
#include <Bounce.h>
#include "bitmaps.h"
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 7
#define TFT_SCK 13
#define TFT_MISO 12
#define TFT_MOSI 11
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
uint8_t use_fb = 0;
uint8_t use_clip_rect = 0;
uint8_t use_set_origin = 0;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
GrafxT3 tft = GrafxT3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO, &SPIN);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
int player_x = 160;
int player_y = 120;
int player_direction = 2;
int x=-0,y=0;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
int camerax = -160 ;
int cameray = -120 ;
int xmax = -220;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////Pixel Color Includes////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
uint16_t palette[16]; // Should probably be 256, but I don't use many colors...
uint16_t pixel_data[2500];
//Extra integers for color palette
int a = 0xa; int b = 0xb; int c = 0xc;
int d = 0xd; int e = 0xe; int f = 0xf;
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////Button assignments//////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//////dpad + select buttons
const int buttonUp = 33; //up button
Bounce ButtonUp = Bounce(buttonUp, 10); // 10 ms debounce
const int buttonDown = 38; //down_button
Bounce ButtonDown = Bounce(buttonDown, 10); // 10 ms debounce
const int buttonLeft = 35; //left button
Bounce ButtonLeft = Bounce(buttonLeft, 10); // 10 ms debounce
const int buttonRight = 17; //right button
Bounce ButtonRight = Bounce(buttonRight, 10); // 10 ms debounce
const int buttonS = 21; //select button
Bounce ButtonS = Bounce(buttonS, 10); // 10 ms debounce
//////action + start buttons
const int buttonX = 32; // X button up
Bounce ButtonX = Bounce(buttonX, 10); // 10 ms debounce
const int buttonY = 26; // Y button left
Bounce ButtonY = Bounce(buttonY, 10); // 10 ms debounce
const int buttonA = 21; // A button right
Bounce ButtonA = Bounce(buttonA, 10); // 10 ms debounce
const int buttonB = 28; // B buttun down
Bounce ButtonB = Bounce(buttonB, 10); // 10 ms debounce
const int buttonT = 4; // Start button
Bounce ButtonT = Bounce(buttonT, 10); // 10 ms debounce
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////Set-up//////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void setup() {
while (!Serial && (millis() < 4000)) ;
Serial.begin(115200);
tft.begin();
tft.setRotation(1);
tft.fillScreen(BLACK);
//tft.setFrameRate(60);
tft.persistence = false;
pinMode(buttonUp, INPUT_PULLUP);
pinMode(buttonDown, INPUT_PULLUP);
pinMode(buttonLeft, INPUT_PULLUP);
pinMode(buttonRight, INPUT_PULLUP);
pinMode(buttonS, INPUT_PULLUP);
pinMode(buttonX, INPUT_PULLUP);
pinMode(buttonY, INPUT_PULLUP);
pinMode(buttonA, INPUT_PULLUP);
pinMode(buttonB, INPUT_PULLUP);
pinMode(buttonT, INPUT_PULLUP);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////Loop////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void loop(void) {
//updates the GameRIot (the display, the sound, the buttons, everyyhing)
//returns true when it's time to render a new frame (20 times/second)
// if(tft.updateAll()){
///////////////////////////////////////////////////////////////////////////////
////////////////////////////////camera controls////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
if(player_x > 160 && camerax < 0 && camerax > -160) {player_x = 160;camerax--;}
//value 59 equals player position on right when camera will start to follow
//value 0 and -52 equals camers boundary positions
else if(player_x < 160 && camerax < 0 && camerax > -160){player_x = 160;camerax++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -52 equals camera boundary positions
else if(player_x > 160 && camerax <= 0 && camerax >= -160)camerax--;
else if(player_x < 160 && camerax <= 0 && camerax >= -160)camerax++;
if(player_y > 160 && cameray < 0 && cameray > -160){player_y = 160;cameray--;}
//value 28 equals player position on right when camera will start to folow
//value 0 and -40 equals camera boundary positions
else if(player_y < 120 && cameray < 0 && cameray > -120){player_y = 120;cameray++;}
//value 15 equals player position on left when camera will start to follow
//value 0 and -40 equals camera boundary positions
else if(player_y > 120 && cameray <= 0 && cameray >= -120)cameray--;
else if(player_y < 120 && cameray <= 0 && cameray >= -120)cameray++;
if(camerax > 0)camerax= 0;
else if(camerax < -160) camerax = -160;
//value 0 and -52 equals camera boundary positions
if(cameray > 0)cameray= 0;
else if(cameray < -120) cameray = -120;
//value 0 and -40 equals camera boundary positions
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////Palette////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// palette[0] = 0;
palette[1] = BLACK;
palette[2] = BLUE;
palette[3] = BROWN;
palette[4] = DARKGREEN;
palette[5] = GREY;
palette[6] = PINK;
palette[7] = RED;
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
palette[8] = LIGHTBROWN;
palette[9] = GREEN;
palette[a]= DARKGREY;
palette[b] = LIGHTGREY;
palette[c] = YELLOW;
palette[d] = PURPLE;
palette[e] = WHITE;
palette[f] = NAVY;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////Tilemap/////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
tft.drawTilemap(camerax, cameray, dune_demo, spritesheet, palette);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////Buttons/////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
if (ButtonUp.update());
if (ButtonDown.update());
if (ButtonLeft.update());
if (ButtonRight.update());
if (ButtonA.update());
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
ButtonUp.rebounce(10);
ButtonDown.rebounce(10);
ButtonLeft.rebounce(10);
ButtonRight.rebounce(10);
ButtonA.rebounce(10);
///////////////////////////////////////////////////////////////////////////////
//////////////////////////Down/////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
if (ButtonUp.fallingEdge()){
tft.writeRectNBPP(player_x, player_y,16,16,4,paul_rearwalk1,palette);
player_direction = 1;
player_y = player_y - 5;
if(checkcolision())player_y--;}
if(player_y <= 16){
player_y = 16;}
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////Up///////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
if (ButtonDown.fallingEdge()){
tft.writeRectNBPP(player_x, player_y,16,16,4,paul_frontwalk1,palette);
player_direction = 2;
player_y = player_y + 5;
if(checkcolision())player_y++;}
if(player_y >= 216){
player_y = 216;}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////Left////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
if (ButtonLeft.fallingEdge()){
tft.writeRectNBPP(player_x, player_y,16,16,4,paul_leftwalk,palette);
player_direction = 3;
player_x = player_x - 5;
if(checkcolision())player_x--;}
if(player_x >= 288){
player_x = 288;}
//////////////////////////////////////////////////////////////////////////////
////////////////////////////Right////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
if (ButtonRight.fallingEdge()){
tft.writeRectNBPP(player_x, player_y,16,16,4,paul_rightwalk,palette);
player_direction = 4;
player_x = player_x + 5;
if(checkcolision())player_x++;}
if(player_x <= 16){
player_x = 16;}
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////PLAYER DIRECTION/////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
if (player_direction == 1){
tft.writeRectNBPP(player_x, player_y,16,16,4,paul_rear,palette);
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
else if (player_direction == 2){
tft.writeRectNBPP(player_x, player_y,16,16,4,paul_front,palette);
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
else if (player_direction == 3){
tft.writeRectNBPP(player_x, player_y,16,16,4,paul_left,palette);
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
else if (player_direction == 4){
tft.writeRectNBPP(player_x, player_y,16,16,4,paul_right,palette);
}
}
//}
/////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////collision/////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
bool checkcolision() { // Transformed it into a function
uint16_t i;
for(i=0; i < tft.numcolision + 1; i++)
{
if(tft.collideRectRect(player_x, player_y,16,16,tft.solid[i].x,tft.solid[i].y,16,16))
{
if(tft.solid[i].spritecol == blank_tile)return false; //Do nothing because it's floor - this line not needed
else if(tft.solid[i].spritecol == rock)return true;
else if(tft.solid[i].spritecol == sand)return false;
else if(tft.solid[i].spritecol == tree)return true;
else if(tft.solid[i].spritecol == grass)return false;
else if(tft.solid[i].spritecol == grasstl)return false;
else if(tft.solid[i].spritecol == grasstr)return false;
else if(tft.solid[i].spritecol == grassbl)return false;
else if(tft.solid[i].spritecol == grassbr)return false;
else if(tft.solid[i].spritecol == rocktl)return true;
else if(tft.solid[i].spritecol == rocktr)return true;
else if(tft.solid[i].spritecol == rocktl)return true;
else if(tft.solid[i].spritecol == rocktr)return true;
else if(tft.solid[i].spritecol == rockbl)return true;
else if(tft.solid[i].spritecol == rockbr)return true;
else if(tft.solid[i].spritecol == stairsl)return true;
else if(tft.solid[i].spritecol == stairsr)return true;
else if(tft.solid[i].spritecol == cave)return true;
else if(tft.solid[i].spritecol == seitch)return true;
}
}
return false; // Return false if don't touch anything
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
Return to Programming Questions
Users browsing this forum: No registered users and 2 guests