Compare commits

..

No commits in common. '86d33a7fc57bbbd1397d216520eba6e38a8ffd73' and '451d7103261d26c77f6cb5f513e81dcf47333c84' have entirely different histories.

  1. 16
      Game/DrawGame.lua
  2. 10
      Game/GameKeyPressed.lua
  3. 31
      Game/UpdateGame.lua
  4. BIN
      assets/powerup.jpeg
  5. 8
      conf.lua
  6. 11
      constants.lua
  7. BIN
      game.love
  8. 20
      main.lua
  9. 38
      player.lua
  10. 70
      powerups/powerup.lua
  11. 9
      restart.lua

@ -6,16 +6,16 @@ end
local function drawHealth() local function drawHealth()
love.graphics.setFont(GameFont) love.graphics.setFont(GameFont)
local height = love.graphics.getHeight() / _G.Y_SCALE local height = love.graphics.getHeight()
local width = love.graphics.getWidth() / _G.X_SCALE local width = love.graphics.getWidth()
love.graphics.print("P1:" .. UserPlayer1.health, 5, 5) love.graphics.print("P1:" .. UserPlayer1.health, 5, 5)
love.graphics.print("P2:" .. UserPlayer2.health, width - 200, height - 95) love.graphics.print("P2:" .. UserPlayer2.health, width - 200, height - 95)
end end
function DrawGame() function DrawGame()
local curWidth, curHeight = love.graphics.getDimensions() local curWidth, curHeight = love.graphics.getDimensions()
--STI
love.graphics.scale(_G.X_SCALE, _G.Y_SCALE) love.graphics.scale(_G.X_SCALE, _G.Y_SCALE)
GameMap:draw(0, 0, _G.X_SCALE, _G.Y_SCALE) GameMap:draw(0, 0, _G.X_SCALE, _G.Y_SCALE)
GameMap:resize(curWidth / _G.X_SCALE, curHeight / _G.Y_SCALE) GameMap:resize(curWidth / _G.X_SCALE, curHeight / _G.Y_SCALE)
@ -25,7 +25,6 @@ function DrawGame()
drawFPS() drawFPS()
end end
-- Bullets
for _, v in ipairs(Bullets1) do for _, v in ipairs(Bullets1) do
v:draw() v:draw()
end end
@ -33,18 +32,9 @@ function DrawGame()
v:draw() v:draw()
end end
-- PowerUps
for _, v in ipairs(PowerUps) do
v:draw()
end
UserPlayer1:draw() UserPlayer1:draw()
UserPlayer2:draw() UserPlayer2:draw()
--Draw Health --Draw Health
--TODO: make this nicer looking
drawHealth() drawHealth()
--TODO: draw running score
--drawScore()
end end

@ -34,10 +34,9 @@ function GameKeyPressed(key)
end end
if DebugFlag and key == "1" then if DebugFlag and key == "1" then
--UserPlayer1.speed = 50000 UserPlayer1.speed = 50000
--print("player1 speed increased!") print("player1 speed increased!")
end end
if DebugFlag and key == "2" then if DebugFlag and key == "2" then
_G.CUR_LEVEL = 2 _G.CUR_LEVEL = 2
RestartGame() RestartGame()
@ -48,9 +47,4 @@ function GameKeyPressed(key)
RestartGame() RestartGame()
love.load() love.load()
end end
if key == "p" then
testP = PowerUp("speed", 300, 300, "assets/powerup.jpeg", 10)
table.insert(PowerUps, testP)
end
end end

