TGC Codebase Backup



Cave Runner by Anonymous Coder

30th Apr 2008 18:51
Summary

This is the Cave Runner standard game of DarkBASIC, with some changes.



Description

This is the Cave Runner standard game of DarkBASIC, with some changes.
- Score and Stage System
- Matrix randomization by stage

Need "caverun.mid", "Final.mid" and "tiles.bmp", all finded in DarkBASIC folder.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem ----------------
rem Cave Runner Demo
rem ----------------
rem Author: DBS-LB99
hide mouse

rem Create level names
dim levels$(9)
levels$(0)="Easiest"
levels$(1)="Easy"
levels$(2)="Something Easy"
levels$(3)="Something Hard"
levels$(4)="Hard"
levels$(5)="Harder"
levels$(6)="Nightmare"
levels$(7)="Truely a Nightmare"
levels$(8)="Almost Impossible"

rem Create level colors
dim colors(9)
colors(0)=rgb(0,255,0)
colors(1)=rgb(63,255,0)
colors(2)=rgb(127,255,0)
colors(3)=rgb(191,255,0)
colors(4)=rgb(247,247,0)
colors(5)=rgb(255,191,0)
colors(6)=rgb(255,127,0)
colors(7)=rgb(255,53,0)
colors(8)=rgb(255,0,0) 

rem Load bitmaps
load bitmap "tiles.bmp",1
get image 1,0,0,256,256
delete bitmap 1

rem Set colors
black=rgb(0,0,0)
white=rgb(255,255,255)

rem Load sound
load sound "hum.wav",1
load sound "explode.wav",2
loop sound 1

rem Load music track
load music "caverun.mid",1
load music "Final.mid",2
loop music 1

rem Activate manual sync
sync on

rem Create score
score=0
loop=0
stage=0

rem Set text
set text font "Monotype Corsiva"
set text size 24

rem Make landscape and ceiling matrix
make matrix 1,2000,5000,10,25
prepare matrix texture 1,1,2,2
make matrix 2,2000,5000,10,25
prepare matrix texture 2,1,2,2
fill matrix 2,0,2
randomize matrix 2,350.0
for t=0 to 25
	set matrix height 2,0,t,-100
	set matrix height 2,10,t,-100
next t
update matrix 2

rem Bagin game loop
do

rem Set seed for same random numbers
randomize 1

rem Clear cave floor
fill matrix 1,0,1

rem Set lighting, fog and setupset ambient light 20
color backdrop 0
if fog available()=1 then fog on : fog color 0 : fog distance 3000

rem Reset speed
x=0
z=0
speed#=0.0

rem Begin main loop
repeat

rem Record old variables
oldx=x
oldgy#=gy#

rem Control key movements
if upkey()=1 then speed#=speed#+1.0 else speed#=speed#-1.0
if leftkey()=1 then rz#=rz#+1.0
if rightkey()=1 then rz#=rz#-1.0

rem Control variables
if speed#<0.0 then speed#=0.0
if speed#<10.0 then speed#=speed#+1.1
if speed#>40.0 then speed#=40.0
rz#=rz#/1.1
x=x-(2*rz#)
loop=loop+(speed#/10.0)
stage=score/200
if stage<8
	if loop>7 then inc score : loop=0
else
	if loop>15 then inc score : loop=0
endif

rem Show Text
ink white,black
text 0,0,"Score - "+str$(score)
ink colors(stage),black
text 0,15,"Level "+str$(stage+1)+" - "+levels$(stage)
if stage=8 then stop music 1 : loop music 2
if stage=9
	stop music 2 : loop music 1
	stage=0
	score=0
	loop=0
endif

rem Scroll landscape
z=z+speed#
if z>200
	z=z-200
	if rnd(3)=0
		mp=mp-1
		mp=mp+rnd(3)
		if mp<1 then mp=1
		if mp>4 then mp=4
	endif
	for t=0 to 0 : set matrix height 1,t,24,450 : set matrix tile 1,t,24,2 : next t
	for t=1 to mp : set matrix height 1,t,24,rnd(200+(100*stage)) : set matrix tile 1,t,24,2 : next t
	for t=mp+1 to mp+1 : set matrix height 1,t,24,rnd(200+(100*stage)) : set matrix tile 1,t,24,3 : next t
	for t=mp+2 to mp+3 : set matrix height 1,t,24,rnd(20+(5*stage)) : set matrix tile 1,t,24,1 : next t
	for t=mp+4 to mp+4 : set matrix height 1,t,24,rnd(200+(100*stage)) : set matrix tile 1,t,24,4 : next t
	for t=mp+5 to 9 : set matrix height 1,t,24,rnd(200+(100*stage)) : set matrix tile 1,t,24,2 : next t
	for t=10 to 10 : set matrix height 1,t,24,450 : next t
	update matrix 1
	shift matrix up 1
	shift matrix up 2
endif

rem Position matrix	
position matrix 1,0,0,2500-z
position matrix 2,0,100,2500-z

rem Position camera
gy#=curvevalue(50+get ground height(1,500+x,z),gy#,3)
position camera 500+x,gy#,2500
zrotate camera wrapvalue(rz#)

rem Control sound frequency
set sound speed 1,10000+(speed#*100)

rem Update screen
sync

rem End main loop when collision with ceiling
until get ground height(2,500+x,z)<gy#-75.0

rem Return camera to point before collision
position camera 500+oldx,oldgy#,2500

rem Reset Score
score=0
loop=0
stage=0

rem Game Over
play sound 2
for c=0 to 255 step 20
	cls rgb(c,0,0)
	if fog available()=1 then fog distance (c*5) : fog color (c*256*256)
	sync
next c

rem End game loop
loop