making menu and subfolders
This commit is contained in:
parent
a3f90645fd
commit
99f0323635
@ -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.setFont(DebugFont)
|
||||
love.graphics.print("FPS: " .. love.timer.getFPS(), 1520, 10)
|
||||
end
|
||||
|
||||
function drawHealth()
|
||||
local function drawHealth()
|
||||
love.graphics.setFont(GameFont)
|
||||
local height = love.graphics.getHeight()
|
||||
local width = love.graphics.getWidth()
|
||||
@ -15,6 +15,7 @@ end
|
||||
function DrawGame()
|
||||
--STI
|
||||
GameMap:draw()
|
||||
|
||||
-- WindField
|
||||
if DebugFlag then
|
||||
World:draw()
|
||||
@ -27,6 +28,7 @@ function DrawGame()
|
||||
for _, v in ipairs(Bullets2) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
UserPlayer1:draw()
|
||||
UserPlayer2:draw()
|
||||
|
@ -1,4 +1,4 @@
|
||||
function KeyPressed(key)
|
||||
function GameKeyPressed(key)
|
||||
if key == "escape" then
|
||||
love.event.quit()
|
||||
end
|
10
Menu/DrawMenu.lua
Normal file
10
Menu/DrawMenu.lua
Normal file
@ -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
|
10
Menu/MenuKeyPressed.lua
Normal file
10
Menu/MenuKeyPressed.lua
Normal file
@ -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
|
2
Menu/UpdateMenu.lua
Normal file
2
Menu/UpdateMenu.lua
Normal file
@ -0,0 +1,2 @@
|
||||
function UpdateMenu(dt)
|
||||
end
|
38
bullet.lua
38
bullet.lua
@ -1,6 +1,7 @@
|
||||
Bullet = Object:extend()
|
||||
cos = math.cos
|
||||
sin = math.sin --optimisation
|
||||
pi = math.pi
|
||||
|
||||
function Bullet:new(x, y, p, speed, rotation)
|
||||
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.collider = World:newCircleCollider(x, y, 10)
|
||||
self.collider:setFixedRotation(true)
|
||||
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
|
||||
self.collider:setCollisionClass("Bullet1")
|
||||
elseif self.p == 2 then
|
||||
self.collider:setCollisionClass("Bullet2")
|
||||
end
|
||||
end
|
||||
|
||||
function Bullet:update(dt)
|
||||
--If a bullet hits a wall, make it bounce off the wall and change its rotation
|
||||
if self.p == 1 then
|
||||
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 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)
|
||||
end
|
||||
dx = cos(self.rotation) * self.speed * dt
|
||||
dy = sin(self.rotation) * self.speed * dt
|
||||
self.collider:setLinearVelocity(dx, dy)
|
||||
end
|
||||
|
||||
if self.p == 2 then
|
||||
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()
|
||||
end
|
||||
|
||||
self.x = self.collider:getX()
|
||||
self.y = self.collider:getY()
|
||||
end
|
||||
|
||||
function Bullet:draw()
|
||||
|
53
main.lua
53
main.lua
@ -1,13 +1,22 @@
|
||||
GAMESTATE = "MENU"
|
||||
|
||||
function love.load()
|
||||
Object = require("classic")
|
||||
require("player")
|
||||
require("bullet")
|
||||
require("menu")
|
||||
WF = require("libs/windfield")
|
||||
STI = require("libs/sti")
|
||||
|
||||
require("UpdateGame")
|
||||
require("UpdateMenu")
|
||||
|
||||
require("DrawGame")
|
||||
require("KeyPressed")
|
||||
require("DrawMenu")
|
||||
|
||||
require("GameKeyPressed")
|
||||
require("MenuKeyPressed")
|
||||
require("mapsloader")
|
||||
|
||||
--WindField
|
||||
World = WF.newWorld(0, 0) --no gravity
|
||||
@ -21,7 +30,8 @@ function love.load()
|
||||
World:addCollisionClass("Wall")
|
||||
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")
|
||||
Walls = {}
|
||||
if GameMap.layers["Walls"] then
|
||||
@ -38,8 +48,10 @@ function love.load()
|
||||
DebugFont = love.graphics.newFont("assets/Daydream.ttf", 12)
|
||||
love.graphics.setFont(GameFont)
|
||||
|
||||
--Game consts
|
||||
HEALTH = 3
|
||||
DELAY = 0.5
|
||||
MAX = 6 --MAX number of bullets
|
||||
DebugFlag = false
|
||||
EnableKeyPress1 = true
|
||||
KeyPressTime1 = 0
|
||||
@ -56,18 +68,41 @@ function love.load()
|
||||
end
|
||||
|
||||
function love.keypressed(key)
|
||||
KeyPressed(key)
|
||||
|
||||
if GAMESTATE == "MENU" then
|
||||
MenuKeyPressed(key)
|
||||
end
|
||||
|
||||
if GAMESTATE == "GAME" then
|
||||
GameKeyPressed(key)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function love.update(dt)
|
||||
UpdateGame(dt)
|
||||
if GAMESTATE == "MENU" then
|
||||
UpdateMenu(dt)
|
||||
end
|
||||
|
||||
if GAMESTATE == "GAME" then
|
||||
UpdateGame(dt)
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
DrawGame()
|
||||
if DebugFlag then
|
||||
love.graphics.setFont(DebugFont)
|
||||
love.graphics.print("Debug Mode", 1200, 850)
|
||||
--love.graphics.print(love.report or "Please wait...")
|
||||
|
||||
--TODO: SWITCH/CASE this!
|
||||
if GAMESTATE == "MENU" then
|
||||
DrawMenu()
|
||||
end
|
||||
|
||||
if GAMESTATE == "GAME" then
|
||||
DrawGame()
|
||||
if DebugFlag then
|
||||
love.graphics.setFont(DebugFont)
|
||||
love.graphics.print("Debug Mode", 1200, 850)
|
||||
--love.graphics.print(love.report or "Please wait...")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?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>
|
||||
<export target="map.lua" format="lua"/>
|
||||
</editorsettings>
|
||||
@ -54,5 +54,9 @@
|
||||
<object id="21" x="256" y="384" width="192" height="192"/>
|
||||
<object id="22" x="128" y="448" width="192" height="320"/>
|
||||
<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>
|
||||
</map>
|
||||
|
1023
maps/map1.lua
Normal file
1023
maps/map1.lua
Normal file
File diff suppressed because it is too large
Load Diff
24
mapsloader.lua
Normal file
24
mapsloader.lua
Normal file
@ -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
|
10
player.lua
10
player.lua
@ -3,13 +3,14 @@ cos = math.cos
|
||||
sin = math.sin --optimisation
|
||||
|
||||
-- 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.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()
|
||||
|
||||
@ -65,6 +66,7 @@ function Player:update(dt)
|
||||
elseif love.keyboard.isDown("d") then
|
||||
self.rotation = self.rotation + (self.rotSpeed * dt)
|
||||
end
|
||||
|
||||
self.collider:setLinearVelocity(self.vx, self.vy)
|
||||
|
||||
-- Check for collision with walls
|
||||
@ -82,6 +84,12 @@ function Player:update(dt)
|
||||
end
|
||||
self.x = self.collider:getX()
|
||||
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
|
||||
-- Handle player 2 controls
|
||||
if love.keyboard.isDown("up") then
|
||||
|
Loading…
x
Reference in New Issue
Block a user