Newbs need help with collision detection.

Understanding the language, error messages, etc.

Re: Newbs need help with collision detection.

Postby Duhjoker » Fri Aug 05, 2016 2:07 am

I ran his example with put changing the library and it compiled and plays. But I did change the library afterwards to see if my code would work afterwards but it froze. Weird thing is it shows the battery Sprite in the corner.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newbs need help with collision detection.

Postby Duhjoker » Fri Aug 05, 2016 4:13 am

im looking at the sketch example that summoner123 provided ands ofcourse I have questions

Code: Select all
#include <Gamebuino.h>
#include <SPI.h>


#define goup    0
#define godown  1
#define goleft  2     /// is this defining an integer for which ever direction for the void loop
#define goright 3

#define solido 1        ////does this define an integer for what is solid
#define passway 2
#define underpass 3 ///does this the different doorways
#define cavepass 4

#define world 0
#define House 1
#define forest 2
#define theend 3     /// do these define integers for the diiferent areas of the world
#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,}; ///// two color player sprites with walking pixels added as 3rd
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,   //////puts harbor area in flash
 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,   ////// world map?
 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;   //// what are these integers
  int tilex=0;
  int tiley=0;
  byte flip = NOFLIP;
 
  const byte *bitmap = plb1;
} character;          ////// curious about this commmand

character player;

int camerax = -144 ;
int cameray = -172 ;      //// camera placement on map? since the camera angle never moves would this be set to zero or is this telling the edges of the world bitmap

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){    //////////do I need these for my code that's one room at a time
 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;}  ////this is good stuff
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;
                                                              ////how would these be set
     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++;   
                                                                                                   //////do I need this
 
      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;
                                                                      ////// do I need this camera stuff
      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;
}



ok I commented // everything I think I need to know, basically the camera stuff. My game is only one room at a time soooo. also the void walk confuses me
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newbs need help with collision detection.

Postby Duhjoker » Fri Aug 05, 2016 6:09 am

all right ive been playing with the sketch above and produced the sketch below. I realize that it prolly gonna look funny do to the camera stuff and other paramters I didn't know. it doesn't like what I did with line 9 and keeps giving me errors that affect the solid commands at the bottom.

Code: Select all
#include <Gamebuino.h>
#include <SPI.h>

#define goup    0
#define godown  1
#define goleft  2
#define goright 3

#define solid 1     ///// does not like this

#define world 0
Gamebuino gb;

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_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,};

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};

typedef struct{
 
  int posx=42;
  int posy=24;
  int tilex=0;
  int tiley=0;
  byte flip = NOFLIP;
 
  const byte *bitmap = sever_front_1;
} character;

character player;

int camerax = -144 ;
int cameray = -172 ;

byte scenery=0;

void setup() {
 
  Serial.begin(9600);
  gb.begin();
  gb.titleScreen(F("LIS"));
  gb.setFrameRate(16); 

}


void loop()
{
 
  if(scenery == world)
  {
 if(gb.update()){
  walk();
  render();
  }
 }

}

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() == solid)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() == solid)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() == solid)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() == solid)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 = sever_rear_1 ;}
else  if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = sever_rear_2;}
   }
   
else   if(direc==godown){
      if(gb.frameCount % 6 >= 0 && gb.frameCount % 6 < 2){player.bitmap = sever_front_1;}
else  if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = sever_front_2;}
   }
   
else   if(direc==goleft){
      if(gb.frameCount % 6 >= 0 && gb.frameCount % 6 < 2){player.bitmap = sever_left_1;}
else  if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = sever_left_2;}
   }
   
else   if(direc==goright){
      if(gb.frameCount % 6 >= 0 && gb.frameCount % 6 < 2){player.bitmap = sever_left_1;}
else  if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = sever_left_2;}
   }
 
 }
 
     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 == port_blanc) //Do nothing because it's floor
    }else      if(gb.display.solid[i].spritecol == bush_bottom);
else      if(gb.display.solid[i].spritecol == bush_top);
else      if(gb.display.solid[i].spritecol == bush);
else      if(gb.display.solid[i].spritecol == rock_terrain);   ///line 9 errors
else      if(gb.display.solid[i].spritecol == turtle_rock);
else      if(gb.display.solid[i].spritecol == port_noir);



      }   
  }   
  return 0;
}
}




