Compare commits

..

No commits in common. '9e968b93900b10c763224d4add61ec4c69645e77' and '6049054a26a9f14079a938d8c736a576f0dd0319' have entirely different histories.

  1. 4
      Game/DrawGame.lua
  2. 2
      Game/GameKeyPressed.lua
  3. 11
      Game/UpdateGame.lua
  4. 9
      Menu/MenuKeyPressed.lua
  5. 1
      Pause/PauseKeyPressed.lua
  6. 33
      Win/DrawWin.lua
  7. 1
      Win/UpdateWin.lua
  8. 7
      Win/WinKeyPressed.lua
  9. 8
      constants.lua
  10. BIN
      game.love
  11. 49
      libs/restart.lua
  12. 57
      main.lua
  13. 6
      mapsloader.lua
  14. 20
      player.lua

@ -8,8 +8,8 @@ local function drawHealth()
love.graphics.setFont(GameFont)
local height = love.graphics.getHeight()
local width = love.graphics.getWidth()
love.graphics.print("P1:" .. UserPlayer1.health, 5, 5)
love.graphics.print("P2:" .. UserPlayer2.health, width - 200, height - 95)
love.graphics.print("" .. UserPlayer1.health, 5, 5)
love.graphics.print("" .. UserPlayer2.health, width - 70, height - 95)
end
function DrawGame()

@ -14,8 +14,6 @@ function GameKeyPressed(key)
--TODO: Better restart
if key == "r" and not _G.PAUSED then
RestartGame()
_G.GAMESTATE = "GAME"
love.load()
end
end

@ -1,14 +1,15 @@
local function checkWinState()
-- Check P1's health
if UserPlayer1.health <= 0 then --P1 win
_G.P1_WIN = false
_G.P2_WIN = true
_G.P1_WIN = true
_G.P2_WIN = false
UserPlayer1.health = 0
return true
end
if UserPlayer2.health <= 0 then --P2 win
_G.P1_WIN = true
_G.P2_WIN = false
_G.P1_WIN = false
_G.P2_WIN = true
UserPlayer2.health = 0
return true
end
return false

@ -33,13 +33,4 @@ function MenuKeyPressed(key)
_G.MENU_POS = _G.MENU_POS + 1
end
end
if key == "r" then
musicBattle:stop()
musicMenu:stop()
musicPause:stop()
musicStory:stop()
_G.GAMESTATE = "MENU"
love.load()
end
end

@ -1,6 +1,5 @@
function PauseKeyPressed(key)
if key == "return" then
-- quickly return to the game
musicBattle:setVolume(0.5)
musicPause:setVolume(0)
-- 0 Return to game

@ -1,33 +0,0 @@
local function winner()
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
local opacity = 0.3
local s = ""
if _G.P1_WIN then
s = "P1 Win! R - Restart"
elseif _G.P2_WIN then
s = "P2 Win! R - Restart"
end
if _G.P1_WIN or _G.P2_WIN then
-- Overlay
DrawGame() --Draw a single frame of the game
love.graphics.setColor(0.1, 0.1, 0.1, opacity) --overlay opaque img
love.graphics.rectangle("fill", 0, 0, width, height)
-- Who won text
local sw, sh = MenuFont:getWidth(s), GameFont:getHeight(s)
local centreX = width / 2
local centreY = height / 2
love.graphics.setFont(MenuFont)
love.graphics.setColor(1, 1, 1) -- white
love.graphics.print(s, centreX - sw / 2, centreY - sh / 2)
end
end
function DrawWin()
winner()
love.graphics.setColor(255, 255, 255) -- reset colours
end

@ -1 +0,0 @@
function UpdateWin(dt) end

@ -1,7 +0,0 @@
function WinKeyPressed(key)
if key == "r" then
RestartGame()
_G.GAMESTATE = "GAME"
love.load()
end
end

@ -15,14 +15,6 @@ PAUSED = false
PAUSE_POS = 0
PAUSE_MAX = 2 -- 0 resume, 1 menu, 2 quit
BULLETS_MAX = 10 -- MAX amount of bullets a player can shoot
--BULLETS_BOUCE_MAX = 7 -- MAX amount of bounces before exploding!
BULLETS_LIFETIME = 50
-- WIN flags for P1 and P2
P1_WIN = false
P2_WIN = false
-- WIN counts!
P1_COUNT = 0
P2_COUNT = 0

Binary file not shown.

