Jump to content




[Question] Help With My Frogger Game


  • You cannot reply to this topic
18 replies to this topic

#1 Henness

  • Members
  • 189 posts

Posted 21 December 2012 - 02:57 AM

My friend challenged me to make Frogger in computer craft, I have mostly succeeded besides the lives and scoring system witch isn't hard at all. But what I'm having a problem with is when you jump on a log or turtle near the back you fall off in the water. I have never made a game before so any suggestions would be helpful.

https://github.com/H...ter/frogger.lua

#2 Henness

  • Members
  • 189 posts

Posted 21 December 2012 - 02:40 PM

bump

#3 ChunLing

  • Members
  • 2,027 posts

Posted 21 December 2012 - 03:13 PM

You're using parallel to try and run all the update functions at the same time, but that means that the relative progress/execution order of the functions isn't fully controlled by your code. Of course there's going to be problems.

#4 Henness

  • Members
  • 189 posts

Posted 21 December 2012 - 04:50 PM

View PostChunLing, on 21 December 2012 - 03:13 PM, said:

You're using parallel to try and run all the update functions at the same time, but that means that the relative progress/execution order of the functions isn't fully controlled by your code. Of course there's going to be problems.

how would I run them at the same time without parallel? I've never made a game so I have no idea how they are usually set up.

#5 anonimo182

  • Members
  • 252 posts
  • LocationIn the universe

Posted 21 December 2012 - 04:54 PM

View PostHenness, on 21 December 2012 - 04:50 PM, said:

View PostChunLing, on 21 December 2012 - 03:13 PM, said:

You're using parallel to try and run all the update functions at the same time, but that means that the relative progress/execution order of the functions isn't fully controlled by your code. Of course there's going to be problems.

how would I run them at the same time without parallel? I've never made a game so I have no idea how they are usually set up.
By using a timer at the main pullEvent(), so every time the timer goes off, you put the functions in order, as you want

#6 Henness

  • Members
  • 189 posts

Posted 21 December 2012 - 05:16 PM

Whats the shortest timer or sleep you can set/do in computer craft? Because I cant do any thing with os.clock() because it only returns seconds witch would make the game super slow

#7 ChunLing

  • Members
  • 2,027 posts

Posted 21 December 2012 - 05:17 PM

You can make timers really short, but I recommend setting one for a frame-rate you find acceptable rather than the shortest possible one.

#8 Henness

  • Members
  • 189 posts

Posted 21 December 2012 - 05:33 PM

should I still run the input parallel with the gameclock?

#9 Henness

  • Members
  • 189 posts

Posted 21 December 2012 - 06:29 PM

I've changed the way the game runs so it has a game clock and now I'm having a problem with it lagging every time the objects get updated.

https://github.com/H...ter/frogger.lua

#10 ChunLing

  • Members
  • 2,027 posts

Posted 21 December 2012 - 06:42 PM

Don't pullEvent("timer"), just pull the event and then either update everything if it's the frame-update timer or grab the input if it's a key event.

That should fix at least some of your apparent lag, for the rest you'll just have to use better code to handle moving stuff, or only execute your really lag-prone code occasionally. Not everything should move every frame, after all.

#11 Henness

  • Members
  • 189 posts

Posted 21 December 2012 - 07:23 PM

View PostChunLing, on 21 December 2012 - 06:42 PM, said:

Don't pullEvent("timer"), just pull the event and then either update everything if it's the frame-update timer or grab the input if it's a key event.

That should fix at least some of your apparent lag, for the rest you'll just have to use better code to handle moving stuff, or only execute your really lag-prone code occasionally. Not everything should move every frame, after all.

Okay I fixed it I accidentally had the sleeps still in the objects function from when I had it in parallel. So it runs super smooth now, I just have to mess with the speeds of the objects. But I'm still back to my original problem, when you move to the end of a log or turtle the next time the object moves you get pushed off into the water.

https://github.com/H...ter/frogger.lua

Thanks for all the help this is a much better way of writing it then with the parallel api.

#12 Henness

  • Members
  • 189 posts

Posted 21 December 2012 - 08:20 PM

Still having the problem, also some one told me this will lag servers if its ran for too long is that true and if so do I need some sort of garbage collection?

#13 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 21 December 2012 - 11:19 PM

View PostHenness, on 21 December 2012 - 08:20 PM, said:

Still having the problem, also some one told me this will lag servers if its ran for too long is that true and if so do I need some sort of garbage collection?

Not sure about that but I accidentally left my computer on with your game playing and after a while the game starts flashing badly because it redraws a lot every second or so

#14 ChunLing

  • Members
  • 2,027 posts

Posted 21 December 2012 - 11:35 PM

Are you continuously expanding a table or something? It doesn't look like you do to me, but I'm not looking at everything. If none of your tables is increasing in size indefinitely, there's no reason this should be a problem.

Try making a debug log by serializing all your tables and saving them to a file every now and then. Run the program and see if you have tables growing out of control, if not then I'd guess you're okay.

As for the falling of the backs of turtles/logs, are you only falling off the very last space? Cause you check death after moving stuff. Which makes sense but it could be pulling stuff out from under you at the last moment. Other than that just make sure you're drawing them where they're supposed to be.

#15 Henness

  • Members
  • 189 posts

Posted 22 December 2012 - 12:22 AM

My runcount variable is ever expanding that probably why, I should make it reset back to zero every minute or so because if it counts 20 every sec in a min it counts up to 1200 so if you run it to long the number will get out of control I didn't think it would be a problem because when you get game over it will restart anyway.

Anyway I still can't figure out the falling of objects bug. Any one have any ideas?

#16 ChunLing

  • Members
  • 2,027 posts

Posted 22 December 2012 - 01:00 AM

Serialize/save the objects table when you die, so that you can check it to see what exactly it was. That should make it easy to hunt down why the screen was displayed in such a way as to make it seem like you were safe when instead you were dead.

#17 Henness

  • Members
  • 189 posts

Posted 22 December 2012 - 03:10 AM

Its showing that the spot is a 1 witch means you do die. But it doesn't make sense why the object doesn't pull you with it when it moves.

#18 Henness

  • Members
  • 189 posts

Posted 22 December 2012 - 03:16 AM

Nvm I got it I had to make it move the player before moving the object so it didn't think the the player was in the water.

#19 ChunLing

  • Members
  • 2,027 posts

Posted 22 December 2012 - 11:59 AM

Oh...you didn't mention that you're supposed to move with the object automatically. Guess I haven't played frogger in a while.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users