im sure there are many things i need to improve on here. im quite new to this and could use all the help i can get. i thought i would start off small and recreate the atari game gauntlet. i have been picking up bits and peices off of the site and studying them to figure out how they work. but im havng some difficulties in a couple of areas.
is there an easier way to create a maze of walls
how do i set the collision in the corners so the character can not slide through
and the alien characters animation does not seem to run correctly
and a few other things, but 1 step at a time. if anyone has an ideas, comments or examples. this is what i have so far.
please help. let me know if there is any other information needed. thanx
Sync On
Sync Rate 0
Backdrop on
autocam off
set display mode 1024,768,32
Set camera range 1,5000
Fog on
Fog distance 5000
Fog color RGB(0,0,0)
Color Backdrop RGB(0,0,0)
movespeed=70
turnspeed=90
time=timer()
CLOCKFACE()
HOURHAND()
MINUTEHAND()
SECONDHAND()
GETTIME()
rem Load images : loads all the required media*************************************************************
load image "textureswater10.bmp",1
load image "heightmap.bmp",100
load image "texturesgrass04.bmp",200
Rem make water matrix****************************************************************************************
rem size of the water matrix
matrixSizeX#=5000:matrixSizeZ#=5000
nsquarex=32:nsquarez=32
tileSizeX#=matrixSizeX#/nsquarex:tileSizeZ#=matrixSizeZ#/nsquarez
rem a sine table, to speed up calculations*****************************************************************
dim sineTable#(360)
for i=0 to 359
sineTable#(i)=sin(i)
next i
rem create the water matrix********************************************************************************
make matrix 1,matrixSizeX#,matrixSizeZ#,nsquarex,nsquarez
position matrix 1,3000,100,1000
dim waves(nsquarex,nsquarez)
for i=0 to nsquarex
for j=0 to nsquarez
waves(i,j)=(rnd(72))*5
next j
next i
rem The wave height is set according to the size of the water matrix
wave_height#=matrixSizeX#/600.00
rem texture the water matrix
prepare matrix texture 1,1,nsquarex,nsquarez
n=0
for j=nsquarez-1 to 0 step -1
for i=0 to nsquarex-1 step 1
inc n
set matrix tile 1,i,j,n
next i
next j
Rem make land matrix****************************************************************************************
mapSize = 10000
segments = 64
heightSize = 512
makeHeightMap(100,100,200,mapSize,heightSize,segments)
rem make outer skybox****************************************************************************************
make object cube 99,-10000
position object 99,5000,-10,5000
ghost object on 99
color object 99,rgb(0,0,200)
set object ambient 99,0
set object light 99,0
Rem building outer walls***********************************************************************************
make object box 200,9980,500,10
position object 200,5000,100,10
color object 200,rgb(10,10,10)
SC_SetupObject 200,1,0
make object box 201,10,500,9990
position object 201,10,100,5000
color object 201,rgb(10,10,10)
SC_SetupObject 201,1,0
make object box 202,9980,500,10
position object 202,5000,100,9990
color object 202,rgb(10,10,10)
SC_SetupObject 202,1,0
make object box 203,10,500,9990
position object 203,9990,100,5000
color object 203,rgb(10,10,10)
SC_SetupObject 203,1,0
rem make walls for maze lvl 1*************************************************************************************
make object box 300,4000,500,10
position object 300,2995,100,2020
color object 300,rgb(10,10,10)
SC_SetupObject 300,1,0
make object box 301,10,500,2000
position object 301,1000,100,1015
color object 301,rgb(10,10,10)
SC_SetupObject 301,1,0
make object box 302,10,500,1900
position object 302,3000,100,1065
color object 302,rgb(10,10,10)
SC_SetupObject 302,1,0
make object box 303,6000,500,10
position object 303,6985,100,1000
color object 303,rgb(10,10,10)
SC_SetupObject 303,1,0
make object box 304,3000,500,10
position object 304,7585,100,2000
color object 304,rgb(10,10,10)
SC_SetupObject 304,1,0
make object box 305,10,500,900
position object 305,9090,100,545
color object 305,rgb(10,10,10)
SC_SetupObject 305,1,0
make object box 306,5000,500,10
position object 306,6585,100,3000
color object 306,rgb(10,10,10)
SC_SetupObject 306,1,0
make object box 307,10,500,5000
position object 307,9090,100,4495
color object 307,rgb(10,10,10)
SC_SetupObject 307,1,0
make object box 308,2000,500,10
position object 308,8090,100,5000
color object 308,rgb(10,10,10)
SC_SetupObject 308,1,0
Rem Make player**********************************************************************************************
load object "alien.x",1
scale object 1,15,15,15
rotate object 1,0,180,0
fix object pivot 1
position object 1,9000,0,2500
rem MAKE THE COMPASS OBJECTS 1098/1099********************************************************************
TYPE Compass
PLATE_NUM AS INTEGER
ARROW_NUM AS INTEGER
PLATE_FILE AS STRING
ARROW_FILE AS STRING
ENDTYPE
dim Compass(5) as Compass
Compass(1).PLATE_NUM = 1098
Compass(1).PLATE_FILE = "compass_plate_icon.bmp"
Compass(1).ARROW_NUM = 1099
Compass(1).ARROW_FILE = "compass_arrow_icon.bmp"
rem the compass plate
make object plain Compass(1).PLATE_NUM,4,4
set object collision off Compass(1).PLATE_NUM
load image Compass(1).PLATE_FILE,Compass(1).PLATE_NUM,1
texture object Compass(1).PLATE_NUM,Compass(1).PLATE_NUM
position object Compass(1).PLATE_NUM,10,7,15
lock object on Compass(1).PLATE_NUM
disable object zdepth Compass(1).PLATE_NUM
ghost object on Compass(1).PLATE_NUM
set object ambient Compass(1).PLATE_NUM,0
set object light Compass(1).PLATE_NUM,0
rem the compass arrow
make object plain Compass(1).ARROW_NUM,6,6
set object collision off Compass(1).ARROW_NUM
load image Compass(1).ARROW_FILE,Compass(1).ARROW_NUM,1
texture object Compass(1).ARROW_NUM,Compass(1).ARROW_NUM
position object Compass(1).ARROW_NUM,10,7,15
lock object on Compass(1).ARROW_NUM
disable object zdepth Compass(1).ARROW_NUM
ghost object on Compass(1).ARROW_NUM
set object ambient Compass(1).ARROW_NUM,0
set object light Compass(1).ARROW_NUM,0
Compass_TOGGLE = 0
ZOOM#=-150
MODE=1
Rem Main loop****************************************************************************************************
Do
gametime=timer()-time
msframe#=gametime*(movespeed/1000.0)
tsframe#=gametime*(turnspeed/1000.0)
UPDATETIME()
rem Store the user's old position on the xyz axis*****************************************************************
OX# = OBJECT POSITION X(1)
OY# = OBJECT POSITION Y(1)
OZ# = OBJECT POSITION Z(1)
rem Store the player's new position on the xyz axis, after they've moved.
X# = OBJECT POSITION X(1)
Y# = OBJECT POSITION Y(1)
Z# = OBJECT POSITION Z(1)
rem Control Camera : Simply controlling camera movement
x# = camera position x()
z# = camera position z()
y# = get ground height(100,x#,z#)
position camera x#,y#+5,z#
control camera using arrowkeys 0, 1, 1
rem recalculate the height of each vertex of the water matrix in a wavy way*****************************************
for i=0 to nsquarex
for j=0 to nsquarez
set matrix height 1,i,j,sineTable#(waves(i,j))*wave_height#
waves(i,j)=waves(i,j)+5
if waves(i,j)>359 then waves(i,j)=0
next j
next i
rem Smooth matrix normals.
SmoothMatrixNormals(1,nsquarex,nsquarez,tileSizeX#,tileSizeZ#)
update matrix 1
rem Display some text so we know what buttons do what************************************************
TEXT 0,140,"[1] = 3rd Person View With Mouse Control"
TEXT 0,160,"[2] = 3rd Person View No Mouse Control"
rem Just getting some statistics on frame rate and player position
text 0, 0, str$(screen fps())
text 0,180, "Player X POS :"+str$(object position x(1))
text 0,200, "Player Z POS :"+str$(object position z(1))
rem different camera modes*****************************************************************************
FOR KEY=2 TO 4
IF KEYSTATE(KEY)=1 THEN MODE=KEY-1
NEXT KEY
rem (Object, Dummy, Mesh, X#, Y#, Z#, XTilt#,YTilt#,ZTilt#, Speed#, DumX, DumY, ObjX, ObjY, MaxUp#, MaxDown#, MaxLeft#, MaxRight#)
rem 3rd Person View with mouse control
IF MODE=1
CameraControl(1,3,1,0,250,-200,0,1,0,.2,1,1,0,0,-10,-10,0,0)
ENDIF
rem 1st Person View no mouse control
IF MODE=2
CameraControl(1,3,1,0,250,-200,0,1,0,0,1,1,0,0,0,0,0,0)
ENDIF
rem *******************************************************************************************
Rem Store Object angle
AngleY# = object angle Y(1)
rem compass needle rotation
rotate object 1099,0,0,0-wrapvalue(angley#)
camdist#=matrixSizeZ#:bearing#=90:azimuth#=300:camchanged=1
rem Control input for camera*****************************************************************
if keystate(17)=1
if object playing(1) = 0
play object 1,670,720
endif
XTest# = Newxvalue(X#,AngleY#,msframe#)
ZTest# = Newzvalue(Z#,AngleY#,msframe#)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
Move object 1,4
endif
endif
If upkey()=1
if object playing(1) = 0
play object 1,670,720
endif
XTest# = Newxvalue(X#,AngleY#,msframe#)
ZTest# = Newzvalue(Z#,AngleY#,msframe#)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
Move object 1,4
endif
endif
If downkey()=1
if object playing(1) = 0
play object 1,670,720
endif
XTest# = Newxvalue(X#,AngleY#,msframe#)
ZTest# = Newzvalue(Z#,AngleY#,msframe#)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
Move object 1,-2
endif
endif
If keystate(31)=1
if object playing(1) = 0
play object 1,670,720
endif
XTest# = Newxvalue(X#,AngleY#,-msframe#)
ZTest# = Newzvalue(Z#,AngleY#,-msframe#)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
Move object 1,-2
endif
endif
If keystate(30)=1 then Yrotate object 1,Wrapvalue(AngleY#-tsframe#)
If keystate(32)=1 then Yrotate object 1,Wrapvalue(AngleY#+tsframe#)
If leftkey()=1 then Yrotate object 1,Wrapvalue(AngleY#-tsframe#)
If rightkey()=1 then Yrotate object 1,Wrapvalue(AngleY#+tsframe#)
X# = Object position x(1)
Z# = Object position z(1)
Y# = Get Ground Height(100,X#,Z#)
Position object 1,X#,Y#,Z#
rem Call the sliding collision function, filling in the necassary variables*************************************
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,200)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,201)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,202)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,203)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,300)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,301)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,302)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,303)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,304)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,305)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,306)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,307)
SlidingCollision(OX#,OY#,OZ#,X#,Y#,Z#,10,1,308)
rem timer****************************************************************************************************
time=timer()
SYNC
LOOP
rem camera control functions***********************************************************************
FUNCTION CameraControl(Object, Dummy, Mesh, X#, Y#, Z#, XTilt#,YTilt#,ZTilt#, Speed#, DumX, DumY, ObjX, ObjY, MaxUp#, MaxDown#, MaxLeft#, MaxRight#)
IF OBJECT EXIST(Dummy)=0
DIM CamX#(0)
DIM CamY#(0)
MAKE OBJECT TRIANGLE Dummy, 0,0,0,0,0,0,0,0,0
MAKE MESH FROM OBJECT Mesh, Dummy
ADD LIMB Dummy, 1, Mesh
DELETE MESH Mesh
ENDIF
IF OBJECT EXIST(Dummy)=1
OFFSET LIMB Dummy, 1, X#, Y#, Z#
IF Speed#=0
IF X#=0 AND Y#=0 AND Z#=0
POSITION CAMERA OBJECT POSITION X(Object),OBJECT POSITION Y(Object),OBJECT POSITION Z(Object)
POINT CAMERA OBJECT POSITION X(Object), OBJECT POSITION Y(Object), OBJECT POSITION Z(Object)
ENDIF
ENDIF
IF X#>0 OR Y#>0 OR Z#>0
POSITION OBJECT Dummy, OBJECT POSITION X(Object),OBJECT POSITION Y(Object), OBJECT POSITION Z(Object)
POSITION CAMERA LIMB POSITION X(Dummy, 1),LIMB POSITION Y(Dummy, 1),LIMB POSITION Z(Dummy, Object)
POINT CAMERA OBJECT POSITION X(Object)+XTilt#, OBJECT POSITION Y(Object)+YTilt#, OBJECT POSITION Z(Object)+ZTilt#
ENDIF
IF Speed#>0
IF X#=0 AND Y#=0 AND Z#=0
POSITION CAMERA OBJECT POSITION X(Object),OBJECT POSITION Y(Object),OBJECT POSITION Z(Object)
XROTATE CAMERA CamX#(0)
YROTATE CAMERA CamY#(0)
ENDIF
CamY#(0)=CamY#(0)+MOUSEMOVEX()*Speed#
CamX#(0)=CamX#(0)+MOUSEMOVEY()*Speed#
IF MaxUp#>0 OR MaxUp#<0
IF CamX#(0)<MaxUp# THEN CamX#(0)=MaxUp#
ENDIF
IF MaxDown#>0 OR MaxDown#<0
IF CamX#(0)>MaxDown# THEN CamX#(0)=MaxDown#
ENDIF
IF MaxLeft#>0 OR MaxLeft#<0
IF CamY#(0)<MaxLeft# THEN CamY#(0)=MaxLeft#
ENDIF
IF MaxRight#>0 OR MaxRight#<0
IF CamY#>MaxRight# THEN CamY#=MaxRight#
ENDIF
IF DumX=1
XROTATE OBJECT Dummy,CamX#(0)
ENDIF
IF DumY=1
YROTATE OBJECT Dummy,CamY#(0)
ENDIF
IF ObjX=1
XROTATE OBJECT Object, CamX#(0)
ENDIF
IF ObjY=1
YROTATE OBJECT Object, CamY#(0)
ENDIF
ENDIF
ENDIF
ENDFUNCTION CameraControl
function SmoothMatrixNormals(numMatrix,sizeX,sizeZ,tileSizeX#,tileSizeZ#)
for z=1 to sizeZ-1
for x=1 to sizeX-1
rem Get matrix heights
h8#=get matrix height(numMatrix,x,z-1)
h4#=get matrix height(numMatrix,x-1,z)
h#=get matrix height(numMatrix,x,z)
h2#=get matrix height(numMatrix,x,z)
rem Calculate projected angle X using heights
x1#=(x-1)*tileSizeX# : y1#=h#
x2#=(x+0)*tileSizeX# : y2#=h4#
dx#=x2#-x1#
dy#=y2#-y1#
ax#=atanfull(dx#,dy#)
ax#=wrapvalue(90-ax#)
rem Calculate projected angle Z using heights
z1#=(z-1)*tileSizeZ# : y1#=h2#
z2#=(z+0)*tileSizeZ# : y2#=h8#
dz#=z2#-z1#
dy#=y2#-y1#
az#=atanfull(dz#,dy#)
az#=wrapvalue(90-az#)
rem Make normal from projected angle
nx#=sin(ax#)
ny#=cos(ax#)
nz#=sin(az#)
rem Setting matrix normal for smoothness
set matrix normal numMatrix,x,z,nx#,ny#,nz#
next x
next z
endfunction
rem clock functions********************************************************************************************
function CLOCKFACE()
make object plain 21,4,4
set object collision off 21
load image "clock_plate_icon.bmp",21
texture object 21,21
position object 21,-12.5,9,18
lock object on 21
disable object zdepth 21
ghost object on 21
set object ambient 21,0
set object light 21,0
endfunction
function HOURHAND()
make object plain 22,4,4
set object collision off 22
load image "hourhand_icon.bmp",22
texture object 22,22
position object 22,-12.5,9,18
lock object on 22
disable object zdepth 22
ghost object on 22
set object ambient 22,0
set object light 22,0
endfunction
function MINUTEHAND()
make object plain 23,4,4
set object collision off 23
load image "minutehand_icon.bmp",23
texture object 23,23
position object 23,-12.5,9,18
lock object on 23
disable object zdepth 23
ghost object on 23
set object ambient 23,0
set object light 23,0
endfunction
function SECONDHAND()
make object plain 24,4,4
set object collision off 24
load image "secondhand_icon.bmp",24
texture object 24,24
position object 24,-12.5,9,18
lock object on 24
disable object zdepth 24
ghost object on 24
set object ambient 24,0
set object light 24,0
endfunction
function GETTIME()
t$=get time$()
hours$=left$(t$,2)
hours=val(hours$)
if hours>12
hours=hours-12
hours$=str$(hours)
endif
minutes$=mid$(t$,4)+mid$(t$,5)
seconds$=right$(t$,2)
zrotate object 22,-wrapvalue(val(hours$)*30)
zrotate object 23,-wrapvalue(val(minutes$)*6)
zrotate object 24,-wrapvalue(val(seconds$)*6)
endfunction
function UPDATETIME()
t$=get time$()
hours$=left$(t$,2)
hours=val(hours$)
if hours>12
hours=hours-12
hours$=str$(hours)
endif
minutes$=mid$(t$,4)+mid$(t$,5)
seconds$=right$(t$,2)
zrotate object 22,-wrapvalue(val(hours$)*30)+(-wrapvalue(val(minutes$)*6)/15)
zrotate object 23,-wrapvalue(val(minutes$)*6)+(-wrapvalue(val(seconds$)*6)/60)
zrotate object 24,-wrapvalue(val(seconds$)*6)
endfunction
function makeHeightMap(mId, heightmap, texture, mapSize, heightSize, segments)
make matrix mId, mapSize, mapSize, segments, segments
prepare matrix texture mId, texture, 1, 1
cls
paste image heightmap, 0, 0
modifier = heightSize / segments
for x = 0 to segments
for y = 0 to segments
pixelColor# = rgbr(point(x * modifier, y * modifier))
set matrix height mId, x, y, pixelColor#
next x
next y
update matrix mId
endfunction
rem Sliding Collision Function
FUNCTION SlidingCollision(X1#,Y1#,Z1#,X2#,Y2#,Z2#,Radius#,Dyn,Obj)
C = sc_SphereSlide(Obj,X1#,Y1#,Z1#,X2#,Y2#,Z2#,Radius#,0)
IF C > 0
cx# = sc_getCollisionSlideX()
cy# = sc_getCollisionSlideY()
cz# = sc_getCollisionSlideZ()
POSITION OBJECT Dyn, cx#, cy#, cz#
ENDIF
ENDFUNCTION
DELETE MEMBLOCK 1