@ -1,49 +0,0 @@
-- Functions to handle restarting
-- all objects
-- Used in map switching and restarting!
function ClearWalls()
for w in pairs(Walls) do
Walls[w] = nil
end
Walls = {}
end
function StopAllMusic()
-- TODO: maybe find a way
-- to find all 'streaming'
-- sounds and then stop them all!
musicBattle:stop()
musicMenu:stop()
musicPause:stop()
--musicStory:stop() -- Unused
end
function ClearPlayerCollision()
UserPlayer1.collider:destroy()
UserPlayer2.collider:destroy()
end
function ClearBullets(bullets)
for i, v in ipairs(bullets) do
v.collider:destroy()
end
end
function RestartGame()
-- Stop the music
StopAllMusic()
-- Clear the players collision
ClearPlayerCollision()
-- Work through and delete all bullets
ClearBullets(Bullets1)
ClearBullets(Bullets2)
--Clear Walls
--ClearWalls()
-- Done!
end

@ -1,14 +1,4 @@
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")
function love.run()
if love.load then
@ -66,25 +56,40 @@ end
function love.load()
Object = require("libs/classic")
require("libs/restart")
require("player")
require("bullet")
require("mapsloader")
WF = require("libs/windfield")
STI = require("libs/sti")
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")
require("mapsloader")
--WindField
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")
World:addCollisionClass("New") -- Used to make sure the bullet doesn't collide with the player that shot it
--STI Map
loadMap(1)
--Fonts used in the game
GameFont = love.graphics.newFont("assets/Daydream.ttf", 60)
@ -94,13 +99,12 @@ function love.load()
--Game consts
HEALTH = 3
DELAY = 0.5
MAX = 6 --MAX number of bullets|
--Bullet lists
Bullets1 = {}
Bullets2 = {}
Walls = {}
DebugFlag = false
EnableKeyPress1 = true
KeyPressTime1 = 0
@ -115,9 +119,9 @@ function love.load()
UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", playerSpeed)
-- 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
musicMenu = love.audio.newSource("music/menu.mp3", "stream")
musicBattle = love.audio.newSource("music/battle.mp3", "stream")
musicStory = love.audio.newSource("music/story.mp3", "stream")
musicPause = musicBattle:clone()
musicPause:setFilter({
@ -125,9 +129,6 @@ function love.load()
volume = 0.7,
highgain = 0.4,
})
--STI Map loading
LoadMap(1)
end
function love.keypressed(key)
@ -140,9 +141,6 @@ function love.keypressed(key)
if _G.GAMESTATE == "GAME" then
GameKeyPressed(key)
end
if _G.GAMESTATE == "WIN" then
WinKeyPressed(key)
end
end
function love.update(dt)
@ -175,7 +173,9 @@ function love.update(dt)
end
end
if _G.GAMESTATE == "WIN" then
UpdateWin(dt)
print(P1_WIN)
print(P2_WIN)
love.event.quit()
end
end
@ -194,7 +194,4 @@ function love.draw()
love.graphics.print("" .. GAMESTATE, 200, 200)
end
end
if _G.GAMESTATE == "WIN" then
DrawWin()
end
end

@ -1,12 +1,10 @@
function LoadMap(lvl)
ClearWalls()
function loadMap(lvl)
local mapfilelocation = "maps/"
local extention = ".lua"
local mapname = mapfilelocation .. "map" .. lvl .. extention
GameMap = STI(mapname)
--Walls = {}
Walls = {}
if GameMap.layers["Walls"] then
for _, obj in ipairs(GameMap.layers["Walls"].objects) do
local wall = World:newRectangleCollider(obj.x, obj.y, obj.width, obj.height)

@ -35,24 +35,16 @@ function Player:new(p, x, y, health, image, speed, max)
--Velocity
self.vx = 0
self.vy = 0
-- Bullets shot
self.shot = 0
end
-- Method to handle shooting
function Player:shoot(bulletSpeed)
if self.shot <= 10 then
self.shot = self.shot + 1
local offsetX = cos(self.rotation) * self.width * 1.5
local offsetY = sin(self.rotation) * self.height * 1.5
local bulletX = self.x + offsetX
local bulletY = self.y + offsetY
local newBullet = Bullet(bulletX, bulletY, self.p, bulletSpeed, self.rotation)
return newBullet
else
return nil
end
local offsetX = cos(self.rotation) * self.width * 1.5
local offsetY = sin(self.rotation) * self.height * 1.5
local bulletX = self.x + offsetX
local bulletY = self.y + offsetY
local newBullet = Bullet(bulletX, bulletY, self.p, bulletSpeed, self.rotation)
return newBullet
end
function Player:handleKeys(up, down, left, right, dt)

Loading…
Cancel
Save