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 910bff4..758bba3 100644 Binary files a/game.love and b/game.love differ 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()