diff --git a/assets.lua b/assets.lua index 548908c..b041cdd 100644 --- a/assets.lua +++ b/assets.lua @@ -4,7 +4,10 @@ multilily = lily.loadMulti({ {lily.newImage, "assets/hud.png"}, {lily.newImage, "assets/captains/steve-layer.png"}, {lily.newImage, "assets/captains/robert-davis.png"}, - {lily.newImage, "assets/captains/john-danger.png"} + {lily.newImage, "assets/captains/john-danger.png"}, + {lily.newImage, "assets/ships/blackstar-5.png"}, + {lily.newImage, "assets/ships/excalibur-iv.png"}, + {lily.newImage, "assets/ships/decorator.png"} }) multilily:onComplete(function(_, lilies) gameLogo = lilies[1][1] @@ -13,6 +16,9 @@ multilily:onComplete(function(_, lilies) CaptainSteve.image = lilies[4][1] CaptainRobert.image = lilies[5][1] CaptainJohn.image = lilies[6][1] + CaptainSteve.ship.image = lilies[7][1] + CaptainRobert.ship.image = lilies[8][1] + CaptainJohn.ship.image = lilies[9][1] windowWidth = love.graphics.getWidth() windowHeight = love.graphics.getHeight() diff --git a/assets/captains/john-danger.png b/assets/captains/john-danger.png index d4f4c27..204c968 100644 Binary files a/assets/captains/john-danger.png and b/assets/captains/john-danger.png differ diff --git a/assets/ships/blackstar-5.png b/assets/ships/blackstar-5.png new file mode 100644 index 0000000..5945bee Binary files /dev/null and b/assets/ships/blackstar-5.png differ diff --git a/assets/ships/blackstar-5.psd b/assets/ships/blackstar-5.psd new file mode 100644 index 0000000..33bcd45 Binary files /dev/null and b/assets/ships/blackstar-5.psd differ diff --git a/assets/ships/decorator.png b/assets/ships/decorator.png new file mode 100644 index 0000000..30267f6 Binary files /dev/null and b/assets/ships/decorator.png differ diff --git a/assets/ships/excalibur-iv.png b/assets/ships/excalibur-iv.png new file mode 100644 index 0000000..8385fa4 Binary files /dev/null and b/assets/ships/excalibur-iv.png differ diff --git a/captain/johndanger.lua b/captain/johndanger.lua index bb7cf2a..488b77a 100644 --- a/captain/johndanger.lua +++ b/captain/johndanger.lua @@ -1,7 +1,8 @@ JohnDanger = Object.extend(Player) function JohnDanger:new() + JohnDanger.super.new(self) self.name = "John Danger"; - self.shipName = "The Decorator" self.image = nil + self.ship = Decorator() end diff --git a/captain/player.lua b/captain/player.lua index b7b0535..71f70ce 100644 --- a/captain/player.lua +++ b/captain/player.lua @@ -4,4 +4,15 @@ function Player:new() self.name = ""; self.shipName = "" self.image = nil + self.ship = nil + self.px = 0 + self.py = 0 + self.rot = 0 + self.speed = 5 + self.acc = 0 + self.accIncr = 0.1 end + +function Player:getShipname() + return self.ship.name +end \ No newline at end of file diff --git a/captain/robertdavis.lua b/captain/robertdavis.lua index 98c7316..4b0c2b3 100644 --- a/captain/robertdavis.lua +++ b/captain/robertdavis.lua @@ -1,7 +1,8 @@ RobertDavis = Object.extend(Player) function RobertDavis:new() + RobertDavis.super.new(self) self.name = "Robert Davis"; - self.shipName = "Excalibur IV" self.image = nil + self.ship = ExcaliburIV() end diff --git a/captain/stevelayer.lua b/captain/stevelayer.lua index 4fe8d0a..e0ccc26 100644 --- a/captain/stevelayer.lua +++ b/captain/stevelayer.lua @@ -1,7 +1,8 @@ SteveLayer = Object.extend(Player) function SteveLayer:new() + SteveLayer.super.new(self) self.name = "Steve Layer" - self.shipName = "Blackstar 5" self.image = nil + self.ship = Blackstar5() end diff --git a/main.lua b/main.lua index 6e66955..e3a6ca2 100644 --- a/main.lua +++ b/main.lua @@ -17,6 +17,8 @@ function love.load() Object = require "vendor/classic" + require "vendor/math" + moonshine = require "shaders" effect = moonshine(moonshine.effects.vignette).chain(moonshine.effects.filmgrain) effect.vignette.softness = 0.4 @@ -26,11 +28,17 @@ function love.load() require "scene/load" require "scene/title" require "scene/game" + require "captain/player" require "captain/robertdavis" require "captain/stevelayer" require "captain/johndanger" + require "ship/ship" + require "ship/blackstar5" + require "ship/excaliburiv" + require "ship/decorator" + LoadScene = LoadScene() TitleScene = TitleScene() GameScene = GameScene() diff --git a/scene/game.lua b/scene/game.lua index 3484c1f..84153dd 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -4,37 +4,129 @@ function GameScene:new() end function GameScene:init() + GameScene:playerChanged(currentPlayer) + movementDelta = 0 end function GameScene:update(dt) - + GameScene:updateInput(dt) + GameScene:updateBounds(dt) end function GameScene:draw() + love.graphics.setColor(255,255,255, 1) + love.graphics.draw( + currentPlayer.ship.image, + currentPlayer.px, + currentPlayer.py, + currentPlayer.rot*(math.pi/180), + 1, 1, + currentPlayer.ship.image:getWidth()/2, + currentPlayer.ship.image:getHeight()/2 + ) + love.graphics.print(currentPlayer.px..","..currentPlayer.py.." s: " .. currentPlayer.speed .. " a: " ..currentPlayer.acc,10,10) end function GameScene:drawHud() - -- Draw images love.graphics.setColor(255,255,255, 1) love.graphics.draw( gameHud, 0, 600-66 ) love.graphics.setColor(255,255,255, 0.75) - love.graphics.draw( currentPlayer.image, 14, 550,0,0.5,0.5 ) + love.graphics.draw( currentPlayer.image, 14, 550, 0, 0.5, 0.5 ) love.graphics.setColor( text.r, text.g, text.b, text.alpha ) love.graphics.print( currentPlayer.name, 48, 550 ) - love.graphics.print( currentPlayer.shipName, 48, 566 ) + love.graphics.print( currentPlayer:getShipname(), 48, 566 ) end function GameScene:keypressed(key,unicode) if key == "1" then - currentPlayer = CaptainSteve + GameScene:playerChanged(CaptainSteve) elseif key == "2" then - currentPlayer = CaptainRobert + GameScene:playerChanged(CaptainRobert) elseif key == "3" then - currentPlayer = CaptainJohn + GameScene:playerChanged(CaptainJohn) end end + +function GameScene:playerChanged(to) + currentPlayer = to + currentPlayer.px = windowWidth/2 + currentPlayer.py = windowHeight/2 + currentPlayer.rot = 0 + currentPlayer.acc = 0 + currentPlayer.bounds = { x1= 20, y1= 20, x2= windowWidth-30, y2= windowHeight - 86} +end + +function GameScene:updateInput(dt) + movementDelta = movementDelta + dt + if (movementDelta > 0.02) then + movementDelta = 0 + + local isUp = false + local isLeft = false + local isDown = false + local isRight = false + local rotation = 0 + + --local hAxis, vAxis, hAxis2, vAxis2 = love.joystick.getAxes(1) + --local axisMargin = 0.5 + + isUp = love.keyboard.isDown( "w" )-- or (not (vAxis == nil) and vAxis < -(1-axisMargin)) or (not (vAxis2 == nil) and vAxis2 < -(1-axisMargin)) or love.joystick.isDown(1, 1) + isDown = love.keyboard.isDown( "s" )-- or (not (vAxis == nil) and vAxis > (1-axisMargin)) or (not (vAxis2 == nil) and vAxis2 > (1-axisMargin)) or love.joystick.isDown(1, 2) + isLeft = love.keyboard.isDown( "a" )-- or (not (hAxis == nil) and hAxis < -(1-axisMargin)) or (not (hAxis2 == nil) and hAxis2 < -(1-axisMargin)) or love.joystick.isDown(1, 3) + isRight = love.keyboard.isDown( "d" )-- or (not (hAxis == nil) and hAxis > (1-axisMargin)) or (not (hAxis2 == nil) and hAxis2 > (1-axisMargin)) or love.joystick.isDown(1, 4) + + if isUp and isLeft then + rotation = 315 + elseif isUp and isRight then + rotation = 45 + elseif isUp then + rotation = 0 + elseif isDown and isLeft then + rotation = 225 + elseif isDown and isRight then + rotation = 135 + elseif isDown then + rotation = 180 + elseif isLeft then + rotation = 270 + elseif isRight then + rotation = 90 + end + + currentPlayer.rot = rotation + + if isUp or isDown or isLeft or isRight then + currentPlayer.acc = currentPlayer.acc + currentPlayer.accIncr + elseif currentPlayer.acc > 0 then + currentPlayer.acc = currentPlayer.acc - currentPlayer.accIncr + end + + currentPlayer.acc = math.clamp(0, currentPlayer.acc, 1) + + if isUp then + currentPlayer.py = currentPlayer.py - (currentPlayer.speed*currentPlayer.acc) + end + + if isDown then + currentPlayer.py = currentPlayer.py + (currentPlayer.speed*currentPlayer.acc) + end + + if isLeft then + currentPlayer.px = currentPlayer.px - (currentPlayer.speed*currentPlayer.acc) + end + + if isRight then + currentPlayer.px = currentPlayer.px + (currentPlayer.speed*currentPlayer.acc) + end + end +end + +function GameScene:updateBounds(dt) + currentPlayer.px = math.clamp( currentPlayer.bounds.x1, currentPlayer.px, currentPlayer.bounds.x2 ) + currentPlayer.py = math.clamp( currentPlayer.bounds.y1, currentPlayer.py, currentPlayer.bounds.y2 ) +end \ No newline at end of file diff --git a/scene/load.lua b/scene/load.lua index 98b5338..e4bbcd6 100644 --- a/scene/load.lua +++ b/scene/load.lua @@ -7,8 +7,8 @@ function LoadScene:update(dt) end function LoadScene:draw() - love.graphics.setColor( text.r, text.g, text.b, text.a ) - love.graphics.print("Loading assets", 10, 10) + --love.graphics.setColor( text.r, text.g, text.b, text.a ) + --love.graphics.print("Loading assets", 10, 10) end function LoadScene:drawHud() diff --git a/scene/title.lua b/scene/title.lua index 860e448..69ab083 100644 --- a/scene/title.lua +++ b/scene/title.lua @@ -43,6 +43,7 @@ function TitleScene:update(dt) if state == "complete" then currentScene = GameScene + currentScene:init() end end diff --git a/ship/blackstar5.lua b/ship/blackstar5.lua new file mode 100644 index 0000000..96d4afd --- /dev/null +++ b/ship/blackstar5.lua @@ -0,0 +1,7 @@ +Blackstar5 = Object.extend(Ship) + +function Blackstar5:new() + Blackstar5.super.new(self) + self.name = "Blackstar 5"; + self.image = nil +end diff --git a/ship/decorator.lua b/ship/decorator.lua new file mode 100644 index 0000000..3b03f6c --- /dev/null +++ b/ship/decorator.lua @@ -0,0 +1,7 @@ +Decorator = Object.extend(Ship) + +function Decorator:new() + Decorator.super.new(self) + self.name = "The Decorator"; + self.image = nil +end diff --git a/ship/excaliburiv.lua b/ship/excaliburiv.lua new file mode 100644 index 0000000..06ed0b3 --- /dev/null +++ b/ship/excaliburiv.lua @@ -0,0 +1,7 @@ +ExcaliburIV = Object.extend(Ship) + +function ExcaliburIV:new() + ExcaliburIV.super.new(self) + self.name = "Excalibur IV"; + self.image = nil +end diff --git a/ship/ship.lua b/ship/ship.lua new file mode 100644 index 0000000..7658c68 --- /dev/null +++ b/ship/ship.lua @@ -0,0 +1,6 @@ +Ship = Object.extend(Object) + +function Ship:new() + self.name = ""; + self.image = nil +end diff --git a/vendor/math.lua b/vendor/math.lua new file mode 100644 index 0000000..ec46adc --- /dev/null +++ b/vendor/math.lua @@ -0,0 +1,64 @@ +-- Averages an arbitrary number of angles (in radians). +function math.averageAngles(...) + local x,y = 0,0 + for i=1,select('#',...) do local a= select(i,...) x, y = x+math.cos(a), y+math.sin(a) end + return math.atan2(y, x) +end + + +-- Returns the distance between two points. +function math.dist(x1,y1, x2,y2) return ((x2-x1)^2+(y2-y1)^2)^0.5 end + + +-- Returns the angle between two points. +function math.angle(x1,y1, x2,y2) return math.atan2(x2-x1, y2-y1) end + + +-- Returns the closest multiple of 'size' (defaulting to 10). +function math.multiple(n, size) size = size or 10 return math.round(n/size)*size end + + +-- Clamps a number to within a certain range. +function math.clamp(low, n, high) return math.min(math.max(low, n), high) end + + +-- Linear interpolation between two numbers. +function lerp(a,b,t) return a+(b-a)*t end + +-- Cosine interpolation between two numbers. +function cerp(a,b,t) local f=(1-math.cos(t*math.pi))*.5 return a*(1-f)+b*f end + + +-- Normalize two numbers. +function math.normalize(x,y) local l=(x*x+y*y)^.5 if l==0 then return 0,0,0 else return x/l,y/l,l end end + + +-- Returns 'n' rounded to the nearest 'deci'th (defaulting whole numbers). +function math.round(n, deci) deci = 10^(deci or 0) return math.floor(n*deci+.5)/deci end + + +-- Randomly returns either -1 or 1. +function math.rsign() return math.random(2) == 2 and 1 or -1 end + + +-- Returns 1 if number is positive, -1 if it's negative, or 0 if it's 0. +function math.sign(n) return n>0 and 1 or n<0 and -1 or 0 end + + +-- Checks if two lines intersect (or line segments if seg is true) +-- Lines are given as four numbers (two coordinates) +function findIntersect(l1p1x,l1p1y, l1p2x,l1p2y, l2p1x,l2p1y, l2p2x,l2p2y, seg1, seg2) + local a1,b1,a2,b2 = l1p2y-l1p1y, l1p1x-l1p2x, l2p2y-l2p1y, l2p1x-l2p2x + local c1,c2 = a1*l1p1x+b1*l1p1y, a2*l2p1x+b2*l2p1y + local det,x,y = a1*b2 - a2*b1 + if det==0 then return false, "The lines are parallel." end + x,y = (b2*c1-b1*c2)/det, (a1*c2-a2*c1)/det + if seg1 or seg2 then + local min,max = math.min, math.max + if seg1 and not (min(l1p1x,l1p2x) <= x and x <= max(l1p1x,l1p2x) and min(l1p1y,l1p2y) <= y and y <= max(l1p1y,l1p2y)) or + seg2 and not (min(l2p1x,l2p2x) <= x and x <= max(l2p1x,l2p2x) and min(l2p1y,l2p2y) <= y and y <= max(l2p1y,l2p2y)) then + return false, "The lines don't intersect." + end + end + return x,y +end \ No newline at end of file