You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
204 lines
4.3 KiB
204 lines
4.3 KiB
Object = require("libs/classic")
|
|
|
|
require("constants")
|
|
WF = require("libs/windfield")
|
|
STI = require("libs/sti")
|
|
|
|
World = WF.newWorld(0, 0) --no gravity
|
|
--World:setQueryDebugDrawing(true) -- Draws the area of a query for 10 frames
|
|
World:addCollisionClass("Player1")
|
|
World:addCollisionClass("Bullet1")
|
|
World:addCollisionClass("Player2")
|
|
World:addCollisionClass("Bullet2")
|
|
World:addCollisionClass("Wall")
|
|
|
|
require("restart")
|
|
require("player")
|
|
require("bullet")
|
|
require("mapsloader")
|
|
|
|
require("Game/UpdateGame")
|
|
require("Menu/UpdateMenu")
|
|
require("Pause/UpdatePause")
|
|
require("Win/UpdateWin")
|
|
|
|
require("Game/DrawGame")
|
|
require("Menu/DrawMenu")
|
|
require("Pause/DrawPause")
|
|
require("Win/DrawWin")
|
|
|
|
require("Game/GameKeyPressed")
|
|
require("Menu/MenuKeyPressed")
|
|
require("Pause/PauseKeyPressed")
|
|
require("Win/WinKeyPressed")
|
|
|
|
--Fonts used in the game
|
|
GameFont = love.graphics.newFont("assets/Daydream.ttf", 60)
|
|
DebugFont = love.graphics.newFont("assets/Daydream.ttf", 12)
|
|
MenuFont = love.graphics.newFont("assets/Daydream.ttf", 45)
|
|
Walls = {}
|
|
|
|
-- Music streaming
|
|
musicMenu = love.audio.newSource("music/menu.mp3", "stream") or nil
|
|
musicBattle = love.audio.newSource("music/battle.mp3", "stream") or nil
|
|
--musicStory = love.audio.newSource("music/story.mp3", "stream") or nil
|
|
|
|
musicPause = musicBattle:clone()
|
|
musicPause:setFilter({
|
|
type = "lowpass",
|
|
volume = 0.7,
|
|
highgain = 0.4,
|
|
})
|
|
|
|
function love.run()
|
|
if love.load then
|
|
love.load(love.arg.parseGameArguments(arg), arg)
|
|
end
|
|
|
|
-- We don't want the first frame's dt to include time taken by love.load.
|
|
if love.timer then
|
|
love.timer.step()
|
|
end
|
|
|
|
local dt = 0
|
|
|
|
-- Main loop time.
|
|
return function()
|
|
-- Process events.
|
|
if love.event then
|
|
love.event.pump()
|
|
for name, a, b, c, d, e, f in love.event.poll() do
|
|
if name == "quit" then
|
|
if not love.quit or not love.quit() then
|
|
return a or 0
|
|
end
|
|
end
|
|
love.handlers[name](a, b, c, d, e, f)
|
|
end
|
|
end
|
|
|
|
-- Update dt, as we'll be passing it to update
|
|
if love.timer then
|
|
dt = love.timer.step()
|
|
end
|
|
|
|
-- Call update and draw
|
|
if love.update then
|
|
love.update(dt)
|
|
end -- will pass 0 if love.timer is disabled
|
|
|
|
if love.graphics and love.graphics.isActive() then
|
|
love.graphics.origin()
|
|
love.graphics.clear(love.graphics.getBackgroundColor())
|
|
|
|
if love.draw then
|
|
love.draw()
|
|
end
|
|
|
|
love.graphics.present()
|
|
end
|
|
|
|
if love.timer then
|
|
love.timer.sleep(0.001)
|
|
end
|
|
end
|
|
end
|
|
|
|
function love.load(args)
|
|
-- Set a random seed
|
|
love.math.setRandomSeed(love.timer.getTime())
|
|
|
|
--Game values (reset after each load)
|
|
HEALTH = 3
|
|
P1_DELAY = 0.5
|
|
P2_DELAY = 0.5
|
|
|
|
--Bullet lists
|
|
Bullets1 = {}
|
|
Bullets2 = {}
|
|
|
|
DebugFlag = false
|
|
EnableKeyPress1 = true
|
|
KeyPressTime1 = 0
|
|
KeyDelay1 = P1_DELAY
|
|
|
|
EnableKeyPress2 = true
|
|
KeyPressTime2 = 0
|
|
KeyDelay2 = P2_DELAY
|
|
|
|
local playerSpeed = 12000
|
|
UserPlayer1 = Player(1, 1000, 100, HEALTH, "assets/player1.png", playerSpeed)
|
|
UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", playerSpeed)
|
|
|
|
--STI Map loading
|
|
LoadMap(_G.CUR_LEVEL)
|
|
end
|
|
|
|
function love.keypressed(key)
|
|
if _G.GAMESTATE == "MENU" then
|
|
MenuKeyPressed(key)
|
|
end
|
|
if _G.GAMESTATE == "PAUSE" then
|
|
PauseKeyPressed(key)
|
|
end
|
|
if _G.GAMESTATE == "GAME" then
|
|
GameKeyPressed(key)
|
|
end
|
|
if _G.GAMESTATE == "WIN" then
|
|
WinKeyPressed(key)
|
|
end
|
|
end
|
|
|
|
function love.update(dt)
|
|
if _G.GAMESTATE == "MENU" then
|
|
UpdateMenu(dt)
|
|
-- Handle music
|
|
if not musicMenu:isPlaying() then
|
|
musicMenu:setVolume(0.5)
|
|
love.audio.play(musicMenu)
|
|
end
|
|
end
|
|
if _G.GAMESTATE == "PAUSE" then
|
|
UpdatePause(dt)
|
|
-- Handle music
|
|
if not musicPause:isPlaying() then
|
|
musicBattle:setVolume(0)
|
|
musicPause:setVolume(0.5)
|
|
love.audio.play(musicBattle)
|
|
love.audio.play(musicPause)
|
|
end
|
|
end
|
|
if _G.GAMESTATE == "GAME" then
|
|
UpdateGame(dt)
|
|
-- Handle music
|
|
if not musicBattle:isPlaying() then
|
|
musicBattle:setVolume(0.5)
|
|
musicPause:setVolume(0)
|
|
love.audio.play(musicBattle)
|
|
love.audio.play(musicPause)
|
|
end
|
|
end
|
|
if _G.GAMESTATE == "WIN" then
|
|
UpdateWin(dt)
|
|
end
|
|
end
|
|
|
|
function love.draw()
|
|
if _G.GAMESTATE == "MENU" then
|
|
DrawMenu()
|
|
end
|
|
if _G.GAMESTATE == "PAUSE" then
|
|
DrawPause()
|
|
end
|
|
if _G.GAMESTATE == "GAME" then
|
|
DrawGame()
|
|
if DebugFlag then
|
|
love.graphics.setFont(DebugFont)
|
|
love.graphics.print("Debug Mode", 1200, 850)
|
|
love.graphics.print("" .. GAMESTATE, 200, 200)
|
|
end
|
|
end
|
|
if _G.GAMESTATE == "WIN" then
|
|
DrawWin()
|
|
end
|
|
end
|
|
|