Hi all!

Working on my first game in LuaFX. So far all that happens is the ai cars try to avoid you.

Code: http://pastebin.com/5EWqXNzf

I am having trouble with the collisions detection right now... for some reason ai cars can "run over" you and you do not get the crash screen. The detection is done on line 231.


If people could test this program that would be great, so I have provided a *.lc for download:
Link
I'm afraid that I'm inexperienced with Lua, but looking at your code, it looks as if it should correctly detect collisions. Does it never properly do collisions, or only sometimes?
Only sometimes. It is usually when I move my car sidways. Instead of the ai car speeding up or slowing down, I just run over it. Maybe I am not clearing the screen properly?
flyingfisch wrote:
Only sometimes. It is usually when I move my car sidways. Instead of the ai car speeding up or slowing down, I just run over it. Maybe I am not clearing the screen properly?
I assume that your coordinates represent the top-left corner of your car and the enemy car. Therefore, remember that this will only work properly when the upper-left corner of your car is within the AI's car.
Yeah, on omni Nick said:

Nick wrote:

hi

i didn't test it (i don't have any casio calc), but i think i found the reason of the crash bug.
it's explained in the image (i hope you understand it xp)



ok, i just saw a mistake in the image. the inequation signs have to be switched in the ai.x statements

in words: your ai.x value collides with the player.x value, so that's oogd
but for the y checking, you also have to iclude the height of the ai cars. in the ai.y<player.y+8 you have to change the ai.y to ai.y+ai.height <player.y+8



So yeah, I think I know what the problem is now. I'll test it and post results.
Unfortunately, he is only half-right. That still won't work, assuming both sprites are 8x8. If my brain is working correctly on fewer than six hours of sleep (which it may well not be), you actually need this check:


Code:
 if (ai.x+8 >= player.x) && (ai.y+8 >= player.y) && (ai.x <= player.x+8) && (ai.y <= player.y+8)
May I ask what the name has to do with the game itself? (Just asking, sometimes I just come up with a random name too)
aeTIos wrote:
May I ask what the name has to do with the game itself? (Just asking, sometimes I just come up with a random name too)


Nothing, really Razz

Except that this is a little different than your typical endless-amount-of-cars-falling-from-the-top-of-the-screen game. This game starts with a certain amount of ai cars that try to beat you to the finish line. I am going to integrate obstacles too, when I get the time.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement