Advertisement
Guest User

Untitled

a guest
Aug 25th, 2024
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.65 KB | None | 0 0
  1.  
  2. function love.load()
  3.     keyconfig = {
  4.         ["up"] = "MOVE_UP",
  5.         ["down"] = "MOVE_DOWN",
  6.         -- ...etc
  7.     }
  8.  
  9.     keystate = {
  10.         -- functions that actually move the player around or perform actions
  11.         ["MOVE_UP"] = moveupfunction,
  12.         ["MOVE_DOWN"] = movedownfunction
  13.         -- ....etc
  14.     }
  15.     player.state = nil
  16. end
  17.  
  18. function love.update(dt)
  19.     if player.state then
  20.         -- run function to update game based on key pressed
  21.         keystate[player.state]()
  22.     end
  23. end
  24.  
  25. function love.draw()
  26.       love.graphics.print( text, 330, 300 )
  27. end
  28.  
  29. function love.keypressed( key )
  30.     player.state = keyconfig[key]
  31. end
  32.  
  33. function love.keyreleased( key )
  34.     player.state = nil
  35. end
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement