I have made a game called BitDodger and all of the mechanics are pretty much in place, so I just have to do the HUD, but I am having a problem with collisions. If you would like to help look at the attached .love file. Basically I made it so you are invincible for 5 seconds, then you can be hit, that is all working but when I go to the top "row" or coord y0 it does not print if I am being hit by a block or not. Which is strange considering I can be hit when I am on the lower rows. The game has the console activated so it will spam not hit or hit, obviously telling you when you are hit or not.
I also have another bug that I would like some guidance on, which now that I think about it may be related to the first bug, whenever I spawn and don't move I cannot be hit.
Should I take the bounding box snippet from the wiki and run it through a for loop and check collisions for each tile against the player? I figured that would be way too resource intensive for what it is.
Collision errors
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Collision errors
- Attachments
-
- bitdodger.love
- Bit Dodger alpha 1
- (6.16 MiB) Downloaded 162 times
Re: Collision errors
Hi toaster. This is the problem: at line 101 you typed:
if ply.y > 0 then
So what happens when you are in the first row (that is, when ply.y == 0)? Nothing, as ply.y is not bigger than 0.
So how to fix it? Just change it to
if ply.y >= 0 then
if ply.y > 0 then
So what happens when you are in the first row (that is, when ply.y == 0)? Nothing, as ply.y is not bigger than 0.
So how to fix it? Just change it to
if ply.y >= 0 then
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: Collision errors
Ok, that worked but I am still getting false positives, when I try to use the players x coordinate to get the tile that he is currently on it gives me the wrong feedback, I am using this:
to get the map table data from the player coordinate. Is that correct?
Code: Select all
ply.x / tile_w
Re: Collision errors
That will most likely return a float number, and it could give errors.
You should get just the integer part of that division. Type math.floor(ply.x/tile_w) instead and let me know if it works.
You should get just the integer part of that division. Type math.floor(ply.x/tile_w) instead and let me know if it works.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: Collision errors
I am already using math.floor I forgot to add it to the snippet, sorry. Any other ideas?
Re: Collision errors
D'oh! I'm clueless now, but if you post your current code I'll have a look
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: Collision errors
No probs! I'll check it when I come back from work this afternoon
Re: Collision errors
I'm back! I've fixed most of your code. Here's what I did:
-I created a new variable ply.status, to save the status "hit", "not hit" and "ignoring, invincible". Thus I can print it on screen. Therefore, I disabled the console as you won't need by now.
-I changed your love.update() function, as it had some errors. For instance, you were only detecting collisions when ply.y>0, so the first row was never taken into account. It should be ply.y>=0 instead. That means always (as your player will never go above y=0), so I just removed that "if" (not sure if you intended that row not to be taken into account on purpose). There are more changes, so have a look to it and let me know any doubts you might have
-ply.u seemed not to do anything, so I removed it from the debug messages.
-I modified the move() and love.keypressed functions so the player never goes further than map_w and map_h.
I hope this is closer to what you wanted to do. May I ask what your project is about? Or are you just learning?
EDIT: the attached zip only contains "conf.lua" and "main.lua". Just copy and overwrite them and you'll be ready to go!
-I created a new variable ply.status, to save the status "hit", "not hit" and "ignoring, invincible". Thus I can print it on screen. Therefore, I disabled the console as you won't need by now.
-I changed your love.update() function, as it had some errors. For instance, you were only detecting collisions when ply.y>0, so the first row was never taken into account. It should be ply.y>=0 instead. That means always (as your player will never go above y=0), so I just removed that "if" (not sure if you intended that row not to be taken into account on purpose). There are more changes, so have a look to it and let me know any doubts you might have
-ply.u seemed not to do anything, so I removed it from the debug messages.
-I modified the move() and love.keypressed functions so the player never goes further than map_w and map_h.
I hope this is closer to what you wanted to do. May I ask what your project is about? Or are you just learning?
EDIT: the attached zip only contains "conf.lua" and "main.lua". Just copy and overwrite them and you'll be ready to go!
- Attachments
-
- bitdodger_fixed.zip
- (1.39 KiB) Downloaded 118 times
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: Collision errors
Well my friend made a version in another language so I just felt it was something easy to port over to Lua meant only as a learning experience. And thank you, I will look at the code and use it as a base and maybe I'll rewrite it (the third time!) since as you can see my variables do not reflect the data (Like ply.d, ply.d stood for player down ie the tile under him)
Not to mention it really isn't as lightweight as it could be I have dupilcates of some files, I have a whole library for 1 function. Thank you again.
Not to mention it really isn't as lightweight as it could be I have dupilcates of some files, I have a whole library for 1 function. Thank you again.
Who is online
Users browsing this forum: Bing [Bot] and 4 guests