dcearth/ai.lua

60 lines
1.3 KiB
Lua
Raw Normal View History

--Manage the AI nodes used by DEFCON.
local t = {}
local bmp = require 'bmp'
local lg = assert( love.graphics )
local print = print
function t.load( filename )
local img, imgd = bmp.load( filename )
local nodes = {
visible = true,
att = {},
ptsAtt = {},
def = {},
ptsDef = {},
img = img,
imgd = imgd }
print( "=== Loading AI Markers: ===" )
for x = 0, 511 do
for y = 0, 284 do
local r, g = imgd:getPixel( x, 284 - y )
if r > 0.5 or g > 0.5 then
local long = x * (360 / imgd:getWidth()) - 180
local lat = y * (200 / img:getHeight()) - 100
local set = (r > 0.5) and nodes.att or nodes.def
set[#set + 1] = {x = long, y = lat}
print( #set, long, lat )
end
end
end
do
local k = 1
for i, point in ipairs( nodes.att ) do
nodes.ptsAtt[k], nodes.ptsAtt[k + 1] = point.x, point.y
k = k + 2
end
k = 1
for j, point in ipairs( nodes.def ) do
nodes.ptsDef[k], nodes.ptsDef[k + 1] = point.x, point.y
k = k + 2
end
end
return setmetatable( nodes, {__index = t } )
end
function t.draw( nodes )
lg.setColor( 1, 0, 0, 0.5 )
lg.points( nodes.ptsAtt )
lg.setColor( 0, 1, 0, 0.5 )
lg.points( nodes.ptsDef )
end
function t.save( nodes, filename )
end
return t