player ship
This commit is contained in:
parent
2f455e9c55
commit
e355e5d3fe
19 changed files with 225 additions and 13 deletions
|
@ -4,7 +4,10 @@ multilily = lily.loadMulti({
|
||||||
{lily.newImage, "assets/hud.png"},
|
{lily.newImage, "assets/hud.png"},
|
||||||
{lily.newImage, "assets/captains/steve-layer.png"},
|
{lily.newImage, "assets/captains/steve-layer.png"},
|
||||||
{lily.newImage, "assets/captains/robert-davis.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)
|
multilily:onComplete(function(_, lilies)
|
||||||
gameLogo = lilies[1][1]
|
gameLogo = lilies[1][1]
|
||||||
|
@ -13,6 +16,9 @@ multilily:onComplete(function(_, lilies)
|
||||||
CaptainSteve.image = lilies[4][1]
|
CaptainSteve.image = lilies[4][1]
|
||||||
CaptainRobert.image = lilies[5][1]
|
CaptainRobert.image = lilies[5][1]
|
||||||
CaptainJohn.image = lilies[6][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()
|
windowWidth = love.graphics.getWidth()
|
||||||
windowHeight = love.graphics.getHeight()
|
windowHeight = love.graphics.getHeight()
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.9 KiB |
BIN
assets/ships/blackstar-5.png
Normal file
BIN
assets/ships/blackstar-5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 397 B |
BIN
assets/ships/blackstar-5.psd
Normal file
BIN
assets/ships/blackstar-5.psd
Normal file
Binary file not shown.
BIN
assets/ships/decorator.png
Normal file
BIN
assets/ships/decorator.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 397 B |
BIN
assets/ships/excalibur-iv.png
Normal file
BIN
assets/ships/excalibur-iv.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 401 B |
|
@ -1,7 +1,8 @@
|
||||||
JohnDanger = Object.extend(Player)
|
JohnDanger = Object.extend(Player)
|
||||||
|
|
||||||
function JohnDanger:new()
|
function JohnDanger:new()
|
||||||
|
JohnDanger.super.new(self)
|
||||||
self.name = "John Danger";
|
self.name = "John Danger";
|
||||||
self.shipName = "The Decorator"
|
|
||||||
self.image = nil
|
self.image = nil
|
||||||
|
self.ship = Decorator()
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,4 +4,15 @@ function Player:new()
|
||||||
self.name = "";
|
self.name = "";
|
||||||
self.shipName = ""
|
self.shipName = ""
|
||||||
self.image = nil
|
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
|
end
|
||||||
|
|
||||||
|
function Player:getShipname()
|
||||||
|
return self.ship.name
|
||||||
|
end
|
|
@ -1,7 +1,8 @@
|
||||||
RobertDavis = Object.extend(Player)
|
RobertDavis = Object.extend(Player)
|
||||||
|
|
||||||
function RobertDavis:new()
|
function RobertDavis:new()
|
||||||
|
RobertDavis.super.new(self)
|
||||||
self.name = "Robert Davis";
|
self.name = "Robert Davis";
|
||||||
self.shipName = "Excalibur IV"
|
|
||||||
self.image = nil
|
self.image = nil
|
||||||
|
self.ship = ExcaliburIV()
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
SteveLayer = Object.extend(Player)
|
SteveLayer = Object.extend(Player)
|
||||||
|
|
||||||
function SteveLayer:new()
|
function SteveLayer:new()
|
||||||
|
SteveLayer.super.new(self)
|
||||||
self.name = "Steve Layer"
|
self.name = "Steve Layer"
|
||||||
self.shipName = "Blackstar 5"
|
|
||||||
self.image = nil
|
self.image = nil
|
||||||
|
self.ship = Blackstar5()
|
||||||
end
|
end
|
||||||
|
|
8
main.lua
8
main.lua
|
@ -17,6 +17,8 @@ function love.load()
|
||||||
|
|
||||||
Object = require "vendor/classic"
|
Object = require "vendor/classic"
|
||||||
|
|
||||||
|
require "vendor/math"
|
||||||
|
|
||||||
moonshine = require "shaders"
|
moonshine = require "shaders"
|
||||||
effect = moonshine(moonshine.effects.vignette).chain(moonshine.effects.filmgrain)
|
effect = moonshine(moonshine.effects.vignette).chain(moonshine.effects.filmgrain)
|
||||||
effect.vignette.softness = 0.4
|
effect.vignette.softness = 0.4
|
||||||
|
@ -26,11 +28,17 @@ function love.load()
|
||||||
require "scene/load"
|
require "scene/load"
|
||||||
require "scene/title"
|
require "scene/title"
|
||||||
require "scene/game"
|
require "scene/game"
|
||||||
|
|
||||||
require "captain/player"
|
require "captain/player"
|
||||||
require "captain/robertdavis"
|
require "captain/robertdavis"
|
||||||
require "captain/stevelayer"
|
require "captain/stevelayer"
|
||||||
require "captain/johndanger"
|
require "captain/johndanger"
|
||||||
|
|
||||||
|
require "ship/ship"
|
||||||
|
require "ship/blackstar5"
|
||||||
|
require "ship/excaliburiv"
|
||||||
|
require "ship/decorator"
|
||||||
|
|
||||||
LoadScene = LoadScene()
|
LoadScene = LoadScene()
|
||||||
TitleScene = TitleScene()
|
TitleScene = TitleScene()
|
||||||
GameScene = GameScene()
|
GameScene = GameScene()
|
||||||
|
|
106
scene/game.lua
106
scene/game.lua
|
@ -4,37 +4,129 @@ function GameScene:new()
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameScene:init()
|
function GameScene:init()
|
||||||
|
GameScene:playerChanged(currentPlayer)
|
||||||
|
movementDelta = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameScene:update(dt)
|
function GameScene:update(dt)
|
||||||
|
GameScene:updateInput(dt)
|
||||||
|
GameScene:updateBounds(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameScene:draw()
|
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
|
end
|
||||||
|
|
||||||
function GameScene:drawHud()
|
function GameScene:drawHud()
|
||||||
|
|
||||||
-- Draw images
|
|
||||||
love.graphics.setColor(255,255,255, 1)
|
love.graphics.setColor(255,255,255, 1)
|
||||||
love.graphics.draw( gameHud, 0, 600-66 )
|
love.graphics.draw( gameHud, 0, 600-66 )
|
||||||
|
|
||||||
love.graphics.setColor(255,255,255, 0.75)
|
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.setColor( text.r, text.g, text.b, text.alpha )
|
||||||
love.graphics.print( currentPlayer.name, 48, 550 )
|
love.graphics.print( currentPlayer.name, 48, 550 )
|
||||||
love.graphics.print( currentPlayer.shipName, 48, 566 )
|
love.graphics.print( currentPlayer:getShipname(), 48, 566 )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameScene:keypressed(key,unicode)
|
function GameScene:keypressed(key,unicode)
|
||||||
if key == "1" then
|
if key == "1" then
|
||||||
currentPlayer = CaptainSteve
|
GameScene:playerChanged(CaptainSteve)
|
||||||
elseif key == "2" then
|
elseif key == "2" then
|
||||||
currentPlayer = CaptainRobert
|
GameScene:playerChanged(CaptainRobert)
|
||||||
elseif key == "3" then
|
elseif key == "3" then
|
||||||
currentPlayer = CaptainJohn
|
GameScene:playerChanged(CaptainJohn)
|
||||||
end
|
end
|
||||||
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
|
|
@ -7,8 +7,8 @@ function LoadScene:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function LoadScene:draw()
|
function LoadScene:draw()
|
||||||
love.graphics.setColor( text.r, text.g, text.b, text.a )
|
--love.graphics.setColor( text.r, text.g, text.b, text.a )
|
||||||
love.graphics.print("Loading assets", 10, 10)
|
--love.graphics.print("Loading assets", 10, 10)
|
||||||
end
|
end
|
||||||
|
|
||||||
function LoadScene:drawHud()
|
function LoadScene:drawHud()
|
||||||
|
|
|
@ -43,6 +43,7 @@ function TitleScene:update(dt)
|
||||||
|
|
||||||
if state == "complete" then
|
if state == "complete" then
|
||||||
currentScene = GameScene
|
currentScene = GameScene
|
||||||
|
currentScene:init()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
7
ship/blackstar5.lua
Normal file
7
ship/blackstar5.lua
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Blackstar5 = Object.extend(Ship)
|
||||||
|
|
||||||
|
function Blackstar5:new()
|
||||||
|
Blackstar5.super.new(self)
|
||||||
|
self.name = "Blackstar 5";
|
||||||
|
self.image = nil
|
||||||
|
end
|
7
ship/decorator.lua
Normal file
7
ship/decorator.lua
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
Decorator = Object.extend(Ship)
|
||||||
|
|
||||||
|
function Decorator:new()
|
||||||
|
Decorator.super.new(self)
|
||||||
|
self.name = "The Decorator";
|
||||||
|
self.image = nil
|
||||||
|
end
|
7
ship/excaliburiv.lua
Normal file
7
ship/excaliburiv.lua
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
ExcaliburIV = Object.extend(Ship)
|
||||||
|
|
||||||
|
function ExcaliburIV:new()
|
||||||
|
ExcaliburIV.super.new(self)
|
||||||
|
self.name = "Excalibur IV";
|
||||||
|
self.image = nil
|
||||||
|
end
|
6
ship/ship.lua
Normal file
6
ship/ship.lua
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
Ship = Object.extend(Object)
|
||||||
|
|
||||||
|
function Ship:new()
|
||||||
|
self.name = "";
|
||||||
|
self.image = nil
|
||||||
|
end
|
64
vendor/math.lua
vendored
Normal file
64
vendor/math.lua
vendored
Normal file
|
@ -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
|
Loading…
Reference in a new issue