Rem Project: SpaceShooter
Rem Created: 03/02/2003 15:15:06
Rem ***** Main Source File *****
RANDOMIZE TIMER()
SET DISPLAY MODE 1024,768,16
AUTOCAM OFF
HIDE MOUSE
REM Some Arrays
REM bulletarray alive,zcoord,xcoord,type
DIM bulletarray(100,4)
REM cleaning up array
for x=1 to 100
for y=1 to 4
bulletarray(x,y)=0
next y
next x
REM ennemyarray alive(1),zcoord(2),xcoord(3),type(4),fzen(5),fxen(6),hp(7),formula(8),offsetz(9),offsetx(10)
DIM alennemy(500,10)
DIM etype$(10)
etype$(1)="models\flysauc2.x"
etype$(2)="models\spcveh20b.x"
DIM ennemyarray(500,10)
REM Object variables
REM !!!! Bullet Object names from 101-200
REM !!!! Ennemy Object names from 201-300
myfighter=1
bulletnames=100
ennemynames=300
REM Some Variables
zrotate=0
light1=2
bulletsallowed=20
ennemyallowed=50
ennemiesonlevel=100
REM LOADING Objects
SET AMBIENT LIGHT 30
MAKE LIGHT 1
SET POINT LIGHT 1,-500,50,-500
POSITION LIGHT 1,-500,50,-500
SET LIGHT RANGE 1,1000
COLOR LIGHT 1,255,255,255
SHOW LIGHT 1
rem LOAD OBJECT "Models\Airpl043.x",myfighter
LOAD OBJECT "Models\airpl043b.x",myfighter
ROTATE OBJECT myfighter,0,90,0
FIX OBJECT PIVOT myfighter
POSITION OBJECT myfighter,0,0,-50
SET OBJECT COLLISION ON myfighter
SET OBJECT COLLISION TO POLYGONS myfighter
SET OBJECT AMBIENT myfighter,1
SET OBJECT LIGHT myfighter,1
POSITION CAMERA 0,100,-50
POINT CAMERA 0,0,0
SYNC RATE 30
SYNC ON
ennemyalive=0
ennemycreated=0
for x=1 to ennemiesonlevel
alennemy(x)=0,0,0,0,0,0,0,0,0,0
RANDOMIZE TIMER()
hier1:
entype=rnd(2)
if entype<1 then goto hier1
hier2:
formula=rnd(4)
if formula<1 then goto hier2
LOAD OBJECT etype$(entype),x+ennemynames
alennemy(x,1)=1
alennemy(x,2)=rnd(5000)+200
alennemy(x,3)=rnd(100)-50
alennemy(x,8)=formula
alennemy(x,7)=1
alennemy(x,4)=x+ennemynames
POSITION OBJECT x+ennemynames,300,0,300
sync
next x
distanceonlevel=0
Do
distanceonlevel=distanceonlevel+1
set CURSOR 100,10
print distanceonlevel
GOSUB _controlmyfighter
rem GOSUB _collisioncontrol
rem GOSUB _bulletflight
GOSUB _makeennemies
rem GOSUB _ennemyflight
SYNC
LOOP
REM Fighter Controls
_controlmyfighter:
IF JOYSTICK UP()=1 AND (OBJECT POSITION Z(myfighter))<50 then POSITION OBJECT myfighter,OBJECT POSITION X(myfighter),OBJECT POSITION Y(myfighter),(OBJECT POSITION Z(myfighter))+1
IF JOYSTICK DOWN()=1 AND (OBJECT POSITION Z(myfighter))>-50 then POSITION OBJECT myfighter,OBJECT POSITION X(myfighter),OBJECT POSITION Y(myfighter),(OBJECT POSITION Z(myfighter))-1
IF JOYSTICK LEFT()=1 AND (OBJECT POSITION X(myfighter))>-70
IF zrotate<30 then zrotate=zrotate+1
ZROTATE OBJECT myfighter,zrotate
POSITION OBJECT myfighter,OBJECT POSITION X(myfighter)-1,OBJECT POSITION Y(myfighter),OBJECT POSITION Z(myfighter)
ENDIF
IF JOYSTICK RIGHT()=1 AND (OBJECT POSITION X(myfighter))<+70
IF zrotate>-30 then zrotate=zrotate-1
ZROTATE OBJECT myfighter,zrotate
POSITION OBJECT myfighter,OBJECT POSITION X(myfighter)+1,OBJECT POSITION Y(myfighter),OBJECT POSITION Z(myfighter)
ENDIF
IF JOYSTICK LEFT()=0 AND zrotate>0
ZROTATE OBJECT myfighter,zrotate
zrotate=zrotate-2
ENDIF
IF JOYSTICK RIGHT()=0 AND zrotate<0
ZROTATE OBJECT myfighter,zrotate
zrotate=zrotate+2
ENDIF
IF JOYSTICK FIRE A()=1 THEN GOSUB _makebullet
RETURN
REM Collision Control
_collisioncontrol:
RETURN
_makebullet:
bulletalive=0
bulletcreated=0
for x=1 to bulletsallowed
bulletalive=bulletarray(x,1)
IF bulletalive=0 AND bulletcreated=0
MAKE OBJECT SPHERE x+bulletnames,1
bulletarray(x,1)=1
bulletarray(x,2)=OBJECT POSITION Z(myfighter)
bulletarray(x,3)=OBJECT POSITION X(myfighter)
POSITION OBJECT x+bulletnames,bulletarray(x,3),0,bulletarray(x,2)
bulletcreated=1
ENDIF
next x
RETURN
_bulletflight:
bulletalive=0
bulletcreated=0
for x=1 to bulletsallowed
bulletalive=bulletarray(x,1)
bulletz=bulletarray(x,2)
IF bulletalive=1 AND bulletz<120 AND OBJECT EXIST(x+bulletnames)=1
bulletarray(x,2)=bulletz+5
objecthit=OBJECT COLLISION(x+bulletnames,0)
REM DID BULLET HIT?
IF objecthit-ennemynames>=1 AND objecthit-ennemynames<=ennemiesonlevel
rem removehitobject(x,objecthit-ennemynames,bulletarray(),ennemyarray())
rem ennemyarray(objecthit-ennemynames,1)=0
rem bulletarray(x,1)=0
DELETE OBJECT x+bulletnames
bulletarray(x,1)=0
hp=ennemyarray(objecthit-ennemynames,7)-1
ennemyarray(objecthit-ennemynames,7)=ennemyarray(objecthit-ennemynames,7)-1
IF hp<=0
DELETE OBJECT objecthit
ennemyarray(objecthit-ennemynames,1)=0
endif
ENDIF
objecthit=0
ENDIF
IF bulletz>=120 AND OBJECT EXIST(x+bulletnames)=1
bulletarray(x,1)=0
DELETE OBJECT x+bulletnames
ENDIF
POSITION OBJECT x+bulletnames,bulletarray(x,3),0,bulletarray(x,2)
next x
RETURN
_makeennemies:
REM ennemyarray alive(1),zcoord(2),xcoord(3),type(4),fzen(5),fxen(6),hp(7),formula(8)
for y=1 to ennemiesonlevel
if alennemy(y,2)<=distanceonlevel and alennemy(y,1)=1
ennemyalive=0
ennemycreated=0
for z=1 to 50
ennemyalive=ennemyarray(z,1)
IF ennemyalive=0 AND ennemycreated=0
ennemyarray(z)=0,0,0,0,0,0,0,0,0,0
ennemyarray(z,1)=1
ennemyarray(z,2)=120
ennemyarray(z,3)=alennemy(y,3)
testo=alennemy(y,4)
ennemyarray(z,4)=testo
ennemyarray(z,8)=alennemy(y,8)
ennemyarray(z,7)=alennemy(y,7)
alennemy(y,1)=0
ennemycreated=1
rem SET OBJECT COLLISION ON (alennemy(y,4))
z=ennemyallowed
SET CURSOR 10,10
REM HERE's the Problem
PRINT ennemyarray(z,4)
ENDIF
next z
ENDIF
next y
RETURN
_ennemyflight:
REM ennemyarray alive(1),zcoord(2),xcoord(3),objectname(4),fzen(5),fxen(6),hp(7),formula(8),offsetz(9),offsetx(10)
ennemyalive=0
ennemycreated=0
for a=1 to ennemyallowed
IF ennemyalive=1 AND OBJECT EXIST(ennemyarray(a,4))=1
originalx=ennemyarray(a,3)
REM FORMULA=STRAIGHTFLIGHT
IF ennemyarray(a,8)=1
ennemyarray(a,2)=straightzflight(ennemyarray(a,2),1)
ENDIF
REM FORMULA=SINUSXFLIGHT
IF ennemyarray(a,8)=2
ennemyarray(a,2)=straightzflight(ennemyarray(a,2),1)
ennemyarray(a,10)=sinusflightx(ennemyarray(a,6))
ennemyarray(a,6)=ennemyarray(a,6)+4
ENDIF
rem FORMULA=X AND Z SInusflight
IF ennemyarray(a,8)=3
ennemyarray(a,2)=straightzflight(ennemyarray(a,2),1)
ennemyarray(a,10)=sinusflightx(ennemyarray(a,6))
ennemyarray(a,9)=sinusflightx(ennemyarray(a,6))
ennemyarray(a,6)=ennemyarray(a,6)+4
ENDIF
rem FORMULA=X SINUS AND Z Cosinusflight
IF ennemyarray(a,8)=4
ennemyarray(a,2)=straightzflight(ennemyarray(a,2),1)
ennemyarray(a,10)=sinusflightx(ennemyarray(a,6))
ennemyarray(a,9)=cosinusflightx(ennemyarray(a,6))
ennemyarray(a,6)=ennemyarray(a,6)+4
ENDIF
POSITION OBJECT ennemyarray(a,4),ennemyarray(a,3)+ennemyarray(a,10),0,ennemyarray(a,2)+ennemyarray(a,9)
REM ENNEMY OUT OF VIEW?
IF ennemyarray(a,2)< -100
ennemyarray(a,1)=0
DELETE OBJECT ennemyarray(a,4)
ENDIF
ENDIF
next z
RETURN
FUNCTION straightzflight(z#,t#)
newz#=z#-t#
ENDFUNCTION newz#
FUNCTION removehitobject(bullet,object)
DELETE OBJECT bullet
DELETE OBJECT object
ENDFUNCTION
FUNCTION sinusflightx(z)
newx=sin(wrapvalue(z))*40
ENDFUNCTION newx
FUNCTION cosinusflightx(z)
newx=cos(wrapvalue(z))*40
ENDFUNCTION newx