https://github.com/H...ter/frogger.lua
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
[Question] Help With My Frogger Game
Started by Henness, 21 December 2012 - 01:57 AMPosted 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
https://github.com/H...ter/frogger.lua
Posted 21 December 2012 - 02:40 PM
bump
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.
Posted 21 December 2012 - 04:50 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.
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.
Posted 21 December 2012 - 04:54 PM
By using a timer at the main pullEvent(), so every time the timer goes off, you put the functions in order, as you wantYou'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.
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
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.
Posted 21 December 2012 - 05:33 PM
should I still run the input parallel with the gameclock?
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
https://github.com/H...ter/frogger.lua
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.
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.
Posted 21 December 2012 - 07:23 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.
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.
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?
Posted 21 December 2012 - 11:19 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?
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
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.
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.
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?
Anyway I still can't figure out the falling of objects bug. Any one have any ideas?
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.
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.
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.
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.