I am using arrays with custom types. (If this helps any)
Type Tile
tilenumber
tilexpos
tileypos
tileoccupied as boolean
endtype
^ How the tiles are defined
Type Unit
name as string
unitno `unit's sprite number
health
unittype `0 = soldiers
tileno `tile the unit is occupying
ownership `0= player, 1=cpu
xpos
ypos
endtype
^How the units are defined
create_tiles:
GLOBAL DIM tiles(25) as tile
load image "Images/Units/unitmarker.jpg",4,1
load image "Images/Units/unitmarker_selected.jpg",8,1
x = 300
y = 190
sprtno = 1
tileno = 1
for s = 1 to 5
for t = 1 to 5
`paste image 4,x,y,1
sprite sprtno,x,y,4
set sprite alpha sprtno, 150
tiles(tileno).tilenumber = sprtno
tiles(tileno).tilexpos = x
tiles(tileno).tileypos = y
tiles(tileno).tileoccupied = 0
x = x + 80
sprtno = sprtno + 1
tileno = tileno + 1
next t
y = y + 80
x = 300
next s
return
^ How the tiles were created and array data filled (no problems here, I'm pretty sure)
loadunits:
GLOBAL unitno = 50
rem soldiers = 700, mineral mine = 701, mineral cafe = 702
load image "Images/Units/soldiers.png ", 100,1
Global DIM units(50) as Unit
return
^How I initialized the units array
createSoldier:
`unitarray = ARRAY COUNT(units())
unitno = unitno + 1
if tiles(tileno).tileoccupied = 0
xposi = tiles(tileno).tilexpos
yposi = tiles(tileno).tileypos
tiles(tileno).tileoccupied = 1
sprite unitno, xposi, yposi, 100
array insert at bottom units()
units().unitno = unitno
units().unittype = unittype
units().tileno = tileno
units().xpos = xposi
units().ypos = yposi
units().health = 20
units().name = "Soldiers"
units().ownership = ownership
endif
if ownership = 0 rem player owns unit
player(1).units = player(1).units + 1
else rem CPU owns unit
cpu(1).units = cpu(1).units + 1
endif
return
^The sub routine used when creating new soldiers
I am not surprised if this will look confusing: it is.
I have a lot of sub routines... which should probably be functions. But I've taken a lay off from programming for a while (only ever did it leisurely). I plan on tidying it up a whole bunch... but I first want to get this sprite issue worked out.
How do I change the coordinates of the actual sprite?
I don't want to just paste its image somewhere else. All data in the array corresponds with the actual sprite.
I'd prefer not to change the basis of the array.. as it is the basis of my concepts and the way I was going about it all. I'd just like some tips! Thanks!