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

109 lines
2.3 KiB

GAMESTATE = "MENU"
5 months ago
function love.load()
Object = require("classic")
require("player")
require("bullet")
require("menu")
5 months ago
WF = require("libs/windfield")
4 months ago
STI = require("libs/sti")
5 months ago
require("UpdateGame")
require("UpdateMenu")
5 months ago
require("DrawGame")
require("DrawMenu")
require("GameKeyPressed")
require("MenuKeyPressed")
require("mapsloader")
5 months ago
--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")
4 months ago
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
4 months ago
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
5 months ago
HEALTH = 3
DELAY = 0.5
MAX = 6 --MAX number of bullets
5 months ago
DebugFlag = false
EnableKeyPress1 = true
KeyPressTime1 = 0
KeyDelay1 = DELAY
EnableKeyPress2 = true
KeyPressTime2 = 0
KeyDelay2 = DELAY
4 months ago
local playerSpeed = 12000
UserPlayer1 = Player(1, 1000, 100, HEALTH, "assets/player1.png", playerSpeed)
UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", playerSpeed)
5 months ago
Bullets1 = {}
Bullets2 = {}
end
function love.keypressed(key)
if GAMESTATE == "MENU" then
MenuKeyPressed(key)
end
if GAMESTATE == "GAME" then
GameKeyPressed(key)
end
5 months ago
end
function love.update(dt)
if GAMESTATE == "MENU" then
UpdateMenu(dt)
end
if GAMESTATE == "GAME" then
UpdateGame(dt)
end
5 months ago
end
function love.draw()
--TODO: SWITCH/CASE this!
if GAMESTATE == "MENU" then
DrawMenu()
5 months ago
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
5 months ago
end