making menu and subfolders

main
Simon Kellet 2 months ago
parent a3f90645fd
commit 99f0323635
  1. 6
      Game/DrawGame.lua
  2. 2
      Game/GameKeyPressed.lua
  3. 0
      Game/UpdateGame.lua
  4. 10
      Menu/DrawMenu.lua
  5. 10
      Menu/MenuKeyPressed.lua
  6. 2
      Menu/UpdateMenu.lua
  7. 36
      bullet.lua
  8. BIN
      game.love
  9. 41
      main.lua
  10. 6
      maps/map.tmx
  11. 1023
      maps/map1.lua
  12. 24
      mapsloader.lua
  13. 10
      player.lua

@ -1,10 +1,10 @@
function drawFPS() local function drawFPS()
love.graphics.setColor(1, 1, 1) -- RGB values for white are (1, 1, 1) love.graphics.setColor(1, 1, 1) -- RGB values for white are (1, 1, 1)
love.graphics.setFont(DebugFont) love.graphics.setFont(DebugFont)
love.graphics.print("FPS: " .. love.timer.getFPS(), 1520, 10) love.graphics.print("FPS: " .. love.timer.getFPS(), 1520, 10)
end end
function drawHealth() local function drawHealth()
love.graphics.setFont(GameFont) love.graphics.setFont(GameFont)
local height = love.graphics.getHeight() local height = love.graphics.getHeight()
local width = love.graphics.getWidth() local width = love.graphics.getWidth()
@ -15,6 +15,7 @@ end
function DrawGame() function DrawGame()
--STI --STI
GameMap:draw() GameMap:draw()
-- WindField -- WindField
if DebugFlag then if DebugFlag then
World:draw() World:draw()
@ -27,6 +28,7 @@ function DrawGame()
for _, v in ipairs(Bullets2) do for _, v in ipairs(Bullets2) do
v:draw() v:draw()
end end
UserPlayer1:draw() UserPlayer1:draw()
UserPlayer2:draw() UserPlayer2:draw()

@ -1,4 +1,4 @@
function KeyPressed(key) function GameKeyPressed(key)
if key == "escape" then if key == "escape" then
love.event.quit() love.event.quit()
end end

@ -0,0 +1,10 @@
function DrawMenu()
love.graphics.setFont(GameFont)
local height = love.graphics.getHeight()
local width = love.graphics.getWidth()
love.graphics.setColor(1,1,1)
love.graphics.rectangle("fill", 0, 0, width, height)
love.graphics.setColor(0,0,0)
love.graphics.print("MENU", 100,100)
end

@ -0,0 +1,10 @@
function MenuKeyPressed(key)
if key == "escape" then
love.event.quit()
end
if key == "space" then
--Change state to GAME!
GAMESTATE = "GAME"
end
end

@ -0,0 +1,2 @@
function UpdateMenu(dt)
end

@ -1,6 +1,7 @@
Bullet = Object:extend() Bullet = Object:extend()
cos = math.cos cos = math.cos
sin = math.sin --optimisation sin = math.sin --optimisation
pi = math.pi
function Bullet:new(x, y, p, speed, rotation) function Bullet:new(x, y, p, speed, rotation)
self.image = love.graphics.newImage("assets/bullet.png") self.image = love.graphics.newImage("assets/bullet.png")
@ -19,43 +20,44 @@ function Bullet:new(x, y, p, speed, rotation)
self.originY = self.height / 2 self.originY = self.height / 2
self.collider = World:newCircleCollider(x, y, 10) self.collider = World:newCircleCollider(x, y, 10)
self.collider:setFixedRotation(true)
self.collider:setPosition(self.x, self.y) self.collider:setPosition(self.x, self.y)
end
function Bullet:update(dt)
--New bullets are set to New Collision Class
--this is to make sure the bullet doesn't collide with the player that shot it
if self.p == 1 or self.p == 2 then
self.collider:setCollisionClass("New")
end
if self.p == 1 then if self.p == 1 then
self.collider:setCollisionClass("Bullet1") self.collider:setCollisionClass("Bullet1")
elseif self.p == 2 then elseif self.p == 2 then
self.collider:setCollisionClass("Bullet2") self.collider:setCollisionClass("Bullet2")
end end
end
if self.p == 1 then function Bullet:update(dt)
local dx = cos(self.rotation) * self.speed * dt
local dy = sin(self.rotation) * self.speed * dt
self.collider:setLinearVelocity(dx, dy)
self.x = self.collider:getX()
self.y = self.collider:getY()
--If a bullet hits a wall, make it bounce off the wall and change its rotation --If a bullet hits a wall, make it bounce off the wall and change its rotation
if self.p == 1 then
if self.collider:enter("Wall") then if self.collider:enter("Wall") then
self.rotation = self.rotation + math.pi --calculate normal of the wall
--calculate the angle of reflection
local angle = (math.atan2(dx, dy))
--get normal of the wall without using getNormal()
----TODO: fix this
--set the new angle
self.rotation = angle
self.collider:setAngle(self.rotation) self.collider:setAngle(self.rotation)
end end
dx = cos(self.rotation) * self.speed * dt
dy = sin(self.rotation) * self.speed * dt
self.collider:setLinearVelocity(dx, dy)
end end
if self.p == 2 then if self.p == 2 then
local dx = cos(self.rotation) * self.speed * dt local dx = cos(self.rotation) * self.speed * dt
local dy = sin(self.rotation) * self.speed * dt local dy = sin(self.rotation) * self.speed * dt
self.collider:setLinearVelocity(dx, dy) self.collider:setLinearVelocity(dx, dy)
end
self.x = self.collider:getX() self.x = self.collider:getX()
self.y = self.collider:getY() self.y = self.collider:getY()
end
end end
function Bullet:draw() function Bullet:draw()

Binary file not shown.

@ -1,13 +1,22 @@
GAMESTATE = "MENU"
function love.load() function love.load()
Object = require("classic") Object = require("classic")
require("player") require("player")
require("bullet") require("bullet")
require("menu")
WF = require("libs/windfield") WF = require("libs/windfield")
STI = require("libs/sti") STI = require("libs/sti")
require("UpdateGame") require("UpdateGame")
require("UpdateMenu")
require("DrawGame") require("DrawGame")
require("KeyPressed") require("DrawMenu")
require("GameKeyPressed")
require("MenuKeyPressed")
require("mapsloader")
--WindField --WindField
World = WF.newWorld(0, 0) --no gravity World = WF.newWorld(0, 0) --no gravity
@ -21,7 +30,8 @@ function love.load()
World:addCollisionClass("Wall") World:addCollisionClass("Wall")
World:addCollisionClass("New") -- Used to make sure the bullet doesn't collide with the player that shot it World:addCollisionClass("New") -- Used to make sure the bullet doesn't collide with the player that shot it
--STI --STI Map
--Making the map have collision
GameMap = STI("maps/map.lua") GameMap = STI("maps/map.lua")
Walls = {} Walls = {}
if GameMap.layers["Walls"] then if GameMap.layers["Walls"] then
@ -38,8 +48,10 @@ function love.load()
DebugFont = love.graphics.newFont("assets/Daydream.ttf", 12) DebugFont = love.graphics.newFont("assets/Daydream.ttf", 12)
love.graphics.setFont(GameFont) love.graphics.setFont(GameFont)
--Game consts
HEALTH = 3 HEALTH = 3
DELAY = 0.5 DELAY = 0.5
MAX = 6 --MAX number of bullets
DebugFlag = false DebugFlag = false
EnableKeyPress1 = true EnableKeyPress1 = true
KeyPressTime1 = 0 KeyPressTime1 = 0
@ -56,18 +68,41 @@ function love.load()
end end
function love.keypressed(key) function love.keypressed(key)
KeyPressed(key)
if GAMESTATE == "MENU" then
MenuKeyPressed(key)
end
if GAMESTATE == "GAME" then
GameKeyPressed(key)
end
end end
function love.update(dt) function love.update(dt)
if GAMESTATE == "MENU" then
UpdateMenu(dt)
end
if GAMESTATE == "GAME" then
UpdateGame(dt) UpdateGame(dt)
end
end end
function love.draw() function love.draw()
--TODO: SWITCH/CASE this!
if GAMESTATE == "MENU" then
DrawMenu()
end
if GAMESTATE == "GAME" then
DrawGame() DrawGame()
if DebugFlag then if DebugFlag then
love.graphics.setFont(DebugFont) love.graphics.setFont(DebugFont)
love.graphics.print("Debug Mode", 1200, 850) love.graphics.print("Debug Mode", 1200, 850)
--love.graphics.print(love.report or "Please wait...") --love.graphics.print(love.report or "Please wait...")
end end
end
end end

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="25" height="15" tilewidth="64" tileheight="64" infinite="0" nextlayerid="5" nextobjectid="24"> <map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="25" height="15" tilewidth="64" tileheight="64" infinite="0" nextlayerid="5" nextobjectid="36">
<editorsettings> <editorsettings>
<export target="map.lua" format="lua"/> <export target="map.lua" format="lua"/>
</editorsettings> </editorsettings>
@ -54,5 +54,9 @@
<object id="21" x="256" y="384" width="192" height="192"/> <object id="21" x="256" y="384" width="192" height="192"/>
<object id="22" x="128" y="448" width="192" height="320"/> <object id="22" x="128" y="448" width="192" height="320"/>
<object id="23" x="128" y="768" width="128" height="64"/> <object id="23" x="128" y="768" width="128" height="64"/>
<object id="30" x="0" y="0" width="16" height="960"/>
<object id="31" x="1584" y="0" width="16" height="960"/>
<object id="32" x="0" y="0" width="1600" height="16"/>
<object id="33" x="0" y="944" width="1600" height="16"/>
</objectgroup> </objectgroup>
</map> </map>

