most of beginning of thing done woop
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
images/bsg v2 source.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 921 B |
BIN
images/bsg v2.xcf
Normal file
BIN
images/viper source.png
Normal file
After Width: | Height: | Size: 219 B |
BIN
images/viper.png
Before Width: | Height: | Size: 219 B After Width: | Height: | Size: 249 B |
BIN
images/viper.xcf
Normal file
@ -6,7 +6,7 @@ function love.conf(t)
|
||||
if debug then t.console = true end
|
||||
|
||||
t.window = {}
|
||||
t.window.title = "Battlestar Galactica, 33"
|
||||
t.window.title = "Thirty-Three"
|
||||
t.window.width = 960
|
||||
t.window.height = 540
|
||||
t.window.fullscreen = false
|
||||
|
BIN
src/img/bsg.png
Normal file
After Width: | Height: | Size: 921 B |
BIN
src/img/viper.png
Normal file
After Width: | Height: | Size: 249 B |
99
src/main.lua
@ -0,0 +1,99 @@
|
||||
local bsg = require "ships.bsg"
|
||||
local viper = require "ships.viper"
|
||||
|
||||
local lg = love.graphics
|
||||
|
||||
local images = {}
|
||||
local ships = {}
|
||||
|
||||
local hx, hy = lg.getWidth() / 2, lg.getHeight() / 2
|
||||
|
||||
local scale = 8
|
||||
|
||||
local selected
|
||||
|
||||
function love.load()
|
||||
lg.setDefaultFilter("linear", "nearest", 1)
|
||||
images.bsg = lg.newImage('img/bsg.png')
|
||||
images.viper = lg.newImage('img/viper.png')
|
||||
lg.setPointSize(10)
|
||||
lg.setPointStyle("rough")
|
||||
|
||||
ships[1] = bsg()
|
||||
for i=1,8 do
|
||||
local v = viper()
|
||||
table.insert(ships, v)
|
||||
ships[1]:dock(v, i)
|
||||
end
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
lg.translate(hx, hy)
|
||||
|
||||
for i=1,#ships do
|
||||
lg.draw(images[ships[i].img], ships[i].x * scale, ships[i].y * scale, ships[i].rotation, scale, scale, ships[i].ox, ships[i].oy)
|
||||
end
|
||||
|
||||
if selected then
|
||||
lg.setColor(220, 180, 0)
|
||||
lg.point(selected.x * scale, selected.y * scale)
|
||||
lg.setColor(255, 255, 255)
|
||||
end
|
||||
end
|
||||
|
||||
function love.keypressed(key, unicode)
|
||||
if key == "escape" then
|
||||
love.event.quit()
|
||||
end
|
||||
end
|
||||
|
||||
local function pointInRadius(x, y, cx, cy, r)
|
||||
cx = cx * scale + hx
|
||||
cy = cy * scale + hy
|
||||
local dx = x - cx
|
||||
local dy = y - cy
|
||||
return r * scale >= math.sqrt(dx * dx + dy * dy)
|
||||
end
|
||||
|
||||
local function pointInAABB(x, y, cx, cy, s, r)
|
||||
-- THIS IS HORRIBLY WRONG, FIX IT LATER
|
||||
--[[
|
||||
var x=((objects[i].x-objects[renderId].x)*Math.cos(rot)-(objects[i].y-objects[renderId].y)*Math.sin(rot))*scaleFactor;
|
||||
var y=((objects[i].x-objects[renderId].x)*Math.sin(rot)+(objects[i].y-objects[renderId].y)*Math.cos(rot))*scaleFactor;
|
||||
]]
|
||||
local nx = (x - cx) * math.cos(r) - (y - cy) * math.sin(r)
|
||||
local ny = (x - cx) * math.sin(r) + (y - cy) * math.cos(r)
|
||||
x = nx
|
||||
y = ny
|
||||
cx = cx * scale + hx
|
||||
cy = cy * scale + hy
|
||||
return x >= cx - s.w * scale / 2 and x <= cx + s.w * scale / 2 and y >= cy - s.h * scale / 2 and y <= cy + s.h * scale / 2
|
||||
end
|
||||
|
||||
function love.mousepressed(x, y, button)
|
||||
if button == "l" then
|
||||
for i=1,#ships do
|
||||
if ships[i].selection.r then
|
||||
if pointInRadius(x, y, ships[i].x, ships[i].y, ships[i].selection.r) then
|
||||
-- selected
|
||||
-- NOW CHECK IF HAS NODES AND IF WE ARE SELECTING A SHIP ON A NODE!
|
||||
selected = {}
|
||||
selected.x = ships[i].x
|
||||
selected.y = ships[i].y
|
||||
end
|
||||
else
|
||||
if pointInAABB(x, y, ships[i].x, ships[i].y, ships[i].selection, ships[i].rotation) then
|
||||
-- we are selecting it!
|
||||
-- NOW CHECK IF HAS NODES AND IF WE ARE SELECTING A SHIP ON A NODE!
|
||||
selected = {}
|
||||
selected.x = ships[i].x
|
||||
selected.y = ships[i].y
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif button == "wd" then
|
||||
scale = scale * 1.1
|
||||
elseif button == "wu" then
|
||||
scale = scale * 0.9
|
||||
end
|
||||
end
|
11
src/ships/Node.lua
Normal file
@ -0,0 +1,11 @@
|
||||
return function(x, y, rotation)
|
||||
local self = {}
|
||||
|
||||
self.x = x or 0
|
||||
self.y = y or 0
|
||||
self.rotation = rotation or 0
|
||||
|
||||
self.docked = false
|
||||
|
||||
return self
|
||||
end
|
58
src/ships/bsg.lua
Normal file
@ -0,0 +1,58 @@
|
||||
local Node = require "ships.Node"
|
||||
|
||||
local ninety = 90 * math.pi / 180
|
||||
|
||||
return function(x, y, rotation)
|
||||
local self = {}
|
||||
|
||||
self.img = "bsg"
|
||||
self.ox = 31.5
|
||||
self.oy = 67
|
||||
|
||||
self.x = x or 0
|
||||
self.y = y or 0
|
||||
self.rotation = rotation or 0
|
||||
|
||||
--[[
|
||||
self.selection = {
|
||||
w = 54,
|
||||
h = 130
|
||||
}
|
||||
--]]
|
||||
self.selection = {
|
||||
r = 27
|
||||
}
|
||||
|
||||
self.node = {
|
||||
Node(23, -16.5, ninety),
|
||||
Node(23, -5.5, ninety),
|
||||
Node(23, 5.5, ninety),
|
||||
Node(23, 16.5, ninety),
|
||||
Node(-23, -16.5, -ninety),
|
||||
Node(-23, -5.5, -ninety),
|
||||
Node(-23, 5.5, -ninety),
|
||||
Node(-23, 16.5, -ninety)
|
||||
}
|
||||
|
||||
self.dock = function(self, ship, node)
|
||||
if self.node[node].docked then return false end
|
||||
|
||||
ship.x = self.node[node].x
|
||||
ship.y = self.node[node].y
|
||||
ship.rotation = self.node[node].rotation
|
||||
|
||||
self.node[node].docked = ship
|
||||
return true
|
||||
end
|
||||
|
||||
self.undock = function(self, node)
|
||||
if not self.node[node].docked then return false end
|
||||
|
||||
local ship = self.node[node].docked
|
||||
self.node[node].docked = false
|
||||
|
||||
return ship
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
25
src/ships/viper.lua
Normal file
@ -0,0 +1,25 @@
|
||||
return function(x, y, rotation)
|
||||
local self = {}
|
||||
|
||||
self.img = "viper"
|
||||
self.ox = 4.5
|
||||
self.oy = 7.5
|
||||
|
||||
self.x = x or 0
|
||||
self.y = y or 0
|
||||
self.rotation = rotation or 0
|
||||
|
||||
--[[
|
||||
self.selection = {
|
||||
w = 9,
|
||||
h = 15
|
||||
}
|
||||
--]]
|
||||
self.selection = {
|
||||
r = 5
|
||||
}
|
||||
|
||||
--self.node = false
|
||||
|
||||
return self
|
||||
end
|