TGC Codebase Backup



Simple Pong by Rburke

30th Sep 2006 8:44
Summary

Pong Classic. This is my first simple 2d game made with Dark Basic. The trial version was used for the production of this game.



Description

Use the Mouse to move player 1 and use the up/down arrow keys to move player two. The ball speed picks up faster until it's too much to handle! Going to work on AI for the next version of the game so you can try to beat the computer!



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `/////////////////////////
`/ REmake OF PONG `//////
`/ Author: Ryan Burke `/
`/ September 30, 2006 `/
`/////////////////////

Set Display Mode 640,480,32

Sync On : Sync Rate 40
Hide Mouse
Randomize 10

ink RGB(255,255,255),0

rem Initial Values

p2tY = 100 ; p2bY = 180
slope = RND(3)
if slope = 0 Then slope = 1
speed = 3

rem Initial Ball Location
bx1 = 640/2 ; bx2 = 640/2 + 10
by1 = 480/2 ; by2 = 480/2 + 10

rem Ball Reset Point
sbx1 = 640/2 ; sbx2 = 640/2 + 10
sby1 = 480/2 ; sby2 = 480/2 + 10

rem MAIN LOOP
do

	rem Set Player 1 Movement Restriction and Location
	if MouseY() < 10 Then p1tY = 11
	if MouseY() < 11 Then p1bY = 71
	if MouseY() > 10 Then p1tY = MouseY()
	if MouseY() > 390 Then p1bY = 470
	if MouseY() > 390 Then p1tY = 395
	if MouseY() < 390 Then p1bY = MouseY() + 80 
	box 50, p1tY, 70, p1bY

	rem Set Player 2 Movement Restriction and Location
	if p2tY < 15 Then p2tY = 15
	if p2tY = 15 Then p2bY = 95
	if p2tY > 380 Then p2bY = 460
	if p2tY > 380 Then p2tY = 380
	if UPKEY() Then p2tY = p2tY - 15
	if UPKEY() Then p2bY = p2bY - 15
	if DOWNKEY() Then p2tY = p2tY + 15
	if DOWNKEY() Then p2bY = p2bY + 15
	box 569,p2tY,589,p2bY

	rem Randomize Slope and Direction at beginning of Round
	while chance = 1
		Direction = RND(1)
		speed = 3
		slope = RND(3)
		if slope = 0 then slope = slope + 1
		chance = 0
	endwhile

	if Direction = 1
		bx1 = bx1 + speed; bx2 = bx2 + speed; by1 = by1 + slope; by2 = by2 + slope
	endif	
	
	if Direction = 0
		bx1 = bx1 - speed; bx2 = bx2 - speed; by1 = by1 + slope; by2 = by2 + slope
	endif

	rem If Player 2 Scores Reset Ball
	if bx1 < 30
		bx1 = sbx1; bx2 = sbx2; by1 = sby1; by2 = sby2
		chance = 1
		p2score = p2score + 1
	endif

	rem If Player 1 Scores Reset Ball
	if bx1 > 640
		bx1 = sbx1; bx2 = sbx2; by1 = sby1; by2 = sby2
		chance = 1	
		p1score = p1score + 1	
	endif

	rem Ball Collision With Floor and Ceiling
	if by2 > 470
		slope = slope - slope - slope
	endif
	if by1 < 10
		slope = slope - slope - slope
	endif

	rem Ball Collision With Player 1
	if bx1 < 70
		if by1 > p1tY and by1 < p1bY
			Direction = 1
			slope = RND(4)
			chance2 = RND(1)
			if chance2 = 1
				slope = slope - slope - slope
			endif
			if chance2 = 0
				slope = slope + slope
			endif
			speed = speed + 1		
		endif
	endif

	rem Ball Collision With Player 2
	if bx1 > 555
		if by1 > p2tY and by1 < p2bY
			Direction = 0
			slope = RND(4)
			chance2 = RND(1)
			if chance2 = 1
				slope = slope - slope - slope
			endif
			if chance2 = 0
				slope = slope + slope
			endif	
			speed = speed + 1
		endif
	endif

	rem Ball Position : Direction 1 is Right, 0 is Left
	box bx1,by1,bx2,by2

	rem Display Score
	Set Cursor 10,10
	ink RGB(255,0,0),1
	Print "Player 1:  ";p1score
	Set Cursor 500,10
	ink RGB(0,0,255),1
	Print "Player 2:  ";p2score	
	ink RGB(255,255,255),1

	rem Update
	sync
	cls

loop