Newbs need help with collision detection.

Understanding the language, error messages, etc.

Re: Newbs need help with collision detection.

Postby Duhjoker » Thu Aug 04, 2016 5:34 am

ok I tried to add the code above and im having a few problems first no class member for solid I assume means its not in my library. and well.....

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

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

ESMERELDA3:60: error: 'i' was not declared in this scope

 for(i=0; i < gb.display.numcolision + 1; i++)

     ^

ESMERELDA3:60: error: 'class Display' has no member named 'numcolision'

 for(i=0; i < gb.display.numcolision + 1; i++)

                         ^

ESMERELDA3:62: error: 'player' was not declared in this scope

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

                           ^

ESMERELDA3:62: error: 'class Display' has no member named 'solid'

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

                                                                  ^

ESMERELDA3:62: error: 'class Display' has no member named 'solid'

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

                                                                                        ^

ESMERELDA3:64: error: 'class Display' has no member named 'solid'

                         ^

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



I have no idea where to find the library with solid included

Code: Select all

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

const byte tilemap[] PROGMEM = {14,8,
6,6,
3,3,3,3,3,3,6,6,3,3,3,3,3,3,
3,3,3,5,3,6,6,6,3,3,3,3,3,3,
3,3,6,6,6,6,6,6,6,3,3,3,3,3,
3,6,6,6,6,6,6,6,6,6,3,3,3,3,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,
3,3,6,6,6,6,6,6,6,6,6,6,3,3,
3,3,6,6,6,6,6,6,6,6,6,6,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3};

const byte bush_bottom[] PROGMEM = {B01001000,B00110000,B01011000,B00000000,B00000000, B00000000 };
const byte bush_top[] PROGMEM = {B00000000, B00000000, B00000000, B00110000,B01001000,B10110100 };
const byte bush[] PROGMEM = {B0010000, B01001000, B10110100, B01001000, B00110000, B01011000 };
const byte rock_terrain[] PROGMEM = {B01011000, B10100100, B00010100, B10100000, B10000100, B01011000 } ;
const byte turtle_rock[] PROGMEM = {B00000000, B01110000, B00101000, B01001000, B01110000, B00000000 };
const byte port_noir[] PROGMEM = {B11111100, B11111100, B11111100, B11111100, B11111100,B11111100 };
const byte port_blanc[] PROGMEM = {B00000000, B00000000, B00000000, B00000000, B00000000, B00000000 } ;

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

const byte sever_front_1[] PROGMEM = {6,6,0x78,0x0,0x0,0x30,0x0,0xcc,};
const byte sever_front_2[] PROGMEM = {6,6,0x84,0x48,0x78,0x84,0x78,0x0,};
const byte sever_right_1[] PROGMEM = {6,6,0x78,0x80,0xc8,0xb4,0x0,0xcc,};
const byte sever_right_2[] PROGMEM = {6,6,0x4,0x58,0x30,0x0,0x78,0x0,};
const byte sever_rear_1[] PROGMEM = {6,6,0X78,0X78,0X0,0X30,0X0,0XCC,};
const byte sever_rear_2[] PROGMEM = {6,6,0x84,0x0,0x78,0x84,0x78,0x0,};
const byte sever_left_1[] PROGMEM = {6,6,0x78,0x4,0x4c,0xb4,0x0,0xcc,};
const byte sever_left_2[] PROGMEM = {6,6,0x80,0x68,0x30,0x0,0x78,0x0,};

  int player_x = 15;
  int player_y = 15;
  int player_direction = 0;

int x=0,y=0;


void setup() {
  gb.begin();
  gb.titleScreen(F("test"));
  gb.display.persistence = false;
}