Code: Select all
Arduino: 1.6.7 (Windows 7), Board: "Arduino Duemilanove or Diecimila, ATmega328"

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino: In function 'byte colisiontest()':

sketch_aug04a:9: error: expected unqualified-id before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:179:66: note: in expansion of macro 'solid'

     if(gb.collideRectRect(player.posx,player.posy,5,8,gb.display.solid[i].x,gb.display.solid[i].y,8,8))

                                                                  ^

sketch_aug04a:9: error: expected unqualified-id before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:179:88: note: in expansion of macro 'solid'

     if(gb.collideRectRect(player.posx,player.posy,5,8,gb.display.solid[i].x,gb.display.solid[i].y,8,8))

                                                                                        ^

sketch_aug04a:9: error: expected unqualified-id before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:183:30: note: in expansion of macro 'solid'

     }else      if(gb.display.solid[i].spritecol == bush_bottom);

                              ^

sketch_aug04a:9: error: expected ')' before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:183:30: note: in expansion of macro 'solid'

     }else      if(gb.display.solid[i].spritecol == bush_bottom);

                              ^

sketch_aug04a:9: error: expected unqualified-id before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:184:25: note: in expansion of macro 'solid'

 else      if(gb.display.solid[i].spritecol == bush_top);

                         ^

sketch_aug04a:9: error: expected ')' before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:184:25: note: in expansion of macro 'solid'

 else      if(gb.display.solid[i].spritecol == bush_top);

                         ^

sketch_aug04a:9: error: expected unqualified-id before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:185:25: note: in expansion of macro 'solid'

 else      if(gb.display.solid[i].spritecol == bush);

                         ^

sketch_aug04a:9: error: expected ')' before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:185:25: note: in expansion of macro 'solid'

 else      if(gb.display.solid[i].spritecol == bush);

                         ^

sketch_aug04a:9: error: expected unqualified-id before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:186:25: note: in expansion of macro 'solid'

 else      if(gb.display.solid[i].spritecol == rock_terrain);

                         ^

sketch_aug04a:9: error: expected ')' before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:186:25: note: in expansion of macro 'solid'

 else      if(gb.display.solid[i].spritecol == rock_terrain);

                         ^

sketch_aug04a:9: error: expected unqualified-id before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:187:25: note: in expansion of macro 'solid'

 else      if(gb.display.solid[i].spritecol == turtle_rock);

                         ^

sketch_aug04a:9: error: expected ')' before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:187:25: note: in expansion of macro 'solid'

 else      if(gb.display.solid[i].spritecol == turtle_rock);

                         ^

sketch_aug04a:9: error: expected unqualified-id before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:188:25: note: in expansion of macro 'solid'

 else      if(gb.display.solid[i].spritecol == port_noir);

                         ^

sketch_aug04a:9: error: expected ')' before numeric constant

 #define solid 1

               ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:188:25: note: in expansion of macro 'solid'

 else      if(gb.display.solid[i].spritecol == port_noir);

                         ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino: At global scope:

sketch_aug04a:194: error: expected unqualified-id before 'return'

   return 0;

   ^

sketch_aug04a:195: error: expected declaration before '}' token

 }

 ^

exit status 1
expected unqualified-id before numeric constant

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newbs need help with collision detection.

Postby Duhjoker » Fri Aug 05, 2016 8:52 am

ok I got a lil closer. Since he had the function to change areas I thought I would add the cave to the first room. heres the current. commented the problems and what I haven't learned yet////

Code: Select all
#include <Gamebuino.h>
#include <SPI.h>

#define goup    0
#define godown  1
#define goleft  2
#define goright 3

#define solido 1
#define port_noir 2  /// cant figure this out


#define world 0
#define cave 1

Gamebuino gb;

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_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,};

const byte cave[] PROGMEM = {14,8,
6,6,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,
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,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,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,6,6,3,3,3,3,3,3};

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};

typedef struct{
 
  int posx=42;
  int posy=24;
  int tilex=0;
  int tiley=0;
  byte flip = NOFLIP;
 
  const byte *bitmap = sever_front_1;
} character;

character player;

//////// have no idea about this
int camerax = -144 ;
int cameray = -172 ;

byte scenery=0;

void setup() {
 
  Serial.begin(9600);
  gb.begin();
  gb.titleScreen(F("test"));
  gb.setFrameRate(16); 

}


void loop() ///I think the first part here helps switch areas
{
 
  if(scenery == world)
  {
 if(gb.update()){
  walk();
  render();
  }         
 }
  if(scenery == cave){
 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() == solid)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() == solid)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() == solid)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() == solid)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 = sever_rear_1 ;}
else  if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = sever_rear_2;}
   }
   
else   if(direc==godown){
      if(gb.frameCount % 6 >= 0 && gb.frameCount % 6 < 2){player.bitmap = sever_front_1;}
else  if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = sever_front_2;}
   }
   
else   if(direc==goleft){
      if(gb.frameCount % 6 >= 0 && gb.frameCount % 6 < 2){player.bitmap = sever_left_1;}
else  if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = sever_left_2;}
   }
   
else   if(direc==goright){
      if(gb.frameCount % 6 >= 0 && gb.frameCount % 6 < 2){player.bitmap = sever_left_1;}
else  if(gb.frameCount % 6 >= 2 && gb.frameCount % 6 < 4){player.bitmap = sever_left_2;}
   }
 
 }
   ////changed thesev to the values naed provided

     if(player.posx > 77)player.posx = 77;
else if(player.posx <  2)player.posx =  2;
   
     if(player.posy > 40)player.posy = 40;
else if(player.posy <  0)player.posy =  0;
 
}

void render()
/////have no idea about the camera stuff we haven't gotten there
{

 
      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 == port_blanc) //Do nothing because it's floor

      if(gb.display.solid[i].spritecol == port_noir) return solid;
else
          if(gb.display.solid[i].spritecol == bush_bottom) return solid;
else      if(gb.display.solid[i].spritecol == bush_top) return solid;
else      if(gb.display.solid[i].spritecol == bush) return solid;
else      if(gb.display.solid[i].spritecol == rock_terrain) return solid;
else      if(gb.display.solid[i].spritecol == turtle_rock)return solid;
else      if(gb.display.solid[i].spritecol == port_noir)return solid;



      }   
  }   
  return 0;
}
}



heres therror im having problems with

Code: Select all
Arduino: 1.6.7 (Windows 7), Board: "Arduino Duemilanove or Diecimila, ATmega328"

sketch_aug04a:14: error: expected unqualified-id before numeric constant

 #define cave 1

              ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:25:12: note: in expansion of macro 'cave'

 const byte cave[] PROGMEM = {14,8,

            ^

sketch_aug04a:10: error: expected unqualified-id before numeric constant

 #define port_noir 2

                   ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:52:12: note: in expansion of macro 'port_noir'

 const byte port_noir[] PROGMEM = {B11111100, B11111100, B11111100, B11111100, B11111100,B11111100 };

            ^

sketch_aug04a:55: error: invalid conversion from 'int' to 'const byte* {aka const unsigned char*}' [-fpermissive]

 const byte *spritesheet[] = {bush_bottom, bush_top, bush, rock_terrain, turtle_rock, port_noir, port_blanc};

                                                                                                           ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino: In function 'void walk()':

sketch_aug04a:109: error: 'solid' was not declared in this scope

       if(gb.buttons.repeat(BTN_UP,1)){direc = goup;player.posy--;flagwalk = true;player.flip = NOFLIP;if(colisiontest() == solid)player.posy++;}

                                                                                                                            ^

sketch_aug04a:112: error: 'solid' was not declared in this scope

       if(gb.buttons.repeat(BTN_DOWN,1)){direc = godown; player.posy++;flagwalk = true;player.flip = NOFLIP;if(colisiontest() == solid)player.posy--;}

                                                                                                                                 ^

sketch_aug04a:115: error: 'solid' was not declared in this scope

       if(gb.buttons.repeat(BTN_LEFT,1)){direc = goleft; player.posx--;flagwalk = true; player.flip = FLIPH;if(colisiontest() == solid)player.posx++;}

                                                                                                                                 ^

sketch_aug04a:118: error: 'solid' was not declared in this scope

       if(gb.buttons.repeat(BTN_RIGHT,1)){direc = goright; player.posx++ ;flagwalk = true;player.flip = NOFLIP;if(colisiontest() == solid)player.posx--;}

                                                                                                                                    ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino: In function 'byte colisiontest()':

sketch_aug04a:10: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

 #define port_noir 2

                   ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:202:43: note: in expansion of macro 'port_noir'

       if(gb.display.solid[i].spritecol == port_noir) return solid;

                                           ^

sketch_aug04a:202: error: 'solid' was not declared in this scope

       if(gb.display.solid[i].spritecol == port_noir) return solid;

                                                             ^

sketch_aug04a:204: error: 'solid' was not declared in this scope

           if(gb.display.solid[i].spritecol == bush_bottom) return solid;

                                                                   ^

sketch_aug04a:205: error: 'solid' was not declared in this scope

 else      if(gb.display.solid[i].spritecol == bush_top) return solid;

                                                                ^

sketch_aug04a:206: error: 'solid' was not declared in this scope

 else      if(gb.display.solid[i].spritecol == bush) return solid;

                                                            ^

sketch_aug04a:207: error: 'solid' was not declared in this scope

 else      if(gb.display.solid[i].spritecol == rock_terrain) return solid;

                                                                    ^

sketch_aug04a:208: error: 'solid' was not declared in this scope

 else      if(gb.display.solid[i].spritecol == turtle_rock)return solid;

                                                                  ^

sketch_aug04a:10: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

 #define port_noir 2

                   ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino:209:47: note: in expansion of macro 'port_noir'

 else      if(gb.display.solid[i].spritecol == port_noir)return solid;

                                               ^

sketch_aug04a:209: error: 'solid' was not declared in this scope

 else      if(gb.display.solid[i].spritecol == port_noir)return solid;

                                                                ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino: At global scope:

sketch_aug04a:217: error: expected declaration before '}' token

 }

 ^

