Code: Select all
REM Car Hunter v.9b
REM ported from c64 game i remember!
REM a few bugs but fun to play!
REM
REM UP TO accelarate
REM DOWN to brake
REM Touch to shoot
REM Touch screen to add energy if cheat
REM is on.
REM Tested on:
REM iOS 8.3 b3 / iPhone 6 plus
REM
REM v.8 - distance is working and bug fixes!
REM
REM v.9 - road fix, more options in setup and bug fixes!
REM need help finishing this project.
rem sound, tweaks, text, code clean up.
rem enjoy...
' screen area
scw = Screen_Width()
sch = Screen_Height()
csw = scw/2
csh = sch/2
' lock rotation of screen and calibrate touch
start:
GOSUB setup
GOSUB title
pause 1
' MAIN GAME LOOP
loop:
coll=coll+1
IF coll>3 THEN
coll=1
END IF
refresh off
graphics clear 0,0,0
GOSUB road
GOSUB distance
GOSUB score
GOSUB controller
GOSUB enemycars
GOSUB playercar
GOSUB bullets
GOSUB particles
GOSUB bombs
refresh on
IF coll=1 THEN
GOSUB carscollision
END IF
IF coll=2 THEN
GOSUB bulletcollision
END IF
IF coll=3 THEN
GOSUB bomb_collision
END IF
'GOSUB score
GOSUB level
IF enfiredelay>0 THEN
enfiredelay=enfiredelay-1
END IF
IF firedelay>0 THEN
firedelay=firedelay-1
END IF
IF energy<=0 THEN
kill=kill+1
GOTO death
END IF
IF distance>99999 THEN
com=com+1
GOTO complete
END IF
IF time=0 THEN
kill=kill+1
GOTO out_of_time
END IF
IF (time<=0) OR (distance>=100000) OR (energy<=0) THEN
GOTO loop
END IF
REM Check hi score and level and
REM update title screen stats
IF level>maxlev THEN
maxlev=level
END IF
IF tscore>hi_score THEN
hi_score=tscore
END IF
tscore=0
'score=0
GOTO loop
' GAME OVER SCREENS
out_of_time:
'PLAY 1, "C3,1, ,1,A3#,2"
draw COLOR 1, 1, 1
DRAW TEXT "You ran out of time." at 10,10
DRAW TEXT "You are dead!" at 10,25
pause 2
GOTO start
complete:
'PLAY 1, "C3,1, ,1,A3#,2"
draw COLOR 1, 1, 1
graphics clear
DRAW TEXT "Congratulations. You survived." at 10,50
pause 2
GOTO start
death:
'PLAY 1, "C3,1, ,1,A3#,2"
draw COLOR 125/255, 125/255, 125/255
graphics clear 0,0,0
DRAW TEXT "You are dead!" at 10,25
pause 2
GOTO start
' SETUP VARIABLES AND ARRAYS
setup:
graphics
cheat = 1 ' 1 = adds energy each time you tap the screen, 0 = no cheating
liney=-60 ' used FOR the white lines
width=1 'The bigger the width the harder the game.
maxwidth=130 ' the max the walls will come in. 10-150 bigger is harder.
time=30*50 '30 secconds
distance=0 ' Meters TO travel.
plx=csw ' set up player's x-position
ply=csh 'set up player's y-position
mxbul=5 ' maximum amount of bullets permitted.
encars=3 ' Number of enemys
energy=150 ' Your energy.
firedelay=1 ' delay between player shots
enspeed=1 ' speed enemy closes in on player
level=1 ' current level
damage=10 ' amount of damage enemy bombs cause
bomnum=50 ' number used to check frequency of bombs
DIM pbx(mxbul+1) ' plaxer x bullet pos.
DIM pby(mxbul+1) ' player y bullet pos.
DIM pbs(mxbul+1) ' player bullet state.
DIM x(encars+1) ' enemy x pos.
DIM y(encars+1) ' enemy y pos.
DIM c(encars+1) ' enemy car state. 1= ok > 50=exploding.
bombs=1 ' no. of bombs enemies drop
DIM bx(bombs+1)
DIM by(bombs+1)
DIM bs(bombs+1)
particles=8 ' no. of particles in explosions
DIM partx(particles+1)
DIM party(particles+1)
DIM px(particles+1)
DIM py(particles+1)
ptst=0
FOR a=1 TO mxbul
pbs(a)=0
NEXT a
FOR a=1 TO encars
c(a)=1
y(a)=-40-(a-1)*100
x(a)=width+RND(scw-(width*2))
NEXT a
RETURN
' CHANGE LEVELS AND INCREASE DIFFICULTY
level:
target_score=10*(level*2)
IF score>target_score THEN
level=level+1
enspeed=enspeed+0.5
bomnum=bomnum-1
score=0
time=30*50
energy=100
width=width+20
damage=damage+(level)
distance=distance+11000
END IF
' Difficulty limits
IF level>10 THEN
level=10
END IF
IF width>maxwidth THEN
width=maxwidth
END IF
IF damage>35 THEN
damage=35
END IF
IF enspeed>4 THEN
enspeed=4
END IF
RETURN
' ENEMY BOMBS
bombs:
FOR a = 1 TO bombs
' DRAW BOMBS
IF bs(a)=1 THEN
fill COLOR RND(1),RND(1),RND(1)
fill RECT bx(a)-3,by(a)-3 to bx(a)+3,by(a)+3
bx(a)=bx(a)
by(a)=by(a)+10
IF by(a)>sch-30 THEN
bs(a)=0
END IF
END IF
NEXT a
RETURN
' CAR EXPOSIONS!!!!
particles:
IF ptst=0 THEN
RETURN
END IF
ptst=ptst-1
fill COLOR RND(1),RND(1),0
FOR a=1 TO particles
fill RECT px(a)-RND(4),py(a)-RND(4) to px(a)+RND(4),py(a)+RND(4)
px(a)=px(a)+partx(a)
py(a)=py(a)+party(a)
NEXT a
RETURN
' PLAYER CAR - ENEMY BOMB COLLISION CHECKS
bomb_collision:
FOR a = 1 TO bombs
IF bs(a)=1 THEN
IF by(a)+5>ply AND by(a)<ply+32 THEN
IF bx(a)+5>plx AND bx(a)<plx+40 THEN
energy=energy-damage
bs(a)=0
END IF
END IF
END IF
NEXT a
RETURN
' ENEMY CAR - PLAYER BULLET COLLISION
bulletcollision:
FOR a=1 TO mxbul
FOR b=1 TO encars
IF pbs(a)=1 AND c(b)=1 THEN
IF pbx(a)>=x(b) AND pbx(a)<=x(b)+29 AND pby(a)>=y(b) AND pby(a)<=y(b)+40 THEN
pbs(a)=0
IF ptst=0 THEN
FOR l=1 TO particles
ptst=20
partx(l)=-5+RND(10)
party(l)=-5+RND(10)
px(l)=pbx(a)
py(l)=pby(a)
NEXT l
END IF
r=INT(RND(3/level))
IF r<1 THEN
c(b)=50
score=score+10
tscore=tscore+10
carkill=carkill+1
END IF
END IF
END IF
NEXT b
NEXT a
RETURN
' PLAYER BULLETS
bullets:
FOR a=1 TO mxbul
IF pbs(a)=1 THEN
fill COLOR 1,1,1
fill RECT pbx(a),pby(a) to pbx(a)+2,pby(a)+10
fill COLOR 255,100+RND(155),0
'fill triangle pbx(a)-2,pby(a)+10 TO pbx(a)+3,pby(a)+10 TO pbx(a)+1,pby(a)+20+(rnd*10)
x1=pbx(a)-2
y1=pby(a)+10
x2=pbx(a)+3
y2=pby(a)+10
x3=pbx(a)+1
y3=pby(a)+20+RND(10)
GOSUB ftriangle
END IF
pby(a)=pby(a)-10+(speed/4)
IF pby(a)<=0 THEN
pbs(a)=0
END IF
NEXT a
RETURN
' SET UP BULLETS TO FIRE!!!
fire:
IF firedelay>0 THEN
RETURN
END IF
FOR a=1 TO mxbul
IF pbs(a)=0 THEN
pbx(a)=plx+14
pby(a)=ply
pbs(a)=1
firedelay=10
a=mxbul+1
IF cheat = 1 THEN
energy=energy+5 ' cheat on
END IF
END IF
NEXT a
RETURN
'ENEMY CAR - PLAYER CAR COLLISION
carscollision:
FOR a=1 TO encars
IF c(a)=1 THEN
IF y(a)>=ply-40 AND y(a)<=ply+40 THEN
IF plx+1>x(a) AND plx<=x(a)+29 AND ply>y(a) AND ply<=y(a)+40 THEN
xm=(speed/2)
speed=speed-(speed/10)
c(a)=2
energy=energy-5
score=score+5
carkill=carkill+1
END IF
IF plx+30>=x(a) AND plx+30<=x(a)+29 AND ply>y(a) AND ply<=y(a)+40 THEN
xm=-(speed/2)
speed=speed-(speed/10)
c(a)=2
energy=energy-5
score=score+5
carkill=carkill+1
END IF
IF plx+1>x(a) AND plx<=x(a)+29 AND ply+40>y(a) AND ply+40<=y(a)+40 THEN
xm=(speed/2)
speed=speed-(speed/10)
c(a)=2
energy=energy-2
score=score+5
carkill=carkill+1
END IF
IF plx+30>=x(a) AND plx+30<=x(a)+29 AND ply+40>y(a) AND ply+40<=y(a)+40 THEN
xm=-(speed/2)
speed=speed-(speed/10)
c(a)=2
score=score+5
energy=energy-2
carkill=carkill+1
END IF
END IF
END IF
NEXT a
RETURN
' DISPLAY TIME LEFT, POINTS ETC
score:
draw COLOR 1,1,1
draw TEXT "TIME LEFT: " & STR$(INT(time/50)) at 5,15
REM Energy bar
fill COLOR 0,0,0
fill RECT 100, sch-20 to 300, sch
fill COLOR 1,1,1
DRAW TEXT "Energy:" at 10,sch-20
IF energy>100 THEN
energy=100
END IF
IF energy>75 THEN
fill COLOR 0, 2,0
END IF
IF energy<=75 THEN
fill COLOR 1, 1,0
END IF
IF energy<50 THEN
fill COLOR 1, 100/255,0
END IF
IF energy<25 THEN
fill COLOR 1, 0,0
END IF
IF energy>100 THEN
energy=100
END IF
fill RECT 100,sch-20 to 100+(energy*2),sch
RETURN
distance:
REM Distance bar
draw COLOR 1,1,1
DRAW TEXT "Distance:" at 5,0
fill RECT 80, 1 to 280,15
fill COLOR 1,100/255,100/255
fill RECT 80,1 to 80+(INT(distance/1000)*2),15
IF distance>100000 THEN
distance=100000
END IF
draw COLOR 210/255,210/255,1
DRAW TEXT "PLAYER SCORE: "&STR$(score) at 5,35
DRAW TEXT "TARGET SCORE: "&STR$(target_score) at 5,55
DRAW TEXT "LEVEL: "&STR$(level) at 5,75
time=time-1
RETURN
' READ INPUT DEVICE
controller:
IF Accel_X() > 0 THEN
xm=xm+.3
END IF
IF Accel_X() < 0 THEN
xm=xm-.3
END IF
IF Accel_Y() < 0 THEN
speed=speed+.3
END IF
IF Accel_Y() > 0 THEN
speed=speed-.2
END IF
IF Touch_x(0) <> -1 THEN GOSUB fire
IF speed>8 THEN
speed=8
END IF
IF speed<1 THEN
speed=1
END IF
plx=plx+xm
ply=csh-(speed*5)
IF xm>0 THEN
xm=xm-.2
IF xm<0 THEN
xm=0
END IF
END IF
IF xm<0 THEN
xm=xm+.2
IF xm>0 THEN
xm=0
END IF
END IF
IF plx<width THEN
plx=width+speed
xm=0
energy=energy-1
END IF
IF xm>speed/2 THEN
xm=speed/2
END IF
IF xm<-(speed/2) THEN
xm=-(speed/2)
END IF
IF plx+31>(scw-width) THEN
plx=((scw-width))-32-speed
energy=energy-1
xm=0
END IF
RETURN
'UPDATE SCREEN AND DRAW ROAD
road:
fill COLOR 30/255,30/255,40/255
fill RECT 0,0 to scw,sch
fill COLOR 1,1,1
h=30
FOR a=liney TO 520 STEP 60
fill RECT csw-8,a to csw+8,a+30
NEXT a
IF level <=5 THEN
fill COLOR 40/255,80/255,40/255
END IF
IF level >5 AND level<=8 THEN
fill COLOR 100/255,80/255,20/255
END IF
IF level >8 THEN
fill COLOR 100/255,100/255,100/255
END IF
fill RECT 0,0 to width,sch
fill RECT scw,0 to scw-width,sch
liney=liney+INT(speed)
IF liney>0 THEN
liney=liney-60
END IF
RETURN
' DRAW PLAYER CAR!!!
playercar:
fill COLOR 255,100,100
fill COLOR 50,50,60
fill RECT plx-2,ply+4 to plx+32,ply+14
fill RECT plx-2,ply+28 to plx+32,ply+38
fill COLOR 115/255,20/255,20/255
fill RECT plx,ply-5 to plx+30,ply+40
fill COLOR 115/255,60/255,60/255
fill RECT plx+3,ply-5 to plx+27,ply+40
fill COLOR 100/255,155/255,1
fill RECT plx+4,ply+7 to plx+26,ply+37
fill COLOR 1,50/255,50/255
fill RECT plx+5,ply+10 to plx+25,ply+35
RETURN
' DRAW ENEMY CARS
enemycars:
FOR a=1 TO encars
IF c(a)=1 THEN
fill COLOR 55/255,55/255,120/255
fill RECT x(a)+1,y(a) to x(a)+29,y(a)+40
fill COLOR 80/255,80/255,80/255
fill RECT x(a)-1,y(a)+3 to x(a)+31,y(a)+14
fill RECT x(a)-2,y(a)+26 to x(a)+32,y(a)+38
fill COLOR 70/255,70/255,170/255
fill RECT x(a)+2,y(a) to x(a)+28,y(a)+40
fill COLOR 20/255,20/255,60/255
fill RECT x(a)+1,y(a)+40 to x(a)+29,y(a)+35
fill COLOR 150/255,150/255,1
fill RECT x(a)+3,y(a)+20 to x(a)+27,y(a)+35
fill COLOR 30/255,30/255,40/255
fill RECT x(a)+3,y(a)+20 to x(a)+27,y(a)+12
END IF
IF c(a)>1 AND c(a)<50 THEN
draw COLOR (255-c(a)*5)/255,(255-c(a)*5)/255,0
draw CIRCLE x(a)+15,y(a)+20 size c(a)
c(a)=c(a)+4
END IF
REM MOVE ENEMY CARS ACCORDING TO PLAYER SPEED
y(a)=y(a)+1+(speed/2)-1
REM RESET CARS IF THEY ARE OFF SCREEN
IF y(a)>sch THEN
y(a)=y(a)-sch-50
x(a)=width+rnd(scw-(width*2))
c(a)=1
carescape=carescape+1
END IF
IF (ply-speed)-y(a)<150 THEN
IF x(a)+32>plx+32 THEN
x(a)=x(a)-enspeed
END IF
IF x(a)<plx THEN
x(a)=x(a)+enspeed
END IF
END IF
NEXT a
REM SET UP ENEMY BOMBS
IF enfiredelay=0 THEN
FOR a=1 TO encars
rnum=RND(bomnum)
IF rnum<1 AND c(a)=1 THEN
IF plx+32>x(a)-2 AND plx-2<x(a)+32 THEN
IF ply>y(a) THEN
FOR i = 1 TO bombs
IF bs(i)=0 THEN
enfiredelay=10
bx(i)=x(a)
by(i)=y(a)
bs(i)=1
i=bombs+1 'x or xx
a=enemy+1
END IF
NEXT i
END IF
END IF
END IF
NEXT a
END IF
RETURN
mainloop:
refresh off
graphics clear 0,0,0
mm=mm+.02
red=100*SIN(mm)
grn=100*SIN(mm/2)
blu=100*SIN(mm/3)
fill COLOR red/255,grb/255,blu/255
'triangle 0,0 TO scw,sch TO 0,sch
x1=0
y1=0
x2=scw
y2=sch
x3=0
y3=sch
GOSUB TRIANGLE
'triangle 0,0 TO scw,sch TO scw,0
x1=0
y1=0
x2=scw
y2=sch
x3=scw
y3=0
GOSUB TRIANGLE
refresh on
RETURN
title:
do
refresh off
graphics clear 0,0,0
draw COLOR 1,1,1
DRAW TEXT "CAR H-U-N-T-E-R" at 80-5+RND(5),1-2+RND(4)
DRAW TEXT "HI SCORE : "+STR$(hi_score) at 10,csh+RND(4)
DRAW TEXT "Tap to Start" at 10-5,20-2+RND(4)
DRAW TEXT "================" at 10-5,30-2+RND(4)
DRAW TEXT "You have survived " + STR$(com) + " time(s)" at 20,45
DRAW TEXT "You have been killed " + STR$(kill) & " time(s)" at 20,60
IF carkill>0 THEN
carper=(carkill/carescape)*100
ELSE
carper=0
END IF
DRAW TEXT STR$(carescape) & " cars escaped" at 20,75
DRAW TEXT "You have killed " & STR$(carkill) & " cars" at 20,90
DRAW TEXT "Killed cars: " & STR$ (INT(carper)) & " %" at 20,110
DRAW TEXT "Max level reached : " & STR$(maxlev) at 20,125
refresh on
until touch_x(0) <> -1
carkill=0
carescape=0
RETURN
'Triangle
'outline
triangle:
DIM xs(4),ys(4)
xs(0)=x1
ys(0)=y1
xs(1)=x2
ys(1)=y2
xs(2)=x3
ys(2)=y3
draw poly xs, ys count 3
RETURN
'fill
ftriangle:
DIM xs(4),ys(4)
xs(0)=x1
ys(0)=y1
xs(1)=x2
ys(1)=y2
xs(2)=x3
ys(2)=y3
fill poly xs, ys count 3
RETURN