I am trying to make an RTS. This is what I did for my controls.
`RTS controls
`Have to do it
randomize timer()
`Make grass texture
ink rgb(128,213,13),0
box 0,0,256,256
for i=1 to 10000
for c=1 to 4
dot rnd(256),rnd(256),rgb(25*c,43*c,2*c)
next c
next i
get image 1,0,0,256,256
cls
create bitmap 1,256,256
paste image 1,0,0
blur bitmap 1,4
get image 1,0,0,256,256
set current bitmap 0
delete bitmap 1
cls
`Make building texture
ink rgb(100,100,100),0
box 0,0,256,256
for i=1 to 10000
for c=1 to 4
dot rnd(256),rnd(256),rgb(c*20,c*20,c*20)
next c
next i
get image 2,0,0,256,256
cls
create bitmap 1,256,256
paste image 2,0,0
blur bitmap 1,4
get image 2,0,0,256,256
set current bitmap 0
delete bitmap 1
cls
`Make Sky texture
ink rgb(3,241,235),0
box 0,0,256,256
for i=1 to 10000
dot rnd(256),rnd(256),-1
next i
get image 3,0,0,256,256
cls
create bitmap 1,256,256
paste image 3,0,0
blur bitmap 1,4
get image 3,0,0,256,256
set current bitmap 0
delete bitmap 1
`1=selected 0=notselected
dim selected(20) as boolean
`xcoordinate of waypoint
dim waypointx(20) as float
`zcoordinate of waypoint
dim waypointz(20) as float
`Red team health
dim healtha(20) as integer
`Blue team health
dim healthb(100) as integer
`Current Action of red team
dim action(20) as string
`Red team healing
dim aheal(20) as boolean
`Blue team healing
dim bheal(100) as boolean
`Get ready for multiple levels!
extraenemies=0
for i=1 to 20
`Health
healtha(i)=255
healthb(i)=255
`They begin waiting
action(i)="Waiting for command"
next i
`To be used for distance...
dista=1
distb=2
obja=3
objb=4
null=make vector2(dista)
null=make vector2(distb)
null=make vector2(obja)
null=make vector2(objb)
`set up camera
sync on
autocam off
set camera range 1,20000
position camera -7500,500,-7500
`make basic world
make object plain 1,20000,20000
xrotate object 1,-90
texture object 1,1
for i=2 to 100
size=rnd(1000)+10
make object box i,rnd(1000)+10,size,rnd(1000)+10
position object i,rnd(20000)-10000,size/2,rnd(20000)-10000
texture object i,2
next i
make object sphere 1000,20000
set object 1000,1,0,0,0,0,0
texture object 1000,3
`four selection area cubes
for i=101 to 104
make object cube i,100
color object i,rgb(0,255,0)
next i
`red team
for i=120 to 139
make object sphere i,100
color object i,rgb(255,0,0)
position object i,rnd(5000)-10000,50,rnd(5000)-10000
waypointx(i-119)=object position x(i)
waypointz(i-119)=object position z(i)
next i
`blue team
for i=140 to 159
make object sphere i,100
color object i,rgb(0,0,255)
position object i,rnd(5000)+5000,50,rnd(5000)+5000
yrotate object i,rnd(360)
next i
`not yet currently clicking
click=0
speed#=2
set text font "book"
set text size 12
do
sync
fps#=screen fps()
if fps#>0
speed#=(100.0-fps#)/20.0
endif
`Display Red team actions
set cursor 1,1
ink rgb(255,0,0),0
for i=1 to 20
print action(i)
next i
`green lines in game
ink rgb(0,255,0),0
`Basic movement of camera
position mouse screen width()/2,screen height()/2
move#=upkey()-downkey()
shift=shiftkey()
control=controlkey()
if shift=1 then move#=move#*3
if control=1 then move#=move#*5
move camera 2*move#*speed#
x#=camera angle x()
xrotate camera 0
yrotate camera camera angle y()+90
move#=rightkey()-leftkey()
if shift=1 then move#=move#*3
if control=1 then move#=move#*5
move camera 2*move#*speed#
yrotate camera camera angle y()-90+mousemovex()/2
xrotate camera x#+mousemovey()/2
if camera angle x()>90 then xrotate camera 90
if camera angle x()<-90 then xrotate camera -90
`If you were not previously clicking
if click=0
`If you are clicking now
if mouseclick()=1
`If you are clicking on something
if pick object(screen width()/2,screen height()/2,1,100)>0
`Position the first selection box where you are clicking
position object 101,get pick vector x()+camera position x(),50,get pick vector z()+camera position z()
`It is now recognized that you have begun clicking
click=1
endif
endif
endif
`If you are clicking
if click=1
if mouseclick()=1
if pick object(screen width()/2,screen height()/2,1,100)>0
`Position other three selection boxes to form a square
position object 102,object position x(101),50,get pick vector z()+camera position z()
position object 103,get pick vector x()+camera position x(),50,object position z(101)
position object 104,get pick vector x()+camera position x(),50,get pick vector z()+camera position z()
endif
endif
endif
`It now recognizes if you are no longer clicking
if mouseclick()=0 then click=0
`If you right click
if mouseclick()=2
`for all the objects you control (120-139)
for i=1 to 20
if object exist(i+119)=1
xsel=0
zsel=0
`Tests to see if the object is in the selected area
if object position x(i+119)>object position x(101)
if object position x(i+119)<object position x(103)
xsel=1
endif
else
if object position x(i+119)>object position x(103)
xsel=1
endif
endif
if object position z(i+119)>object position z(101)
if object position z(i+119)<object position z(104)
zsel=1
endif
else
if object position z(i+119)>object position z(104)
zsel=1
endif
endif
`If it is then it is recorded in the selected array
if xsel+zsel=2
selected(i)=1
else
selected(i)=0
endif
else
`If the object doesn't exist how could it be selected?
selected(i)=0
endif
next i
`If you are clicking on part of the world
if pick object(screen width()/2,screen height()/2,1,100)>0
`Set the new waypoint coordinates
wayptx#=get pick vector x()+camera position x()
wayptz#=get pick vector z()+camera position z()
`For all the objects you control
for i=1 to 20
`If they are selected
if selected(i)=1
`Their waypoint is the new waypoint
waypointx(i)=wayptx#
waypointz(i)=wayptz#
endif
next i
endif
endif
`Draw the lines between the selection boxes
screenx#=object screen x(101)
screeny#=object screen y(101)
screenx2#=object screen x(102)
screeny2#=object screen y(102)
screenx3#=object screen x(103)
screeny3#=object screen y(103)
screenx4#=object screen x(104)
screeny4#=object screen y(104)
line screenx#,screeny#,screenx2#,screeny2#
line screenx3#,screeny3#,screenx#,screeny#
line screenx3#,screeny3#,screenx4#,screeny4#
line screenx4#,screeny4#,screenx2#,screeny2#
`For all the red team (the one you control)
for i=1 to 20
if object exist(i+119)=1
`If they are currently at their waypoint
if object position x(i+119)+1*speed#>waypointx(i) and object position x(i+119)-1*speed#<waypointx(i) and object position z(i+119)+1*speed#>waypointz(i) and object position z(i+119)-1*speed#<waypointz(i)
action(i)="Waiting for command"
else
`Point and move to their waypoint
point object i+119,waypointx(i),50,waypointz(i)
move object i+119,1*speed#
action(i)="Moving to waypoint"
endif
endif
next i
`Heal if they are not attacking
for i=1 to 20
aheal(i)=1
next i
for i=1 to 20+extraenemies
bheal(i)=1
next b
`For the red team
for a=120 to 139
if object exist(a)=1
`For all the buildings
for b=2 to 100
`If they are colliding then have the red team member move around
if object collision (a,b)=1
move object a,-2*speed#
move object right a,1*speed#
endif
next b
`For all the members of the red team
for b=120 to 139
if object exist(b)=1
`You can't test collision between one object and the same object
if a<>b
`If they are colliding
if object collision (a,b)=1
`Find which is closer to the waypoint
set vector2 obja,object position x(a),object position z(a)
set vector2 objb,waypointx(a-119),waypointz(a-119)
subtract vector2 dista,obja,objb
dista#=length vector2(dista)
set vector2 obja,object position x(b),object position z(b)
set vector2 objb,waypointx(b-119),waypointz(b-119)
subtract vector2 distb,obja,objb
distb#=length vector2(distb)
`Have the one further away from their waypoint wait
if dista#>distb#
move object a,-1*speed#
action(a-119)="Following leader"
else
move object b,-1*speed#
action(b-119)="Following leader"
endif
endif
endif
endif
next b
`Attack!
`For all of blue team
for b=140 to 159+extraenemies
if object exist(b)=1
`Is it closer to the waypoint or the enemy?
set vector2 obja,object position x(a),object position z(a)
set vector2 objb,waypointx(a-119),waypointz(a-119)
subtract vector2 dista,obja,objb
dista#=length vector2(dista)
set vector2 objb,object position x(b),object position z(b)
subtract vector2 distb,obja,objb
distb#=length vector2(distb)
`If the enemy is not miles and miles away, and not touching
if distb#<500 and distb#>100
`Red team aims at blue team
waypointx(a-119)=object position x(b)
waypointz(a-119)=object position z(b)
`Blue team aims are red team
point object b,object position x(a),50,object position z(a)
move object b,1*speed#
action(a-119)="Moving to attack!"
endif
`Don't walk into the enemy (looks like collision)
if distb#<100
waypointx(a-119)=object position x(a)
waypointz(a-119)=object position z(a)
`And the blood shed begins
healtha(a-119)=healtha(a-119)-2
healthb(b-139)=healthb(b-139)-2
action(a-119)="Attacking"
if healthb(b-139)=<0
delete object b
endif
aheal(a-119)=0
bheal(b-139)=0
endif
endif
next b
if healtha(a-119)=<0
delete object a
action(a-119)="Dead"
endif
endif
next a
for b=140 to 159+extraenemies
if object exist(b)=1
if bheal(b-139)=1
`Healing
if healthb(b-139)<255
healthb(b-139)=healthb(b-139)+1
endif
`Random Moving (Almost AI)
yrotate object b,object angle y(b)+rnd(10)-5
move object b,1.5*speed#
for i=2 to 100
if object collision (b,i)=1
move object b,-3*speed#
yrotate object b,object angle y(b)+rnd(10)-5
endif
next i
if abs(object position x(b))>10000 or abs(object position z(b))>10000
move object b,-3*speed#
yrotate object b,object angle y(b)+rnd(10)-5
endif
if abs(object position x(b))>10010 or abs(object position z(b))>10010
position object b,rnd(5000)+5000,50,rnd(5000)+5000
endif
endif
color object b,rgb(0,0,healthb(b-139))
endif
next b
for a=120 to 139
if object exist(a)=1
if aheal(a-119)=1 and healtha(a-119)<255 then healtha(a-119)=healtha(a-119)+1
color object a,rgb(healtha(a-119),0,0)
endif
next a
`Position the sky
position object 1000,camera position x(),camera position y(),camera position z()
`Check for Defeat
dead=0
for i=120 to 139
if object exist(i)=0
inc dead
endif
next i
if dead=20 then ink -1,0 : set text size 50 : center text screen width()/2,screen height()/2,"You Lose" : sync : wait 200 : wait key : end
dead=0
for i=140 to 159+extraenemies
if object exist(i)=0
inc dead
endif
next i
`Check for Victory
if dead=20+extraenemies
ink -1,0 : set text size 50 : center text screen width()/2,screen height()/2,"Next Level" : sync : wait 200 : wait key : set text size 12
inc extraenemies,10
for i=2 to 100
delete object i
size=rnd(1000)+10
make object box i,rnd(1000)+10,size,rnd(1000)+10
position object i,rnd(20000)-10000,size/2,rnd(20000)-10000
texture object i,2
next i
for i=120 to 139
if object exist(i)=0
make object sphere i,100
color object i,rgb(255,0,0)
endif
position object i,rnd(5000)-10000,50,rnd(5000)-10000
waypointx(i-119)=object position x(i)
waypointz(i-119)=object position z(i)
next i
for i=140 to 159+extraenemies
if object exist(i)=0
make object sphere i,100
color object i,rgb(0,0,255)
endif
position object i,rnd(5000)+5000,50,rnd(5000)+5000
yrotate object i,rnd(360)
next i
position camera -7500,500,-7500
rotate camera 0,0,0
endif
eleft=20+extraenemies-dead
ink rgb(0,0,255),0
set text size 16
text screen width()-200,0,"Enemies Left: "+str$(eleft)
set text size 12
loop
Insanity is just a state of mind