void loop() {
  if(gb.update()){
    if (gb.buttons.repeat(BTN_RIGHT,1));
    if (gb.buttons.repeat(BTN_LEFT,1));
    if (gb.buttons.repeat(BTN_DOWN,1));
    if (gb.buttons.repeat(BTN_UP,1));
    gb.display.drawTilemap(x,y,tilemap,spritesheet);


for(i=0; i < gb.display.numcolision + 1; i++)
   {
    if(gb.collideRectRect(player.posx,player.posy,8,8,gb.display.solid[i].x,gb.display.solid[i].y,8,8))
    {
          if(gb.display.solid[i].spritecol == port_blanc); //Do nothing because it's floor
else      if(gb.display.solid[i].spritecol == port_noir);
else      if(gb.display.solid[i].spritecol == rock_terrain);
else      if(gb.display.solid[i].spritecol == turtle_rock);
else      if(gb.display.solid[i].spritecol == bush);
else      if(gb.display.solid[i].spritecol == bush_bottom);
else      if(gb.display.solid[i].spritecol == bush_top);
      }   
  } 
   
   

 if(gb.buttons.repeat(BTN_UP,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_1);
       }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_rear_2);
    }
      player_direction = 1;
      player_y = player_y - 1;}
    if(player_y <= 0){
      player_y = 0;}



    if(gb.buttons.repeat(BTN_DOWN,1)){
      gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_front_1);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_front_2);
    }
      player_direction = 2;
      player_y = player_y + 1;}
    if(player_y >= 40){
      player_y = 40;}
 


    if(gb.buttons.repeat(BTN_RIGHT,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_right_1);
    }
     gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_right_2);
    }
      player_direction = 3;
      player_x = player_x + 1;}
    if(player_x >= 77){
      player_x = 77;}


    if(gb.buttons.repeat(BTN_LEFT,1)){
       gb.display.setColor(BLACK);{
    gb.display.drawBitmap(player_x,player_y,sever_left_1);
    }
    gb.display.setColor(GRAY);{
    gb.display.drawBitmap(player_x,player_y,sever_left_2);
    }
      player_direction = 4;
      player_x = player_x - 1;}
    if(player_x <= -2){
      player_x = -2;}
     
      ////////////PLAYER DIRECTION/////////////

 if (player_direction == 1){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_rear_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_rear_2);
        }
 }
     
      else if (player_direction == 2){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_2);
        }
      }
else if (player_direction == 3){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_left_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_left_2);
        }
}
      else if (player_direction == 4){
        gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_right_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_right_2);
        }
      }
      else {  gb.display.setColor(BLACK);{
        gb.display.drawBitmap(player_x,player_y,sever_front_1);
      }
        gb.display.setColor(GRAY);{
        gb.display.drawBitmap(player_x,player_y,sever_front_2);
        }
      }
       
  }
 
}
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 naed » Thu Aug 04, 2016 6:23 am

It's there in the thread I linked you to Summoner123 tells you what code to add to your library, although I had problems getting it to work
User avatar
naed
 
Posts: 140
Joined: Tue May 31, 2016 3:18 pm

Re: Newbs need help with collision detection.

Postby Duhjoker » Thu Aug 04, 2016 6:45 am

Ahhh man are you kidding me? I have to mess around with a .cpp file? Did you get it to work?
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 » Thu Aug 04, 2016 7:15 am

installing visual studio express now, may take a minute. Do I just write that starting at line 735 then save it or do I try to compile it?
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 naed » Thu Aug 04, 2016 1:50 pm

I tried to just write it to the file using notepad+ but it gave me a permission error when compiling the gamebuino code
User avatar
naed
 
Posts: 140
Joined: Tue May 31, 2016 3:18 pm

Re: Newbs need help with collision detection.

Postby Duhjoker » Thu Aug 04, 2016 8:01 pm

Yea I've tried that before too. I ended up having to leave my laptop on all night so VSE could finish installing. I am able to open the file now but still not sure where to put the extra lines of code.
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 naed » Thu Aug 04, 2016 8:27 pm

I'm sure Sumoner123 states what line the code needs to be inputted into
User avatar
naed
 
Posts: 140
Joined: Tue May 31, 2016 3:18 pm

Re: Newbs need help with collision detection.

Postby Duhjoker » Thu Aug 04, 2016 8:35 pm

OK I sent a private messgage to summoner123 and he was nice enough to shrare a his display.h and .cpp with us. these two files will give us....

gb.display.numcollision

gb.display.solid[index].x

gb.display.solid[index].y

gb.display.solid[index].sprite col

you can find them here at my dropbox

https://www.dropbox.com/sh/89kqtgi27sf1 ... 2SVRa?dl=0

I also have a link to 4shared if you need it here....

http://www.4shared.com/rar/qVqkpLkQce/d ... er123.html

he says to make copies of the current display.h and .cpp and drag and drop his versions back to the library folder.

Thank you so much summoner123


You can test with this

Code: Select all


//this code will check if a character is touching in any tile on the screen

for(i=0; i < gb.display.numcolision + 1; i++)  //Range  "i" to number of tiles rendered

   {

 if(gb.collideRectRect(player.posX,player.posY,8,8,gb.display.solid[i].x,gb.display.solid[i].y,8,8))
    {
   
         //here - Colision is true

          if(gb.display.solid[i].spritecol == pointer )
             {
              //  sprite has collided with your character = Pointer
              }

      }   
  } 
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 naed » Thu Aug 04, 2016 9:14 pm

Oh wow! That's awesome ☺

Looks like I'm playing with this tonight then, I'll post my results
User avatar
naed
 
Posts: 140
Joined: Tue May 31, 2016 3:18 pm

Re: Newbs need help with collision detection.

Postby Duhjoker » Thu Aug 04, 2016 9:20 pm

:P
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 8 guests

cron