Browse Source

added Buttons, Textboxes, and a basic tutorial ingame

tags/v0.0.6_dev
Niro 2 years ago
parent
commit
7d495afebd
7 changed files with 184 additions and 7 deletions
  1. +28
    -0
      data/textbox.lua
  2. +3
    -0
      import.lua
  3. +17
    -5
      main.lua
  4. +9
    -0
      src/calc.lua
  5. +80
    -0
      src/class/Button.lua
  6. +2
    -2
      src/class/Player.lua
  7. +45
    -0
      src/class/Textbox.lua

+ 28
- 0
data/textbox.lua View File

@@ -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

+ 3
- 0
import.lua View File

@@ -10,12 +10,15 @@ controls = require "data/controls"
settings = require "data/settings"
starshipTypes = require "data/starshipTypes"
font = require "data/font"
text = require "data/textbox"

-- Game Source:
calc = require "src/calc"

-- Game Classes:
require "src/class/Menubutton"
require "src/class/Button"
require "src/class/Textbox"
require "src/class/Player"
require "src/class/Gui"
require "src/class/Planet"


+ 17
- 5
main.lua View File

@@ -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:
cam = Camera()
@@ -119,8 +129,7 @@ function cameraControls()
end

-- 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
zoomlevel = min
end
@@ -221,13 +230,11 @@ function love.update(dt)

-- Gui:
gui:update(dt)
button.tutorial:update()

-- Camera:
cam:lookAt(player.x, player.y)
cameraControls()
--debug(player.x .. " " .. player.y)

end
menubuttonUpdate()
end
@@ -250,6 +257,11 @@ function love.draw()
-- Gui:
player:drawPositionIndicator()
gui:draw()

if button.tutorial.isActive then
textbox.tutorial:draw()
end
button.tutorial:draw()
end
menubuttonDraw()
end

+ 9
- 0
src/calc.lua View File

@@ -4,6 +4,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
@@ -50,5 +51,13 @@ function calc.closestObj(target)
return minPlanet
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

+ 80
- 0
src/class/Button.lua View File

@@ -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

+ 2
- 2
src/class/Player.lua View File

@@ -189,7 +189,7 @@ function Player:isLanded()
if self:getOrbitHeight(p) <= 1 then
landed = true
self.landedOn = p
debug("Player touched down on: "..p.name)
--debug("Player touched down on: "..p.name)
end
end
-- Save Landing Speed:
@@ -198,7 +198,7 @@ function Player:isLanded()
local planet = math.abs(self.landedOn:getSpeed())

self.landingspeed = math.abs(player-planet)
debug("Landing speed: "..self.landingspeed)
--debug("Landing speed: "..self.landingspeed)
end
self:hasCrashed()
return landed


+ 45
- 0
src/class/Textbox.lua View File

@@ -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

Loading…
Cancel
Save