Compare commits

...

2 Commits

Author SHA1 Message Date
Simon Kellet 19e10d6601 added pause and music 4 months ago
Simon Kellet bcada33441 updated readme 4 months ago
  1. 15
      Game/GameKeyPressed.lua
  2. 3
      Menu/DrawMenu.lua
  3. 1
      Menu/MenuKeyPressed.lua
  4. 45
      Pause/DrawPause.lua
  5. 44
      Pause/PauseKeyPressed.lua
  6. 2
      Pause/UpdatePause.lua
  7. 30
      README.md
  8. 2
      conf.lua
  9. 7
      constants.lua
  10. BIN
      game.love
  11. 68
      libs/classic.lua
  12. 46
      main.lua
  13. BIN
      music/battle.mp3
  14. BIN
      music/fight.mp3
  15. BIN
      music/menu.mp3
  16. BIN
      music/story.mp3

@ -1,14 +1,21 @@
function GameKeyPressed(key) function GameKeyPressed(key)
if key == "escape" then if key == "escape" then
_G.GAMESTATE = "MENU" musicBattle:setVolume(0)
print("STATE CHANEGD: MENU!") musicPause:setVolume(0.5)
_G.GAMESTATE = "PAUSE"
print("STATE CHANEGD: PAUSED!")
_G.PAUSED = true
end end
if key == "b" then if key == "b" and not _G.PAUSED then
DebugFlag = not DebugFlag DebugFlag = not DebugFlag
end end
if key == "r" then --[[
if key == "r" and not _G.PAUSED then
love.load() love.load()
end end
]]--
end end

@ -19,7 +19,6 @@ local function button(x,y, w, h, text, selected)
-- Place text inside the rectangle -- Place text inside the rectangle
love.graphics.setFont(MenuFont) love.graphics.setFont(MenuFont)
love.graphics.print(text, textX, textY) love.graphics.print(text, textX, textY)
end end
local function title() local function title()
@ -40,4 +39,6 @@ function DrawMenu()
button(100, 350, bwidth, bheight, "???", MENU_POS == 1 and true or false) button(100, 350, bwidth, bheight, "???", MENU_POS == 1 and true or false)
button(100, 500, bwidth, bheight, "???", MENU_POS == 2 and true or false) button(100, 500, bwidth, bheight, "???", MENU_POS == 2 and true or false)
button(100, 650, bwidth, bheight, "Quit", MENU_POS == 3 and true or false) button(100, 650, bwidth, bheight, "Quit", MENU_POS == 3 and true or false)
love.graphics.setColor(255,255,255) -- reset colours
end end

@ -8,6 +8,7 @@ function MenuKeyPressed(key)
--Change state to GAME! --Change state to GAME!
_G.GAMESTATE = "GAME" _G.GAMESTATE = "GAME"
print("STATE CHANEGD: GAME!") print("STATE CHANEGD: GAME!")
musicMenu:stop()
elseif MENU_POS == 1 then elseif MENU_POS == 1 then
print("STATE CHANEGD: DUNNO!") print("STATE CHANEGD: DUNNO!")

@ -0,0 +1,45 @@
local function button(x,y, w, h, text, selected)
--x,y is the top left corner of the button
local rounding = 30 -- used for rounding the buttons
if not selected then
love.graphics.setColor(love.math.colorFromBytes(41,134,204))
elseif selected then
love.graphics.setColor(love.math.colorFromBytes(244,67,54))
end
-- Draw rectangle
love.graphics.rectangle("fill", x, y, w, h, rounding, rounding)
-- Get width and height of text
local tw = MenuFont:getWidth(text)
local th = MenuFont:getHeight(text)
-- Calculate position to center the text
local textX = x + (w - tw) / 2
local textY = y + (h - th) / 2
-- Place text inside the rectangle
love.graphics.setFont(MenuFont)
love.graphics.setColor(1,1,1) -- reset colours
love.graphics.print(text, textX, textY)
end
function DrawPause()
local opacity = 0.3
local height = love.graphics.getHeight()
local width = love.graphics.getWidth()
local bwidth, bheight = 300, 140
love.graphics.setFont(GameFont)
DrawGame() --Draw a single frame of the game
love.graphics.setColor(0.1,0.1,0.1, opacity) --overlay opaque img
love.graphics.rectangle("fill", 0, 0, width, height)
love.graphics.setColor(1,1,1)
love.graphics.print("PAUSED", 100,100)
--love.graphics.print("" .. PAUSE_POS, 200,200)
button(100, 200, bwidth, bheight, "Return", PAUSE_POS == 0 and true or false)
button(100, 350, bwidth, bheight, "Menu", PAUSE_POS == 1 and true or false)
button(100, 500, bwidth, bheight, "Quit", PAUSE_POS == 2 and true or false)
love.graphics.setColor(255,255,255) -- reset colours
end

@ -0,0 +1,44 @@
function PauseKeyPressed(key)
if key == 'return' then
musicBattle:setVolume(0.5)
musicPause:setVolume(0)
-- 0 Return to game
-- 1 Quit
if PAUSE_POS == 0 then
-- unpause the game
_G.GAMESTATE = "GAME"
print("STATE CHANEGD: GAME!")
_G.PAUSED = false
musicBattle:setVolume(0.5)
musicPause:setVolume(0)
elseif PAUSE_POS == 1 then
_G.GAMESTATE = "MENU"
print("STATE CHANEGD: MENU!")
_G.PAUSED = false
musicPause:stop()
musicBattle:stop()
elseif PAUSE_POS == 2 then
love.event.quit()
end
end
if love.keyboard.isDown("up") then
if _G.PAUSE_POS == 0 then
_G.PAUSE_POS = 0
else
_G.PAUSE_POS = _G.PAUSE_POS - 1
end
end
if love.keyboard.isDown("down") then
if _G.PAUSE_POS >= _G.PAUSE_MAX then
_G.PAUSE_POS = _G.PAUSE_MAX
else
_G.PAUSE_POS = _G.PAUSE_POS + 1
end
end
end

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

@ -0,0 +1,30 @@
# Tanks-A-Lot (LÖVE2D Game)
## How to install
### Download
### Build from source (LÖVE2D must be installed already)
To build and make **.love** file:
```sh
zip -r game.love . -x '*.git*'
```
To play, use:
```sh
love game.love
```
## How to Play
## Credits
* Programming: Simon
* Art: Laura
* Music: AJ
# TODOS
* Links to socials
* Exe files
* Release stuff
* how to play instructions
* images for git

@ -2,5 +2,5 @@
function love.conf(t) function love.conf(t)
t.window.width = 1600 t.window.width = 1600
t.window.height = 960 t.window.height = 960
t.window.title = "Game" t.window.title = "Tanks-A-Lot"
end end

@ -1,3 +1,8 @@
GAMESTATE = "MENU" GAMESTATE = "MENU"
MENU_POS = 0 MENU_POS = 0
MENU_MAX = 3 MENU_MAX = 3 --0 play, 1 ?, 2 ?, 3 quit
PAUSED = false
PAUSE_POS = 0
PAUSE_MAX = 2 -- 0 resume, 1 menu, 2 quit

Binary file not shown.

@ -0,0 +1,68 @@
--
-- classic
--
-- Copyright (c) 2014, rxi
--
-- This module is free software; you can redistribute it and/or modify it under
-- the terms of the MIT license. See LICENSE for details.
--
local Object = {}
Object.__index = Object
function Object:new()
end
function Object:extend()
local cls = {}
for k, v in pairs(self) do
if k:find("__") == 1 then
cls[k] = v
end
end
cls.__index = cls
cls.super = self
setmetatable(cls, self)
return cls
end
function Object:implement(...)
for _, cls in pairs({...}) do
for k, v in pairs(cls) do
if self[k] == nil and type(v) == "function" then
self[k] = v
end
end
end
end
function Object:is(T)
local mt = getmetatable(self)
while mt do
if mt == T then
return true
end
mt = getmetatable(mt)
end
return false
end
function Object:__tostring()
return "Object"
end
function Object:__call(...)
local obj = setmetatable({}, self)
obj:new(...)
return obj
end
return Object

@ -43,7 +43,7 @@ function love.run()
end end
function love.load() function love.load()
Object = require("classic") Object = require("libs/classic")
require("player") require("player")
require("bullet") require("bullet")
@ -52,12 +52,15 @@ function love.load()
require("Game/UpdateGame") require("Game/UpdateGame")
require("Menu/UpdateMenu") require("Menu/UpdateMenu")
require("Pause/UpdatePause")
require("Game/DrawGame") require("Game/DrawGame")
require("Menu/DrawMenu") require("Menu/DrawMenu")
require("Pause/DrawPause")
require("Game/GameKeyPressed") require("Game/GameKeyPressed")
require("Menu/MenuKeyPressed") require("Menu/MenuKeyPressed")
require("Pause/PauseKeyPressed")
require("mapsloader") require("mapsloader")
@ -102,12 +105,28 @@ function love.load()
local playerSpeed = 12000 local playerSpeed = 12000
UserPlayer1 = Player(1, 1000, 100, HEALTH, "assets/player1.png", playerSpeed) UserPlayer1 = Player(1, 1000, 100, HEALTH, "assets/player1.png", playerSpeed)
UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", playerSpeed) UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", playerSpeed)
-- Music streaming
musicMenu = love.audio.newSource("music/menu.mp3", "stream")
musicBattle = love.audio.newSource("music/battle.mp3", "stream")
musicStory = love.audio.newSource("music/story.mp3", "stream")
musicPause = musicBattle:clone()
musicPause:setFilter{
type = 'lowpass',
volume = 0.3,
highgain = 0.4,
}
end end
function love.keypressed(key) function love.keypressed(key)
if _G.GAMESTATE == "MENU" then if _G.GAMESTATE == "MENU" then
MenuKeyPressed(key) MenuKeyPressed(key)
end end
if _G.GAMESTATE == "PAUSE" then
PauseKeyPressed(key)
end
if _G.GAMESTATE == "GAME" then if _G.GAMESTATE == "GAME" then
GameKeyPressed(key) GameKeyPressed(key)
end end
@ -117,9 +136,31 @@ end
function love.update(dt) function love.update(dt)
if _G.GAMESTATE == "MENU" then if _G.GAMESTATE == "MENU" then
UpdateMenu(dt) UpdateMenu(dt)
-- Handle music
if not musicMenu:isPlaying() then
musicMenu:setVolume(0.5)
love.audio.play(musicMenu)
end
end
if _G.GAMESTATE == "PAUSE" then
UpdatePause(dt)
-- Handle music
if not musicPause:isPlaying() then
--musicBattle:setVolume(0)
--musicPause:setVolume(0.5)
love.audio.play(musicBattle)
love.audio.play(musicPause)
end
end end
if _G.GAMESTATE == "GAME" then if _G.GAMESTATE == "GAME" then
UpdateGame(dt) UpdateGame(dt)
-- Handle music
if not musicBattle:isPlaying() then
--musicBattle:setVolume(0.5)
--musicPause:setVolume(0)
love.audio.play(musicBattle)
love.audio.play(musicPause)
end
end end
end end
@ -127,6 +168,9 @@ function love.draw()
if _G.GAMESTATE == "MENU" then if _G.GAMESTATE == "MENU" then
DrawMenu() DrawMenu()
end end
if _G.GAMESTATE == "PAUSE" then
DrawPause()
end
if _G.GAMESTATE == "GAME" then if _G.GAMESTATE == "GAME" then
DrawGame() DrawGame()
if DebugFlag then if DebugFlag then

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save