@ -37,7 +37,6 @@ function UpdateGame(dt)
EnableKeyPress2 = true EnableKeyPress2 = true
end end
-- Update Bullets1
for i, v in ipairs(Bullets1) do for i, v in ipairs(Bullets1) do
v:update(dt) v:update(dt)
@ -83,7 +82,6 @@ function UpdateGame(dt)
end end
end end
-- Update Bullets2
for i, v in ipairs(Bullets2) do for i, v in ipairs(Bullets2) do
v:update(dt) v:update(dt)
@ -129,35 +127,6 @@ function UpdateGame(dt)
end end
end end
-- PowerUp updates
for i, v in ipairs(PowerUps) do
v:update(dt)
if v.collider:enter("Player1") then
UserPlayer1:getPowerUp(v)
UserPlayer1:powerup()
table.remove(PowerUps, i)
v.collider:destroy()
end
if v.collider:enter("Player2") then
UserPlayer2:getPowerUp(v)
UserPlayer2:powerup()
table.remove(PowerUps, i)
v.collider:destroy()
end
end
--PowerUp timer to place
PUTimeToPlace = PUTimeToPlace - dt
--print(PUTimeToPlace)
if PUTimeToPlace <= 0 then
local w, h = love.graphics.getDimensions()
local ranx = love.math.random(30, w)
local rany = love.math.random(100, h)
local newPU = PowerUp("speed", ranx, rany, "assets/powerup.jpeg", 10)
table.insert(PowerUps, newPU)
PUTimeToPlace = _G.PU_TIMER --reset
end
UserPlayer1:handleKeys("w", "s", "a", "d", dt) UserPlayer1:handleKeys("w", "s", "a", "d", dt)
UserPlayer2:handleKeys("up", "down", "left", "right", dt) UserPlayer2:handleKeys("up", "down", "left", "right", dt)
UserPlayer1:updateCol() UserPlayer1:updateCol()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

@ -1,11 +1,7 @@
--Config file for the game --Config file for the game
function love.conf(t) function love.conf(t)
--t.window.width = 1366 t.window.width = 1366
--t.window.height = 768 t.window.height = 768
t.window.width = 1600
t.window.height = 960
t.window.title = "Tanks-A-Lot" t.window.title = "Tanks-A-Lot"
t.window.resizable = true t.window.resizable = true
t.version = "11.5" t.version = "11.5"

@ -32,20 +32,13 @@ PAUSE_POS = 0
PAUSE_MAX = 2 -- 0 resume, 1 menu, 2 quit PAUSE_MAX = 2 -- 0 resume, 1 menu, 2 quit
BULLETS_MAX = 10 -- MAX amount of bullets a player can shoot BULLETS_MAX = 10 -- MAX amount of bullets a player can shoot
BULLETS_BOUNCE_MAX = 10 -- MAX amount of bounces before exploding! BULLETS_BOUNCE_MAX = 7 -- MAX amount of bounces before exploding!
BULLETS_LIFETIME = 50 --TODO: impl. lifetime for a bullet! BULLETS_LIFETIME = 50
-- Power up timer
PU_TIMER = 10
-- WIN flags for P1 and P2 -- WIN flags for P1 and P2
P1_WIN = false P1_WIN = false
P2_WIN = false P2_WIN = false
-- Default speeds for bullets and player
DEFAULT_P_SPEED = 12000
DEFAULT_B_SPEED = 22000
-- WIN counts! -- WIN counts!
P1_COUNT = 0 P1_COUNT = 0
P2_COUNT = 0 P2_COUNT = 0

Binary file not shown.

