Understanding the language, error messages, etc.
by Duhjoker » Mon Jul 17, 2017 8:40 am
Ok I've been playing with this between updating the libraries but I can't figure out why the collision function refuses to work. The return doesn't work either. I used a working template for Esmerelda to derive the functions in the sketch. And it works. Could it be something to do with the way I'm displaying bitmaps now in 4bpp? The tiles are still full tiles and 16x16 so there shouldn't be a problem.
Could it be something with using flash instead of progmem? Or maybe I should use collideBitmapBitmap()?
I'm not asking any one to debug or write code. I can fix it but I could use a hint at what could be causing the collision to not work.
The full sketch can be found here.....
https://github.com/Duhjoker/GameR-Iot_Dune_demo
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
by Duhjoker » Tue Jul 18, 2017 4:57 am
Check this out. I put a return on the rock to display purple. This happens but very sporadically and after some play.
https://youtu.be/MzJgTL08zP0
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
by Linky439 » Tue Jul 18, 2017 7:36 am
Though this is not 100% Gamebuino, I guess the basic function are the same? I have to say I have ran into several collision glitches during my tests with the software, and I tend to use the good old collideRectRect function more than anything else.
I'd like to take a look at this "check_collision" function, but I can't seem to find it in your GitHub files. Could you upload it ?
(Or tell me where it is in your file, it's not 10 in the morning here yet, I'm still tired so I might have missed it
)
-
Linky439
-
- Posts: 17
- Joined: Sat Dec 17, 2016 6:33 pm
by Duhjoker » Tue Jul 18, 2017 8:35 am
If you go to my github page and look at the dune demo it will be at the bottom of the .ino file. It uses collideRectRect as well. If your looking for the collision functions themselves in the library they will be after the bitmap section and labeled collision.
- Code: Select all
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 == cave)return true;
else if(tft.solid[i].spritecol == grass)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 == grasstl)return false;
else if(tft.solid[i].spritecol == grasstr)return false;
else if(tft.solid[i].spritecol == rock){tft.fillScreen(PURPLE); return true;} //Return True if character have touched the wall
else if(tft.solid[i].spritecol == rockbl)return true;
else if(tft.solid[i].spritecol == rockbr)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 == sand)return false;
else if(tft.solid[i].spritecol == seitch)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 == tree)return false;
}
}
return false; // Return false if don't touch anything
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
its already set up for 16x16 just like its written in the gamebuino libraries.
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
by Linky439 » Tue Jul 18, 2017 9:01 am
Oh, thanks, I didn't see it the first time.
Your problem may have something to do with your "for" statement. Where and when is your variable tft.numcolision declared? How much is it supposed to be?
-
Linky439
-
- Posts: 17
- Joined: Sat Dec 17, 2016 6:33 pm
by Linky439 » Wed Jul 19, 2017 8:50 am
I'm just gonna make a wild guess on this one, but are you sure you don't have more than 256 solid objects in your map? The "numcolision" variable is a byte, so if you exceed 256 you're going to be in a world of trouble.
-
Linky439
-
- Posts: 17
- Joined: Sat Dec 17, 2016 6:33 pm
by Duhjoker » Thu Jul 20, 2017 3:52 am
Ok I was able to get the collision to work properly. The number of solid objects in the type def structure for the tilemap and collision had to be changed to 300 and the byte numcollision had to be changed to int instead of byte. Now it works perfectly.
The changes have been made to repository as well so be sure to always check for updates. I'm constantly working to improve and fix any bugs and functions.
https://youtu.be/EN1Iql2mEuk
-
Duhjoker
-
- Posts: 446
- Joined: Sat Jul 02, 2016 4:57 am
- Location: Where Palm trees grow
Return to Programming Questions
Who is online
Users browsing this forum: No registered users and 1 guest