Переглянути джерело

added gamestate, completed Menubutton, added menu

tags/v0.0.6_dev
Niro 2 роки тому
джерело
коміт
0016c01a0f
7 змінених файлів з 167 додано та 40 видалено
  1. +6
    -0
      data/font.lua
  2. +1
    -0
      data/info.lua
  3. +1
    -1
      data/starshipTypes.lua
  4. +2
    -3
      import.lua
  5. +75
    -33
      main.lua
  6. +82
    -2
      src/class/Menubutton.lua
  7. +0
    -1
      src/font.lua

+ 6
- 0
data/font.lua Переглянути файл

@@ -0,0 +1,6 @@
font = {
default = love.graphics.setNewFont(20),
gametitle = love.graphics.setNewFont(40)
}

return font

+ 1
- 0
data/info.lua Переглянути файл

@@ -1,6 +1,7 @@
info = {}

info.name = "Questionable Örbital Mechanics"
info.title = info.name
info.version = "0.0.2_dev"
info.authors = {
"NiroUwU",


+ 1
- 1
data/starshipTypes.lua Переглянути файл

@@ -3,7 +3,7 @@ starshipTypes = {
orbiter = {
name = "Classic Orbiter",
description = "Dolor fugiat irure sit aliqua labore. Culpa voluptate occaecat anim exercitation proident sint ex dolor. Officia in labore sint Lorem ea. Ad minim aliqua aliqua non commodo qui in ea sit excepteur excepteur qui.",
impacttolerance = 9999,
impacttolerance = 0.75,
mass = 100000, -- idk, feels better but holy fuck thats a thicc ass boi xD
speed = 0.05,
specials = {"orbitSync"},


+ 2
- 3
import.lua Переглянути файл

@@ -9,14 +9,13 @@ texture = require "textures/textures"
controls = require "data/controls"
settings = require "data/settings"
starshipTypes = require "data/starshipTypes"
font = require "data/font"

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



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


+ 75
- 33
main.lua Переглянути файл

@@ -1,14 +1,33 @@
require "import"
debug = calc.debug
calc.isDebug = true

function love.load()
require "import"
-- Debugging / Logging:
debug = calc.debug
calc.isDebug = true

-- Declaration:
love.window.setTitle(info.name.." - v"..info.version)
--love.graphics.setDefaultFilter("nearest", "nearest")
width, height = love.graphics.getDimensions()

-- Gamestate:
gamestate = {
quit = "stateQUIT",
menu = "stateMENU",
game = "stateGAME"
}
GAMESTATE = gamestate.menu

-- Menubuttons:
menubutton = {
menu = {
startGame = Menubutton(20, 100, 200, 50, gamestate.game, nil, "Start Game", {255, 255, 255}, {57, 45, 66}),
quitGame = Menubutton(30, 170, 180, 40, gamestate.quit, nil, "Quit Game", {255, 255, 255}, {57, 45, 66})
},
game = {
-- Pause button or something here in future?
}
}


-- Camera:
cam = Camera()
zoomlevel = settings.zoom.reset
@@ -152,37 +171,59 @@ end
-- MAIN

function love.update(dt)
-- Game Objects:
for i=1, timewarpControls() do
-- Physics go in here:
updatePlanets()
player:update(dt)
end
player:throttleControls()

-- Gui:
gui:update(dt)
if GAMESTATE == gamestate.quit then
debug("Game has been quit, goodbye :)")
love.event.quit(0)

-- Camera:
cam:lookAt(player.x, player.y)
cameraControls()
--debug(player.x .. " " .. player.y)
end
elseif GAMESTATE == gamestate.menu then
menubutton.menu.startGame:update(dt)
menubutton.menu.quitGame:update(dt)

function love.draw()
cam:attach()
elseif GAMESTATE == gamestate.game then
-- Game Objects:
drawPlanets()
drawEffects()
player:draw()

-- Camera Zoom Player Location Indicator: OVERWORK SOON PLS KAY; IT UGLY
if zoomlevel < 0.3 then
love.graphics.setColor(1, 1, 1, 0.2)
love.graphics.circle("fill", player.x, player.y, (1/zoomlevel)*10)
for i=1, timewarpControls() do
-- Physics go in here:
updatePlanets()
player:update(dt)
end
cam:detach()
player:throttleControls()

-- Gui:
gui:update(dt)

-- Gui:
gui:draw()
-- Camera:
cam:lookAt(player.x, player.y)
cameraControls()
--debug(player.x .. " " .. player.y)
end
end

function love.draw()
if GAMESTATE == gamestate.menu then
-- Game Title:
love.graphics.setColor(1, 1, 0.6)
love.graphics.setFont(font.gametitle)
love.graphics.printf(info.title, 20, 20, width, "left")

-- Buttons:
menubutton.menu.startGame:draw()
menubutton.menu.quitGame:draw()

elseif GAMESTATE == gamestate.game then
cam:attach()
-- Game Objects:
drawPlanets()
drawEffects()
player:draw()

-- Camera Zoom Player Location Indicator: OVERWORK SOON PLS KAY; IT UGLY
if zoomlevel < 0.3 then
love.graphics.setColor(1, 1, 1, 0.2)
love.graphics.circle("fill", player.x, player.y, (1/zoomlevel)*10)
end
cam:detach()

-- Gui:
gui:draw()
end
end

+ 82
- 2
src/class/Menubutton.lua Переглянути файл

@@ -1,5 +1,85 @@
Menubutton = Class {}

function Menubutton:init(tempX, tempY, tempW, tempH)
function Menubutton:init(tempX, tempY, tempW, tempH, tempState, tempFormat, tempText, tempTC, tempBC)
-- Position and Dimensions:
self.x = tempX
self.y = tempY
self.w = tempW
self.h = tempH

-- State to jump to:
self.toState = tempState

-- Formatting:
self.format = tempFormat
if self.format == "center" or self.format == "centre" then
self.x = self.x - self.w
self.y = self.y - self.h
end

-- Text and Colours:
self.text = tempText
self.colour = {
text = tempTC,
background = tempBC
}
end



-- FUNCTIONS

function Menubutton: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 Menubutton:click()
local click = false
if self:hover() and love.mouse.isDown(1) then
click = true
end
return click
end



-- MAIN

function Menubutton:update(dt)
if self:click() then
-- Here is room for calling effects or something... looking at you madi qwq xD
GAMESTATE = self.toState
end
end

function Menubutton:draw()
local x, y, w, h = self.x, self.y, self.w, self.h
local bg, tx = self.colour.background, self.colour.text
bg, tx = calc.colour(bg[1], bg[2], bg[3]), calc.colour(tx[1], tx[2], tx[3])

-- Hover Effects
if self:hover() then
-- Slight Colour Lightup
for i = 1, #bg do
bg[i] = bg[i]*1.1
end

-- Slight pop up effect (purly visual)
local pop = 3
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

+ 0
- 1
src/font.lua Переглянути файл

@@ -1 +0,0 @@
default = love.graphics.setNewFont(20)

Завантаження…
Відмінити
Зберегти