Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("player")
- require("Food")
- require("AnAL")
- require("menu")
- function love.load()
- gamestate = "menu"
- -- butons
- button_spawn(140,120,"PRESS A TO START")
- button_spawn(147,160, "PRESS B TO QUIT")
- --highscores = {}
- p = player:new()
- nom = Food:new()
- width = love.graphics.getWidth() --startmenu
- height = love.graphics.getHeight() --startmenu
- playingBgm = love.audio.newSource("sfx/bga.ogg", "stream")
- collectCoinBgm = love.audio.newSource("sfx/nom.ogg", "static")
- playingBgm:setLooping(true)
- playingBgm:setVolume(.25)
- animUp = newAnimation(p.imgUp, 32, 32, 0.1, 0)
- animDown = newAnimation(p.imgDown, 32, 32, 0.1, 0)
- animLeft = newAnimation(p.imgLeft, 32, 32, 0.1, 0)
- animRight = newAnimation(p.imgRight, 32, 32, 0.1, 0)
- if not love.filesystem.exists("scores.lua") then
- scores = love.filesystem.newFile("scores.lua")
- end
- --for lines in love.filesystem.lines("scores.lua") do
- -- table.insert(highscores, lines)
- end
- --p.highscore = highscores[3]
- backgroundImage = love.graphics.newImage("img/bg.png")
- font20 = love.graphics.newFont("font/Nobile-Regular.ttf", 15)
- titleImage = love.graphics.newImage("img/ph.png")
- function love.draw()
- if gamestate == "playing" then
- love.graphics.draw(backgroundImage, 0, 0)
- if o.facing == "left" then
- animLeft:draw(p.x, p.y)
- end
- if o.facing == "right" then
- animRight:draw(p.x, p.y)
- end
- if o.facing == "up" then
- animUp:draw(p.x, p.y)
- end
- if o.facing == "down" then
- animDown:draw(p.x, p.y)
- nom:draw()
- love.graphics.setFont(font20)
- love.graphics.print("Score:".. p.score, 10, 10)
- layingBgm:play()
- --love.graphics.print("Highscore: " .. p.highscore, 200, 10)
- end
- end
- if gamestate == "menu" then
- love.graphics.draw(titleImage, 0, 0)
- button_draw()
- end
- end
- function love.update(dt)
- if gamestate == "playing" then
- p:update(dt)
- nom:update(dt)
- end
- --if p.score > tonumber(p.highscore) then
- --p.highscore = p.score
- --love.filesystem.write("scores.lua", "p.highscore\n=\n" .. p.highscore)
- --end
- if o.facing == "left" then
- animLeft:update(dt)
- end
- if o.facing == "right" then
- animRight:update(dt)
- end
- if o.facing == "up" then
- animUp:update(dt)
- end
- if o.facing == "down" then
- animDown:update(dt)
- end
- end
- function love.keypressed(key)
- if key == "y" then love.gamestate = "playing" --NOT WORKING!
- end
- end
- function love.keypressed(key) -- key pressed/ menu gui is here<<<
- if key == "b" then love.quit() --menu gui
- end
- end
- --function love.keypressed(key
- --loveframes.keypressed(key)
- function love.quit()
- love.event.quit()
- love.filesystem.write("scores.lua", "p.highscore\n=\n" .. p.highscore)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement