Display territory.
This commit is contained in:
parent
171177ea82
commit
56f23199e9
7
bmp.lua
7
bmp.lua
|
@ -1,5 +1,6 @@
|
|||
--Load and save the bmp formats used by DEFCON.
|
||||
local t = {}
|
||||
local love = assert( love )
|
||||
local lfs = love.filesystem
|
||||
|
||||
--FFI bit-twiddling stuff.
|
||||
|
@ -7,9 +8,9 @@ local ffi = require 'ffi'
|
|||
local bit = require 'bit'
|
||||
|
||||
function t.load( filename )
|
||||
local bytes, size = lfs.read( filename )
|
||||
|
||||
print( "LOADED", filename, size)
|
||||
local imgd = love.image.newImageData( filename )
|
||||
print( "LOADING BITMAP: ", filename, imgd:getSize(), imgd:getFormat(), imgd:getDimensions() )
|
||||
return love.graphics.newImage( imgd )
|
||||
end
|
||||
|
||||
function t.save( data, format )
|
||||
|
|
11
camera.lua
11
camera.lua
|
@ -1,11 +1,16 @@
|
|||
local tf = love.math.newTransform()
|
||||
local tfTerritory = love.math.newTransform()
|
||||
local lg = assert( love.graphics )
|
||||
local Camera = { x = 0, y = 0, w = 360, h = 200, zoom = 1, tf = tf }
|
||||
local Camera = { x = 0, y = 0, w = 360, h = 200, zoom = 1, tf = tf, tfTerritory = tfTerritory }
|
||||
|
||||
function Camera.GetWorldCoordinate( x, y )
|
||||
return tf:inverseTransformPoint( x, y )
|
||||
end
|
||||
|
||||
function Camera.GetBitmapCoordinate( x, y )
|
||||
return tfTerritory:inverseTransformPoint( x, y )
|
||||
end
|
||||
|
||||
function Camera.Zoom( out )
|
||||
local scale = out and 1.1 or 0.9
|
||||
tf:scale( scale, scale )
|
||||
|
@ -28,6 +33,10 @@ function Camera.Set( x, y, w, h )
|
|||
tf:reset()
|
||||
tf:scale( w / 360, -h / 200 )
|
||||
tf:translate( 180 - x, -y - 100 )
|
||||
|
||||
tfTerritory:reset()
|
||||
tfTerritory:scale( w / 512, h / 285 )
|
||||
tfTerritory:translate( -x * 512 / 360, y * 512 / 360 )
|
||||
end
|
||||
|
||||
function Camera.Resize( w, h )
|
||||
|
|
13
cities.lua
13
cities.lua
|
@ -1,5 +1,5 @@
|
|||
--Load and save the fixed width plaintext data used by DEFCON.
|
||||
local t = { visible = true, active = false}
|
||||
local t = {}
|
||||
local io = io
|
||||
local math = math
|
||||
local table = table
|
||||
|
@ -14,7 +14,7 @@ local caps = {}
|
|||
t.selectedCity = nil
|
||||
|
||||
function t.draw()
|
||||
if t.visible then lg.points( points ) end
|
||||
if cities.visible then lg.points( points ) end
|
||||
end
|
||||
|
||||
function t.drawSelected( r )
|
||||
|
@ -30,18 +30,11 @@ end
|
|||
|
||||
function t.selectNearestCity(x, y)
|
||||
t.selectedCity = cities:getClosestPoint(x, y)
|
||||
|
||||
if t.selectedCity then
|
||||
local city = t.selectedCity
|
||||
print( "SELECTED CITY", city.x, city.y, city.name, city.pop, city.capital)
|
||||
else
|
||||
print( "NO SELECTED CITY" )
|
||||
end
|
||||
end
|
||||
|
||||
function t.load( filename )
|
||||
|
||||
cities = {}
|
||||
cities = { visible = true, active = false }
|
||||
local n = 1
|
||||
local idxPts = 1
|
||||
local idxCaps = 1
|
||||
|
|
14
conf.lua
14
conf.lua
|
@ -16,12 +16,12 @@ function love.conf(t)
|
|||
t.window.height = 600 -- The window height (number)
|
||||
t.window.borderless = false -- Remove all border visuals from the window (boolean)
|
||||
t.window.resizable = true -- Let the window be user-resizable (boolean)
|
||||
t.window.minwidth = 1 -- Minimum window width if the window is resizable (number)
|
||||
t.window.minheight = 1 -- Minimum window height if the window is resizable (number)
|
||||
t.window.minwidth = 512 -- Minimum window width if the window is resizable (number)
|
||||
t.window.minheight = 285 -- Minimum window height if the window is resizable (number)
|
||||
t.window.fullscreen = false -- Enable fullscreen (boolean)
|
||||
t.window.fullscreentype = "desktop" -- Choose between "desktop" fullscreen or "exclusive" fullscreen mode (string)
|
||||
t.window.vsync = 0 -- Vertical sync mode (number)
|
||||
t.window.msaa = 0 -- The number of samples to use with multi-sampled antialiasing (number)
|
||||
t.window.msaa = 2 -- The number of samples to use with multi-sampled antialiasing (number)
|
||||
t.window.depth = nil -- The number of bits per sample in the depth buffer
|
||||
t.window.stencil = nil -- The number of bits per sample in the stencil buffer
|
||||
t.window.display = 1 -- Index of the monitor to show the window in (number)
|
||||
|
@ -30,7 +30,7 @@ function love.conf(t)
|
|||
t.window.x = nil -- The x-coordinate of the window's position in the specified display (number)
|
||||
t.window.y = nil -- The y-coordinate of the window's position in the specified display (number)
|
||||
|
||||
t.modules.audio = true -- Enable the audio module (boolean)
|
||||
t.modules.audio = false -- Enable the audio module (boolean)
|
||||
t.modules.data = true -- Enable the data module (boolean)
|
||||
t.modules.event = true -- Enable the event module (boolean)
|
||||
t.modules.font = true -- Enable the font module (boolean)
|
||||
|
@ -41,10 +41,10 @@ function love.conf(t)
|
|||
t.modules.math = true -- Enable the math module (boolean)
|
||||
t.modules.mouse = true -- Enable the mouse module (boolean)
|
||||
t.modules.physics = false -- Enable the physics module (boolean)
|
||||
t.modules.sound = true -- Enable the sound module (boolean)
|
||||
t.modules.sound = false -- Enable the sound module (boolean)
|
||||
t.modules.system = true -- Enable the system module (boolean)
|
||||
t.modules.thread = true -- Enable the thread module (boolean)
|
||||
t.modules.timer = true -- Enable the timer module (boolean), Disabling it will result 0 delta time in love.update
|
||||
t.modules.thread = false -- Enable the thread module (boolean)
|
||||
t.modules.timer = false -- Enable the timer module (boolean), Disabling it will result 0 delta time in love.update
|
||||
t.modules.touch = false -- Enable the touch module (boolean)
|
||||
t.modules.video = false -- Enable the video module (boolean)
|
||||
t.modules.window = true -- Enable the window module (boolean)
|
||||
|
|
|
@ -39,7 +39,11 @@ function t.addToCurrentPolygon( x, y )
|
|||
|
||||
end
|
||||
|
||||
function t.deletePolygon( )
|
||||
function t.deletePolygon( poly )
|
||||
|
||||
end
|
||||
|
||||
function t.drawPolygonEditHandles( poly )
|
||||
|
||||
end
|
||||
|
||||
|
|
52
main.lua
52
main.lua
|
@ -23,6 +23,8 @@ function love.update( dt )
|
|||
if love.keyboard.isScancodeDown( "a" ) then moveCamera = true; tx = tx - 1 end
|
||||
if love.keyboard.isScancodeDown( "s" ) then moveCamera = true; ty = ty - 1 end
|
||||
if love.keyboard.isScancodeDown( "d" ) then moveCamera = true; tx = tx + 1 end
|
||||
if love.keyboard.isScancodeDown( "q" ) then Camera.Zoom( true ) end
|
||||
if love.keyboard.isScancodeDown( "e" ) then Camera.Zoom( false ) end
|
||||
if moveCamera then Camera.Translate( tx, ty ) end
|
||||
|
||||
|
||||
|
@ -37,12 +39,14 @@ function love.draw()
|
|||
--Status bar.
|
||||
local x, y = love.mouse.getPosition()
|
||||
local wx, wy = Camera.GetWorldCoordinate( x, y )
|
||||
local bx, by = Camera.GetBitmapCoordinate( x, y )
|
||||
local h = love.graphics.getHeight() - 30
|
||||
love.graphics.setColor( 0.2, 0.1, 0.1, 0.5 )
|
||||
love.graphics.rectangle( "fill", 0, h, love.graphics.getWidth() / 2, 30 )
|
||||
love.graphics.setColor( 1, 1, 1, 1 )
|
||||
love.graphics.rectangle( "line", 0, h, love.graphics.getWidth() / 2, 30 )
|
||||
love.graphics.print(("SCREEN\t%d\t%d\nWORLD \t%5.2f\t%5.2f"):format(x, y, wx, wy), 0, h)
|
||||
love.graphics.print(("BITMAP\t%5.2f\t%5.2f"):format(bx, by), 200, h )
|
||||
|
||||
--Edit box.
|
||||
love.graphics.rectangle( "line", love.graphics.getWidth() / 2, h, love.graphics.getWidth() / 2, 30 )
|
||||
|
@ -79,19 +83,37 @@ function love.mousemoved( x, y, dx, dy, istouch )
|
|||
map.cities.selectNearestCity( Camera.GetWorldCoordinate( x, y ) )
|
||||
end
|
||||
|
||||
function love.keypressed(key)
|
||||
if key == "l" then
|
||||
-- To open a file or folder, "file://" must be prepended to the path.
|
||||
love.system.openURL("file://"..love.filesystem.getSaveDirectory())
|
||||
end
|
||||
if key == "1" then
|
||||
map.coastlines.visible = not map.coastlines.visible
|
||||
end
|
||||
if key == "2" then
|
||||
map.coastlinesLow.visible = not map.coastlinesLow.visible
|
||||
end
|
||||
if key == "3" then
|
||||
map.international.visible = not map.international.visible
|
||||
end
|
||||
wasKeyPressed = true
|
||||
local function ToggleVisibility( layer )
|
||||
if not layer then return end
|
||||
local ml
|
||||
if map[layer] then ml = map[layer] end
|
||||
if map.territory[layer] then ml = map.territory[layer] end
|
||||
assert( ml )
|
||||
ml.visible = not( ml.visible )
|
||||
print( layer, ml.visible )
|
||||
end
|
||||
|
||||
local layerVisibilityKeybinds = {
|
||||
["1"] = "africa",
|
||||
["2"] = "europe",
|
||||
["3"] = "northamerica",
|
||||
["4"] = "southamerica",
|
||||
["5"] = "southasia",
|
||||
["6"] = "russia",
|
||||
["7"] = "sailable",
|
||||
["8"] = "coastlines",
|
||||
["9"] = "coastlinesLow",
|
||||
["0"] = "international",
|
||||
["-"] = "cities"
|
||||
}
|
||||
|
||||
function love.keypressed(key)
|
||||
ToggleVisibility( layerVisibilityKeybinds[key] )
|
||||
|
||||
if key == "l" then
|
||||
-- To open a file or folder, "file://" must be prepended to the path.
|
||||
love.system.openURL("file://"..love.filesystem.getSaveDirectory())
|
||||
end
|
||||
|
||||
wasKeyPressed = true
|
||||
end
|
||||
|
|
34
map.lua
34
map.lua
|
@ -4,18 +4,19 @@ local Lines = require 'lines'
|
|||
local Nodes = require 'nodes'
|
||||
local Bitmap = require 'bmp'
|
||||
local Camera = require 'camera'
|
||||
local Territory = require 'territory'
|
||||
|
||||
local map = {
|
||||
coastlines = false,
|
||||
coastlinesLow = false,
|
||||
international = false,
|
||||
territory = {
|
||||
af = false,
|
||||
eu = false,
|
||||
na = false,
|
||||
ru = false,
|
||||
sa = false,
|
||||
as = false
|
||||
africa = false,
|
||||
europe = false,
|
||||
northamerica = false,
|
||||
russia = false,
|
||||
southamerica = false,
|
||||
southasia = false
|
||||
},
|
||||
travelnodes = false,
|
||||
sailable = false,
|
||||
|
@ -29,11 +30,32 @@ 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" )
|
||||
for k, v in pairs(map.territory) do
|
||||
map.territory[k] = Territory.load( "data/earth/"..k..".bmp", k )
|
||||
end
|
||||
map.sailable = Territory.load( "data/earth/sailable.bmp", "sailable" )
|
||||
end
|
||||
|
||||
function map.draw()
|
||||
lg.clear( 0, 0, 0, 1 )
|
||||
|
||||
|
||||
do --travel nodes
|
||||
map.travelnodes:draw()
|
||||
end
|
||||
|
||||
|
||||
do --territory
|
||||
lg.replaceTransform( Camera.tfTerritory )
|
||||
lg.setBlendMode( "add" )
|
||||
for k, v in pairs(map.territory) do
|
||||
if v.visible then v:draw() end
|
||||
end
|
||||
if map.sailable.visible then map.sailable:draw() end
|
||||
lg.setBlendMode( "alpha" )
|
||||
end
|
||||
|
||||
|
||||
do --all this stuff is drawn in world coordinates, ( -180, 180 ) x ( -100, 100 )
|
||||
|
||||
lg.replaceTransform( Camera.tf )
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
--the pathfinding nodes form a connected graph.
|
||||
local t = {}
|
||||
local bmp = require 'bmp'
|
||||
local lg = assert( love.graphics )
|
||||
|
||||
function t.load( filename )
|
||||
local nodes = { points = {}, connections = {}, img = bmp.load( filename ) }
|
||||
local nodes = { visible = true, points = {}, connections = {}, img = bmp.load( filename ) }
|
||||
|
||||
return setmetatable( nodes, {__index = t } )
|
||||
end
|
||||
|
@ -15,7 +16,8 @@ function t.isConnected( nodes )
|
|||
end
|
||||
|
||||
function t.draw( nodes )
|
||||
|
||||
lg.points( nodes.points )
|
||||
lg.draw( nodes.img )
|
||||
end
|
||||
|
||||
function t.drawConnections( nodes )
|
||||
|
|
|
@ -1,8 +1,24 @@
|
|||
local t = {}
|
||||
local bmp = require 'bmp'
|
||||
local lg = assert( love.graphics )
|
||||
|
||||
local colours = {
|
||||
africa = {1,0,0,0.5},
|
||||
europe = {0,1,0,0.5},
|
||||
northamerica = {0,0,1,0.5},
|
||||
russia = {0,1,1,0.5},
|
||||
southamerica = {1,0,1,0.5},
|
||||
southasia = {1,1,0,0.5},
|
||||
sailable = {1, 1, 1, 0.2},
|
||||
}
|
||||
|
||||
function t.load( filename, name )
|
||||
local territory = { img = bmp.load( filename ) }
|
||||
local territory = {
|
||||
visible = true,
|
||||
name = name,
|
||||
colour = colours[name],
|
||||
img = assert( bmp.load( filename ) )
|
||||
}
|
||||
return setmetatable( territory, {__index = t } )
|
||||
end
|
||||
|
||||
|
@ -16,6 +32,10 @@ function t.getPixel( territory, x, y )
|
|||
return territory.img[math.floor( 512 * ( x + 180 ) / 360 ) ][ math.floor( 285 * ( y + 100 ) / 200 ) ]
|
||||
end
|
||||
|
||||
function t.toggleVisibility( territory )
|
||||
|
||||
end
|
||||
|
||||
--[[
|
||||
0
|
||||
20 -- once sailable.bmp is brighter than this, the area is traversable by ships
|
||||
|
@ -27,8 +47,9 @@ SO:
|
|||
TERRITORY: 131 ( place land if sailable <= 60 ), 61 ( place sea ), 0
|
||||
]]
|
||||
|
||||
function t.draw( nodes )
|
||||
|
||||
function t.draw( territory )
|
||||
lg.setColor( territory.colour )
|
||||
lg.draw( territory.img )
|
||||
end
|
||||
|
||||
function t.drawConnections( nodes )
|
||||
|
|
Loading…
Reference in New Issue