From 9918992fbd1268bd063d39616fb356a509c1dc42 Mon Sep 17 00:00:00 2001 From: Madi Date: Fri, 21 Jan 2022 09:08:35 +0600 Subject: [PATCH] Added rotatable engine controls --- data/controls.lua | 5 ++++- data/info.lua | 3 ++- main.lua | 2 +- src/calc.lua | 2 +- src/class/Player.lua | 28 ++++++++++++++++++++++++++-- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/data/controls.lua b/data/controls.lua index eaa4a3b..bec4621 100755 --- a/data/controls.lua +++ b/data/controls.lua @@ -18,7 +18,10 @@ controls = { up = "w", down = "s", left = "a", - right = "d" + right = "d", + engine = "space", + rotleft = "q", + rotright = "e" }, -- Time Warp Controls: diff --git a/data/info.lua b/data/info.lua index 80001b3..c06cab3 100755 --- a/data/info.lua +++ b/data/info.lua @@ -3,7 +3,8 @@ info = {} info.name = "Questionable Örbital Mechanics" info.version = "0.0.2_dev" info.authors = { - "NiroUwU" + "NiroUwU", + "Madiwka4" } return info \ No newline at end of file diff --git a/main.lua b/main.lua index babba06..6abf3be 100755 --- a/main.lua +++ b/main.lua @@ -8,7 +8,7 @@ function love.load() love.window.setTitle(info.name.." - v"..info.version) width, height = love.graphics.getDimensions() cam = Camera() - zoomlevel = 0.005 + zoomlevel = 0.5 diff --git a/src/calc.lua b/src/calc.lua index 8805b31..ca4cc81 100755 --- a/src/calc.lua +++ b/src/calc.lua @@ -3,7 +3,7 @@ calc = {} -- G-Constant calc.G = 6.67e-11 -- TWEAKABLE FOR LATER DEPENDING ON SCALE!!!!!!!!!!! - +calc.pi = 3.14 -- Development debugging/logging thing function calc.debug(text) if calc.isDebug then diff --git a/src/class/Player.lua b/src/class/Player.lua index efdf147..9bcc717 100755 --- a/src/class/Player.lua +++ b/src/class/Player.lua @@ -30,6 +30,9 @@ function Player:init(tempX, tempY) -- Mass: self.m = 10 + + -- Rotation: + self.angle = calc.pi/2 end @@ -98,6 +101,21 @@ function Player:flightControls() debug("Player control: right") end + + -- Main Engine controls: + if love.keyboard.isDown(controls.flight.thrust.engine) then + self.xSpeed = self.xSpeed + math.cos(self.angle) * speedChange + debug("Ship thrusters X: " .. math.cos(self.angle) .. " " .. math.sin(self.angle) .. " " .. self.angle) + self.ySpeed = self.ySpeed - math.sin(self.angle) * speedChange + end + if love.keyboard.isDown(controls.flight.thrust.rotleft) then + self.angle = self.angle + 1/love.timer.getFPS() + end + if love.keyboard.isDown(controls.flight.thrust.rotright) then + self.angle = self.angle - 1/love.timer.getFPS() + end + + -- Reset: if love.keyboard.isDown(controls.flight.reset) then self:reset() @@ -189,7 +207,11 @@ function Player:update(dt) self:updatePosition() end self:throttleControls() - + if self.angle > calc.pi*2 then + self.angle = 0 + elseif self.angle < 0 then + self.angle = calc.pi*2 + end self.coolDown = self.coolDown - 1 end @@ -207,10 +229,12 @@ function Player:draw() -- Right Bottom x+dist, y+dist } - love.graphics.setColor(0.5, 0.5, 0.7) love.graphics.polygon("fill", vertices) love.graphics.setColor(1, 0, 0) love.graphics.circle("fill", x, y, 5, 20) + + -- Directional Circle (temporary until actual rotatable ship texture is made) + love.graphics.circle("fill", x+dist*math.cos(self.angle), y-dist*math.sin(self.angle), 3, 20) end \ No newline at end of file