A few weeks ago I downloaded Chipmunk BASIC for my Mac. I haven't programmed anything for probably 25 years now, but I'm already able to do things I only dreamt of doing on my TRS-80 MC-10 when I was a kid. I'm enormously proud of this game (code below), for example. Not the most elegant coding, perhaps, but I'm getting back into the swing of it. The point of this experiment is to relearn enough programming skills to teach my kids something useful about how computers work (their experience is way too confined to the apps they've downloaded for their iPad). If there's anyone out there who is as nostalgic about BASIC as I am and wants to comment on or critique what I've done here, feel free. But please keep in mind that we're still in the very early stages of my own own self-re-education.
10 home
20 graphics 0
30 x = 200 : y = 400 : r = 20
35 tt = timer+60
40 vc = -20
42 pp = -10
45 ac = 1
46 gosub 500
50 graphics color 100,100,100
60 gosub 400
150 y = y+vc
155 vc = vc+ac
170 if y > 400 then vc = vc*-1 : vc = vc+7 : y = 399
175 if y < 0 then vc = vc*-1 : y = 1 180 if x < 0 then mv = mv*-1 : x = 1 190 if x > 600 then mv = mv*-1 : x = 599
205 x = x+mv
206 if mv > 0 then mv = mv-1
207 if mv < 0 then mv = mv+1 220 graphics color 100,0,0 230 gosub 400 240 t = timer 250 s = timer 260 if s-t < 0.05 then goto 250 275 k$ = inkey$ 277 if k$ <> "" then mm = mm+1
280 if k$ = "a" then mv = mv-20
290 if k$ = "l" then mv = mv+20
300 if k$ = " " and vc < 0 then vc = vc*-1 310 if k$ = " " and vc > 0 then vc = vc+10
320 if k$ = "x" then end
340 goto 50
390 end
400 for v = 1 to 360
410 a = x+r*cos(v*3.14/180)
420 b = y+r*sin(v*3.14/180)
425 moveto x,y
430 lineto a,b
435 if tx < a and a < tx+20 and ty < b and b < ty+20 then gosub 500
440 next v
450 return
500 graphics color 0,0,0
502 pp = pp+10-mm
503 ss = int(tt-timer)
504 if ss < 0 then goto 700
505 score$ = "You made "+str$(mm)+" moves. Your score is "+str$(pp)+". You have "+str$(ss)+" seconds left. "
506 moveto 180,500 : graphics text score$
507 mm = 0
509 graphics color 100,100,100
510 gosub 600
520 tx = rnd(480)+80
530 ty = rnd(300)+50
540 graphics color 0,0,100
550 gosub 600
560 return
600 for vv = 0 to 19
610 moveto tx,ty+vv
620 lineto tx+19,ty+vv
630 next vv
640 return
700 rem GAME OVER
701 ss = 0
703 graphics color 0,0,0
705 score$ = "You made "+str$(mm)+" moves. Your score is "+str$(pp)+". You have "+str$(ss)+" seconds left. "
706 moveto 180,500 : graphics text score$
710 moveto 300,200
715 graphics color 100,0,0
720 game$ = "GAME OVER!"
730 graphics text game$
740 moveto 220,240
750 game$ = "Press Space to Play Again. Press X to quit"
755 graphics color 0,0,0
760 graphics text game$
770 get k$
780 if k$ = " " then run
790 if k$ = "x" then end
800 goto 770
No comments:
Post a Comment