Well, I'm about done with this for now. Here is a screenshot attached. I haven't commented it out too well yet but I figured it would show you how to do a few different thing. It started getting a little unorganized toward the end but I think it is still fairly readable.
type mType ` our udt for minions
health as integer
dest as integer
delay as integer
endtype
type pType ` our udt for path points, we can also use it for tower points
x as integer
y as integer
target as integer
endtype
` initialize the arrays
dim mData(0) as mType ` minion array
global mData
global mQty = 0
global mLeft = 0
dim pData(0) as pType ` path point array
global pData
global pQty = 0
dim tData(255) as pType ` tower point array
global tData
global tQty
global currentTower = 0
global towerRange = 1000
global fireDelay = timer()
global credit# = 5000.0
global towerCost# = 100.0
global priceInflation# = 1.1
global currentWave
`------------------------
set display mode 1024,768,32,1
draw sprites last
sync on
sync rate 60
hide mouse
dummy=make vector2(1)
load image "background.png", 1,0
load bitmap "buildmap.png",1
load image "minion.png",2
load image "towerbase.png",3
load image "towerturret.png",4
load image "cursor.png",5
set current bitmap 0
makePath(26)
setPoint(0,128,-64)
setPoint(1,128,128)
setPoint(2,192,192)
setPoint(3,256,192)
setPoint(4,320,256)
setPoint(5,320,320)
setPoint(6,256,384)
setPoint(7,192,384)
setPoint(8,128,448)
setPoint(9,128,576)
setPoint(10,192,640)
setPoint(11,320,640)
setPoint(12,448,512)
setPoint(13,448,448)
setPoint(14,512,384)
setPoint(15,512,320)
setPoint(16,448,256)
setPoint(17,448,192)
setPoint(18,512,128)
setPoint(19,640,128)
setPoint(20,704,192)
setPoint(21,704,256)
setPoint(22,640,320)
setPoint(23,640,448)
setPoint(24,768,576)
setPoint(25,1088,576)
do
if mLeft = 0
key$ = inkey$()
select key$
case "1":
makeWave(8,2000,2)
currentWave = 1
endcase
case "2":
makeWave(8,1500,2)
currentWave = 2
endcase
case "3":
makeWave(8,1000,2)
currentWave = 3
endcase
case "4":
makeWave(16,2000,2)
currentWave = 4
endcase:
case "5":
makeWave(16,1000,2)
currentWave = 5
endcase
case "6":
makeWave(16,500,2)
currentWave = 6
endcase
case "7":
makeWave(32,1000,2)
currentWave = 7
endcase
case "8":
makeWave(32,750,2)
currentWave = 8
endcase
case "9":
makeWave(32,500,2)
currentWave = 9
endcase
case "0":
makeWave(64,250,2)
currentWave = 10
endcase
endselect
endif
paste image 1,0,0
sprite 1,mousex(),mousey(),5
offset sprite 1,sprite width(1)*0.5,sprite height(1)*0.5
if checkBuildMap()=1 then set sprite diffuse 1,255,0,0
if checkBuildMap()=0 then set sprite diffuse 1,0,255,0
if mouseclick()=1 then addTower()
updateTowers()
updateMinions()
if timer()>firedelay
for tower = 0 to 255
if tData(tower).target>0
dec mData(tData(tower).target-1).health
endif
next tower
firedelay = timer() + 250
endif
updateHealthBars()
ink rgb(0,255,0),0
set cursor 850,0
print "Credits: ",credit#
ink rgb(255,0,0),0
set cursor 850,16
print "Tower Cost: ",towerCost#
ink rgb(0,0,0),0
set cursor 850,32
print "Current Wave: ",currentWave
ink rgb(64,64,64),0
set cursor 850,48
print mLeft,"/",mQty+1," Enemies Left"
ink rgb(0,0,0),0
set cursor 800,48+32
print "Use NumKeys to Cycle Waves"
sync
loop
end
function makePath(qty) ` initializes the path and also clears previous path
empty array pData(0)
dim pData(qty-1) as pType
pQty = qty-1
endfunction
function setPoint(index, x, y) ` adds a point to the path at the given index
pData(index).x = x
pData(index).y = y
endfunction
function makeWave(qty,delay,img)` creates a wave with given quantity, delay(in ms), health, and image
empty array mData(0) ` also destroys previous wave
dim mData(qty-1) as mType
mQty = qty-1
mLeft = qty
for minion = 0 to mQty
mData(minion).health = 100
mData(minion).dest = 1
mData(minion).delay = timer()+(minion*delay)
if sprite exist(minion+100)
delete sprite minion+100
endif
sprite minion+100,pData(0).x,pData(0).y, img ` place sprites at first path point
offset sprite minion+100,16,16
next minion
endfunction
function updateMinions()
for minion = 0 to mQty
if mData(minion).health < 1 and sprite exist(minion+100)
delete sprite minion+100
dec mLeft
credit#=credit#+(25*currentWave)
endif
if timer()>mData(minion).delay and sprite exist(minion+100)
XD#=sprite x(minion+100)-pData(mData(minion).dest).x
YD#=sprite y(minion+100)-pData(mData(minion).dest).y
Ang#=0.0-ATANFULL(xd#,yd#)
rotate sprite minion+100,int(ang#)
move sprite minion+100,1
if sprite x(minion+100) = pData(mData(minion).dest).x and sprite y(minion+100) =pData(mData(minion).dest).y
inc mData(minion).dest
endif
rotate sprite minion+100, 0
set sprite priority minion+100,sprite y(minion+100)
endif
if mData(minion).dest > pQty then GameOver()
next minion
endfunction
function checkBuildMap()
set current bitmap 1
result = 0
for x = mousex()-15 to mousex()+15
for y = mousey()-15 to mousey()+15
if rgbr(point(x,y)) = 0 then result = 1
next y
next x
set current bitmap 0
endfunction result
function addTower()
if checkBuildMap()=0 and credit#>=towerCost#
set current bitmap 1
for x = mousex()-15 to mousex()+15
for y = mousey()-15 to mousey()+15
dot x,y,rgb(0,0,0)
next y
next x
set current bitmap 0
sprite currentTower+1000,mousex(),mousey(),3
sprite currentTower+2000,mousex(),mousey(),4
offset sprite currentTower+1000,16,16
offset sprite currentTower+2000,16,16
inc currentTower
credit#=credit#-towerCost#
towerCost#=towerCost#*priceInflation#
endif
endfunction
function updateTowers()
for tower = 0 to 255
tData(tower).target = 0
if sprite exist(tower+2000)
for minion = mQty to 0 step -1
if sprite exist(minion+100)
d = int(dist#(sprite x(tower+2000),sprite y(tower+2000), sprite x(minion+100),sprite y(minion+100)))
if d < 0 then d = -d
if d < 100 then tData(tower).target = minion + 1
if tData(tower).target > 0 and sprite exist(tData(tower).target+99)
XD#=sprite x(tData(tower).target+99) - sprite x(tower+2000)
YD#=sprite y(tData(tower).target+99) - sprite y(tower+2000)
Ang#=0.0-ATANFULL(xd#,yd#)
rotate sprite tower+2000, int(ang#)+90
endif
endif
next minion
endif
next tower
endfunction
function updateHealthBars()
for minion = 0 to mQty
if sprite exist(minion+100)
if mData(minion).health > 0
hp = int(mData(minion).health*0.1)
ink rgb(255,0,0),0
x = sprite x(minion+100)
y = sprite y(minion+100)
line x-5,y+16,x+4,y+16
ink rgb(0,255,0),0
x = sprite x(minion+100)
y = sprite y(minion+100)
line x-5,y+16,x-5+hp,y+16
endif
endif
next minion
endfunction
function dist#(x1#,y1#,x2#,y2#)
dist# = Sqrt((X2# - X1#)^2 + (Y2# - Y1#)^2)
endFunction dist#
function gameOver()
end
endfunction