Turn based game?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- ixjackinthebox
- Prole
- Posts: 45
- Joined: Sun Apr 29, 2012 6:00 pm
Turn based game?
How would I go about making my game update on the press of a button or some other event?
- dreadkillz
- Party member
- Posts: 223
- Joined: Sun Mar 04, 2012 2:04 pm
- Location: USA
Re: Turn based game?
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?
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.
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.
Code: Select all
function love.update(dt)
if doUpdate then
updateGameLogic(dt)
end
moveSprites(dt)
updateAnimations(dt)
updateSoundeffects(dt)
end
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.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Turn based game?
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
Who is online
Users browsing this forum: Bing [Bot] and 0 guests