TGC Codebase Backup



Platfoms by NanoGamez guy

13th Jan 2007 7:02
Summary

A simple game where you jump from platform to platfom.



Description

There are platforms which you have to jump up to land on them. Can be quite frustrating but addictive. Eatch level you advance the platforms move faster and it is harder. I bet no one can get to level four. If you do please tell me!



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem basics
sync on : hide mouse
set window title "Platforms"
set display mode 400,300,16

rem load sounds (You can add them if you want)
if file exist("music.mp3")=1 then load music "music.mp3",1
if file exist("level up.wav")=1 then load sound "level up.wav",1
if file exist("die.wav")=1 then load sound "die.wav",2
if file exist("bounce.wav")=1 then load sound "bounce.wav",3

rem loop music
if music exist(1)=1 then loop music 1

rem define platform levels in game
ml=25

rem set up arrays
dim l(ml,5,7)
dim nll(ml)

rem restart point
Restart:

rem reset counter for instructions
c2=200

rem reset lives
ll=3
rem reset level
gl=1

rem level up point
Levelup:

rem lose a life point
Loselife:

rem clear the screen
cls
rem set up basic variables
hx=200
hl=0
ol=1
bl=1
hi=0
hj=0
hs=0
hg=0

rem say "Generating level..."
ink rgb(0,0,255),0
print "Generating level..."

rem generate level
for i=1 to ml
	nll(i)=rnd(1)+1
	for j=1 to nll(i)
		l(i,j,1)=(rnd(15)+8)*2
		Lst:
		l(i,j,2)=rnd(160)+240
		l(i,j,3)=rnd(160)
		if i>1
			if l(i,j,2)>l(i-1,j,2) or l(i,j,3)<l(i-1,j,3) then goto Nxt else goto Lst
		endif
		Nxt:
		l(i,j,4)=rnd(gl)+1
		l(i,j,5)=l(i,j,2)-79
		l(i,j,6)=rnd(1)
		l(i,j,7)=1
	next j
next i

rem clear the screen
cls

rem main loop
do

	rem clear the screen
	cls 

	rem hide the mouse
	hide mouse
 
	rem predict when to jump
	if spacekey()=1 and ol=1 and c1<0
		if sound exist(3)=1 then play sound 3
		hg=15
		bl=0
		ol=0
		c1=10
		if hi>0 and hj>0 then l(hi,hj,4)=rnd(gl)+1
	endif
	c1=c1-1

	rem control sideways speed
	if rightkey()=1 then hs=hs+2
	if leftkey()=1 then hs=hs-2
	if hs>0 then hs=hs-1
	if hs<0 then hs=hs+1
	if hs>5 then hs=5
	if hs<-5 then hs=-5
	hx=hx+hs	
	if hx<5 then hx=5
	if hx>395 then hx=395

	rem check if player has landed
	if ol=0
		hg=hg-1
		for i=1 to ml
			for j=1 to nll(i)
				if hg>-51
					if l(i,j,7)=1 and hx>l(i,j,5)-(l(i,j,1)/2) and hx<l(i,j,5)+(l(i,j,1)/2) and (290-(hl*10))-hg=(290-(i*10))
						hl=i
						hg=0
						ol=1
						l(i,j,4)=0
						hi=i
						hj=j
					endif
				endif
			next j
		next i
	endif
	if ol=1 and bl=0
		if hx<l(hi,hj,5)-(l(hi,hj,1)/2) or hx>l(hi,hj,5)+(l(hi,hj,1)/2)
			ol=0
			hg=1
		endif
	endif

	rem control the platforms
	ink rgb(0,0,255),0
	for i=1 to ml
		for j=1 to nll(i)
			if l(i,j,7)=1
				if l(i,j,4)=0 and i<>hi or l(i,j,4)=0 and j<>hj then l(i,j,4)=rnd(gl)+1
				if l(i,j,6)=1 then l(i,j,5)=l(i,j,5)+l(i,j,4)
				if l(i,j,6)=0 then l(i,j,5)=l(i,j,5)-l(i,j,4)
				if l(i,j,5)+(l(i,j,1)/2)>=l(i,j,2) then l(i,j,6)=0
				if l(i,j,5)-(l(i,j,1)/2)<=l(i,j,3) then l(i,j,6)=1
				line l(i,j,5)-(l(i,j,1)/2),(290-(i*10)),l(i,j,5)+(l(i,j,1)/2),(290-(i*10))
			endif
		next j
	next i

	rem if player hasn't jumped make a line under him
	ink rgb(0,0,255),0
	if bl=1 then line 1,290,399,290

	rem make the spikes
	line 1,299,399,299
	for i=9 to 399 step 10
		line i,299,i-2,293
	next i

	rem make the walls
	line 399,1,399,299
	line 1,1,1,299

	rem make the man
	ink rgb(255,0,0),0
	line hx,(290-(hl*10))-hg-2,hx,(290-(hl*10))-hg-7
	line hx,(290-(hl*10))-hg-2,hx-2,(290-(hl*10))-hg-0
	line hx,(290-(hl*10))-hg-2,hx+2,(290-(hl*10))-hg-0
	line hx-2,(290-(hl*10))-hg-5,hx+2,(290-(hl*10))-hg-5
	circle hx,(290-(hl*10))-hg-8,1

	rem check if player has won the level
	ink rgb(255,0,0),0
	if ol=1 and hl=25
		set text size 40
		center text 200,120,"LEVEL UP!"
		if sound exist(1)=1 then play sound 1
		sleep 4000
		gl=gl+1
		ll=ll+1
		goto Levelup
	endif

	rem check if player has fallen onto the spikes
	if ol=0 and (290-(hl*10))-hg>293
		ll=ll-1
		if ll=0
			if sound exist(2)=1 then play sound 2
			ink rgb(255,0,0),0
			set text size 40
			center text 200,120,"YOU LOSE!"
			sleep 1000
			center text 200,160,"NEW GAME"
			sleep 1000
			goto Restart
		else
			set text size 40
			center text 200,120,"LOST A LIFE!"
			if sound exist(2)=1 then play sound 2
			sleep 1000
			goto Loselife
		endif
	endif

	rem print the basic stuff
	ink rgb(255,0,0),0
	set cursor 5,0
	print "Level: ";gl
	set cursor 5,15
	print "Lives: ";ll

	rem display instuctions
	ink rgb(255,0,0),0
	set cursor 60,0
	if c2>0 then print "Space=jump, right and left arrow keys=move"
	c2=c2-1

	rem refresh the screen
	sync

rem end of main loop
loop