exit status 1
expected unqualified-id before numeric constant

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newbs need help with collision detection.

Postby Summoner123 » Fri Aug 05, 2016 6:07 pm

Duhjoker wrote:ok I got a lil closer. Since he had the function to change areas I thought I would add the cave to the first room. heres the current. commented the problems and what I haven't learned yet////
[/code]



Hi Guy...

you have tried to compile my code? It's worked for you?


I thinks this errors stand related with the name of your constant values and variable names. Look:

Code: Select all
#define solid 1 //where writed solid the compiler will put "1"


But you have a variable named "solid" into the Dispay library

Code: Select all
gb.display.solid[i].x; //This is confliting with your const declaration


In my code a have named the const value to "solido" (solido = solid in portuguese... hahaha)
The same to the other declarations, you have a const named "cave" and one variable with the same name

Code: Select all
#define cave 1
....

const byte cave[] PROGMEM = {14,8,
6,6,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,
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,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,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,6,6,3,3,3,3,3,3};


Try change the name of variables or const values and see if it will compile.

the comand description of "typedef struct" you can see here -> http://www.tutorialspoint.com/cprogramming/c_typedef.htm

Basicaly with this:
Code: Select all
typedef struct{
 
  int posx=42;
  int posy=24;   //// what are these integers
  int tilex=0;
  int tiley=0;
  byte flip = NOFLIP;
 
  const byte *bitmap = plb1;
} character;         


I tell to compiler to create a "type" of Variable named "character" wich conteins inside these variables

Code: Select all
 
  int posx=42;
  int posy=24;   
  int tilex=0;
  int tiley=0;
  byte flip = NOFLIP;
 
  const byte *bitmap = plb1;


So a I can declare a new variable (named "player" for example) of type "character" , something like this
Code: Select all
character player;


Now I have access to all these atributes of type "character" inside my "player" variable... And I can modify or read this values

Code: Select all
player.posx++;        //Writing - Increment this value

if(player.posx > 50) ; //Reading - In the "if" condition test

gb.display.drawBitmap(player.posx,player.posy,player.bitmap,NOROT,player.flip);
//Or use it like a parameter to drawm a bitmap


basically you will access it like any other variable.
User avatar
Summoner123
 
Posts: 26
Joined: Fri Mar 20, 2015 12:35 am

Re: Newbs need help with collision detection.

Postby Duhjoker » Fri Aug 05, 2016 8:18 pm

still lokking at the above information.

can someone tell me why this compiles but freezes when I try to load? is it the placement of the solid variables?

Code: Select all

#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

int i;

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_x,player_y,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);
        }
      }
       
  }
 
}


User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newbs need help with collision detection.

Postby Summoner123 » Sat Aug 06, 2016 12:20 am

Duhjoker wrote:still lokking at the above information.

can someone tell me why this compiles but freezes when I try to load? is it the placement of the solid variables?


I have debugged your code and I can see it's crashing at this line:

