Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. -- Recognizing hipocricy isn't the strong suite of a twelve year-old. (that's for SOMEONE I KNOW)
  2. -- TODO: Make a weapon selection system and enemies with health.
  3.  
  4. --draw "Hello world!" as a main menu and wait for input."
  5. function love.draw()
  6.     love.graphics.print("Hello world!", 400,300) -- However, this doesn't seem to work. a "then" function would probably help nicely.
  7. end
  8.  
  9. function love.load() -- load the player controller into the game
  10.     player = {}
  11. end
  12.  
  13. function love.load() -- put the player into the starting position
  14.         player = {
  15.                 x = 256,
  16.                 y = 256,
  17.                 facing = up,
  18.     }
  19. end
  20.  
  21. function love.keypressed(key) -- we define the keys for the movement. TODO: change the keys to variables so that we can set custom controls in an options menu.
  22. -- we have also defined player.facing as a variable to set the direction the player is facing so we can use this to make our shooting script later on.
  23.     if key == "w" then
  24.         player.y = player.y - 32
  25.         player.facing = "up"
  26.     elseif key == "s" then
  27.         player.y = player.y + 32
  28.         player.facing = "down"
  29.     elseif key == "a" then
  30.         player.x = player.x - 32
  31.         player.facing = "left"
  32.     elseif key == "d" then
  33.         player.x = player.x + 32
  34.         player.facing = "right"
  35.     end
  36. end
  37.  
  38. function love.draw()
  39.         love.graphics.rectangle("fill", player.x, player.y, 32, 32) -- we call a draw function to create a white rectangle in the coordinates we just called.
  40.         love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 0, 10) -- we print out the FPS onto the top of the screen.
  41.         -- the if and elseif lines below display the direction the player is facing.
  42.         if player.facing == "up" then
  43.             love.graphics.print("Facing: Up", 0, 20)
  44.         elseif player.facing == "down" then
  45.             love.graphics.print("Facing: Down", 0, 20)
  46.         elseif player.facing == "left" then
  47.             love.graphics.print("Facing: Left", 0, 20)
  48.         elseif player.facing == "right" then
  49.             love.graphics.print("Facing: Right", 0, 20)
  50.         end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement