Here is the code so far, based off of Phaelix's Real Time Strategy tutorial:
sync on
sync rate 60
backdrop on
color backdrop rgb(0,0,0)
load image "worker.bmp",1
load image "fighter.bmp",2
sw2 = screen width()/2
sh2 = screen height()/2
rem object number of character
character = 15
rem speed at which character will move
speed# = 3.0
mouse = 0
moveFlag = 0
```````````````````
` TYPES
```````````````````
type basicUnitActions
isMoving as boolean
isAttacking as boolean
isSelected as boolean
endtype
type basicUnitProperties
name as string
maxLife as integer
armor as integer
range as integer
speed as float
endtype
dim characterType(2) as basicUnitProperties
#constant SOLDIER = 1
#constant WORKER = 2
characterType(SOLDIER).name = "Grunt"
characterType(SOLDIER).maxLife = 80
characterType(SOLDIER).armor = 4
characterType(SOLDIER).range = 0
characterType(SOLDIER).speed = 3.5
characterType(WORKER).name = "Peasant"
characterType(WORKER).maxLife = 45
characterType(WORKER).armor = 0
characterType(WORKER).range = 0
characterType(WORKER).speed = 2.25
type character
object as integer
action as basicUnitActions
isHarvesting as integer
targetX as float
targetZ as float
group as integer
unit as integer
life as integer
endtype
dim characters(0) as character
rem create 5 soldiers
for t = 10 to 14
sprite t,sw2,sh2,2
offset sprite t,5,5
array insert at bottom characters(0)
index = array count(characters(0))
characters(index).object = t
characters(index).action.isMoving = 0
characters(index).action.isAttacking = 0
characters(index).action.isSelected = 0
characters(index).isHarvesting = 0
characters(index).group = -1
characters(index).unit = SOLDIER
characters(index).life = characterType(SOLDIER).maxLife
next t
rem create 2 workers
for t = 15 to 16
sprite t,sw2,sh2,1
offset sprite t,5,5
array insert at bottom characters(0)
index = array count(characters(0))
characters(index).object = t
characters(index).action.isMoving = 0
characters(index).action.isAttacking = 0
characters(index).action.isSelected = 0
characters(index).isHarvesting = 0
characters(index).group = -1
characters(index).unit = WORKER
characters(index).life = characterType(WORKER).maxLife
next t
``````````````````
` END OF TYPES
``````````````````
remstart
***********************
*#####################*
*#### ####*
*####~ MAIN LOOP ~####*
*#### ####*
*#####################*
***********************
remend
do
mb = mouseclick()
gosub selec
gosub move
sync
loop
remstart
***********************
*#####################*
*#### ####*
*####~ END OF ~####*
*####~ MAIN LOOP ~####*
*#### ####*
*#####################*
***********************
remend
selec:
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
endif
return
move:
for char = 1 to array count(characters(0))
rem get object number of this character for future object related actions
obj = characters(char).object
ink rgb(0,255,0),0
text 0,0,"Selected: " + STR$(characters(char).action.isSelected)
cx = sprite x(obj)
cy = sprite y(obj)
if cx > bx0 and cx < bx1 and cy > by0 and cy < by1
characters(char).action.isSelected = 1
else
characters(char).action.isSelected = 0
endif
if characters(char).action.isSelected = 1
set sprite diffuse obj,120,200,120
else
set sprite diffuse obj,255,255,255
endif
rem if user is currently drawing a selection box
if characters(char).action.isSelected = 1
if mb = 2 and mouse = 0
targetX# = mousex()
targetY# = mousey()
mouse = 1
moveFlag = 1
rem get the angle between the character and targeted spot
angle# = atanfull( sprite y(obj)-targetY#, sprite x(obj)-targetX#)
rem rotate character to point towards target
rotate sprite obj, wrapvalue(angle#-90)
endif
if mb <> 2 then mouse = 0
if moveFlag = 1
sx = sprite x(obj)
sy = sprite y(obj)
rem get character's new position
x# = newxvalue(sx, angle#, speed#)
y# = newyvalue(sy, angle#, speed#)
paste sprite obj, x#, y#
rem if character is within range of target, then stop moving
if sqrt(((targetX#- x#)*(targetX#- x#))*((targetY#-y#)*(targetY#-y#))) < (speed#)
moveFlag = 0
endif
endif
text 0,20,"sq dis: " + STR$(sqrt(((targetX#- x#)*(targetX#- x#))*((targetY#-y#)*(targetY#-y#))))
endif
next char
return
function getSquaredDistance#(fx#,fy#,ftargetX#,ftargetY#)
a2 = (fx#-ftargetX#)*(fx#-ftargetX#)
b2 = (fy#-ftargetY#)*(fy#-ftargetY#)
c2 = a2+b2
endfunction c2
As you can see, I have not remarked it, so it may be complicated to understand, and if anyone needs me to remark it so they can help me, though I don't think that will be the case, let me know and I will.
The problem im having is that the sprites dont move like they should
You can select them, tell them to move, and they rotate towards where you clicked, and try to move, but they just kind of wiggle.
Now I'm thinking that this is because of hte way I used:
NewXValue and NewYValue but I'm not sure. If anyone could help me out, please, do so.
The 2 images are attached, something like 300 kilobytes so don't worry.
AMD Athlon 64 3200 - GeForce 6800 GT - 320GB Hard Drive
1024MB RAM