Newbs need help with collision detection.

Understanding the language, error messages, etc.

Re: Newbs need help with collision detection.

Postby Duhjoker » Sun Aug 07, 2016 1:34 am

If your really interested I can handle the player sprites and terrain, what we need is some nice looking 8 bit monsters original or not. You pick!

Edit::: really thank you summoner123 will look at all soon :P
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 » Sun Aug 07, 2016 2:03 am

Will probably update this few times to save forum space.......

Ok I started up my Sprite maker and started doing some counting. In order to fit all elements into each room I need a 14 X 8 tile map. So I came up with a total resolution of 64x112 pixels per map not much bigger than the current Gamebuino LCD. That's not nearly as big as I thought it would it be. Just a lil scrolling.

Update: 10:44 pm....... I must have accidentally erased my original file with all my 8-bit sprites so I've been busy doing all the main terrain files for the first 12 rooms. Not gonna worry about shading on those but it I'm going to try to make some grey and black sever sprites now.

11:48...... Just finished the sever sprites. There is a whole pic of all but rear for reference. Two color.

https://www.dropbox.com/s/h3pdjvale10bw ... e.png?dl=0

Just got done encoding the sprites. I added valley terrain for angled pieces of map that couldn't really be included in the 6-bit. I found and online encoder that allows you to copy and paste so that made that part a lil easier.
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 » Sun Aug 07, 2016 8:43 am

Logging off. Had to change tile map size to 15x9 to be able do the rooms right so scroll will have to be used. Still haven't looked at code examples yet. Forgot to do void and cave entrance tiles. Then I played with summoner123's latest tile map editor so I could get the right proportions with the maps.

What do you guys think, should i build one massive world map with all twelve of the individual rooms and the camera scroll all the way around or make a bunch of rooms in the sketch where it only shows 1 room at a time with a slight scrolling. One thing to thonk about would be the lost desert where you have to go through a patern of rooms to reach the grave yard. I hope that made since.

The full room of twelve would be 108 X 132 bit map sprites
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 » Mon Aug 08, 2016 7:27 am

ok I just got debugging the code the best I could and testing it. I cant get the player sprite to center screen and if I
Code: Select all
int x=-50,y=50;

It just loads the player sprite no tilemap but player sprite can move ,change and hold direction.....if I....
Code: Select all
int x=0,y=0;


It prints the tile map and character but it wont move it changes direction and holds but that's it.

I commented // what I changed but I didn't note the extra terrain sprites.

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



const byte tilemap[] 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,  /////////112x64 pix res
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 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 *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};

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_right_black[] PROGMEM = {8,8,0x9f,0xbe,0x80,0x82,0x7f,0x00,0x3e,0x62,};
const byte sever_right_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_left_black[] PROGMEM = {8,8,0xf9,0x7d,0x01,0x41,0xfe,0x00,0x7c,0x46,};
const byte sever_left_grey[] PROGMEM = {8,8,0x00,0x00,0xe8,0x3c,0x00,0xa9,0x00,0x00,};

  int player_x = 70;    //cant get these to center
  int player_y = 70;    //cant get these to center
  int player_direction = 0;

int x=-50,y=50; ///if 0 player spite will not move, -50,50 no tilemap


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++;}
    gb.display.drawTilemap(x,y,tilemap,spritesheet); // draw the tilemap
//    gb.display.cursorY = 12; gb.display.println( x );gb.display.println( y );

 if(gb.buttons.repeat(BTN_UP,1)){
       gb.display.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))///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);
else      if(gb.display.solid[i].spritecol == port_noir);
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);
else      if(gb.display.solid[i].spritecol == rock_valley_nw);
else      if(gb.display.solid[i].spritecol == rock_valley_se);
else      if(gb.display.solid[i].spritecol == rock_valley_sw);
else      if(gb.display.solid[i].spritecol == turtle_rock);
else      if(gb.display.solid[i].spritecol == water_left_bottom);
else      if(gb.display.solid[i].spritecol == water_left_middle);
else      if(gb.display.solid[i].spritecol == water_left_top);
else      if(gb.display.solid[i].spritecol == water_right_bottom);
else      if(gb.display.solid[i].spritecol == water_right_middle);
else      if(gb.display.solid[i].spritecol == water_right_top);
else      if(gb.display.solid[i].spritecol == water_middle_bottom);
else      if(gb.display.solid[i].spritecol == water_middle_middle);
else      if(gb.display.solid[i].spritecol == water_middle_top);
 
      }
   }
    //return false; // Return false if don't touch anything
  }     

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 » Mon Aug 08, 2016 8:52 pm

