2PlayerShooter/main.lua
2024-04-21 19:28:24 +01:00

89 lines
2.0 KiB
Lua

function love.load()
-- Objects, classes
Object = require("classic")
require("player")
require("bullet")
require("walls")
require("background")
-- Lua files for the game
require("updateGame")
require("drawGame")
require("keyPressed")
-- Background
Backgrounds = {}
local loadBG = function(speed, img)
table.insert(Backgrounds, BG(1, 0, speed, img))
end
loadBG(10, "/assets/bg1.png")
loadBG(-15, "/assets/bg2.png")
--Moonshine effects
Moonshine = require("moonshine")
ScrnEffect = Moonshine(Moonshine.effects.glow).chain(Moonshine.effects.crt)
ScrnEffect.glow.strength = 10
ScrnEffect.crt.distortionFactor = { 1, 1.065 }
-- Set random seed
love.math.setRandomSeed(os.time())
GameFont = love.graphics.newFont("Daydream.ttf", 60)
GameSubFont = love.graphics.newFont("Daydream.ttf", 30)
DebugFont = love.graphics.newFont("Daydream.ttf", 12)
love.graphics.setFont(GameFont)
ScrnHeight = love.graphics.getHeight()
ScrnWidth = love.graphics.getWidth()
EnableKeyPress1 = true
KeyPressTime1 = 0
KeyDelay1 = 0.5
EnableKeyPress2 = true
KeyPressTime2 = 0
KeyDelay2 = 0.5
GameSounds = {}
--static, loaded into memory all time
--stream, loaded into memory when played
GameSounds.shoot1 = love.audio.newSource("/sounds/shoot1.wav", "static")
GameSounds.shoot2 = love.audio.newSource("/sounds/shoot2.wav", "static")
GameSounds.hit = love.audio.newSource("/sounds/hit.wav", "static")
GameSounds.bg = love.audio.newSource("/sounds/bgmusic.wav", "stream")
GameSounds.bg:setLooping(true)
GameSounds.bg:setVolume(0.5)
GameSounds.bg:play()
Player1Img = "/assets/player1.png"
Player2Img = "/assets/player2.png"
BulletImg = "/assets/bullet.png"
UserPlayer1 = Player(400, ScrnHeight - 30, 1, 3, Player1Img, 450)
UserPlayer2 = Player(200, 0, 2, 3, Player2Img, 450)
Bullets1 = {}
Bullets2 = {}
Walls = {}
TIMER = 8
TimeToPlaceWall = TIMER
HasP1Won = false
HasP2Won = false
Debug = false
end
function love.keypressed(key)
keyPressed(key)
end
function love.update(dt)
updateGame(dt)
end
function love.draw()
drawGame()
end