@ -11,11 +11,9 @@ World:addCollisionClass("Bullet1")
World:addCollisionClass("Player2") World:addCollisionClass("Player2")
World:addCollisionClass("Bullet2") World:addCollisionClass("Bullet2")
World:addCollisionClass("Wall") World:addCollisionClass("Wall")
World:addCollisionClass("PowerUp")
require("gui") require("gui")
require("powerups/powerup")
require("powerups/speed")
require("restart") require("restart")
require("truncate") require("truncate")
require("player") require("player")
@ -116,10 +114,17 @@ end
function love.load() function love.load()
-- Set a random seed -- Set a random seed
love.math.setRandomSeed(love.timer.getTime()) love.math.setRandomSeed(love.timer.getTime())
-- Figure out the X_SCALE and Y_SCALE -- Figure out the X_SCALE and Y_SCALE
local curWidth, curHeight = love.graphics.getDimensions() local curWidth, curHeight = love.graphics.getDimensions()
print("------")
print(love.graphics.getDimensions())
_G.X_SCALE = truncate(curWidth / GAME_WORLD_DIM_WIDTH, 3) _G.X_SCALE = truncate(curWidth / GAME_WORLD_DIM_WIDTH, 3)
_G.Y_SCALE = truncate(curHeight / GAME_WORLD_DIM_HEIGHT, 3) _G.Y_SCALE = truncate(curHeight / GAME_WORLD_DIM_HEIGHT, 3)
print("x scale:" .. _G.X_SCALE)
print("y scale:" .. _G.Y_SCALE)
--Game values (reset after each load) --Game values (reset after each load)
HEALTH = 3 HEALTH = 3
@ -130,10 +135,6 @@ function love.load()
Bullets1 = {} Bullets1 = {}
Bullets2 = {} Bullets2 = {}
--PowerUp stuff
PowerUps = {}
PUTimeToPlace = _G.PU_TIMER
DebugFlag = false DebugFlag = false
EnableKeyPress1 = true EnableKeyPress1 = true
KeyPressTime1 = 0 KeyPressTime1 = 0
@ -143,9 +144,10 @@ function love.load()
KeyPressTime2 = 0 KeyPressTime2 = 0
KeyDelay2 = P2_DELAY KeyDelay2 = P2_DELAY
local playerSpeed = 12000
--TODO: two player speeds for upgrades --TODO: two player speeds for upgrades
UserPlayer1 = Player(1, 1000, 100, HEALTH, "assets/player1.png", 12000) UserPlayer1 = Player(1, 1000, 100, HEALTH, "assets/player1.png", playerSpeed)
UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", 12000) UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", playerSpeed)
--STI Map loading --STI Map loading
LoadMap(_G.CUR_LEVEL) LoadMap(_G.CUR_LEVEL)

@ -1,7 +1,6 @@
Player = Object:extend() Player = Object:extend()
local cos = math.cos local cos = math.cos
local sin = math.sin --optimisation local sin = math.sin --optimisation
local max = math.max --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)
@ -11,15 +10,9 @@ function Player:new(p, x, y, health, image, speed)
self.y = y self.y = y
self.health = health self.health = health
self.speed = speed self.speed = speed
self.bulletSpeed = _G.DEFAULT_B_SPEED
self.width = self.image:getWidth() self.width = self.image:getWidth()
self.height = self.image:getHeight() self.height = self.image:getHeight()
--Power up flag
self.PUName = ""
self.PUTime = 0
self.PUOn = false
-- Collision Stuff -- Collision Stuff
--self.collider = World:newRectangleCollider(x, y, 50, 62) --self.collider = World:newRectangleCollider(x, y, 50, 62)
self.collider = World:newCircleCollider(x, y, 24 * X_SCALE) self.collider = World:newCircleCollider(x, y, 24 * X_SCALE)
@ -33,7 +26,7 @@ function Player:new(p, x, y, health, image, speed)
-- Rotation Stuff -- Rotation Stuff
self.rotation = math.rad(90) self.rotation = math.rad(90)
self.rotSpeed = 3 self.rotSpeed = 2
--self.scaleX = 1 * _G.X_SCALE --self.scaleX = 1 * _G.X_SCALE
--self.scaleY = 1 * _G.Y_SCALE --self.scaleY = 1 * _G.Y_SCALE
self.scaleX = 1 self.scaleX = 1
@ -93,36 +86,13 @@ function Player:updateCol()
end end
end end
function Player:getPowerUp(powerup)
self.PUName = powerup.name
self.PUTime = powerup.time
end
function Player:powerup()
self.PUOn = true
if self.PUName == "speed" then
--print("" .. self.PUName .. " for " .. self.PUTime)
self.speed = self.speed * 2.5
self.rotSpeed = self.rotSpeed * 1.5
end
end
-- Update method for the Player class -- Update method for the Player class
function Player:update(dt) function Player:update(dt)
if self.PUOn then local bulletSpeed = 20000
self.PUTime = self.PUTime - dt
if max(0, self.PUTime) <= 0 then
-- Reset the player
self.PUName = "none"
self.PUTime = 0
self.PUOn = false
self.speed = _G.DEFAULT_P_SPEED
end
end
if EnableKeyPress1 == true and self.p == 1 then if EnableKeyPress1 == true and self.p == 1 then
if love.keyboard.isDown("space") then if love.keyboard.isDown("space") then
local newBullet = self:shoot(self.bulletSpeed) local newBullet = self:shoot(bulletSpeed)
table.insert(Bullets1, newBullet) table.insert(Bullets1, newBullet)
KeyPressTime1 = KeyDelay1 KeyPressTime1 = KeyDelay1
EnableKeyPress1 = false EnableKeyPress1 = false
@ -131,7 +101,7 @@ function Player:update(dt)
if EnableKeyPress2 == true and self.p == 2 then if EnableKeyPress2 == true and self.p == 2 then
if love.keyboard.isDown("return") then if love.keyboard.isDown("return") then
local newBullet = self:shoot(self.bulletSpeed) local newBullet = self:shoot(bulletSpeed)
table.insert(Bullets2, newBullet) table.insert(Bullets2, newBullet)
KeyPressTime2 = KeyDelay2 KeyPressTime2 = KeyDelay2
EnableKeyPress2 = false EnableKeyPress2 = false

