Page 1 of 1

Need opinion on code so far (space game)

Posted: Thu Jul 25, 2013 11:57 am
by RunningGamesStudios
Ive been making a space combat type game in love for a while now. I would like some opinions on my code

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

Posted: Thu Jul 25, 2013 1:25 pm
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.

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

Posted: Fri Jul 26, 2013 6:02 pm
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.

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

Posted: Fri Jul 26, 2013 6:28 pm
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: