Turn based game?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
ixjackinthebox
Prole
Posts: 45
Joined: Sun Apr 29, 2012 6:00 pm

Turn based game?

Post by ixjackinthebox »

How would I go about making my game update on the press of a button or some other event?
User avatar
dreadkillz
Party member
Posts: 223
Joined: Sun Mar 04, 2012 2:04 pm
Location: USA

Re: Turn based game?

Post 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
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Turn based game?

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Turn based game?

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests