From 68b76eaaaff5608418d54c39eaad3c880570cd7b Mon Sep 17 00:00:00 2001 From: Simon Kellet Date: Fri, 19 Jul 2024 13:20:04 +0100 Subject: [PATCH] state changes and a menu --- .gitignore | 2 + Game/GameKeyPressed.lua | 3 +- Menu/DrawMenu.lua | 39 +- Menu/MenuKeyPressed.lua | 40 +- constants.lua | 3 + game.love | Bin 94895 -> 95834 bytes main.lua | 103 ++-- maps/map.lua | 1023 --------------------------------------- mapsloader.lua | 16 +- player.lua | 122 ++--- 10 files changed, 210 insertions(+), 1141 deletions(-) create mode 100644 .gitignore create mode 100644 constants.lua delete mode 100644 maps/map.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ca0973 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store + diff --git a/Game/GameKeyPressed.lua b/Game/GameKeyPressed.lua index 41194db..42e0ee3 100644 --- a/Game/GameKeyPressed.lua +++ b/Game/GameKeyPressed.lua @@ -1,6 +1,7 @@ function GameKeyPressed(key) if key == "escape" then - love.event.quit() + _G.GAMESTATE = "MENU" + print("STATE CHANEGD: MENU!") end if key == "b" then diff --git a/Menu/DrawMenu.lua b/Menu/DrawMenu.lua index b2db24f..f3e120f 100644 --- a/Menu/DrawMenu.lua +++ b/Menu/DrawMenu.lua @@ -1,10 +1,43 @@ -function DrawMenu() - love.graphics.setFont(GameFont) +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("line", 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.print(text, textX, textY) + +end + +local function title() local height = love.graphics.getHeight() local width = love.graphics.getWidth() - love.graphics.setColor(1,1,1) + love.graphics.setFont(GameFont) + love.graphics.setColor(0.5,1,1) love.graphics.rectangle("fill", 0, 0, width, height) love.graphics.setColor(0,0,0) love.graphics.print("MENU", 100,100) +end + +function DrawMenu() + local bwidth, bheight = 300, 140 + title() + button(100, 200, bwidth, bheight, "Play", MENU_POS == 0 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, 650, bwidth, bheight, "Quit", MENU_POS == 3 and true or false) end \ No newline at end of file diff --git a/Menu/MenuKeyPressed.lua b/Menu/MenuKeyPressed.lua index 194f8e7..7905a9f 100644 --- a/Menu/MenuKeyPressed.lua +++ b/Menu/MenuKeyPressed.lua @@ -1,10 +1,40 @@ function MenuKeyPressed(key) - if key == "escape" then - love.event.quit() + if key == 'return' then + -- 0 Start Game + -- 1 ?? + -- 2 ??? + -- 3 Quit + if MENU_POS == 0 then + --Change state to GAME! + _G.GAMESTATE = "GAME" + print("STATE CHANEGD: GAME!") + + elseif MENU_POS == 1 then + print("STATE CHANEGD: DUNNO!") + + elseif MENU_POS == 2 then + print("STATE CHANEGD: DUNNO!") + + elseif MENU_POS == 3 then + love.event.quit() + end + end - if key == "space" then - --Change state to GAME! - GAMESTATE = "GAME" + if love.keyboard.isDown("up") then + if _G.MENU_POS == 0 then + _G.MENU_POS = 0 + else + _G.MENU_POS = _G.MENU_POS - 1 + end end + + if love.keyboard.isDown("down") then + if _G.MENU_POS >= _G.MENU_MAX then + _G.MENU_POS = _G.MENU_MAX + else + _G.MENU_POS = _G.MENU_POS + 1 + end + end + end diff --git a/constants.lua b/constants.lua new file mode 100644 index 0000000..3beeb17 --- /dev/null +++ b/constants.lua @@ -0,0 +1,3 @@ +GAMESTATE = "MENU" +MENU_POS = 0 +MENU_MAX = 3 \ No newline at end of file diff --git a/game.love b/game.love index 910bff435b3487fc6539c0285136e297e73bb004..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4f zYdg=q`S`QaVM(g-;rXBNM#Z0ob$#MW;{{5E#trqJcL>i)u8{E@d2s_InWlfS@|dk~ z2mKJtN`0kuaU(AMsw*W$&m$`$VkbyJMKEx*sN%0BIzFk9EBOsYB`4W4yIgtO&A?pX z!#fTF(S5DHS==Px0I5unn)-)l!qycP)fo>e5$)&EkIP^{36e_KF&uyS*gTEd_AHA8c? z60PRcIZy{7TS<04n)*0TCGO3`8-(Y%s?em}45);D$3W#W=D zs=5LT%q?zs(-l}^2Dl;79qfl|u0R(f$@9}V?S=+8&C4*Tr}ya-!2?M20ydcLJXq%i)bam+aSQJ13j{qfNOt5(0rJZ=&V*pmYaC7nqpPIj zjV{99k0H?;oo=ZNR_xYaDj|~(I!$^5wD$pKn282h=z~u0I}HIDt?L;zFZ3d#OQW~2 z>*S@HFS5ZwGSJ52zamuSO+l#QiyG~l2(@{OAKpL>%#ZKzg)f@+X=W(thsI4{hW>u2 zU8e&({D6j7Yj_`lu>CEs7S$i5!wABG{PQs+p@cu+$D-`ONL~H^iQ%8UB`g8@5%nug zpbw7H#Loxc4nQ|zoj>5jR9e9ffAq~IT0?;VU;`{6IRMxKQP>`UzUfF?cpwm66ITNC z2?R!%90IHj1R9K8&n@svf;a3SPY^mzB>;%QFCJ+8^Fe5Q6MIMw0)kN16LsgH9Wb-! zU|SGSfV(+x@%$3wFysmbLQpvn{qu7H%4+Yo=m2n3fcKa2lji|q e=0XlW0y_eLEFTl|?lw4v{>*t1#K>WHL;MFBN?Y{+ diff --git a/main.lua b/main.lua index 5d30b08..cf099e6 100644 --- a/main.lua +++ b/main.lua @@ -1,21 +1,64 @@ -GAMESTATE = "MENU" +require 'constants' + +function love.run() + if love.load then love.load(love.arg.parseGameArguments(arg), arg) end + + -- We don't want the first frame's dt to include time taken by love.load. + if love.timer then love.timer.step() end + + local dt = 0 + + -- Main loop time. + return function() + -- Process events. + if love.event then + love.event.pump() + for name, a,b,c,d,e,f in love.event.poll() do + if name == "quit" then + if not love.quit or not love.quit() then + return a or 0 + end + end + love.handlers[name](a,b,c,d,e,f) + end + end + + -- Update dt, as we'll be passing it to update + if love.timer then dt = love.timer.step() end + + -- Call update and draw + if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled + + if love.graphics and love.graphics.isActive() then + love.graphics.origin() + love.graphics.clear(love.graphics.getBackgroundColor()) + + if love.draw then love.draw() end + + love.graphics.present() + end + + if love.timer then love.timer.sleep(0.001) end + end +end 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("Game/UpdateGame") + require("Menu/UpdateMenu") + + require("Game/DrawGame") + require("Menu/DrawMenu") - require("DrawGame") - require("DrawMenu") + require("Game/GameKeyPressed") + require("Menu/MenuKeyPressed") - require("GameKeyPressed") - require("MenuKeyPressed") require("mapsloader") --WindField @@ -31,31 +74,27 @@ function love.load() 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 + loadMap(1) --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) + MenuFont = love.graphics.newFont("assets/Daydream.ttf", 45) --Game consts HEALTH = 3 DELAY = 0.5 - MAX = 6 --MAX number of bullets + MAX = 6 --MAX number of bullets| + + --Bullet lists + Bullets1 = {} + Bullets2 = {} + DebugFlag = false EnableKeyPress1 = true KeyPressTime1 = 0 KeyDelay1 = DELAY + EnableKeyPress2 = true KeyPressTime2 = 0 KeyDelay2 = DELAY @@ -63,45 +102,37 @@ function love.load() 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 + if _G.GAMESTATE == "MENU" then MenuKeyPressed(key) end - - if GAMESTATE == "GAME" then + if _G.GAMESTATE == "GAME" then GameKeyPressed(key) end end function love.update(dt) - if GAMESTATE == "MENU" then + if _G.GAMESTATE == "MENU" then UpdateMenu(dt) end - - if GAMESTATE == "GAME" then + if _G.GAMESTATE == "GAME" then UpdateGame(dt) end end function love.draw() - - --TODO: SWITCH/CASE this! - if GAMESTATE == "MENU" then + if _G.GAMESTATE == "MENU" then DrawMenu() end - - if GAMESTATE == "GAME" then + if _G.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...") + love.graphics.print("" .. GAMESTATE, 200, 200) end end diff --git a/maps/map.lua b/maps/map.lua deleted file mode 100644 index b0b9a47..0000000 --- a/maps/map.lua +++ /dev/null @@ -1,1023 +0,0 @@ -return { - version = "1.10", - luaversion = "5.1", - tiledversion = "1.10.2", - class = "", - orientation = "orthogonal", - renderorder = "right-down", - width = 25, - height = 15, - tilewidth = 64, - tileheight = 64, - nextlayerid = 5, - nextobjectid = 36, - properties = {}, - tilesets = { - { - name = "floor-tiles", - firstgid = 1, - class = "", - tilewidth = 64, - tileheight = 64, - spacing = 0, - margin = 0, - columns = 9, - image = "../assets/tileset.png", - imagewidth = 576, - imageheight = 384, - objectalignment = "unspecified", - tilerendersize = "tile", - fillmode = "stretch", - tileoffset = { - x = 0, - y = 0, - }, - grid = { - orientation = "orthogonal", - width = 64, - height = 64, - }, - properties = {}, - wangsets = {}, - tilecount = 54, - tiles = {}, - }, - }, - layers = { - { - type = "tilelayer", - x = 0, - y = 0, - width = 25, - height = 15, - id = 1, - name = "Floor + Outer Walls", - class = "", - visible = true, - opacity = 1, - offsetx = 0, - offsety = 0, - parallaxx = 1, - parallaxy = 1, - properties = {}, - encoding = "lua", - data = { - 4, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 5, - 6, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 13, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 14, - 15, - 22, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 24, - }, - }, - { - type = "tilelayer", - x = 0, - y = 0, - width = 25, - height = 15, - id = 2, - name = "Inner Walls", - class = "", - visible = true, - opacity = 1, - offsetx = 0, - offsety = 0, - parallaxx = 1, - parallaxy = 1, - properties = {}, - encoding = "lua", - data = { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 7, - 9, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 7, - 8, - 8, - 8, - 9, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 16, - 18, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 25, - 26, - 26, - 26, - 27, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 25, - 27, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 7, - 8, - 9, - 0, - 0, - 7, - 8, - 8, - 8, - 8, - 8, - 9, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 7, - 8, - 17, - 17, - 18, - 0, - 0, - 16, - 17, - 17, - 17, - 17, - 17, - 18, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 16, - 17, - 17, - 26, - 26, - 8, - 8, - 17, - 26, - 26, - 26, - 26, - 26, - 27, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 16, - 17, - 18, - 0, - 0, - 16, - 17, - 18, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 16, - 17, - 18, - 0, - 0, - 25, - 26, - 27, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 7, - 8, - 8, - 8, - 9, - 0, - 0, - 0, - 0, - 16, - 17, - 27, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 7, - 8, - 9, - 0, - 0, - 0, - 16, - 17, - 17, - 17, - 18, - 0, - 0, - 0, - 0, - 25, - 27, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 16, - 17, - 18, - 0, - 0, - 0, - 16, - 17, - 17, - 17, - 18, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 25, - 26, - 27, - 0, - 0, - 0, - 25, - 26, - 26, - 26, - 27, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - }, - }, - { - type = "objectgroup", - draworder = "topdown", - id = 4, - name = "Walls", - class = "", - visible = false, - opacity = 1, - offsetx = 0, - offsety = 0, - parallaxx = 1, - parallaxy = 1, - properties = {}, - objects = { - { - id = 10, - name = "", - type = "", - shape = "rectangle", - x = 512, - y = 128, - width = 320, - height = 128, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 11, - name = "", - type = "", - shape = "rectangle", - x = 1344, - y = 64, - width = 128, - height = 192, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 12, - name = "", - type = "", - shape = "rectangle", - x = 1152, - y = 640, - width = 320, - height = 256, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 13, - name = "", - type = "", - shape = "rectangle", - x = 768, - y = 704, - width = 192, - height = 192, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 19, - name = "", - type = "", - shape = "rectangle", - x = 576, - y = 384, - width = 448, - height = 192, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 20, - name = "", - type = "", - shape = "rectangle", - x = 448, - y = 512, - width = 192, - height = 192, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 21, - name = "", - type = "", - shape = "rectangle", - x = 256, - y = 384, - width = 192, - height = 192, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 22, - name = "", - type = "", - shape = "rectangle", - x = 128, - y = 448, - width = 192, - height = 320, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 23, - name = "", - type = "", - shape = "rectangle", - x = 128, - y = 768, - width = 128, - height = 64, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 30, - name = "", - type = "", - shape = "rectangle", - x = 0, - y = 0, - width = 16, - height = 960, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 31, - name = "", - type = "", - shape = "rectangle", - x = 1584, - y = 0, - width = 16, - height = 960, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 32, - name = "", - type = "", - shape = "rectangle", - x = 0, - y = 0, - width = 1600, - height = 16, - rotation = 0, - visible = true, - properties = {}, - }, - { - id = 33, - name = "", - type = "", - shape = "rectangle", - x = 0, - y = 944, - width = 1600, - height = 16, - rotation = 0, - visible = true, - properties = {}, - }, - }, - }, - }, -} diff --git a/mapsloader.lua b/mapsloader.lua index dc25147..f1c9f40 100644 --- a/mapsloader.lua +++ b/mapsloader.lua @@ -1,17 +1,9 @@ -function LoadMap(lvlnum) - --TODO: FINISH THIS +function loadMap(lvl) local mapfilelocation = "maps/" local extention = ".lua" + local mapname = mapfilelocation .. "map" .. lvl .. extention - --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 + GameMap = STI(mapname) Walls = {} if GameMap.layers["Walls"] then for _, obj in ipairs(GameMap.layers["Walls"].objects) do @@ -21,4 +13,4 @@ function LoadMap(lvlnum) Walls[#Walls]:setCollisionClass("Wall") end end -end +end \ No newline at end of file diff --git a/player.lua b/player.lua index 7c1f310..b5e7dee 100644 --- a/player.lua +++ b/player.lua @@ -47,80 +47,80 @@ function Player:shoot(bulletSpeed) return newBullet end +function handleKeys(dt) +end + -- Update method for the Player class function Player:update(dt) - self.vx = 0 - self.vy = 0 - local bulletSpeed = 20000 + if _G.GAMESTATE == "GAME" then + self.vx = 0 + self.vy = 0 + local bulletSpeed = 20000 - if self.p == 1 then - -- Handle player 1 controls - if love.keyboard.isDown("w") then - self.vx = cos(self.rotation) * (self.speed * dt) - self.vy = sin(self.rotation) * (self.speed * dt) - elseif love.keyboard.isDown("s") then - self.vx = cos(self.rotation) * (self.speed * dt) * -1 - self.vy = sin(self.rotation) * (self.speed * dt) * -1 - elseif love.keyboard.isDown("a") then - self.rotation = self.rotation - (self.rotSpeed * dt) - elseif love.keyboard.isDown("d") then - self.rotation = self.rotation + (self.rotSpeed * dt) - end + if self.p == 1 then + -- Handle player 1 controls + if love.keyboard.isDown("w") then + self.vx = cos(self.rotation) * (self.speed * dt) + self.vy = sin(self.rotation) * (self.speed * dt) + elseif love.keyboard.isDown("s") then + self.vx = cos(self.rotation) * (self.speed * dt) * -1 + self.vy = sin(self.rotation) * (self.speed * dt) * -1 + elseif love.keyboard.isDown("a") then + self.rotation = self.rotation - (self.rotSpeed * dt) + elseif love.keyboard.isDown("d") then + self.rotation = self.rotation + (self.rotSpeed * dt) + end - self.collider:setLinearVelocity(self.vx, self.vy) + self.collider:setLinearVelocity(self.vx, self.vy) - -- Check for collision with walls - if self.collider:enter("Wall") then - print("Player 1 collided with wall") - end + -- Check for collision with walls + if self.collider:enter("Wall") then + print("Player 1 collided with wall") + end - if EnableKeyPress1 == true then - if love.keyboard.isDown("space") then - local newBullet = self:shoot(bulletSpeed) - table.insert(Bullets1, newBullet) - KeyPressTime1 = KeyDelay1 - EnableKeyPress1 = false + if EnableKeyPress1 == true and GAMESTATE == "GAME" then + if love.keyboard.isDown("space") then + local newBullet = self:shoot(bulletSpeed) + table.insert(Bullets1, newBullet) + KeyPressTime1 = KeyDelay1 + EnableKeyPress1 = false + end end - end - self.x = self.collider:getX() - self.y = self.collider:getY() + 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 - self.vx = cos(self.rotation) * (self.speed * dt) - self.vy = sin(self.rotation) * (self.speed * dt) - elseif love.keyboard.isDown("down") then - self.vx = cos(self.rotation) * (self.speed * dt) * -1 - self.vy = sin(self.rotation) * (self.speed * dt) * -1 - elseif love.keyboard.isDown("left") then - self.rotation = self.rotation - (self.rotSpeed * dt) - elseif love.keyboard.isDown("right") then - self.rotation = self.rotation + (self.rotSpeed * dt) - end - self.collider:setLinearVelocity(self.vx, self.vy) + elseif self.p == 2 then + -- Handle player 2 controls + if love.keyboard.isDown("up") then + self.vx = cos(self.rotation) * (self.speed * dt) + self.vy = sin(self.rotation) * (self.speed * dt) + elseif love.keyboard.isDown("down") then + self.vx = cos(self.rotation) * (self.speed * dt) * -1 + self.vy = sin(self.rotation) * (self.speed * dt) * -1 + elseif love.keyboard.isDown("left") then + self.rotation = self.rotation - (self.rotSpeed * dt) + elseif love.keyboard.isDown("right") then + self.rotation = self.rotation + (self.rotSpeed * dt) + end + self.collider:setLinearVelocity(self.vx, self.vy) - -- Check for collision with walls - if self.collider:enter("Wall") then - print("Player 2 collided with wall") - end + -- Check for collision with walls + if self.collider:enter("Wall") then + print("Player 2 collided with wall") + end - if EnableKeyPress2 == true then - if love.keyboard.isDown("return") then - local newBullet = self:shoot(bulletSpeed) - table.insert(Bullets2, newBullet) - KeyPressTime2 = KeyDelay2 - EnableKeyPress2 = false + if EnableKeyPress2 == true then + if love.keyboard.isDown("return") then + local newBullet = self:shoot(bulletSpeed) + table.insert(Bullets2, newBullet) + KeyPressTime2 = KeyDelay2 + EnableKeyPress2 = false + end end end + self.x = self.collider:getX() + self.y = self.collider:getY() end - self.x = self.collider:getX() - self.y = self.collider:getY() end function Player:draw()