Need opinion on code so far (space game)

Show off your games, demos and other (playable) creations.
Post Reply
RunningGamesStudios
Prole
Posts: 46
Joined: Fri May 31, 2013 9:42 pm

Need opinion on code so far (space game)

Post by RunningGamesStudios »

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
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Need opinion on code so far (space game)

Post by micha »

Your code looks very well organized. I had no trouble reading and understanding it.

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
Besides that: Well done. Looks like a solid start.
RunningGamesStudios
Prole
Posts: 46
Joined: Fri May 31, 2013 9:42 pm

Re: Need opinion on code so far (space game)

Post by RunningGamesStudios »

micha wrote:Your code looks very well organized. I had no trouble reading and understanding it.

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
Besides that: Well done. Looks like a solid start.
Would not doing the third one slow down the game or something? or is it more of different method?
Other then that, Thank you. Your post was very helpful.
User avatar
MPQC
Citizen
Posts: 65
Joined: Fri Jun 28, 2013 2:45 pm

Re: Need opinion on code so far (space game)

Post by MPQC »

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. :awesome:
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest