All,
Just posting a small project to display the Galaxy 1 map for the BBC Micro Elite game. Not the finished product but it works.
-- BBC Micro Elite Game Galaxy1 map
-- by Bri_G with help frm dave1707
viewer.mode = LANDSCAPE_LEFT
function setup()
--
sW,sH,cW,cH = WIDTH, HEIGHT, WIDTH/2, HEIGHT/2
xmax,ymax,xmin,ymin = 100,100,100,100
planets = {}
pdist = {}
docked = 8
px,py = 420,200
time = 0
path = asset.documents[galaxy[1]] — csv file in Codea root ‘documents’
csv = readText(path)
parsePlanet(csv)
scene = asset.documents.galaxy01
galpic = image(1024,768)
setContext(galpic)
spriteMode(CENTER)
sprite(scene,WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
ellipseMode(CENTER)
fill(117, 214, 218, 159)
noStroke()
for gl = 1, 256 do
radius = planets[gl].rad/800
ellipse(planets[gl].pos.x*4,planets[gl].pos.y*3,radius,radius)
end
setContext()
end
function draw()
--
time = time + 0.1
sprite(galpic,cW,cH,sW,sH)
if time < 10 then
pushStyle()
fill(241, 222, 47)
font("Baskerville-SemiBold")
fontSize(32)
textMode(CENTER)
text("BBC MICRO ELITE - Galaxy 1",WIDTH/2,HEIGHT-40)
popStyle()
else
showData(docked,px,py)
end
end
function touched(touch)
--
if touch.state == ENDED then
docked = distance(touch)
if touch.x < cW then px = 568 else px = 56 end
if touch.y < cH then py = 300 else py = 40 end
showData(docked,px,py)
end
end
function parsePlanet(str)
-- galaxy_num,system_num,name,x,y,economy_id,economy,govtype_id,govtype,techlev,
-- productivity, radius,population,description
for a,_,b,_,c,_,d,_,e,_,f,_,g,_,h,_,i,_,j,_,k,_,l,_,m,_,n,_
in string.gmatch(str,"(.-)(,)(.-)(,)(.-)(,)(.-)(,)(.-)(,)(.-)(,)(.-)(,)(.-)(,)(.-)(,)(.-)(,)(.-)(,)(.-)(,)(.-)(,)(.-)(,)") do
table.insert(planets,
{gal=tonumber(a),sys=tonumber(b),name=c,pos=vec2(tonumber(d),tonumber(e)),
econ_id=f,econ=g,gov_id=h,gov=i,
tech=tonumber(j),prod=tonumber(k),rad=tonumber(l),pop=tonumber(m),desc=n})
end
end
function showData(pl,sdx,sdy)
--
local planet = planets[pl]
stroke(255)
strokeWidth(2)
noFill()
ellipseMode(CENTER)
ellipse(planets[pl].pos.x*4,planets[pl].pos.y*3,80,80)
fill(255, 243, 0)
textMode(CORNER)
fontSize(18)
text(planets[pl].name,planets[pl].pos.x*4+24,planets[pl].pos.y*3+24)
fill(255)
rectMode(CORNER)
fill(44, 37, 109, 173)
rect(sdx,sdy,320,440)
fill(21, 83, 236)
rect(sdx,sdy+408,320,32)
fill(255, 243, 0)
font("Arial-BoldMT")
fontSize(24)
txtStart = 410
text("Planet - "..planets[pl].name,sdx+24,sdy+txtStart)
fontSize(20)
text("Economy : "..planets[pl].econ,sdx+12,sdy+txtStart-30)
text("Government : "..planets[pl].gov,sdx+12,sdy+txtStart-60)
text("Tech Level : "..planets[pl].tech,sdx+12,sdy+txtStart-90)
text("Productivity : "..planets[pl].prod,sdx+12,sdy+txtStart-120)
text("Radius : "..planets[pl].rad,sdx+12,sdy+txtStart-150)
text("Population : "..planets[pl].pop,sdx+12,sdy+txtStart-180)
text("Position : "..planets[pl].pos.x.."_"..planets[pl].pos.y,sdx+12,sdy+txtStart-210)
text("Description :",sdx+12,sdy+txtStart-240)
des = split(planets[pl].desc,30)
for lp = 1,#des do
text(des[lp],sdx+12,sdy+txtStart-240-lp*30)
end
end
function distance(t)
--
local pdist = {}
nearest = 0
for lp = 1, 256 do
pdist[lp] = math.sqrt((t.x-planets[lp].pos.x*4)^2+(t.y-planets[lp].pos.y*3)^2)
end
id = 256
small = 1000
for lp = 256,1,-1 do
if pdist[lp] < small then
small = pdist[lp]
id = lp
end
end
nearest = id
return nearest
end
function split(str, max_line_length)
local lines = {}
local line
str:gsub('(%s*)(%S+)',
function(spc, word)
if not line or #line + #spc + #word > max_line_length then
table.insert(lines, line)
line = word
else
line = line..spc..word
end
end
)
table.insert(lines, line)
return lines
end
galaxy = {
"Galaxy1"
}
The csv file and image have been posted in another thread, but will be reposted here for convenience. You will need to edit the paths for this in the above code by adding your own file location. Also exported zip file.