I managed to find the problem and before 5pm yay!!!!!! It's the little things!!

All I did was change player_x and player_y back to 8,8 and then switched the Internet X=0,y=0, back and it works.

Added 6 rooms last night but I need to connect them to each other. Still only uses about 48% of the flash. We will get to that later first I need to look at the camera controls that summoner123 left us as an example.
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 » Mon Aug 08, 2016 9:45 pm

Hey, good news on the progress

Sorry I not been around to help as much, had a lot on the last few days.


The camera controls seem pretty easy to add to your game project, so hopefully that should be ready and glitch free (although nothing ever is in this project :lol: )

I'm still looking at sprites for you, I'm going to fire up the code you posted above and see what sort of style your using for sprites, then as soon ai get some time I'll be working on it
User avatar
naed
 
Posts: 140
Joined: Tue May 31, 2016 3:18 pm

Re: Newbs need help with collision detection.

Postby Duhjoker » Mon Aug 08, 2016 11:40 pm

Awesome thank you. My sever sprites need work and welcome the collaboration!!!

Been making rooms today tring to see the limit


Edit:
So far I'm at 4 X 5 rooms, 4 up 5 across for a total 20. It's ridiculous the amount of space the rooms are (not) taking up. I might actually be able to split the game 4 X instead 6 or 9 or 12!!!!!!
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 » Tue Aug 09, 2016 8:50 am

Just finished the whole quadrant on the tile map editor, just need to copy them down to progmem fortunately I have all but 6 done. From the looks of it I might actually be able to split twice and not more. But we can start out with five rows for now so we can include the first dungeon entrance or just the 4 rows by 9. Still can't believe I could fit them with plenty of space to add the rest of the program.

Could one do one sketch with just progmem then add another sketch that to for all the commands?
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 » Tue Aug 09, 2016 9:38 am

just had a look at the camera controls for you if you add this to your code in void loop() the camera should scroll really nice

Code: Select all
        if(player_x > 64 ) {camerax-=2; player_x -=2;}    //Y Scrolling  right
else  if(player_x < 10 ){camerax+=2; player_x +=2;}   //Y Scrolling  left
        if(player_y > 28 ) {cameray-=2; player_y -=2;}    //Y Scrolling  Down
else  if(player_y < 10 ){cameray+=2; player_y +=2;}   //Y Scrolling  Up
 
    gb.display.drawTilemap(camerax,cameray,tilemap,spritesheet); // draw the tilemap


this line in the above code
Code: Select all
gb.display.drawTilemap(camerax,cameray,tilemap,spritesheet);

replaces this one in your project
Code: Select all
gb.display.drawTilemap(x,y,tilemap,spritesheet);


Image

EDIT #1

also i cannot get your Sever sprites to work correctly, it just confuses me with how much grey/black there is (and the fact the emulator doesn't display grey correctly)

why not try something more simple like this
Sever.png
Sever.png (2.18 KiB) Viewed 83267 times


EDIT #2

you need to be more careful with your coding, i was confused as to why i was getting a weird sprite displayed when going left and right so looked a bit closer at your code

simple mistake i know, but by checking and double checking you could have avoided this (not an error the compiler will pick up, but testing your code definitely showed it)

the mistakes are here
Code: Select all
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);
        }
      }


you had set player_direction above to the following

1 = up
2 = down
3 = right
4 = left

the above code has the left/right sprites mixed up, so its displaying incorrectly

hope this helps

EDIT #3 :lol: :lol:

and in answer to your question you can have your sprites separate from the other code

in the top right of Arduino IDE there is a drop down arrow that lets you open a new tab, this can then be used to store your sprites, BUT you would need to make your other code read from that second tab or it will mot know where the code is

you would do this using the code

Code: Select all
extern const byte sever_front_black[];
extern const byte sever_front_grey[]
... etc


for all your listed sprites
User avatar
naed
 
Posts: 140
Joined: Tue May 31, 2016 3:18 pm

Re: Newbs need help with collision detection.

Postby Duhjoker » Wed Aug 10, 2016 12:42 am

Just got done adding the whole lower right quadrant of rooms. 36 all together and it doesn't seem to have changed the the amount of ram at all.

Gonna look at the camera controls this evening, looks simple enough but like you said.....

New sever sprites look great I'll try that!

Yea I think it might be better to split the commands and sprites to different sketches at some point.
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 13 guests

cron