Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. require("player")
  2. require("Food")
  3. require("AnAL")
  4. require("menu")
  5.  
  6.  
  7. function love.load()
  8.  
  9.     gamestate = "menu"
  10.  
  11.     -- butons
  12.     button_spawn(140,120,"PRESS A TO START")
  13.     button_spawn(147,160, "PRESS B TO QUIT")
  14.      
  15.  
  16. --highscores = {}
  17.  
  18. p = player:new()
  19. nom = Food:new()
  20.  
  21. width = love.graphics.getWidth() --startmenu
  22. height = love.graphics.getHeight() --startmenu
  23.  
  24. playingBgm = love.audio.newSource("sfx/bga.ogg", "stream")
  25. collectCoinBgm = love.audio.newSource("sfx/nom.ogg", "static")
  26.  
  27. playingBgm:setLooping(true)
  28. playingBgm:setVolume(.25)
  29.  
  30. animUp = newAnimation(p.imgUp, 32, 32, 0.1, 0)
  31. animDown = newAnimation(p.imgDown, 32, 32, 0.1, 0)
  32. animLeft = newAnimation(p.imgLeft, 32, 32, 0.1, 0)
  33. animRight = newAnimation(p.imgRight, 32, 32, 0.1, 0)
  34.  
  35. if not love.filesystem.exists("scores.lua") then
  36.     scores = love.filesystem.newFile("scores.lua")
  37.     end
  38.  
  39.     --for lines in love.filesystem.lines("scores.lua") do
  40.     --  table.insert(highscores, lines)
  41.     end
  42.  
  43.     --p.highscore = highscores[3]
  44.  
  45.     backgroundImage = love.graphics.newImage("img/bg.png")
  46.  
  47.     font20 = love.graphics.newFont("font/Nobile-Regular.ttf", 15)
  48.  
  49.    titleImage = love.graphics.newImage("img/ph.png")
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. function love.draw()
  58.  
  59.     if gamestate == "playing" then
  60.  
  61.     love.graphics.draw(backgroundImage, 0, 0)
  62.  
  63.  
  64.     if o.facing == "left" then
  65.         animLeft:draw(p.x, p.y)
  66.     end
  67.     if o.facing == "right" then
  68.         animRight:draw(p.x, p.y)
  69.     end
  70.     if o.facing == "up" then
  71.         animUp:draw(p.x, p.y)
  72.     end
  73.     if o.facing == "down" then
  74.         animDown:draw(p.x, p.y)
  75.         nom:draw()
  76.         love.graphics.setFont(font20)
  77.         love.graphics.print("Score:".. p.score, 10, 10)
  78.         layingBgm:play()
  79. --love.graphics.print("Highscore: " .. p.highscore, 200, 10)
  80. end
  81.  
  82.  
  83.      end
  84.  
  85.      if gamestate == "menu" then
  86.     love.graphics.draw(titleImage, 0, 0)
  87.     button_draw()
  88.      end
  89. end
  90.  
  91.  
  92.  
  93.      
  94.  
  95. function love.update(dt)
  96.  
  97.     if gamestate == "playing" then
  98. p:update(dt)
  99. nom:update(dt)
  100.  
  101. end
  102. --if p.score > tonumber(p.highscore) then
  103. --p.highscore = p.score
  104. --love.filesystem.write("scores.lua", "p.highscore\n=\n" .. p.highscore)
  105.     --end
  106.  
  107.     if o.facing == "left" then
  108.         animLeft:update(dt)
  109.     end
  110.     if o.facing == "right" then
  111.           animRight:update(dt)
  112.     end
  113.     if o.facing == "up" then
  114.         animUp:update(dt)
  115.     end
  116.     if o.facing == "down" then
  117.         animDown:update(dt)
  118.        
  119.     end
  120. end
  121.  
  122. function love.keypressed(key)
  123. if key == "y" then love.gamestate = "playing" --NOT WORKING!
  124.  
  125.     end
  126. end
  127.  
  128.  
  129. function love.keypressed(key) -- key pressed/ menu gui is here<<<
  130. if key == "b" then love.quit() --menu gui
  131.     end
  132. end
  133.  
  134. --function love.keypressed(key
  135.     --loveframes.keypressed(key)
  136.  
  137. function love.quit()
  138.     love.event.quit()
  139.     love.filesystem.write("scores.lua", "p.highscore\n=\n" .. p.highscore)
  140. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement