Need opinion on code so far (space game)
-
- Prole
- Posts: 46
- Joined: Fri May 31, 2013 9:42 pm
Need opinion on code so far (space game)
Ive been making a space combat type game in love for a while now. I would like some opinions on my code
- Attachments
-
- space.love
- (5.5 KiB) Downloaded 228 times
Re: Need opinion on code so far (space game)
Your code looks very well organized. I had no trouble reading and understanding it.
Here are some minor suggestions:
Here are some minor suggestions:
- The function fireProjectile does not use dt so you don't need to pass it
- The projectiles' velocity is stored in dx and dy. I would rather call them vx and vy (for velocity). In my understanding dx = vx * dt, so dx is the actual displacement in one frame (changes with dt) while vx is the velocity (constant). But maybe that's only me.
- In the update-function you check for pressed keys and then pass them to the movePlayer function. I suggest you put the input-check directly into the movePlayer function and then put movePlayer into a function called game:update(dt). The main update function would look like this then:
Code: Select all
love.update(dt) if gameState == 'play' then game:update(dt) elseif gameState == 'menu' then menu:update(dt) end end
Check out my blog on gamedev
-
- Prole
- Posts: 46
- Joined: Fri May 31, 2013 9:42 pm
Re: Need opinion on code so far (space game)
Would not doing the third one slow down the game or something? or is it more of different method?micha wrote:Your code looks very well organized. I had no trouble reading and understanding it.
Here are some minor suggestions:Besides that: Well done. Looks like a solid start.
- The function fireProjectile does not use dt so you don't need to pass it
- The projectiles' velocity is stored in dx and dy. I would rather call them vx and vy (for velocity). In my understanding dx = vx * dt, so dx is the actual displacement in one frame (changes with dt) while vx is the velocity (constant). But maybe that's only me.
- In the update-function you check for pressed keys and then pass them to the movePlayer function. I suggest you put the input-check directly into the movePlayer function and then put movePlayer into a function called game:update(dt). The main update function would look like this then:
Code: Select all
love.update(dt) if gameState == 'play' then game:update(dt) elseif gameState == 'menu' then menu:update(dt) end end
Other then that, Thank you. Your post was very helpful.
Re: Need opinion on code so far (space game)
Doing a simple if statement every frame (update) will have no performance loss at all really. I set mine up similar to what code he posted.
Who is online
Users browsing this forum: No registered users and 0 guests