Compare commits

...

10 Commits

Author SHA1 Message Date
Simon Kellet f689632a92 better wall init and clearing 2 months ago
Simon Kellet da8bb7d083 removed unused music stops 2 months ago
Simon Kellet 0a25d11ac5 hitbox now circle and slower going backwards 2 months ago
Simon Kellet 71d1f6e929 changed 2 months ago
Simon Kellet a392755844 global tracker of current level 2 months ago
Simon Kellet f4d3969a1f new map for testing 2 months ago
Simon Kellet 2cd9f263e6 walls now properly get destoryed 2 months ago
Simon Kellet ff40a5507b draws score 2 months ago
Simon Kellet 26398f52b5 fixed wins 2 months ago
Simon Kellet 38826d0cd8 debug keys 2 months ago
  1. 12
      Game/GameKeyPressed.lua
  2. 10
      Game/UpdateGame.lua
  3. 1
      Menu/MenuKeyPressed.lua
  4. 11
      Win/DrawWin.lua
  5. 3
      constants.lua
  6. 10
      libs/restart.lua
  7. 24
      main.lua
  8. 290
      maps/map2.lua
  9. 61
      maps/map2.tmx
  10. 4
      mapsloader.lua
  11. 11
      player.lua

@ -18,4 +18,16 @@ function GameKeyPressed(key)
_G.GAMESTATE = "GAME"
love.load()
end
-- debug map changes!
if DebugFlag and key == "1" then
_G.CUR_LEVEL = 1
RestartGame()
love.load()
end
if DebugFlag and key == "2" then
_G.CUR_LEVEL = 2
RestartGame()
love.load()
end
end

@ -1,12 +1,14 @@
local function checkWinState()
local function checkLossState()
-- Check P1's health
if UserPlayer1.health <= 0 then --P1 win
if UserPlayer1.health <= 0 then --P1 Lost, P2 Win
_G.P2_COUNT = _G.P2_COUNT + 1
_G.P1_WIN = false
_G.P2_WIN = true
return true
end
if UserPlayer2.health <= 0 then --P2 win
if UserPlayer2.health <= 0 then --P2 Lost, P1 Win
_G.P1_COUNT = _G.P1_COUNT + 1
_G.P1_WIN = true
_G.P2_WIN = false
return true
@ -18,7 +20,7 @@ local max = math.max -- optimisations
function UpdateGame(dt)
--Check if anyone has won
if checkWinState() == true then
if checkLossState() == true then
print("STATE CHNAGED: WIN!")
_G.GAMESTATE = "WIN"
end

@ -38,7 +38,6 @@ function MenuKeyPressed(key)
musicBattle:stop()
musicMenu:stop()
musicPause:stop()
musicStory:stop()
_G.GAMESTATE = "MENU"
love.load()
end

@ -4,9 +4,9 @@ local function winner()
local opacity = 0.3
local s = ""
if _G.P1_WIN then
if not _G.P1_WIN then
s = "P1 Win! R - Restart"
elseif _G.P2_WIN then
elseif not _G.P2_WIN then
s = "P2 Win! R - Restart"
end
@ -23,7 +23,12 @@ local function winner()
love.graphics.setFont(MenuFont)
love.graphics.setColor(1, 1, 1) -- white
love.graphics.print(s, centreX - sw / 2, centreY - sh / 2)
love.graphics.print(s, centreX - sw / 2, centreY - sh / 2) -- who won
love.graphics.print(
"" .. _G.P1_COUNT .. ":" .. "" .. _G.P2_COUNT,
(centreX - sw / 2),
(centreY - sh / 2) - sh / 1.5
) -- score
end
end

@ -26,3 +26,6 @@ P2_WIN = false
-- WIN counts!
P1_COUNT = 0
P2_COUNT = 0
-- Current Level
CUR_LEVEL = 1