File diff suppressed because it is too large Load Diff

@ -0,0 +1,24 @@
function LoadMap(lvlnum)
--TODO: FINISH THIS
local mapfilelocation = "maps/"
local extention = ".lua"
--unload the current map
if GameMap then
GameMap:removeLayer("Walls")
end
--load the new map
GameMap = mapfilelocation .. "map" .. lvlnum .. extention
--load the new map's 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)
wall:setType("static")
table.insert(Walls, wall)
Walls[#Walls]:setCollisionClass("Wall")
end
end
end

@ -3,13 +3,14 @@ cos = math.cos
sin = math.sin --optimisation sin = math.sin --optimisation
-- Constructor for the Player class -- Constructor for the Player class
function Player:new(p, x, y, health, image, speed) function Player:new(p, x, y, health, image, speed, max)
self.p = p self.p = p
self.image = love.graphics.newImage(image) self.image = love.graphics.newImage(image)
self.x = x self.x = x
self.y = y self.y = y
self.health = health self.health = health
self.speed = speed self.speed = speed
self.max = max
self.width = self.image:getWidth() self.width = self.image:getWidth()
self.height = self.image:getHeight() self.height = self.image:getHeight()
@ -65,6 +66,7 @@ function Player:update(dt)
elseif love.keyboard.isDown("d") then elseif love.keyboard.isDown("d") then
self.rotation = self.rotation + (self.rotSpeed * dt) self.rotation = self.rotation + (self.rotSpeed * dt)
end end
self.collider:setLinearVelocity(self.vx, self.vy) self.collider:setLinearVelocity(self.vx, self.vy)
-- Check for collision with walls -- Check for collision with walls
@ -82,6 +84,12 @@ function Player:update(dt)
end end
self.x = self.collider:getX() self.x = self.collider:getX()
self.y = self.collider:getY() self.y = self.collider:getY()
-- Handlle map changes
if love.keyboard.isDown("1") then
LoadMap("1")
print("Map 1 loaded")
end
elseif self.p == 2 then elseif self.p == 2 then
-- Handle player 2 controls -- Handle player 2 controls
if love.keyboard.isDown("up") then if love.keyboard.isDown("up") then

Loading…
Cancel
Save