Start loading travel nodes; fix bitmap loading issue.

This commit is contained in:
wan-may 2023-08-26 18:05:48 -03:00
parent 56f23199e9
commit ee7a32af21
6 changed files with 80 additions and 8 deletions

30
ai.lua
View File

@ -0,0 +1,30 @@
--Manage the AI nodes used by DEFCON.
local t = {}
local bmp = require 'bmp'
local lg = assert( love.graphics )
function t.load( filename )
local img, imgd = bmp.load( filename )
local nodes = {
visible = true,
att = {},
def = {},
img = img,
imgd = imgd }
print( "PIXEL: ", imgd:getPixel( 1, 1 ) )
return setmetatable( nodes, {__index = t } )
end
function t.draw( nodes )
lg.points( nodes.att )
lg.points( nodes.def )
lg.draw( nodes.img )
end
function t.save( nodes, filename )
end
return t

View File

@ -10,7 +10,7 @@ local bit = require 'bit'
function t.load( filename )
local imgd = love.image.newImageData( filename )
print( "LOADING BITMAP: ", filename, imgd:getSize(), imgd:getFormat(), imgd:getDimensions() )
return love.graphics.newImage( imgd )
return love.graphics.newImage( imgd ), imgd
end
function t.save( data, format )

View File

@ -1,7 +1,12 @@
local tf = love.math.newTransform()
local tfTerritory = love.math.newTransform()
local tfNodes = love.math.newTransform()
local lg = assert( love.graphics )
local Camera = { x = 0, y = 0, w = 360, h = 200, zoom = 1, tf = tf, tfTerritory = tfTerritory }
local Camera = {
x = 0, y = 0,
w = 360, h = 200,
zoom = 1, tf = tf,
tfTerritory = tfTerritory, tfNodes = tfNodes }
function Camera.GetWorldCoordinate( x, y )
return tf:inverseTransformPoint( x, y )
@ -11,6 +16,10 @@ function Camera.GetBitmapCoordinate( x, y )
return tfTerritory:inverseTransformPoint( x, y )
end
function Camera.GetNodeCoordinate( x, y )
return tfNodes:inverseTransformPoint( x, y )
end
function Camera.Zoom( out )
local scale = out and 1.1 or 0.9
tf:scale( scale, scale )
@ -37,6 +46,11 @@ function Camera.Set( x, y, w, h )
tfTerritory:reset()
tfTerritory:scale( w / 512, h / 285 )
tfTerritory:translate( -x * 512 / 360, y * 512 / 360 )
tfNodes:reset()
tfNodes:scale( w / 360, h / 200 )
tfNodes:translate( 180 - x , y + 100 )
--tfNodes:translate( -x * 800 / 360, y * 400 / 200 )
end
function Camera.Resize( w, h )

14
map.lua
View File

@ -1,4 +1,5 @@
local lg = love.graphics
local AI = require 'ai'
local Cities = require 'cities'
local Lines = require 'lines'
local Nodes = require 'nodes'
@ -30,6 +31,7 @@ function map.load()
map.coastlinesLow = Lines.load( "data/earth/coastlines-low.dat" )
map.international = Lines.load( "data/earth/international.dat" )
map.travelnodes = Nodes.load( "data/earth/travel_nodes.bmp" )
map.ainodes = AI.load( "data/earth/ai_markers.bmp" )
for k, v in pairs(map.territory) do
map.territory[k] = Territory.load( "data/earth/"..k..".bmp", k )
end
@ -39,9 +41,10 @@ end
function map.draw()
lg.clear( 0, 0, 0, 1 )
do --travel nodes
map.travelnodes:draw()
do -- ai nodes
lg.replaceTransform( Camera.tfTerritory )
map.ainodes:draw()
end
@ -93,6 +96,11 @@ function map.draw()
lg.line( -180, 100, 180, 100 )
lg.line( -180, -100, 180, -100 )
end
do --travel nodes
lg.replaceTransform( Camera.tfNodes )
map.travelnodes:draw()
end
end

View File

@ -6,8 +6,25 @@ local bmp = require 'bmp'
local lg = assert( love.graphics )
function t.load( filename )
local nodes = { visible = true, points = {}, connections = {}, img = bmp.load( filename ) }
local img, imgd = bmp.load( filename )
local nodes = { visible = true, points = {}, connections = {}, img = img }
print( "=== Loading Nodes: ===" )
for x = 0, 799 do
for y = 0, 399 do
if imgd:getPixel( x, 399 - y ) > 0 then
local long = 360 * ( x - 800 ) / 800 - 360 / 2 + 360
local lat = 360 * ( 600 / 800 ) * ( 600 - y ) / 600 - 180
local n = #nodes.points
nodes.points[n + 1] = long
nodes.points[n + 2] = lat
print( long, lat )
end
end
end
print( "=== Nodes Loaded ===" )
return setmetatable( nodes, {__index = t } )
end
@ -16,8 +33,9 @@ function t.isConnected( nodes )
end
function t.draw( nodes )
lg.setPointSize( 10 )
lg.setColor( 1, 1, 1, 0.5 )
lg.points( nodes.points )
lg.draw( nodes.img )
end
function t.drawConnections( nodes )

View File

@ -13,11 +13,13 @@ local colours = {
}
function t.load( filename, name )
local img, imgd = assert( bmp.load( filename ) )
local territory = {
visible = true,
name = name,
colour = colours[name],
img = assert( bmp.load( filename ) )
img = img,
imgd = imgd
}
return setmetatable( territory, {__index = t } )
end