@ -2,12 +2,10 @@
-- all objects
-- Used in map switching and restarting!
function ClearWalls()
for w in pairs(Walls) do
Walls[w] = nil
function ClearWalls(walls)
for i = #walls, 1, -1 do
walls[i]:destroy()
end
Walls = {}
end
function StopAllMusic()
@ -43,7 +41,7 @@ function RestartGame()
ClearBullets(Bullets2)
--Clear Walls
--ClearWalls()
ClearWalls(Walls)
-- Done!
end

@ -10,6 +10,12 @@ World:addCollisionClass("Player2")
World:addCollisionClass("Bullet2")
World:addCollisionClass("Wall")
--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 = {}
function love.run()
if love.load then
love.load(love.arg.parseGameArguments(arg), arg)
@ -86,10 +92,8 @@ function love.load()
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)
-- Set a random seed
love.math.setRandomSeed(love.timer.getTime())
--Game consts
HEALTH = 3
@ -99,8 +103,6 @@ function love.load()
Bullets1 = {}
Bullets2 = {}
Walls = {}
DebugFlag = false
EnableKeyPress1 = true
KeyPressTime1 = 0
@ -127,7 +129,7 @@ function love.load()
})
--STI Map loading
LoadMap(1)
LoadMap(_G.CUR_LEVEL)
end
function love.keypressed(key)
@ -158,8 +160,8 @@ function love.update(dt)
UpdatePause(dt)
-- Handle music
if not musicPause:isPlaying() then
--musicBattle:setVolume(0)
--musicPause:setVolume(0.5)
musicBattle:setVolume(0)
musicPause:setVolume(0.5)
love.audio.play(musicBattle)
love.audio.play(musicPause)
end
@ -168,8 +170,8 @@ function love.update(dt)
UpdateGame(dt)
-- Handle music
if not musicBattle:isPlaying() then
--musicBattle:setVolume(0.5)
--musicPause:setVolume(0)
musicBattle:setVolume(0.5)
musicPause:setVolume(0)
love.audio.play(musicBattle)
love.audio.play(musicPause)
end

@ -0,0 +1,290 @@
return {
version = "1.10",
luaversion = "5.1",
tiledversion = "1.11.0",
class = "",
orientation = "orthogonal",
renderorder = "right-down",
width = 25,
height = 15,
tilewidth = 64,
tileheight = 64,
nextlayerid = 4,
nextobjectid = 16,
properties = {},
tilesets = {
{
name = "floor",
firstgid = 1,
class = "",
tilewidth = 64,
tileheight = 64,
spacing = 0,
margin = 0,
columns = 9,
image = "../assets/tileset.png",
imagewidth = 576,
imageheight = 384,
objectalignment = "unspecified",
tilerendersize = "tile",
fillmode = "stretch",
tileoffset = {
x = 0,
y = 0
},
grid = {
orientation = "orthogonal",
width = 64,
height = 64
},
properties = {},
wangsets = {},
tilecount = 54,
tiles = {}
}
},
layers = {
{
type = "tilelayer",
x = 0,
y = 0,
width = 25,
height = 15,
id = 1,
name = "floor",
class = "",
visible = true,
opacity = 1,
offsetx = 0,
offsety = 0,
parallaxx = 1,
parallaxy = 1,
properties = {},
encoding = "lua",
data = {
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21
}
},
{
type = "tilelayer",
x = 0,
y = 0,
width = 25,
height = 15,
id = 2,
name = "inner walls",
class = "",
visible = true,
opacity = 1,
offsetx = 0,
offsety = 0,
parallaxx = 1,
parallaxy = 1,
properties = {},
encoding = "lua",
data = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 29, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 28, 29, 29, 29, 29, 29, 30, 0, 0, 37, 38, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 37, 38, 38, 38, 38, 38, 39, 0, 0, 46, 47, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 46, 47, 38, 38, 38, 47, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 37, 38, 39, 0, 0, 0, 0, 28, 29, 30, 0, 0, 0, 0, 28, 29, 30, 0, 0, 0, 0,
0, 0, 0, 0, 37, 38, 39, 0, 0, 0, 0, 37, 38, 39, 0, 0, 0, 0, 37, 38, 39, 0, 0, 0, 0,
0, 0, 0, 0, 37, 38, 39, 0, 0, 0, 0, 37, 38, 39, 0, 0, 0, 0, 37, 38, 39, 0, 0, 0, 0,
0, 0, 0, 0, 37, 38, 39, 0, 0, 0, 0, 37, 38, 39, 0, 0, 0, 0, 37, 38, 39, 0, 0, 0, 0,
0, 0, 0, 0, 46, 47, 48, 0, 0, 0, 0, 46, 47, 48, 0, 0, 0, 0, 37, 38, 39, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 29, 38, 38, 38, 29, 30, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 29, 30, 0, 0, 37, 38, 38, 38, 38, 38, 39, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 38, 39, 0, 0, 46, 47, 47, 47, 47, 47, 48, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46, 47, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}
},
{
type = "objectgroup",
draworder = "topdown",
id = 3,
name = "Walls",
class = "",
visible = false,
opacity = 1,
offsetx = 0,
offsety = 0,
parallaxx = 1,
parallaxy = 1,
properties = {},
objects = {
{
id = 1,
name = "",
type = "",
shape = "rectangle",
x = 128,
y = 128,
width = 448,
height = 192,
rotation = 0,
visible = true,
properties = {}
},
{
id = 2,
name = "",
type = "",
shape = "rectangle",
x = 256,
y = 320,
width = 192,
height = 320,
rotation = 0,
visible = true,
properties = {}
},
{
id = 3,
name = "",
type = "",
shape = "rectangle",
x = 704,
y = 80,
width = 192,
height = 176,
rotation = 0,
visible = true,
properties = {}
},
{
id = 4,
name = "",
type = "",
shape = "rectangle",
x = 704,
y = 320,
width = 192,
height = 320,
rotation = 0,
visible = true,
properties = {}
},
{
id = 5,
name = "",
type = "",
shape = "rectangle",
x = 704,
y = 704,
width = 192,
height = 192,
rotation = 0,
visible = true,
properties = {}
},
{
id = 6,
name = "",
type = "",
shape = "rectangle",
x = 1024,
y = 640,
width = 448,
height = 192,
rotation = 0,
visible = true,
properties = {}
},
{
id = 7,
name = "",
type = "",
shape = "rectangle",
x = 1152,
y = 320,
width = 192,
height = 320,
rotation = 0,
visible = true,
properties = {}
},
{
id = 9,
name = "",
type = "",
shape = "rectangle",
x = 0,
y = 0,
width = 1184,
height = 16,
rotation = 0,
visible = true,
properties = {}
},
{
id = 10,
name = "",
type = "",
shape = "rectangle",
x = 1184,
y = 0,
width = 416,
height = 16,
rotation = 0,
visible = true,
properties = {}
},
{
id = 11,
name = "",
type = "",
shape = "rectangle",
x = 1584,
y = 0,
width = 16,
height = 960,
rotation = 0,
visible = true,
properties = {}
},
{
id = 12,
name = "",
type = "",
shape = "rectangle",
x = 0,
y = 944,
width = 1600,
height = 16,
rotation = 0,
visible = true,
properties = {}
},
{
id = 13,
name = "",
type = "",
shape = "rectangle",
x = 0,
y = 0,
width = 16,
height = 960,
rotation = 0,
visible = true,
properties = {}
}
}
}
}
}

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="25" height="15" tilewidth="64" tileheight="64" infinite="0" nextlayerid="4" nextobjectid="16">
<editorsettings>
<export target="map2.lua" format="lua"/>
</editorsettings>
<tileset firstgid="1" name="floor" tilewidth="64" tileheight="64" tilecount="54" columns="9">
<image source="../assets/tileset.png" width="576" height="384"/>
</tileset>
<layer id="1" name="floor" width="25" height="15">
<data encoding="csv">
1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,
19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21
</data>
</layer>
<layer id="2" name="inner walls" width="25" height="15">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,28,29,30,0,0,0,0,0,0,0,0,0,0,0,
0,0,28,29,29,29,29,29,30,0,0,37,38,39,0,0,0,0,0,0,0,0,0,0,0,
0,0,37,38,38,38,38,38,39,0,0,46,47,48,0,0,0,0,0,0,0,0,0,0,0,
0,0,46,47,38,38,38,47,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,37,38,39,0,0,0,0,28,29,30,0,0,0,0,28,29,30,0,0,0,0,
0,0,0,0,37,38,39,0,0,0,0,37,38,39,0,0,0,0,37,38,39,0,0,0,0,
0,0,0,0,37,38,39,0,0,0,0,37,38,39,0,0,0,0,37,38,39,0,0,0,0,
0,0,0,0,37,38,39,0,0,0,0,37,38,39,0,0,0,0,37,38,39,0,0,0,0,
0,0,0,0,46,47,48,0,0,0,0,46,47,48,0,0,0,0,37,38,39,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,29,38,38,38,29,30,0,0,
0,0,0,0,0,0,0,0,0,0,0,28,29,30,0,0,37,38,38,38,38,38,39,0,0,
0,0,0,0,0,0,0,0,0,0,0,37,38,39,0,0,46,47,47,47,47,47,48,0,0,
0,0,0,0,0,0,0,0,0,0,0,46,47,48,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<objectgroup id="3" name="Walls" visible="0">
<object id="1" x="128" y="128" width="448" height="192"/>
<object id="2" x="256" y="320" width="192" height="320"/>
<object id="3" x="704" y="80" width="192" height="176"/>
<object id="4" x="704" y="320" width="192" height="320"/>
<object id="5" x="704" y="704" width="192" height="192"/>
<object id="6" x="1024" y="640" width="448" height="192"/>
<object id="7" x="1152" y="320" width="192" height="320"/>
<object id="9" x="0" y="0" width="1184" height="16"/>
<object id="10" x="1184" y="0" width="416" height="16"/>
<object id="11" x="1584" y="0" width="16" height="960"/>
<object id="12" x="0" y="944" width="1600" height="16"/>
<object id="13" x="0" y="0" width="16" height="960"/>
</objectgroup>
</map>

