Edit: Oh yeah, there are 12 players. Those are the filled in circles. The outline only stars are neutral.
colors.lua
Code: Select all
color = {{}}
color[1] = { 30/255, 144/255, 255/255 }
color[2] = { 255/255, 0, 0 }
color[3] = { 199/255, 21/255, 133/255 }
color[4] = { 255/255, 165/255, 0 }
color[5] = { 255/255, 255/255, 0 }
color[6] = { 100/255, 0, 100/255 }
color[7] = { 0, 128/255, 0 }
color[8] = { 0, 255/255, 0 }
color[9] = { 0, 255/255, 255/255 }
color[10] = { 80/255, 80/255, 0 }
color[11] = { 210/255, 180/255, 140/255 }
color[12] = { 139/255, 69/255, 19/255 }
color[13] = { 128/255, 128/255, 128/255 }
Code: Select all
require("colors")
function love.load()
love.window.setFullscreen(true, "desktop")
width, height = love.window.getDesktopDimensions(1)
love.math.setRandomSeed(love.timer.getTime())
star = {}
for i = 1, 200 do
star[i] = {}
end
player = {}
InitStars()
InitPlayers()
end
function love.update(dt)
if love.keyboard.isDown("escape") then love.event.quit() end
if love.keyboard.isDown("n") then
InitStars()
InitPlayers()
end
BuildShips()
end
function love.draw()
DrawStars()
DrawShips()
end
function BuildShips()
for i = 1, 200 do
r = love.math.random(1000)
if star[i].owner == 13 then
if r / 4 < star[i].size then
star[i].ships = star[i].ships + 1
end
else
if r / 8 < star[i].size then
star[i].ships = star[i].ships + 1
end
end
end
end
function InitStars()
for i = 1, 200 do
::try_again::
star[i].x = love.math.random(20, width - 20)
star[i].y = love.math.random(20, height - 30)
for j = 1, i do
if j ~= i then
if Distance(star[i].x, star[j].x, star[i].y, star[j].y) < 60 then
goto try_again
end
end
end
star[i].size = love.math.random(5) + love.math.random(5) + love.math.random(5)
star[i].owner = 13
star[i].ships = 10
end
end
function InitPlayers()
::IP2::
for i = 1, 12 do
::IP1::
player[i] = love.math.random(200)
for j = 1, i do
if j ~= i then
if player[i] == player[j] then
goto IP1
end
end
end
for j = 1, i do
if j ~= i then
x1 = star[player[i]].x
x2 = star[player[j]].x
y1 = star[player[i]].y
y2 = star[player[j]].y
if Distance(x1,x2,y1,y2) < 320 then
goto IP2
end
end
end
end
for i = 1, 12 do
star[player[i]].owner = i
star[player[i]].size = 10
star[player[i]].ships = 100
end
end
function DrawStars()
for i = 1, 200 do
if star[i].owner == 13 then
love.graphics.setColor(color[star[i].size - 2])
love.graphics.circle("line", star[i].x, star[i].y, star[i].size + 3)
love.graphics.circle("line", star[i].x, star[i].y, star[i].size + 2)
else
love.graphics.setColor(color[star[i].owner])
love.graphics.circle("fill", star[i].x, star[i].y, star[i].size + 3)
end
end
end
function DrawShips()
love.graphics.setColor(0.8, 0.8, 0.8)
for i = 1, 200 do
x = star[i].x - 4
y = star[i].y + star[i].size + 4
love.graphics.printf(star[i].ships, x - 46, y, 100, "center")
end
end
function Distance(x1, x2, y1, y2)
return math.sqrt(((x2 - x1) ^ 2) + ((y2 - y1) ^ 2))
end