@ -1,70 +0,0 @@
PowerUp = Object:extend()
-- PowerUp is the super class for all power-ups
-- found in the game
function PowerUp:new(name, x, y, image, time, lifetime)
self.name = name
self.x = x
self.y = y
self.image = love.graphics.newImage(image)
self.time = time
self.lifetime = lifetime
self.width = self.image:getWidth()
self.height = self.image:getHeight()
self.rotation = 1
self.scaleX = 1
self.scaleY = 1
self.originX = self.width / 2
self.originY = self.height / 2
-- Collider
self.collider = World:newRectangleCollider(x, y, 20, 20)
self.collider:setCollisionClass("PowerUp")
self.collider:setType("static")
self.collider:setPosition(self.x, self.y)
end
-- TODO: clean up colliosn on reset
-- make image draw
-- more stuff
-- see you later
function PowerUp:apply(player) end
function PowerUp:remove(player) end
function PowerUp:update(dt)
--check if the power up is past its lifetime
--spinnnnnn
self.rotation = self.rotation + 1.5 * dt
--grown and shrink
--[[
if self.scaleX >= 1.0 then
self.scaleX = self.scaleX - 0.2 * dt
elseif self.scaleX <= 1.8 then
self.scaleX = self.scaleX + 0.2 * dt
end
]]
self.x = self.collider:getX()
self.y = self.collider:getY()
end
function PowerUp:draw()
for _, _ in ipairs(PowerUps) do
love.graphics.draw(
self.image,
self.x,
self.y,
self.rotation,
self.scaleX,
self.scaleY,
self.originX,
self.originY
)
end
end

@ -8,12 +8,6 @@ function ClearWalls(walls)
end end
end end
function ClearPowerUps(powerup)
for i, v in ipairs(powerup) do
v.collider:destroy()
end
end
function StopAllMusic() function StopAllMusic()
-- TODO: maybe find a way -- TODO: maybe find a way
-- to find all 'streaming' -- to find all 'streaming'
@ -74,8 +68,5 @@ function RestartGame()
--Clear Walls --Clear Walls
ClearWalls(Walls) ClearWalls(Walls)
--ClearPowerUps
ClearPowerUps(PowerUps)
-- Done! -- Done!
end end

Loading…
Cancel
Save