Start loading travel nodes; fix bitmap loading issue.
This commit is contained in:
parent
56f23199e9
commit
ee7a32af21
30
ai.lua
30
ai.lua
|
@ -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
|
2
bmp.lua
2
bmp.lua
|
@ -10,7 +10,7 @@ local bit = require 'bit'
|
||||||
function t.load( filename )
|
function t.load( filename )
|
||||||
local imgd = love.image.newImageData( filename )
|
local imgd = love.image.newImageData( filename )
|
||||||
print( "LOADING BITMAP: ", filename, imgd:getSize(), imgd:getFormat(), imgd:getDimensions() )
|
print( "LOADING BITMAP: ", filename, imgd:getSize(), imgd:getFormat(), imgd:getDimensions() )
|
||||||
return love.graphics.newImage( imgd )
|
return love.graphics.newImage( imgd ), imgd
|
||||||
end
|
end
|
||||||
|
|
||||||
function t.save( data, format )
|
function t.save( data, format )
|
||||||
|
|
16
camera.lua
16
camera.lua
|
@ -1,7 +1,12 @@
|
||||||
local tf = love.math.newTransform()
|
local tf = love.math.newTransform()
|
||||||
local tfTerritory = love.math.newTransform()
|
local tfTerritory = love.math.newTransform()
|
||||||
|
local tfNodes = love.math.newTransform()
|
||||||
local lg = assert( love.graphics )
|
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 )
|
function Camera.GetWorldCoordinate( x, y )
|
||||||
return tf:inverseTransformPoint( x, y )
|
return tf:inverseTransformPoint( x, y )
|
||||||
|
@ -11,6 +16,10 @@ function Camera.GetBitmapCoordinate( x, y )
|
||||||
return tfTerritory:inverseTransformPoint( x, y )
|
return tfTerritory:inverseTransformPoint( x, y )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Camera.GetNodeCoordinate( x, y )
|
||||||
|
return tfNodes:inverseTransformPoint( x, y )
|
||||||
|
end
|
||||||
|
|
||||||
function Camera.Zoom( out )
|
function Camera.Zoom( out )
|
||||||
local scale = out and 1.1 or 0.9
|
local scale = out and 1.1 or 0.9
|
||||||
tf:scale( scale, scale )
|
tf:scale( scale, scale )
|
||||||
|
@ -37,6 +46,11 @@ function Camera.Set( x, y, w, h )
|
||||||
tfTerritory:reset()
|
tfTerritory:reset()
|
||||||
tfTerritory:scale( w / 512, h / 285 )
|
tfTerritory:scale( w / 512, h / 285 )
|
||||||
tfTerritory:translate( -x * 512 / 360, y * 512 / 360 )
|
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
|
end
|
||||||
|
|
||||||
function Camera.Resize( w, h )
|
function Camera.Resize( w, h )
|
||||||
|
|
14
map.lua
14
map.lua
|
@ -1,4 +1,5 @@
|
||||||
local lg = love.graphics
|
local lg = love.graphics
|
||||||
|
local AI = require 'ai'
|
||||||
local Cities = require 'cities'
|
local Cities = require 'cities'
|
||||||
local Lines = require 'lines'
|
local Lines = require 'lines'
|
||||||
local Nodes = require 'nodes'
|
local Nodes = require 'nodes'
|
||||||
|
@ -30,6 +31,7 @@ function map.load()
|
||||||
map.coastlinesLow = Lines.load( "data/earth/coastlines-low.dat" )
|
map.coastlinesLow = Lines.load( "data/earth/coastlines-low.dat" )
|
||||||
map.international = Lines.load( "data/earth/international.dat" )
|
map.international = Lines.load( "data/earth/international.dat" )
|
||||||
map.travelnodes = Nodes.load( "data/earth/travel_nodes.bmp" )
|
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
|
for k, v in pairs(map.territory) do
|
||||||
map.territory[k] = Territory.load( "data/earth/"..k..".bmp", k )
|
map.territory[k] = Territory.load( "data/earth/"..k..".bmp", k )
|
||||||
end
|
end
|
||||||
|
@ -39,9 +41,10 @@ end
|
||||||
function map.draw()
|
function map.draw()
|
||||||
lg.clear( 0, 0, 0, 1 )
|
lg.clear( 0, 0, 0, 1 )
|
||||||
|
|
||||||
|
|
||||||
do --travel nodes
|
do -- ai nodes
|
||||||
map.travelnodes:draw()
|
lg.replaceTransform( Camera.tfTerritory )
|
||||||
|
map.ainodes:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,6 +96,11 @@ function map.draw()
|
||||||
lg.line( -180, 100, 180, 100 )
|
lg.line( -180, 100, 180, 100 )
|
||||||
lg.line( -180, -100, 180, -100 )
|
lg.line( -180, -100, 180, -100 )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do --travel nodes
|
||||||
|
lg.replaceTransform( Camera.tfNodes )
|
||||||
|
map.travelnodes:draw()
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
22
nodes.lua
22
nodes.lua
|
@ -6,8 +6,25 @@ local bmp = require 'bmp'
|
||||||
local lg = assert( love.graphics )
|
local lg = assert( love.graphics )
|
||||||
|
|
||||||
function t.load( filename )
|
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 } )
|
return setmetatable( nodes, {__index = t } )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -16,8 +33,9 @@ function t.isConnected( nodes )
|
||||||
end
|
end
|
||||||
|
|
||||||
function t.draw( nodes )
|
function t.draw( nodes )
|
||||||
|
lg.setPointSize( 10 )
|
||||||
|
lg.setColor( 1, 1, 1, 0.5 )
|
||||||
lg.points( nodes.points )
|
lg.points( nodes.points )
|
||||||
lg.draw( nodes.img )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function t.drawConnections( nodes )
|
function t.drawConnections( nodes )
|
||||||
|
|
|
@ -13,11 +13,13 @@ local colours = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function t.load( filename, name )
|
function t.load( filename, name )
|
||||||
|
local img, imgd = assert( bmp.load( filename ) )
|
||||||
local territory = {
|
local territory = {
|
||||||
visible = true,
|
visible = true,
|
||||||
name = name,
|
name = name,
|
||||||
colour = colours[name],
|
colour = colours[name],
|
||||||
img = assert( bmp.load( filename ) )
|
img = img,
|
||||||
|
imgd = imgd
|
||||||
}
|
}
|
||||||
return setmetatable( territory, {__index = t } )
|
return setmetatable( territory, {__index = t } )
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue