TGC Codebase Backup



Cube game by yuri_dragon 17

16th Dec 2006 14:32
Summary

Simple Get the green cube game. An improvement on "simple game concept" posted 20th Sep 06



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ` This code was downloaded from The Game Creators
` It is reproduced here with full permission
` http://www.thegamecreators.com

` This code was downloaded from The Game Creators
` It is reproduced here with full permission
` http://www.thegamecreators.com
` select number of cubes to get
`put this to "on" to test play
test$="off"
hide mouse
print "SELECT LEVEL"
print "1-3"
if test$<>"on" then input level
if test$="on" then level=1
winpoints=5*level
fglvl=5000

` give instructions
set cursor 0,175
print "SIMPLE CUBE GAME"
print "USE ARROW KEYS TO MOVE"
print "PRESS SPACE KEY TO SPEED UP"
print "RELEASE TO SLOW DOWN"
print "THE OBJECT OF THE GAME IS TO GET ";winpoints;" POINTS BY GETTING ";winpoints; " GREEN CUBES"
print "BE CAREFUL! THERE ARE RED, GREEN, AND BLUE CYLINDERS AND CONES"
print "THERE ARE ALSO RED AND BLUE CUBES!"
print "PRESS ANY KEY TO PLAY!"
if test$<> "on" then wait key
cls


`intial setup
rem make ammo
ammo# = 10
loopammo# = ammo#

rem make bullet array
dim bullet#(ammo#+500,1)
autocam off
rem loop and create bullet
for i = 500 to loopammo#+500
bullet#(i,1)=0
make object sphere i,50
next i
minspeed=20
playergrav#=2.0
randomize timer()
`change this to your drive name
cd "C:\Documents and Settings\James\Desktop\HOME\Computers etc\Programming\DARKBASIC\media for cube game"
load image "bmps\green.bmp",3
load image "bmps\blue.bmp",2
load image "bmps\red.bmp",1
load image "bmps\rgb.bmp",4
load sound "sounds\crash.wav",1
Sync on
Sync rate 30

backdrop on
fog on
set camera range 1,6000
fog distance fglvl
fog color RGB(128,128,128)
color backdrop RGB(128,128,128)

`make player

make object sphere 200,50
texture object 200,4
set object collision to spheres 200

position object 200,rnd(10000),0,rnd(10000)

`make obstacles
For x = 1 to 10
   make object cube x,100
   position object x,rnd(10000),0,rnd(10000)
	texture object x, rnd(1)+1
Next x
For x = 11 to 50
   make object cone x,100
   position object x,rnd(10000),0,rnd(10000)
	texture object x, rnd(2)+1
Next x
For x = 51 to 100
   make object cylinder x,100
   position object x,rnd(10000),0,rnd(10000)
	texture object x, rnd(2)+1
Next x

`make goal

make object cube 201,100
texture object 201,3
position object 201,rnd(10000),0,rnd(10000)
set object collision to boxes 201

`make matrix
make matrix 1,10000,10000,20,20
set matrix wireframe off 1
rotate image 4,rnd(360)

position matrix 1,0,-50,0
for s=1 to 100
set object collision to spheres s
next s
`main loop
Do

texture object 200,4
      `print stuff
      set cursor 0,0
      Print "Get the green cubes"
      set cursor 0,12
      Print "Score: ",Score
		set cursor 0,24
		
		` calculate win
		if score<winpoints then print "cubes left: ";winpoints-score
		if score=>winpoints then print "YOU WIN!!!"
		if score=winpoints and a=0 then s=5000
		if score=winpoints then a=1
		if s>0 then dec s
		if score = winpoints and s=0 then end
		set cursor 0,36
		print "Speed: ";speed
      `store variables
      aY# = object angle Y(200)

      `controls
      If upkey()=1 then move object 200,speed
      if leftkey()=1 then yrotate object 200,wrapvalue(aY#-5)
      if rightkey()=1 then yrotate object 200,wrapvalue(aY#+5)
      if downkey()=1 then move object 200,speed-speed-speed
		if spacekey()=1 and upkey()=1 or spacekey()=1 and downkey()=1
		inc speed,2
		else
		dec speed,2
		endif
		if speed <minspeed then speed=minspeed
		if upkey()=0 and downkey()=0 then speed=minspeed

      `get player positions
      X# = object position x(200)
      Z# = object position z(200)

      `get camera values
      cZ# = newzvalue(Z#,aY#-180,100)
      cX# = newxvalue(X#,aY#-180,100)

      `position camera
      position camera cX#,100,CZ#
      point camera X#,50,Z#
if speed<101 then set ambient light speed
		for a=1 to 100
		if object collision(a,200)>0
		play sound 1
		speed=0
		move object 200,-10
		endif
		next a

      `collision data
      if object collision(201,200)>0
		play sound 1
		cls
		rotate image 4,rnd(360)
		texture object 200,4
      inc score
		if score>winpoints then wait 500
      position object 201,rnd(10000),0,rnd(10000)
		for zz=1 to 100
		position object zz,rnd(10000),0,rnd(10000)
		next zz
      endif
      Sync




rem now to get to the bullet
rem check if current bullet is inactive(0)

	if controlkey()=1 and bullet#(ammo#+500,1)=0 
rem after spacebar go to check if bullet released
		bullet#(ammo#,1)=1
	endif

	if spacekey()=0 and bullet#(ammo#,1)=1
rem go to set up bullet and positionig
		bullet#(ammo#+500,1)=2
		ammo# = ammo# - 1	
	endif

rem loop the bullets
	for i = 500 to loopammo#+500
rem position bullet with camera and rotate it to the same way
rem the camera is positioned
		if bullet#(i,1)=2
			position object i,x#,y#,z#
			yrotate object i,camera angle y()
rem now bullet is ready
			bullet#(i,1)=3
		endif
rem check if bullet is ready
		if bullet#(i,1)=3
rem begin moveing the bullet
			move object i,20
		endif
	next i

rem print how much ammo left
set cursor 0,48
print ammo#

Loop