| @@ -0,0 +1,28 @@ | |||||
| -- Storage for longer text strings and dialogue (?) in future for primarily textboxes | |||||
| text = { | |||||
| tutorial = { | |||||
| "Throttle:\n", | |||||
| " " .. controls.flight.throttle.up .. ", " .. controls.flight.throttle.down .. " - Changes your throttle (gui box left bottom)\n", | |||||
| " " .. controls.flight.throttle.full .. ", " .. controls.flight.throttle.none .. " - Quick toggle full or no thrust\n\n", | |||||
| "Engines:\n", | |||||
| " " .. controls.flight.thrust.engine .. " - Hold to activate your main engine", | |||||
| " " .. controls.flight.thrust.up .. ", "..controls.flight.thrust.left .. ", " .. controls.flight.thrust.down .. ", " .. controls.flight.thrust.right .. " - Small thrust in the four directions\n\n", | |||||
| "Steering:\n", | |||||
| " " .. controls.flight.thrust.rotleft .. ", " .. controls.flight.thrust.rotright .. " - Rotate spacecraft left and right\n\n", | |||||
| "Time Warp:\n", | |||||
| " " .. controls.flight.warp.up .. ", " .. controls.flight.warp.down .. " (period and comma) - Speed time warp up/down \n", | |||||
| " " .. controls.flight.warp.reset .. " (minus) - Reset time warp to default (1)\n\n", | |||||
| "Camera:\n", | |||||
| " " .. "Scroll mouse wheel" .. " - Zoom in and out\n", | |||||
| " " .. "Mouse Button "..controls.camera.zoom.reset .. " - Reset zoom to default\n\n\n", | |||||
| "Key bindings can be changed in game files [data/controls.lua]!" | |||||
| } | |||||
| } | |||||
| return text | |||||
| @@ -10,12 +10,15 @@ controls = require "data/controls" | |||||
| settings = require "data/settings" | settings = require "data/settings" | ||||
| starshipTypes = require "data/starshipTypes" | starshipTypes = require "data/starshipTypes" | ||||
| font = require "data/font" | font = require "data/font" | ||||
| text = require "data/textbox" | |||||
| -- Game Source: | -- Game Source: | ||||
| calc = require "src/calc" | calc = require "src/calc" | ||||
| -- Game Classes: | -- Game Classes: | ||||
| require "src/class/Menubutton" | require "src/class/Menubutton" | ||||
| require "src/class/Button" | |||||
| require "src/class/Textbox" | |||||
| require "src/class/Player" | require "src/class/Player" | ||||
| require "src/class/Gui" | require "src/class/Gui" | ||||
| require "src/class/Planet" | require "src/class/Planet" | ||||
| @@ -27,6 +27,16 @@ function love.load() | |||||
| } | } | ||||
| } | } | ||||
| -- Buttons: | |||||
| button = { | |||||
| tutorial = Button(width - 70, 20, 50, 30, "help", {255, 255, 255}, {40, 40, 40}, false) | |||||
| } | |||||
| -- Textboxes: | |||||
| textbox = { | |||||
| tutorial = Textbox(40, 40, width-80, height-80, text.tutorial, "center", {255, 255, 255}, {0, 0, 0}) | |||||
| } | |||||
| -- Camera: | -- Camera: | ||||
| cam = Camera() | cam = Camera() | ||||
| @@ -119,8 +129,7 @@ function cameraControls() | |||||
| end | end | ||||
| -- Zoom Limit: | -- Zoom Limit: | ||||
| local max = settings.zoom.max | |||||
| local min = settings.zoom.min | |||||
| local max, min = settings.zoom.max, settings.zoom.min | |||||
| if zoomlevel < min then | if zoomlevel < min then | ||||
| zoomlevel = min | zoomlevel = min | ||||
| end | end | ||||
| @@ -221,13 +230,11 @@ function love.update(dt) | |||||
| -- Gui: | -- Gui: | ||||
| gui:update(dt) | gui:update(dt) | ||||
| button.tutorial:update() | |||||
| -- Camera: | -- Camera: | ||||
| cam:lookAt(player.x, player.y) | cam:lookAt(player.x, player.y) | ||||
| cameraControls() | cameraControls() | ||||
| --debug(player.x .. " " .. player.y) | |||||
| end | end | ||||
| menubuttonUpdate() | menubuttonUpdate() | ||||
| end | end | ||||
| @@ -250,6 +257,11 @@ function love.draw() | |||||
| -- Gui: | -- Gui: | ||||
| player:drawPositionIndicator() | player:drawPositionIndicator() | ||||
| gui:draw() | gui:draw() | ||||
| if button.tutorial.isActive then | |||||
| textbox.tutorial:draw() | |||||
| end | |||||
| button.tutorial:draw() | |||||
| end | end | ||||
| menubuttonDraw() | menubuttonDraw() | ||||
| end | end | ||||
| @@ -4,6 +4,7 @@ calc = {} | |||||
| -- G-Constant | -- G-Constant | ||||
| calc.G = 6.67e-11 -- TWEAKABLE FOR LATER DEPENDING ON SCALE!!!!!!!!!!! | calc.G = 6.67e-11 -- TWEAKABLE FOR LATER DEPENDING ON SCALE!!!!!!!!!!! | ||||
| calc.pi = 3.14 | calc.pi = 3.14 | ||||
| -- Development debugging/logging thing | -- Development debugging/logging thing | ||||
| function calc.debug(text) | function calc.debug(text) | ||||
| if calc.isDebug then | if calc.isDebug then | ||||
| @@ -50,5 +51,13 @@ function calc.closestObj(target) | |||||
| return minPlanet | return minPlanet | ||||
| end | end | ||||
| -- Loops through a table and concatenate all stings (for textboxes) | |||||
| function calc.getText(stringTable) | |||||
| local string = "" | |||||
| for i, s in ipairs(stringTable) do | |||||
| string = string .. s | |||||
| end | |||||
| return string | |||||
| end | |||||
| return calc | return calc | ||||
| @@ -0,0 +1,80 @@ | |||||
| Button = Class {} | |||||
| function Button:init(tempX, tempY, tempW, tempH, tempText, tempTC, tempBC, tempActive) | |||||
| -- Position and Dimensions: | |||||
| self.x = tempX | |||||
| self.y = tempY | |||||
| self.w = tempW | |||||
| self.h = tempH | |||||
| -- Status: | |||||
| self.isActive = tempActive | |||||
| -- Text and Colours: | |||||
| self.text = tempText | |||||
| self.colour = { | |||||
| text = calc.colour(tempTC[1], tempTC[2], tempTC[3]), | |||||
| background = calc.colour(tempBC[1], tempBC[2], tempBC[3]) | |||||
| } | |||||
| -- Click Cooldown: | |||||
| self.cooldownLimit = 30 | |||||
| self.cooldown = 0 | |||||
| end | |||||
| -- FUNCTIONS | |||||
| function Button:hover() | |||||
| local hover = false | |||||
| local x,y = love.mouse.getPosition() | |||||
| if x > self.x and x < self.x + self.w and y > self.y and y < self.y + self.h then | |||||
| hover = true | |||||
| end | |||||
| return hover | |||||
| end | |||||
| function Button:click() | |||||
| local click = false | |||||
| if self:hover() and love.mouse.isDown(1) then | |||||
| click = true | |||||
| end | |||||
| return click | |||||
| end | |||||
| -- MAIN | |||||
| function Button:update(dt) | |||||
| if self:click() and self.cooldown <= 0 then | |||||
| self.isActive = not self.isActive | |||||
| self.cooldown = self.cooldownLimit | |||||
| end | |||||
| self.cooldown = self.cooldown - 1 | |||||
| end | |||||
| function Button:draw() | |||||
| local x, y, w, h = self.x, self.y, self.w, self.h | |||||
| local bg, tx = self.colour.background, self.colour.text | |||||
| -- Hover Effects | |||||
| if self:hover() and self.cooldown <= 0 then | |||||
| --[[ Slight Colour Lightup -- broken and idk why qwq | |||||
| for i = 1, #bg do | |||||
| bg[i] = bg[i]*1.1 | |||||
| end]] | |||||
| -- Slight pop up effect (purly visual) | |||||
| local pop = 1 | |||||
| x, y, w, h = x-pop, y-pop, w+pop*2, h+pop*2 | |||||
| end | |||||
| -- Draw Background | |||||
| love.graphics.setColor(bg[1], bg[2], bg[3]) | |||||
| love.graphics.rectangle("fill", x, y, w, h) | |||||
| -- Draw Text | |||||
| love.graphics.setFont(font.default) | |||||
| love.graphics.setColor(tx[1], tx[2], tx[3]) | |||||
| love.graphics.printf(self.text, x, y, w, "center") | |||||
| end | |||||
| @@ -189,7 +189,7 @@ function Player:isLanded() | |||||
| if self:getOrbitHeight(p) <= 1 then | if self:getOrbitHeight(p) <= 1 then | ||||
| landed = true | landed = true | ||||
| self.landedOn = p | self.landedOn = p | ||||
| debug("Player touched down on: "..p.name) | |||||
| --debug("Player touched down on: "..p.name) | |||||
| end | end | ||||
| end | end | ||||
| -- Save Landing Speed: | -- Save Landing Speed: | ||||
| @@ -198,7 +198,7 @@ function Player:isLanded() | |||||
| local planet = math.abs(self.landedOn:getSpeed()) | local planet = math.abs(self.landedOn:getSpeed()) | ||||
| self.landingspeed = math.abs(player-planet) | self.landingspeed = math.abs(player-planet) | ||||
| debug("Landing speed: "..self.landingspeed) | |||||
| --debug("Landing speed: "..self.landingspeed) | |||||
| end | end | ||||
| self:hasCrashed() | self:hasCrashed() | ||||
| return landed | return landed | ||||
| @@ -0,0 +1,45 @@ | |||||
| Textbox = Class {} | |||||
| function Textbox:init(tempX, tempY, tempW, tempH, tempText, tempAlign, tempTC, tempBC) | |||||
| -- Dimensions: | |||||
| self.x = tempX | |||||
| self.y = tempY | |||||
| self.w = tempW | |||||
| self.h = tempH | |||||
| -- Text: | |||||
| self.text = calc.getText(tempText) | |||||
| self.align = tempAlign | |||||
| -- Colours: | |||||
| self.colour = { | |||||
| text = calc.colour(tempTC[1], tempTC[2], tempTC[3]), | |||||
| background = calc.colour(tempBC[1], tempBC[2], tempBC[3]) | |||||
| } | |||||
| end | |||||
| -- FUNCTIONS | |||||
| function Textbox:drawBox() | |||||
| local c = self.colour.background | |||||
| love.graphics.setColor(c[1], c[2], c[3], 0.7) | |||||
| love.graphics.rectangle("fill", self.x, self.y, self.w, self.h) | |||||
| end | |||||
| function Textbox:drawText() | |||||
| local border = 3 | |||||
| local c = self.colour.text | |||||
| love.graphics.setFont(font.default) | |||||
| love.graphics.setColor(c[1], c[2], c[3]) | |||||
| love.graphics.printf(self.text, self.x + border, self.y + border, self.w + border*2, self.align) | |||||
| end | |||||
| -- MAIN | |||||
| function Textbox:draw() | |||||
| self:drawBox() | |||||
| self:drawText() | |||||
| end | |||||