Rem Project: SpaceInvaders Clone by James B.
Rem Created: 9/7/2003 19:51:00
Rem ***** Main Source File *****
`Variables-----------------------------------
intPlayerX as float
intPlayerBulletCol as integer
intBaddieShoots as integer
intBaddieBulletCol as integer
intBaddiesRem as integer
intPlayerLives as integer=3
dwoScore as dword
intBadParticleDelay as integer
intPlayerParticleDelay as integer
`----------------------------------------------
gosub _InitSystem
gosub _InitMedia
gosub _InitMusic
gosub _InitPlayer
gosub _InitBaddies
gosub _InitBlockades
gosub _InitBaddieParticles
gosub _initPlayerParticles
gosub _FirstTime
gosub _GetReadyMsg
gosub _MAIN
`START MAIN LOOP----------------------------------------
_MAIN:
DO
intPlayerX=object position x(1)
`move player left and right
if leftkey()=1 and intplayerx > -3.75
position object 1,object position x(1) - .05,object position y(1),object position z(1)
endif
if rightkey()=1 and intplayerx < 3.75
position object 1,object position x(1) + .05,object position y(1),object position z(1)
endif
`player shoot at baddies
if controlkey()=1
gosub _MakePlayerBullet
endif
if object exist(2)
if object position y(2) < 5.75
position object 2, object position x(2),object position y(2)+.125, object position z(2)
intPlayerBulletCol=object collision(2,0)
`if bullet hit baddie
if intPlayerBulletCol >= 3 and intPlayerBulletCol <= 42
position particles 2,object position x(intPlayerBulletCol),object position y(intPlayerBulletCol),object position z(intPlayerBulletCol)
show particles 2
intBadParticleDelay=Timer() + 500
delete object 2
delete object intPlayerBulletCol
play sound 5
intbaddiesrem=intbaddiesrem-1
dwoScore=dwoScore + 150
if intbaddiesrem=0
gosub _InitBaddies
gosub _GetReadyMsg
endif
endif
if intPlayerBulletCol >= 43 and intPlayerBulletCol <= 45
delete object 2
endif
else
delete object 2
endif
endif
`test for particle duration end
if timer() > intBadParticleDelay then hide particles 2
`baddies shoot at player
gosub _GetBaddieShooter
gosub _MakeBaddieBullet
if object exist(46)=1
if object position y(46) > -3.5
position object 46, object position x(46),object position y(46)-.1, object position z(46)
intBaddieBulletCol=object collision(46,0)
`if bullet hit player
if intBaddieBulletCol = 1
hide object 1
hide object 46
position particles 1,object position x(1),object position y(1),object position z(1)
show particles 1
delete object 1
delete object 46
play sound 3
`TCA FIXED
gosub _KillArtifacts
for intPlayerParticleDelay=1 to 20
sync
wait 50
next intPlayerParticleDelay
hide particles 1
`player died - get new player
intPlayerLives=intPlayerLives-1
if intPlayerLives > 0
gosub _InitPlayer
gosub _GetReadyMsg
else
hide particles 1
sync
gosub _GameOver
endif
endif
if intBaddieBulletCol >= 43 and intBaddieBulletCol <= 45
delete object 46
endif
else
delete object 46
endif
endif
`Pause game
if spacekey()=1
set cursor 300,250
print "PAUSED"
gosub _UpdateScore
sync
wait key
endif
`quit game
if escapekey()=1 then end
gosub _UpdateScore
sync
loop
RETURN
`END MAIN LOOP-----------------------------------------------------------
`SUBROUTINES-------------------------------------------------------------
_UpdateScore:
set cursor 0,0
print str$(dwoScore)
Return
_GetBaddieShooter:
randomize timer()
intBaddieShoots=rnd(39)+3
Return
_MakeBaddieBullet:
` Player Bullet OBJECT 46
if not object exist (46)
if object exist(intbaddieshoots)
make object cylinder 46,.2
position object 46,object position x(intbaddieshoots),object position y(intbaddieshoots)-.45,object position z(intbaddieshoots)
color object 46,rgb(255,100,100)
set object collision on 46
play sound 4
endif
endif
Return
_InitPlayer:
`Player OBJECT 1
if not object exist(1)
make object cone 1,.5
position object 1,0,-3,0
color object 1,rgb(0,0,220)
endif
Return
_GetReadyMsg:
sync
set cursor 285,250
print "GET READY"
gosub _UpdateScore
sync
play sound 1
wait 2000
Return
_MakePlayerBullet:
` Player Bullet OBJECT 2
if object exist(1)
if not object exist (2)
make object cylinder 2,.2
position object 2,object position x(1),object position y(1)+.45,object position z(1)
color object 2,rgb(100,100,255)
set object collision on 2
play sound 2
endif
endif
Return
_InitBaddies:
`Baddies OBJECTS 3-42
objcounter as integer=3
intLoop2 as integer
intLoop as integer
for intLoop2=5 to 1 step -1
for intLoop = 3 to 10
if not object exist(objcounter)
make object sphere objcounter,.5
position object objcounter,intLoop-6.5,intLoop2,0
color object objcounter,rgb(220,0,0)
endif
inc objcounter
next intLoop
next intLoop2
gosub _KillArtifacts
intBaddiesRem=40
Return
_KillArtifacts:
if object exist(2) then delete object 2 : `kill leftover player bullet
if object exist(46) then delete object 46 : `kill leftover baddie bullet
Return
_InitBlockades:
`Blockcades OBJECTS 43-45
make object cube 43,.75
position object 43,0,-1.75,0
make object cube 44,.75
position object 44,-3,-1.75,0
make object cube 45,.75
position object 45,3,-1.75,0
Return
_InitSystem:
`screen & camera
sync on
sync rate 100
hide mouse
color backdrop 0,0
autocam off
position camera 0,0,0,-10
Return
_GameOver:
set cursor 285,250
print "GAME OVER !"
gosub _UpdateScore
sync
wait 3000
cls
gosub _StartScreen
Return
_InitBaddieParticles:
make particles 2,1,25,2
color particles 2, 255, 200, 200
set particle emissions 2, 10
set particle speed 2, 0.1
set particle gravity 2, 10
hide particles 2
Return
_InitPlayerParticles:
make particles 1,1,25,3
color particles 1, 200, 200, 255
set particle emissions 1, -10
set particle speed 1, 0.1
set particle gravity 1, 10
hide particles 1
Return
_Re_InitVars:
intPlayerX=0
intPlayerBulletCol=0
intBaddieShoots=0
intBaddieBulletCol=0
intBaddiesRem=0
intPlayerLives=3
dwoScore=0
intBadParticleDelay=0
intPlayerParticleDelay=0
Return
_InitMedia:
load sound "InitPlayer.wav",1
load sound "PlayerShoot.wav",2
load sound "PlayerDie.wav",3
load sound "BaddieShoot.wav",4
load sound "BaddieDie.wav",5
load music "Triumph.mp3",1
load image "test.bmp",1
Return
_InitMusic:
play music 1
loop music 1
Return
_StartScreen:
hide particles 1
hide particles 2
cls
sync
set cursor 190,screen height()/2
print "Any Key for New Game, ESC to Quit"
gosub _UpdateScore
sync
wait key
if escapekey()=1 then end
gosub _Re_InitVars
gosub _InitPlayer
gosub _initBaddies
gosub _GetReadyMsg
gosub _MAIN
Return
_FirstTime:
cls
sync
set cursor 190,screen height()/2
print "Any Key for New Game, ESC to Quit"
sync
wait key
if escapekey()=1 then end
Return
you can load and run it just rem out all LOAD SOUND, and PLAY SOUND lines
(is incomplete game in that baddies don't move)
-RUST-