You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
love2d-tank/main.lua

108 lines
2.3 KiB

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("DrawMenu")
require("GameKeyPressed")
require("MenuKeyPressed")
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
--Making the map have collision
GameMap = STI("maps/map.lua")
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
--Fonts used in the game
GameFont = love.graphics.newFont("assets/Daydream.ttf", 60)
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
KeyDelay1 = DELAY
EnableKeyPress2 = true
KeyPressTime2 = 0
KeyDelay2 = DELAY
local playerSpeed = 12000
UserPlayer1 = Player(1, 1000, 100, HEALTH, "assets/player1.png", playerSpeed)
UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", playerSpeed)
Bullets1 = {}
Bullets2 = {}
end
function love.keypressed(key)
if GAMESTATE == "MENU" then
MenuKeyPressed(key)
end
if GAMESTATE == "GAME" then
GameKeyPressed(key)
end
end
function love.update(dt)
if GAMESTATE == "MENU" then
UpdateMenu(dt)
end
if GAMESTATE == "GAME" then
UpdateGame(dt)
end
end
function love.draw()
--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