Code: Select all
gb.display.drawTilemap(x,y,tilemap,spritesheet); // draw the tilemap


try to set the "x" and "y" variables to "-50" like this:
Code: Select all
 int x=-50, y=50;


If you decrement or incrment much the "X" value it will crash.
why this happens ? I don't know... : (
User avatar
Summoner123
 
Posts: 26
Joined: Fri Mar 20, 2015 12:35 am

Re: Newbs need help with collision detection.

Postby Duhjoker » Sat Aug 06, 2016 1:26 am

Awesome thank you!!!!

On the other sketch that I was playing with that you provided does work but im still having a problem. I removed the #define solid and port noir and cave(for now). Now its giving me this....

Code: Select all
Arduino: 1.6.7 (Windows 7), Board: "Arduino Duemilanove or Diecimila, ATmega328"

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino: In function 'void loop()':

sketch_aug04a:85: error: 'cenary' was not declared in this scope

   if(cenary == world)

      ^

sketch_aug04a:92: error: 'cenary' was not declared in this scope

   if(cenary == cave){

      ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino: In function 'void walk()':

sketch_aug04a:106: error: 'solid' was not declared in this scope

       if(gb.buttons.repeat(BTN_UP,1)){direc = goup;player.posy--;flagwalk = true;player.flip = NOFLIP;if(colisiontest() == solid)player.posy++;}

                                                                                                                            ^

sketch_aug04a:109: error: 'solid' was not declared in this scope

       if(gb.buttons.repeat(BTN_DOWN,1)){direc = godown; player.posy++;flagwalk = true;player.flip = NOFLIP;if(colisiontest() == solid)player.posy--;}

                                                                                                                                 ^

sketch_aug04a:112: error: 'solid' was not declared in this scope

       if(gb.buttons.repeat(BTN_LEFT,1)){direc = goleft; player.posx--;flagwalk = true; player.flip = FLIPH;if(colisiontest() == solid)player.posx++;}

                                                                                                                                 ^

sketch_aug04a:115: error: 'solid' was not declared in this scope

       if(gb.buttons.repeat(BTN_RIGHT,1)){direc = goright; player.posx++ ;flagwalk = true;player.flip = NOFLIP;if(colisiontest() == solid)player.posx--;}

                                                                                                                                    ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino: In function 'byte colisiontest()':

sketch_aug04a:199: error: 'solid' was not declared in this scope

       if(gb.display.solid[i].spritecol == port_noir) return solid;

                                                             ^

sketch_aug04a:201: error: 'solid' was not declared in this scope

           if(gb.display.solid[i].spritecol == bush_bottom) return solid;

                                                                   ^

sketch_aug04a:202: error: 'solid' was not declared in this scope

 else      if(gb.display.solid[i].spritecol == bush_top) return solid;

                                                                ^

sketch_aug04a:203: error: 'solid' was not declared in this scope

 else      if(gb.display.solid[i].spritecol == bush) return solid;

                                                            ^

sketch_aug04a:204: error: 'solid' was not declared in this scope

 else      if(gb.display.solid[i].spritecol == rock_terrain) return solid;

                                                                    ^

sketch_aug04a:205: error: 'solid' was not declared in this scope

 else      if(gb.display.solid[i].spritecol == turtle_rock)return solid;

                                                                  ^

sketch_aug04a:206: error: 'solid' was not declared in this scope

 else      if(gb.display.solid[i].spritecol == port_noir)return solid;

                                                                ^

C:\Users\duhjoker\Desktop\sketch_aug04a\sketch_aug04a.ino: At global scope:

sketch_aug04a:214: error: expected declaration before '}' token

 }

 ^

exit status 1
'cenary' was not declared in this scope

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.


User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newbs need help with collision detection.

Postby Duhjoker » Sat Aug 06, 2016 1:46 am

Problem solvrd not relevant to thread
Last edited by Duhjoker on Sat Aug 06, 2016 9:30 am, edited 1 time in total.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

Re: Newbs need help with collision detection.

Postby Duhjoker » Sat Aug 06, 2016 3:36 am

Ok I think we need to start over I'm starting to get confused and I can't understand why my tilemaps refuse to show now.
User avatar
Duhjoker
 
Posts: 446
Joined: Sat Jul 02, 2016 4:57 am
Location: Where Palm trees grow

PreviousNext

Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 3 guests

cron