Hey Im new to the forums.
I know a little about DB, but I am still a noob.
Anyway, I am making an RTS. Here is the code for it:
rem ******************************
rem * RTS by Amax125 *
rem ******************************
rem ===============================================
rem |you can use the arrow keys to move the camera|
rem ===============================================
rem Make a simple scene for the camera to look at
make matrix 1,10000.0,10000.0,25,25
load bitmap "Lime01.bmp",1
get image 1,0,0,256,256
delete bitmap 1
prepare matrix texture 1,1,2,2
randomize matrix 1,50.0
set matrix height 1,12,12,300.0
update matrix 1
rem define character variables
oldmousex#=0
oldmousez#=0
mousex#=4300
mousez#=4600
mousey#=0
walking=0
characterselected=0
rem define camera variables
x#=4000
y#=600
z#=4500
rem Load your object
load object "idle.x",1
rem Add walk animation data to your object appending to frame 100
append object "walk.x",1,100
rem Update character
mousey#=get ground height(1,mousex#,mousez#)
position object 1,mousex#,mousey#,mousez#
yrotate object 1,mousea#
rem Reset model so character faces Y angle of zero
rotate object 1,0,180,0
fix object pivot 1
rem Rotate model to face right
yrotate object 1,90
rem set character
set object 1,1,0,0,1
rem Set new speed for your model
set object speed 1,20
rem Animate your object
loop object 1
rem Set object to interpolate to a new frame at a speed of 25%
set object interpolation 1,25
rem Activate manual sync
sync on
GOTO MAINLOOP
ANIMATE:
rem If walk animation required, make sure can perform animation
if animpause=0
animpause=4
if walking=1
if animstate=0
rem then slowly interpolate to the first walk frame
animstate=1
stop object 1
set object frame 1,105
endif
else
if animstate=1
rem else slowly interpolate to the first idle frame
animstate=0
stop object 1
set object frame 1,0
endif
endif
else
rem Count down until the interpolation has finished
animpause=animpause-1
if animpause=0
if animstate=0 then loop object 1,0,20
if animstate=1 then loop object 1,105,125
endif
endif
RETURN
MAINLOOP:
rem Begin loop
do
GOSUB ANIMATE
rem Control camera with arrow keys
if rightkey()=1 then x#=x#+10:z#=z#-10
if leftkey()=1 then x#=x#-10:z#=z#+10
if upkey()=1 then z#=z#+10:x#=x#+10
if downkey()=1 then z#=z#-10:x#=x#-10
rem position camera
position camera x#,600,z#
point camera x#+300,0,z#+300
rem check if left mouse is pressed
if mouseclick()=1
rem if so, then get values of mouse
rem oldmousex#=OBJECT POSITION X(2)
rem oldmousez#=OBJECT POSITION Z(2)
rem if OBJECT COLLISION(2,1)=1
characterselected=1
rem endif
endif
rem check if right mouse is pressed
if mouseclick()=2
rem mousex#=OBJECT POSITION X(2)
rem mousez#=OBJECT POSITION Z(2)
rem if so, move character to that area
walking = 1
rem test = 0
rem POINT OBJECT 1,mousex#,OBJECT SIZE Y(1),mousez#
rem while test < abs(mousex#+mousez#-oldmousex#+oldmousez#)
rem GOSUB ANIMATE
rem MOVE OBJECT 1,10
rem Update character
rem mousey#=get ground height(1,mousex#,mousez#)
rem position object 1,mousex#,mousey#,mousez#
rem yrotate object 1,mousea#
rem test=test+10
rem endwhile
walking=0
endif
SET CURSOR 50, 50
print "Mousex#: "; mousex()
SET CURSOR 50, 70
print "Mousey#: "; mousey()
SET CURSOR 50, 90
print "Mousez#: "; mousez()
rem Syncronise
sync
rem End loop
loop
I want to select the character with the left mouse button and move him to a different location when I click the right mouse button. To do that, though, I would have to find the coordinates of the mouse in a 3D space. Is that too hard to do with a randomized matrix? Should I be using a shape instead for the landscape?