WOW, that is alot of work just to change it to 2d... I spent so much time and its not working, I'm sure its just a few little things, anyone wanna help me make this work right?
Its supposed to make the guys move to where you right click once youve selected them, now, I'v enever used sprites up until today, so making an rts out of sprites may be a dumb idea, but i've got a pretty good idea of what to do based on Phaelix's 3D-RTS tutorial... so here it is
uncommented and all.
sync on
sync rate 60
global ranm
randomize ranm
load image "fighter.bmp",2
load image "worker.bmp",1
type unitaction
moving as boolean
selected as boolean
attacking as boolean
gathering as boolean
standing as boolean
endtype
type unitstats
name as string
health as integer
armor as integer
range as integer
speed as float
damage as integer
endtype
type unit
obj as integer
life as integer
action as unitaction
targetx as float
targety as float
group as integer
untype as integer
endtype
dim unittype(2)as unitstats
#Constant soldier = 2
#Constant worker = 1
unittype(soldier).name="Fighter"
unittype(soldier).health=200
unittype(soldier).armor = 8
unittype(soldier).range = 0
unittype(soldier).speed = 1
unittype(soldier).damage = 20+rnd(5)
unittype(worker).name="Worker"
unittype(worker).health=95
unittype(worker).armor=1
unittype(worker).range=0
unittype(worker).speed=.75
unittype(worker).damage=7+rnd(4)
dim units(0)as unit
for u = 100 to 104
sprite u,(screen width()/2),(screen height()/2),2
set sprite 2,0,1
array insert at bottom units(0)
index = array count(units(0))
units(index).obj=u
units(index).life=unittype(soldier).health
units(index).action.moving=0
units(index).action.selected=0
units(index).action.standing=0
units(index).action.attacking=0
units(index).action.gathering=0
units(index).group=-1
units(index).untype=soldier
next u
for u = 105 to 106
sprite u,(screen width()/2),(screen height()/2),1
set sprite 1,0,1
array insert at bottom units(0)
index = array count(units(0))
units(index).obj=u
units(index).life=unittype(worker).health
units(index).action.moving=0
units(index).action.selected=0
units(index).action.standing=0
units(index).action.attacking=0
units(index).action.gathering=0
units(index).group=-1
units(index).untype=worker
next u
do
ranm = ranm + 1
mb = mouseclick()
if mb = 1 and selection = 0
selection = 1
bx = mouseX()
by = mouseY()
endif
if mb = 1 And selection = 1
bx2 = mouseX()
by2 = mouseY()
endif
if mb <> 1 then selection = 0
if selection = 1
if bx < bx2
bx0 = bx
bx1 = bx2
else
bx0 = bx2
bx1 = bx
endif
if by < by2
by0 = by
by1 = by2
else
by0 = by2
by1 = by
endif
ink rgb(0,255,0),0
line bx0, by0, bx1, by0
line bx0, by1, bx1, by1
line bx0, by0, bx0, by1
line bx1, by0, bx1, by1
if mb = 2 and mouse = 0
mouse = 1
mx = mousex()
my = mousey()
targetmove = 1
endif
for c = 1 to array count(units(0))
obj = units(c).obj
if units(c).action.selected=1
if targetmove=1
units(c).action.moving=1
units(c).targetx=mx
units(c).targety=my
angle# = atanfull(mx - sprite x(obj), my - sprite y(obj))
rotate sprite obj,angle#
endif
endif
if units(c).action.moving=1
speed# = unittype(units(c).untype).speed
x# = newxvalue(sprite x(obj), angle#, speed#)
y# = newyvalue(sprite y(obj), angle#, speed#)
paste sprite obj,x#,y#
tx# = units(c).targetX
ty# = units(c).targety
rem if character is within range of target, then stop moving
if getsquareddistance#(x#, y#, tx#, ty#) < (speed# * speed#)
units(c).action.moving = 0
endif
endif
next char
for character = 100 to 106
cx = sprite x(character)
cy = sprite y(character)
if cx > bx0 and cx < bx1 and cy > by0 and cy < by1
selected = 1
else
selected = 0
endif
next character
endif
text 0,0,"Selected: " + STR$(selected)
sync
cls
loop
function getsquareddistance#(posx#, posy#, postx#, posty#)
asqrd#=((postx#-posx#)*(postx#-posx#))
bsqrd#=((posty#-posy#)*(posty#-posy#))
csqrd#=asqrd#+bsqrd#
endfunction csqrd#
AMD Athlon 64 3200 - GeForce 6800 GT - 320GB Hard Drive
1024MB RAM