From 8a80e3d9f656576bc05caca42379333c25dc7918 Mon Sep 17 00:00:00 2001 From: Guard13007 Date: Thu, 15 Jan 2015 14:56:26 -0800 Subject: [PATCH] ships stuff and camera (slightly broken) --- src/Debug.lua | 16 ++++++----- src/Player.lua | 1 - src/Ships/Demo.lua | 40 +++++++++++++++++++++++++++ src/main.lua | 68 ++++++++-------------------------------------- 4 files changed, 61 insertions(+), 64 deletions(-) create mode 100644 src/Ships/Demo.lua diff --git a/src/Debug.lua b/src/Debug.lua index f286a64..3f89cba 100644 --- a/src/Debug.lua +++ b/src/Debug.lua @@ -8,25 +8,27 @@ local debug = { fuelNumber = "above", -- (white) fuel/max fuel in numerical form } -function Debug:drawAbove() +function Debug:drawAbove(x, y) for k,v in pairs(debug) do if v == "above" then - Debug[k]() + Debug[k](x, y) end end end -function Debug:drawBelow() +function Debug:drawBelow(x, y) for k,v in pairs(debug) do if v == "below" then - Debug[k]() + Debug[k](x, y) end end end -function Debug:hitRadius() +function Debug:hitRadius(x, y) love.graphics.setLineWidth(1) love.graphics.setColor(255, 0, 255) -- as much as I love this orange: 188, 128, 90, THIS NEEDS TO STAND OUT + -- DOES NOT WORK FOR NO REASON + --love.graphics.arc("line", x + player.Ship.x, y + player.Ship.y, player.Ship.Hull.hitRadius, 0, math.pi*2, 20) love.graphics.arc("line", player.Ship.x, player.Ship.y, player.Ship.Hull.hitRadius, 0, math.pi*2, 20) end @@ -37,9 +39,9 @@ function Debug:middleLines() love.graphics.line(0, love.graphics.getHeight() / 2, love.graphics.getWidth(), love.graphics.getHeight() / 2) end -function Debug:playerCenter() +function Debug:playerCenter(x, y) love.graphics.setColor(255, 100, 100) - love.graphics.arc("fill", player.Ship.x, player.Ship.y, 3, 0, math.pi*2, 20) + love.graphics.arc("fill", x + player.Ship.x, y + player.Ship.y, 3, 0, math.pi*2, 20) end function Debug:fpsCounter() diff --git a/src/Player.lua b/src/Player.lua index 510119c..a71b48a 100644 --- a/src/Player.lua +++ b/src/Player.lua @@ -1,5 +1,4 @@ local class = require "lib.middleclass" -local Ship = require "Ship" local Player = class('Player') diff --git a/src/Ships/Demo.lua b/src/Ships/Demo.lua new file mode 100644 index 0000000..0e6202e --- /dev/null +++ b/src/Ships/Demo.lua @@ -0,0 +1,40 @@ +local Player = require "Player" +local Ship = require "Ship" +local Hull = require "Hull" +local Shield = require "Shield" +local Engine = require "Engine" +local Thruster = require "Thruster" + +Ship = Player(Ship( +Hull("images/fighter1.png", 1.5, 16, 10000), +Shield("images/shieldhit1.png", 1.6), +Engine(40000, 0.95, 10, 7.5, 33, 0.93, 0.5), +{ + Thruster(1300, "forward", -8.5, 16.5, {160, 250, 255}, 2.4, 0.7), + Thruster(1300, "forward", 8.5, 16.5, {160, 250, 255}, 2.4, 0.7), + Thruster(650, "backward", -13, 1.8, {200, 240, 255}, 1.8, 0.8), + Thruster(650, "backward", 13, 1.8, {200, 240, 255}, 1.8, 0.8), + Thruster(320, "left", 6, -4.4, {220, 230, 250}, 0.6, 1), + Thruster(540, "left", 17.5, 5.5, {220, 230, 250}, 1.2, 0.9), + Thruster(320, "right", -6, -4.4, {220, 230, 250}, 0.6, 1), + Thruster(540, "right", -17.5, 5.5, {220, 230, 250}, 1.2, 0.9), + Thruster(90, "rotateleft", 4.4, -16, {250, 200, 200}, 0.4, 1.1), + Thruster(110, "rotateleft", -11, 14.3, {255, 230, 230}, 0.6, 1), + Thruster(110, "rotateleft", 13, 11, {250, 200, 200}, 0.6, 1), + Thruster(90, "rotateright", -4.8, -16, {250, 200, 200}, 0.4, 1.1), + Thruster(110, "rotateright", 10.4, 14.3, {255, 230, 230}, 0.6, 1), + Thruster(110, "rotateright", -13.6, 11, {250, 200, 200}, 0.6, 1), + }, + { + x = love.graphics.getWidth() / 2, + y = love.graphics.getHeight() / 2, + v = { + x = 0, + y = 0 + }, + currentRotation = 0, + rotationSpeed = 0 + } +)) + +return Ship diff --git a/src/main.lua b/src/main.lua index 884e6cf..1aa4192 100644 --- a/src/main.lua +++ b/src/main.lua @@ -7,14 +7,6 @@ console = { -- Camera (offset) local Camera = { x = 0, y = 0 } --- Classes -local Player = require "Player" -local Ship = require "Ship" -local Hull = require "Hull" -local Shield = require "Shield" -local Engine = require "Engine" -local Thruster = require "Thruster" - local Debug = require "Debug" -- GLOBALS @@ -25,37 +17,7 @@ Render = { hudFont = love.graphics.newFont("fonts/Audimat Mono Regular.ttf", 16), } -player = Player(Ship( - Hull("images/fighter1.png", 1.5, 16, 10000), - Shield("images/shieldhit1.png", 1.6), - Engine(40000, 0.95, 10, 7.5, 33, 0.93, 0.5), - { - Thruster(1300, "forward", -8.5, 16.5, {160, 250, 255}, 2.4, 0.7), - Thruster(1300, "forward", 8.5, 16.5, {160, 250, 255}, 2.4, 0.7), - Thruster(650, "backward", -13, 1.8, {200, 240, 255}, 1.8, 0.8), - Thruster(650, "backward", 13, 1.8, {200, 240, 255}, 1.8, 0.8), - Thruster(320, "left", 6, -4.4, {220, 230, 250}, 0.6, 1), - Thruster(540, "left", 17.5, 5.5, {220, 230, 250}, 1.2, 0.9), - Thruster(320, "right", -6, -4.4, {220, 230, 250}, 0.6, 1), - Thruster(540, "right", -17.5, 5.5, {220, 230, 250}, 1.2, 0.9), - Thruster(90, "rotateleft", 4.4, -16, {250, 200, 200}, 0.4, 1.1), - Thruster(110, "rotateleft", -11, 14.3, {255, 230, 230}, 0.6, 1), - Thruster(110, "rotateleft", 13, 11, {250, 200, 200}, 0.6, 1), - Thruster(90, "rotateright", -4.8, -16, {250, 200, 200}, 0.4, 1.1), - Thruster(110, "rotateright", 10.4, 14.3, {255, 230, 230}, 0.6, 1), - Thruster(110, "rotateright", -13.6, 11, {250, 200, 200}, 0.6, 1), - }, - { - x = love.graphics.getWidth() / 2, - y = love.graphics.getHeight() / 2, - v = { - x = 0, - y = 0 - }, - currentRotation = 0, - rotationSpeed = 0 - } -)) +player = require "Ships.Demo" function love.update(dt) -- player rotation input @@ -107,15 +69,9 @@ function love.update(dt) player.Ship.y = player.Ship.y + player.Ship.v.y * dt -- Camera position updated - local dx = (player.Ship.x - Camera.x - love.graphics.getWidth() / 2) / 10 --love.graphics.getWidth() --/ 2 - local dy = (player.Ship.y - Camera.y - love.graphics.getHeight() / 2) / 10 --love.graphics.getHeight() --/ 2 - --add min/max stuff here - if dx > love.graphics.getWidth() then - dx = love.graphics.getWidth() / 3 - end - if dy > love.graphics.getHeight() then - dy = love.graphics.getHeight() / 3 - end + local dx = (player.Ship.x + Camera.x - love.graphics.getWidth() / 2) * math.abs((player.Ship.x + Camera.x - love.graphics.getWidth() / 2) / love.graphics.getWidth() / 5) + local dy = (player.Ship.y + Camera.y - love.graphics.getHeight() / 2) * math.abs((player.Ship.y + Camera.y - love.graphics.getHeight() / 2) / love.graphics.getHeight() / 5) + --add min/max stuff here? Camera.x = Camera.x - dx Camera.y = Camera.y - dy @@ -125,7 +81,7 @@ end function love.draw() -- Debug below! - Debug:drawBelow() + Debug:drawBelow(Camera.x, Camera.y) -- Ship draw love.graphics.setColor(255, 255, 255) @@ -143,39 +99,39 @@ function love.draw() if love.keyboard.isDown('w') and player.Ship.Hull.fuelAmount > 0 then for i=1,#player.Ship.Thrusters do if player.Ship.Thrusters[i].direction == "forward" then - player.Ship.Thrusters[i]:draw(player.Ship.x, player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) + player.Ship.Thrusters[i]:draw(Camera.x + player.Ship.x, Camera.y + player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) end end elseif love.keyboard.isDown('s') and player.Ship.Hull.fuelAmount > 0 then for i=1,#player.Ship.Thrusters do if player.Ship.Thrusters[i].direction == "backward" then - player.Ship.Thrusters[i]:draw(player.Ship.x, player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) + player.Ship.Thrusters[i]:draw(Camera.x + player.Ship.x, Camera.y + player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) end end end if love.keyboard.isDown('j') and player.Ship.Hull.fuelAmount > 0 then for i=1,#player.Ship.Thrusters do if player.Ship.Thrusters[i].direction == "left" then - player.Ship.Thrusters[i]:draw(player.Ship.x, player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) + player.Ship.Thrusters[i]:draw(Camera.x + player.Ship.x, Camera.y + player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) end end elseif love.keyboard.isDown('l') and player.Ship.Hull.fuelAmount > 0 then for i=1,#player.Ship.Thrusters do if player.Ship.Thrusters[i].direction == "right" then - player.Ship.Thrusters[i]:draw(player.Ship.x, player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) + player.Ship.Thrusters[i]:draw(Camera.x + player.Ship.x, Camera.y + player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) end end end if love.keyboard.isDown('q') and player.Ship.Hull.fuelAmount > 0 or love.keyboard.isDown('a') and player.Ship.Hull.fuelAmount > 0 then for i=1,#player.Ship.Thrusters do if player.Ship.Thrusters[i].direction == "rotateleft" then - player.Ship.Thrusters[i]:draw(player.Ship.x, player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) + player.Ship.Thrusters[i]:draw(Camera.x + player.Ship.x, Camera.y + player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) end end elseif love.keyboard.isDown('e') and player.Ship.Hull.fuelAmount > 0 or love.keyboard.isDown('d') and player.Ship.Hull.fuelAmount > 0 then for i=1,#player.Ship.Thrusters do if player.Ship.Thrusters[i].direction == "rotateright" then - player.Ship.Thrusters[i]:draw(player.Ship.x, player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) + player.Ship.Thrusters[i]:draw(Camera.x + player.Ship.x, Camera.y + player.Ship.y, player.Ship.currentRotation - (player.Ship.currentRotation % player.Ship.Engine.degreeLock)) end end end @@ -190,5 +146,5 @@ function love.draw() love.graphics.rectangle("fill", 4, love.graphics.getHeight() - 12, player.Ship.Hull.fuelAmount / player.Ship.Hull.fuelCapacity * 123, 8) --max width is 123 -- Debug above! - Debug:drawAbove() + Debug:drawAbove(Camera.x, Camera.y) end