@ -1,12 +1,10 @@
function LoadMap(lvl)
ClearWalls()
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)

@ -3,19 +3,19 @@ cos = math.cos
sin = math.sin --optimisation
-- Constructor for the Player class
function Player:new(p, x, y, health, image, speed, max)
function Player:new(p, x, y, health, image, speed)
self.p = p
self.image = love.graphics.newImage(image)
self.x = x
self.y = y
self.health = health
self.speed = speed
self.max = max
self.width = self.image:getWidth()
self.height = self.image:getHeight()
-- Collision Stuff
self.collider = World:newRectangleCollider(x, y, 64, 64)
--self.collider = World:newRectangleCollider(x, y, 50, 62)
self.collider = World:newCircleCollider(x, y, 24)
self.collider:setFixedRotation(true)
if self.p == 1 then
@ -61,14 +61,13 @@ function Player:handleKeys(up, down, left, right, dt)
self.vx = cos(self.rotation) * (self.speed * dt)
self.vy = sin(self.rotation) * (self.speed * dt)
elseif love.keyboard.isDown(down) then
self.vx = cos(self.rotation) * (self.speed * dt) * -1
self.vy = sin(self.rotation) * (self.speed * dt) * -1
self.vx = cos(self.rotation) * (self.speed / 2 * dt) * -1
self.vy = sin(self.rotation) * (self.speed / 2 * dt) * -1
elseif love.keyboard.isDown(left) then
self.rotation = self.rotation - (self.rotSpeed * dt)
elseif love.keyboard.isDown(right) then
self.rotation = self.rotation + (self.rotSpeed * dt)
end
self.collider:setLinearVelocity(self.vx, self.vy)
end

Loading…
Cancel
Save