Page 1 of 1

Turn based game?

Posted: Wed Dec 12, 2012 3:11 pm
by ixjackinthebox
How would I go about making my game update on the press of a button or some other event?

Re: Turn based game?

Posted: Wed Dec 12, 2012 3:14 pm
by dreadkillz
You can set up a toggle variable which you can change with a key press or mouse press.

Code: Select all

function love.update(dt)
 if doUpdate then
 ...
 end
end

function love.keypressed(k)
 if k == ' ' then doUpdate = not doUpdate end
end

Re: Turn based game?

Posted: Wed Dec 12, 2012 5:47 pm
by Inny
I'm assuming that you want the game logic turn based, but still want things like animations. Dreadkillz idea is a good one, and we can expand upon it a bit.

Code: Select all

function love.update(dt)
  if doUpdate then
    updateGameLogic(dt)
  end

  moveSprites(dt)
  updateAnimations(dt)
  updateSoundeffects(dt)
end
The idea is that you'll still want to do all of the other things that happen in a game and make it pretty, and not pause absolutely everything.

The "moveSprites" function in this example would already know where sprites are going, and probably has some "dx" or "destinationX" and the corresponding Y coordinate, and all the function does is physically relocate the visual positions of the sprite, but doesn't change it's "logical" position. Meaning that whatever bullets are floating back and forth don't check for collision detection during an animation, they'll be travelling to a destination as well. How do you know if the bullets hit or not without collision detection? Considering it's a turn based game, you can check against some hit/evade stat (hidden or known to the player) at the time the bullet is shot in the updateGameLogic, and let the bullet carry the "thisIsAHit" or "thisIsAMiss" tag, and animate it as a hit or miss when it reaches the destination.

Re: Turn based game?

Posted: Wed Dec 12, 2012 6:00 pm
by bartbes
Alternatively, you could write the update function more cleverly:

Code: Select all

function love.update(dt)
  moveSprites(dt)
  updateAnimations(dt)
  updateSoundeffects(dt)

  if not doUpdate then return end

  updateGameLogic(dt)
end