4 коммитов

Автор SHA1 Сообщение Дата
  Niro 0016c01a0f added gamestate, completed Menubutton, added menu 2 лет назад
  nirokay 63820e69f9
Merge pull request #5 from NiroUwU/testing 2 лет назад
  Madiwka 3e41bd9e52 I swear i'm going to end the lives of those who inventer game developing if this keeps up 2 лет назад
  Madiwka 9fcad0dde2 Fixed ship texture rotation 2 лет назад
9 измененных файлов: 204 добавлений и 51 удалений
  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. +3
    -1
      src/class/Planet.lua
  8. +34
    -10
      src/class/Player.lua
  9. +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 = 0.5,
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

+ 3
- 1
src/class/Planet.lua Просмотреть файл

@@ -41,7 +41,7 @@ end
-- FUNCTIONS

function Planet:getSpeed()
return math.abs(self.xSpeed) + math.abs(self.ySpeed)
return math.abs(self.xSpeed) + math.abs(self.ySpeed) + math.abs(self.orbitalY) + math.abs(self.orbitalX)
end

function Planet:updatePosition()
@@ -95,4 +95,6 @@ function Planet:draw()
local col = self.colour
love.graphics.setColor(calc.c(col[1]), calc.c(col[2]), calc.c(col[3]))
love.graphics.circle("fill", self.x, self.y, self.r)
love.graphics.setColor(0.1,0.1,0.1,0.2)
love.graphics.circle("fill", self.x, self.y, self.r*2)
end

+ 34
- 10
src/class/Player.lua Просмотреть файл

@@ -9,6 +9,9 @@ function Player:init(tempX, tempY, tempT)
self.xStart = tempX
self.yStart = tempY

self.orbitalX = 0
self.orbitalY = 0

-- Speed:
self.xSpeed = 0
self.ySpeed = 0
@@ -30,9 +33,12 @@ function Player:init(tempX, tempY, tempT)

-- Status:
self.exploding = false
self.inRange = nil

--TEXTURE HERE?
self.texture = love.graphics.newImage(starshipTypes[tempT].texture)
self.width = self.texture:getWidth()
self.height = self.texture:getHeight()
end


@@ -71,7 +77,8 @@ end
function Player:reset()
self.x = self.xStart
self.y = self.yStart

self.landingspeed = 0
self.angle = calc.pi/2
self.xSpeed = 0
self.ySpeed = 0
end
@@ -142,7 +149,7 @@ function Player:flightControls()
end

function Player:getSpeed() -- absolute speed
return math.abs(self.xSpeed) + math.abs(self.ySpeed)
return math.abs(self.xSpeed) + math.abs(self.ySpeed) + math.abs(self.orbitalY) + math.abs(self.orbitalX)
end

function Player:getSpeedTo(obj) -- relative speed to an object
@@ -166,7 +173,7 @@ end
function Player:isLanded()
local landed = false
for i, p in ipairs(planet) do
if self:getOrbitHeight(p) <= 0 then
if self:getOrbitHeight(p) <= 1 then
landed = true
self.landedOn = p
debug("Player touched down on: "..p.name)
@@ -188,25 +195,39 @@ function Player:gravity()
if self:isLanded() then
-- Player is landed:
local p = self.landedOn
self.xSpeed, self.ySpeed = math.abs(p.xSpeed), math.abs(p.ySpeed)
self.xSpeed, self.ySpeed = 0, 0
end
local p = calc.closestObj(player)
if self:getOrbitHeight(p) < p.r and p.parent then
if self.inRange ~= p then
self.xSpeed = 0
self.ySpeed = 0
self.inRange = p
end
self.orbitalX = p.xSpeed + p.orbitalX
self.orbitalY = p.ySpeed + p.orbitalY
debug("Synced speed" .. self.orbitalX .. " " .. self.orbitalY .. " with " .. p.name)
else
self.inRange = nil
self.orbitalX = 0
self.orbitalY = 0
end
end

function Player:updatePosition()
self.x = self.x + self.xSpeed
self.y = self.y + self.ySpeed
self.x = self.x + self.xSpeed + self.orbitalX
self.y = self.y + self.ySpeed + self.orbitalY
end

function Player:drawTexture(x, y, r)
-- Texture offset and size
local t = {s = 50}
t.x = x - love.graphics.getPixelWidth(self.texture)/2 -- ?????????????????????????????????
t.y = y - love.graphics.getPixelHeight(self.texture)/2

-- Draw Texture
love.graphics.setColor(1, 1, 1)
love.graphics.draw(self.texture, t.x, t.y, r)
debug("Angle: "..self.angle)
love.graphics.draw(self.texture, self.x, self.y, -(self.angle-calc.pi/2), 1, 1, self.width/2, self.height/2)
--debug("Angle: "..self.angle)
end


@@ -230,7 +251,10 @@ function Player:draw()
local x, y = self.x, self.y
local dist = 10

if not self.exploding then
self:drawTexture(x, y, calc.pi/2 - self.angle)
end


if not self.exploding then
if calc.isDebug then


+ 0
- 1
src/font.lua Просмотреть файл

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

Загрузка…
Отмена
Сохранить