Advertisement
Guest User

Untitled

a guest
Jan 25th, 2012
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. function love.load()
  2.     background = {}
  3.         background.image = love.graphics.newImage("background.png")
  4.     ground = {}
  5.         ground.image = love.graphics.newImage("ground.png")
  6.     music = {}
  7.         music.menu = love.audio.newSource("mainmenu.ogg",static)
  8.         love.audio.play(music.menu)
  9.     mouse = {}
  10.         mouse.x = love.mouse.getX()
  11.         mouse.y = love.mouse.getY()
  12.     player = {}
  13.         player.x = 300
  14.         player.y = 327
  15.         player.image = love.graphics.newImage("player.png")
  16.     player.vel = {}
  17.         player.vel.x = 0
  18.         player.vel.y = 0
  19.         landed = true
  20.     menu = {}
  21.         menu.image = love.graphics.newImage("ui/menu.png")
  22.     pause = {}
  23.         pause.image = love.graphics.newImage("ui/paused.png")
  24.     play = false
  25.     paused = false
  26.     win = false
  27.     playbutton = false
  28.     pausebutton = false
  29.     restartbutton = false
  30.     start = false
  31. end
  32.  
  33. function love.update(dt)
  34.     mouse.x = love.mouse.getX()
  35.     mouse.y = love.mouse.getY()
  36.     if not play and not paused and not win and mouse.x > 286 and mouse.x < 993 and mouse.y > 86 and mouse.y < 736 then
  37.         playbutton = true
  38.     else
  39.         playbutton = false
  40.     end
  41.         if play and start then
  42.         love.audio.stop()
  43.         start = false
  44.         textactive = true
  45.     end
  46.     player.x = player.x + player.vel.x
  47.     player.y = player.y + player.vel.y
  48.     if love.keyboard.isDown("left") then
  49.         player.vel.x = player.vel.x - 0.2
  50.     elseif love.keyboard.isDown("right") then
  51.         player.vel.x = player.vel.x + 0.2
  52.     elseif player.vel.x > 0 then
  53.         player.vel.x = player.vel.x - 0.1
  54.     elseif player.vel.x < 0 then
  55.         player.vel.x = player.vel.x + 0.1
  56.     end
  57.     if player.vel.x > -0.1 and player.vel.x < 0.1 then
  58.         player.vel.x = 0
  59.     end
  60.     if player.y > 327 then
  61.         player.y = 327
  62.         player.vel.y = 0
  63.         landed = true
  64.     elseif landed == false then
  65.         player.vel.y = player.vel.y + 0.4
  66.     end
  67. end
  68.  
  69. function love.draw()
  70.     if not play and not paused and not win then
  71.         menu.graphic = love.graphics.draw(menu.image,0,-165)
  72.     elseif paused then
  73.         pause.graphic = love.graphics.draw(pause.image,0,-165)
  74.     elseif play then
  75.         love.graphics.draw(background.image,0,0)
  76.         love.graphics.draw(ground.image,0,527)
  77.         love.graphics.draw(player.image,player.x,player.y)
  78.     end
  79. end
  80.  
  81. function love.mousepressed(x,y,button)
  82.     if playbutton and button == "l" then
  83.         playbutton = false
  84.         play = true
  85.         paused = false
  86.         start = true
  87.     elseif paused and button == "l" then
  88.         play = true
  89.         paused = false
  90.         start = true
  91.     end
  92. end
  93.  
  94. function love.keypressed(key)
  95.     if key == "up" and landed == true then
  96.         player.vel.y = -10
  97.         landed = false
  98.     end
  99.     if key == "escape" then
  100.         play = false
  101.         paused = true
  102.         start = true
  103.     end
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement