Take Control Away From Player?
The idea behind the code is that I want some way to not let the player control the sprite, for example during dialogue or something. No matter how much I press Q though, I’m still able to move the sprite even when pressing arrow keys while holding down Q.
https://microstudio.io/i/Trondei/prac9givecontrol/
And is it possible to use playerHasControl
as a string instead of a boolean? I’d like to be able to switch between "has"
and "has not"
.
init = function()
playerHasControl = false
playerAnimation = "front"
playerX = 0
playerY = 0
facing = 1
end
update = function()
if playerHasControl = true then
if keyboard.UP then
playerY += 1
playerAnimation = "up"
facing = 1
end
if keyboard.DOWN then
playerY -= 1
playerAnimation = "front" // do NOT use 'and' after 'then'
facing = 1
end
if keyboard.RIGHT then
playerX += 1
playerAnimation = "side"
facing = 1
end
if keyboard.LEFT then
playerX -= 1
playerAnimation = "side"
facing = -1
end
end
if keyboard.Q then playerHasControl = true
else playerHasControl = false
end
end
draw = function()
HSbackGround ()
screen.setDrawScale ( facing, 1 )
screen.drawSprite ( playerAnimation, playerX, playerY, 30 )
screen.setDrawScale (1)
end