DECLARE SUB dostars (xsv!, ysv!, x!(), y!(), xv!(), yv!()) DECLARE SUB drawlife (LIFE!, thecolor!) DECLARE SUB levelup2 () DECLARE SUB levelup () DECLARE FUNCTION normalize! (x!, y!) DECLARE FUNCTION hittest! (x!, y!, rad!, x2!, y2!, rad2!) DECLARE FUNCTION drawdood! (x!, y!, rad!, thecolor!) DECLARE FUNCTION spawndood! (x!, y!, xv!, yv!, rad!, inuse!) DECLARE FUNCTION drawfire! (x!, y!, thecolor!) DECLARE FUNCTION drawplayer! (x!, y!, angle!, thecolor!) REM -------------------------------------------------------------- REM Setup the system and variables: CLS SCREEN 13 PRINT "" PRINT "ShooterZapper 4000!" PRINT "" PRINT "By: Ivan Kluzak" PRINT "" PRINT "" PRINT "press any key to continue" WHILE anykey$ = "" anykey$ = INKEY$ WEND CLS anykey$ = "" REM Slowdown amount for fast PC's PRINT "Calibrating to your PC's speed..." PRINT "Please wait..." timethen = TIMER FOR i = 0 TO 8000000 NEXT i timenow = TIMER REM To get 50fps DELAYAMOUNT = (8000000 / (timenow - timethen)) / 50 PRINT "Delay loops detected: ", DELAYAMOUNT PRINT "" PRINT "" PRINT "Controls:" PRINT " a = turn left" PRINT " d = turn right" PRINT " w = fire" PRINT " spacebar = thrust" PRINT " q = quit" PRINT "" PRINT "Avoid the blobs to stay alive, shoot" PRINT "them to earn points" PRINT "" PRINT "press any key to begin" WHILE anykey$ = "" anykey$ = INKEY$ WEND anykey$ = "" CLS REM Player coordinates xpos = 160 ypos = 100 xvel = 0 yvel = 0 angle = 0 oldangle = 0 SPEED = .1 ' Throttle kinda :) drawflame = 0 LIFE = 15 ' 15 lives before you die SCORE = 0 ' The players score l1 = 0 ' Level flags l2 = 0 l3 = 0 l4 = 0 REM Projectile coordinates fire = 0 xfire = 160 yfire = 100 xvfire = 0 yvfire = 0 REM Bad Guys DIM usedood(30) DIM xdood(30) DIM ydood(30) DIM xvdood(30) DIM yvdood(30) DIM raddood(30) maxdoods = 3 ' Max base level of doods MDOODS = 30 ' the max total number doodcount = 0 REM init these to zero FOR i = 0 TO MDOODS usedood(i) = 0 xdood(i) = 0 ydood(i) = 0 xvdood(i) = 0 yvdood(i) = 0 raddood(i) = 0 NEXT i REM Starfield... kinda... DIM xstar(50) DIM ystar(50) DIM xvstar(50) DIM yvstar(50) FOR i = 0 TO 50 xstar(i) = RND * 320 ystar(i) = RND * 200 xvstar(i) = 1 - (RND * .5) yvstar(i) = 1 - (RND * .5) NEXT i REM -------------------------------------------------------------- REM Main Loop: WHILE key$ <> "q" REM How many doods are on the playing field? WHILE doodcount < maxdoods doodindex = -1 REM Find a free dood FOR i = 0 TO MDOODS IF usedood(i) = 0 THEN doodindex = i i = MDOODS END IF NEXT i REM If we found a free dood IF doodindex <> -1 THEN doodcount = doodcount + 1 i = doodindex duh = spawndood(xdood(i), ydood(i), xvdood(i), yvdood(i), raddood(i), usedood(i)) ELSE PRINT "error: out of doods" GOTO done END IF WEND REM --------[ Handle Input key$ = INKEY$ SELECT CASE key$ CASE "8" yvel = yvel - SPEED CASE "2" yvel = yvel + SPEED CASE "4" xvel = xvel - SPEED CASE "6" xvel = xvel + SPEED CASE "5" xvel = 0 yvel = 0 CASE "a" oldangle = angle angle = angle - 6 CASE "d" oldangle = angle angle = angle + 6 CASE " " thrust = SPEED SOUND 100, .1 SOUND 200, .1 SOUND 100, .1 SOUND 200, .1 CASE "w" IF fire = 0 THEN fire = 1 xfire = xpos yfire = ypos xvfire = xvel + (5 * COS(angle * 3.141593 / 180)) yvfire = yvel + (5 * SIN(angle * 3.141593 / 180)) SOUND 200, .2 SOUND 400, .2 SOUND 200, .2 SOUND 400, .2 END IF END SELECT REM -------[ Do Physics: duh = drawplayer(xpos, ypos, oldangle, 0) ' erase the old ship duh = drawplayer(xpos, ypos, angle, 0) ' erase the old ship FOR i = 0 TO MDOODS IF usedood(i) = 1 THEN duh = drawdood(xdood(i), ydood(i), raddood(i), 0) END IF NEXT i FOR i = 0 TO MDOODS IF usedood(i) = 1 THEN xdood(i) = xdood(i) + xvdood(i) ydood(i) = ydood(i) + yvdood(i) IF xdood(i) < 0 THEN xdood(i) = xdood(i) + 320 IF xdood(i) > 320 THEN xdood(i) = xdood(i) - 320 IF ydood(i) < 0 THEN ydood(i) = ydood(i) + 200 IF ydood(i) > 200 THEN ydood(i) = ydood(i) - 200 END IF NEXT i IF thrust > 0 THEN xvel = xvel + (thrust * COS(angle * 3.141593 / 180)) yvel = yvel + (thrust * SIN(angle * 3.141593 / 180)) thrust = 0 END IF xpos = xpos + xvel ypos = ypos + yvel IF fire = 1 THEN duh = drawfire(xfire, yfire, 0) xfire = xfire + xvfire yfire = yfire + yvfire END IF REM -------[ Collision Test: IF xpos < 0 THEN xpos = xpos + 320 END IF IF xpos > 320 THEN xpos = xpos - 320 END IF IF ypos < 0 THEN ypos = ypos + 200 END IF IF ypos > 200 THEN ypos = ypos - 200 END IF IF xfire < 0 THEN duh = drawfire(xfire, yfire, 0) fire = 0 END IF IF xfire > 320 THEN duh = drawfire(xfire, yfire, 0) fire = 0 END IF IF yfire < 0 THEN duh = drawfire(xfire, yfire, 0) fire = 0 END IF IF yfire > 200 THEN duh = drawfire(xfire, yfire, 0) fire = 0 END IF REM Test each dood to see if we ran into one! FOR i = 0 TO MDOODS REM if it's been allocated IF usedood(i) = 1 THEN REM Do a collision check duh = hittest(xpos, ypos, 7, xdood(i), ydood(i), raddood(i)) IF duh = 1 THEN drawlife LIFE, 0 ' erase old life bar LIFE = LIFE - 1 ' remove a life point REM Get distance between two objects that we REM will need to seperate these by... spawnback = raddood(i) + 7 REM Get a reverse direction unit vector IF xvel = 0 AND yvel = 0 THEN REM if we arn't moving use it's velocity xvel = xvdood(i) yvel = yvdood(i) ELSE xdir = -xvel ydir = -yvel END IF duh = normalize(xdir, ydir) REM Move the player back exactly spawnback ammount xpos = xpos + (xdir * spawnback) ypos = ypos + (ydir * spawnback) REM Add in the velocity of what hit you oldplayerxv = xvel ' save for moving the object oldplayeryv = yvel xvel = -xvel yvel = -yvel REM Do the same to dood(i), get normalized unit IF xvdood(i) = 0 AND yvdood(i) = 0 THEN REM if dood isn't moving use players velocity xvdood(i) = oldplayerxv yvdood(i) = oldplayeryv ELSE xdir = -xvdood(i) ydir = -yvdood(i) END IF duh = normalize(xdir, ydir) REM Move dood back exactly spawnback amount xdood(i) = xdood(i) + (xdir * spawnback) ydood(i) = ydood(i) + (ydir * spawnback) xvdood(i) = -xvdood(i) yvdood(i) = -yvdood(i) SOUND 1000, .1 END IF END IF NEXT i REM Test each dood to see if we shot one IF fire = 1 THEN FOR i = 0 TO MDOODS REM if it's been allocated IF usedood(i) = 1 THEN REM Do a collision check duh = hittest(xfire, yfire, 2, xdood(i), ydood(i), raddood(i)) IF duh = 1 THEN REM erase the old dood duh = drawdood(xdood(i), ydood(i), raddood(i), 0) IF raddood(i) <= 5 THEN SCORE = SCORE + 5 ' 5 points for killing one doodcount = doodcount - 1 usedood(i) = 0 ELSE REM we have a net gain of 1 dood doodcount = doodcount + 1 SCORE = SCORE + 1 ' 1 point for splitting one REM ---------------[ SPLIT the dood FOR j = 0 TO MDOODS IF usedood(j) = 0 THEN freedood = j j = MDOODS END IF NEXT j j = freedood usedood(j) = 1 raddood(j) = raddood(i) / 2 xdood(j) = xdood(i) - (raddood(j) * 1.2) ydood(j) = ydood(i) - (raddood(j) * 1.2) xvdood(j) = RND * .5 yvdood(j) = RND * .5 REM Make the 2nd one FOR j = 0 TO MDOODS IF usedood(j) = 0 THEN freedood = j j = MDOODS END IF NEXT j j = freedood usedood(j) = 1 raddood(j) = raddood(i) / 2 xdood(j) = xdood(i) + (raddood(j) * 1.2) ydood(j) = ydood(i) + (raddood(j) * 1.2) xvdood(j) = RND * .5 yvdood(j) = RND * .5 REM Mark the old one as unused usedood(i) = 0 END IF SOUND 900, 1 END IF END IF NEXT i END IF REM Test each dood to see if it hit another dood FOR i = 0 TO MDOODS REM if it's been allocated IF usedood(i) = 1 THEN FOR j = (i + 1) TO MDOODS IF usedood(j) THEN duh = hittest(xdood(i), ydood(i), raddood(i), xdood(j), ydood(j), raddood(j)) IF duh = 1 THEN spawnback = raddood(i) + raddood(j) spawnback = spawnback * 2.2 REM spawnback = spawnback / 2 REM bounce the smaller one IF raddood(j) > raddood(i) THEN xdood(i) = xdood(i) - (xvdood(i) * spawnback) ydood(i) = ydood(i) - (yvdood(i) * spawnback) xvdood(i) = -xvdood(i) yvdood(i) = -yvdood(i) ELSE xdood(j) = xdood(j) - (xvdood(j) * spawnback) ydood(j) = ydood(j) - (yvdood(j) * spawnback) xvdood(j) = -xvdood(j) yvdood(j) = -yvdood(j) END IF SOUND 5000, .1 END IF END IF NEXT j END IF NEXT i REM -------[ Draw the ship/etc: REM first the background... dostars xvel, yvel, xstar(), ystar(), xvstar(), yvstar() FOR i = 0 TO MDOODS IF usedood(i) = 1 THEN duh = drawdood(xdood(i), ydood(i), raddood(i), 3) END IF NEXT i duh = drawplayer(xpos, ypos, angle, 15) ' Draw the new ship IF fire = 1 THEN duh = drawfire(xfire, yfire, 5) END IF REM Draw our HUD (life display/etc...) drawlife LIFE, 5 REM -----------------------------[ Handle dying and level changes: IF LIFE <= 0 THEN GOTO done: IF SCORE >= 50 AND SCORE < 100 AND l1 = 0 THEN l1 = 1 levelup REM Speed up the game DELAYAMOUNT = DELAYAMOUNT * .8 END IF IF SCORE >= 100 AND SCORE < 150 AND l2 = 0 THEN l2 = 1 levelup REM Speed up the game DELAYAMOUNT = DELAYAMOUNT * .8 END IF IF SCORE >= 150 AND SCORE < 200 AND l3 = 0 THEN l3 = 1 levelup REM Speed up the game DELAYAMOUNT = DELAYAMOUNT * .8 END IF IF SCORE >= 200 AND SCORE < 300 AND l4 = 0 THEN l4 = 1 levelup2 levelup2 REM Speed up the game DELAYAMOUNT = DELAYAMOUNT * .6 IF doodcount > maxdoods THEN maxdoods = doodcount + 5 ELSE maxdoods = maxdoods + 5 END IF IF maxdoods > MDOODS THEN maxdoods = MDOODS END IF FOR i = 0 TO DELAYAMOUNT REM Delay Loop for fast PC's NEXT i WEND IF key$ = "q" GOTO done2: done: timenow = TIMER CLS PRINT "" PRINT " Game Over!" PRINT "" PRINT " You died!" PRINT "" PRINT "Your Score: "; SCORE PRINT "Time Elapsed: "; timenow - timethen; " seconds" PRINT "" GOTO reallydone: done2: CLS PRINT "" PRINT "Leaving so soon?" PRINT "" PRINT "Please play again! :)" PRINT "" reallydone: SUB dostars (sxv, syv, x(), y(), xv(), yv()) FOR i = 0 TO 50 PSET (x(i), y(i)), 0 x(i) = x(i) + xv(i) + sxv y(i) = y(i) + yv(i) + syv IF x(i) > 320 THEN x(i) = x(i) - 320 IF x(i) < 0 THEN x(i) = x(i) + 320 IF y(i) > 200 THEN y(i) = y(i) - 200 IF y(i) < 0 THEN y(i) = y(i) + 200 PSET (x(i), y(i)), 7 NEXT i END SUB FUNCTION drawdood (x, y, rad, thecolor) CIRCLE (x, y), rad, thecolor drawdood = 0 END FUNCTION FUNCTION drawfire (x, y, thecolor) CIRCLE (x, y), 2, thecolor END FUNCTION SUB drawlife (LIFE, thecolor) LINE (0, 0)-(LIFE * 3, 0), thecolor LINE (0, 1)-(LIFE * 3, 1), thecolor LINE (0, 2)-(LIFE * 3, 2), thecolor LINE (0, 3)-(LIFE * 3, 3), thecolor END SUB FUNCTION drawplayer (x, y, angle, thecolor) REM Draw a player character on the screen x2 = 10 * COS(angle * 3.141593 / 180) y2 = 10 * SIN(angle * 3.141593 / 180) x2 = x2 + x y2 = y2 + y CIRCLE (x, y), 4, thecolor CIRCLE (x, y), 1, thecolor CIRCLE (x2, y2), 1, thecolor LINE (x, y)-(x2, y2), thecolor drawplayer = 0 END FUNCTION FUNCTION hittest (x, y, rad, x2, y2, rad2) hitme = 0 dx = x - x2 dy = y - y2 length = SQR((dx * dx) + (dy * dy)) IF length < (rad + rad2) THEN hitme = 1 END IF hittest = hitme END FUNCTION SUB levelup CLS PRINT "" PRINT "" PRINT "" PRINT " LEVEL UP!" FOR i = 0 TO 50 SOUND 50 + i * 10, .5 NEXT i CLS END SUB SUB levelup2 CLS PRINT "" PRINT "" PRINT "" PRINT " !!! HYPER LEVEL !!!" FOR i = 0 TO 60 SOUND 50 + i * 10, .5 NEXT i FOR i = 60 TO 0 SOUND 50 + i * 10, .5 NEXT i CLS END SUB FUNCTION normalize (x, y) REM Get the length of the vector length = SQR((x * x) + (y * y)) IF (length = 0) THEN length = 1 x = x / length y = y / length REM return this for kicks normalize = length END FUNCTION FUNCTION spawndood (x, y, xv, yv, rad, inuse) x = RND * 320 y = RND * 320 xv = .5 - (RND) yv = .5 - (RND) rad = 8 + (RND * 15) inuse = 1 spawndood = 0 END FUNCTION