mirror of
https://github.com/inexorabletash/jsbasic.git
synced 2024-12-04 11:49:51 +00:00
73 lines
2.3 KiB
Plaintext
73 lines
2.3 KiB
Plaintext
10 rem Asteroids Ship Demo
|
|
20 rem Double Buffering Demo by Golden Child
|
|
|
|
500 dim a(10,4)
|
|
510 read p
|
|
520 for i = 1 to p:read x,y:a(i,1)=x:a(i,2)=y:? p,i,a(p,1),a(p,2):next
|
|
530 hgr :hcolor=3 : VTAB 23: PRINT "Double Buffering Demo:"
|
|
531 print "END/PAGE DOWN to turn":PRINT "HOME/PAGE UP for thrust"
|
|
532 print "click on window to set input focus";
|
|
533 x0=139:y0=79:gosub 5000:goto 4000
|
|
|
|
540 rem draw ship
|
|
590 x2=-999 : rem dont draw first segment
|
|
601 sz=2:for i = 1 to p:x=a(i,1)*sz:y=a(i,2)*sz:x1=x0+x*cos(a0)-y*sin(a0):y1=y0+y*cos(a0)+x*sin(a0)
|
|
610 if x2<>-999 then if x1 > 0 and x1 < 279 and x2 > 0 and x2< 279 and y1 > 0 and y1 < 191 and y2 > 0 and y2<191 then c=3:gosub 5100
|
|
615 x2=x1:y2=y1
|
|
620 next
|
|
|
|
621 g=0.04 :yv=yv+g : rem gravity
|
|
622 fr=0.01 : rem friction
|
|
623 if sqr(xv^2 + yv^2) < fr then xv=0 : yv=0: goto 630
|
|
624 xd = xv / sqr(xv^2 + yv^2):yd=yv / sqr(xv^2 + yv^2)
|
|
625 xv = xv - xd * fr : yv=yv - yd * fr
|
|
630 return
|
|
|
|
1000 data 5,3,0,-2,2,0,0,-2,-2,3,0,-999
|
|
|
|
4000 co=3:gosub 540:gosub 5500
|
|
4001 t=3.14/24
|
|
4010 if peek(49248)>=128 then a0=a0+t
|
|
4020 if peek(49250)>=128 then a0=a0-t
|
|
4021 if peek(49249)>=128 then xv=xv+0.5*cos(a0):yv=yv+0.5*sin(a0)
|
|
4022 if peek(49251)>=128 then xv=xv-0.5*cos(a0):yv=yv-0.5*sin(a0)
|
|
4023 if x0 < 20 then x0=280-20
|
|
4024 if x0 > 280-20 then x0=20
|
|
4025 if y0<20 then y0=160-20
|
|
4026 if y0>160-20 then y0=20
|
|
4030 x0=x0+xv : y0=y0+yv
|
|
4040 rem ? xv,yv
|
|
4050 goto 4000
|
|
|
|
|
|
|
|
5000 rem init display list : rem SC = screen to draw
|
|
5001 IF NOT (dk) then dim dl(2,100,5) : dk=1
|
|
5002 hgr2:hgr
|
|
5003 SC=0 : DL(0,0,0)=0 : DL(1,0,0)=0 :gosub 5500: rem DL(X,0,0) = NUM OF POINTS
|
|
5004 return
|
|
|
|
5100 rem draw line on other screen
|
|
5110 poke 230,(SC+1) * 32
|
|
5111 if not(x1>=0 and x1 <=279 and x2 >=0 and x2<=279 and y1>=0 and y1 <=159 and y2>=0 and y2<=159) then return
|
|
5120 SP = DL(SC,0,0) + 1 : DL(SC,0,0)=SP : rem ? sp
|
|
5130 DL(SC,SP,0)=CO
|
|
5131 DL(SC,SP,1)=X1
|
|
5132 DL(SC,SP,2)=Y1
|
|
5133 DL(SC,SP,3)=X2
|
|
5134 DL(SC,SP,4)=Y2
|
|
5140 HCOLOR=CO : HPLOT X1,Y1 TO X2,Y2
|
|
5190 RETURN
|
|
|
|
5400 rem erase lines
|
|
5410 for SP = 1 TO DL(SC,0,0) : HCOLOR=0
|
|
5411 HPLOT DL(SC,SP,1),DL(SC,SP,2) TO DL(SC,SP,3),DL(SC,SP,4) : NEXT
|
|
5412 DL(SC,0,0)=0 : rem clear the list after erasing
|
|
5420 RETURN
|
|
|
|
5500 rem swap screens
|
|
5510 SC = NOT SC
|
|
5511 POKE 49236+(NOT SC),0 : rem select visible page that we're not drawing to
|
|
5515 poke 230,32*(sc+1):gosub 5400 : rem switch drawing page and erase lines
|
|
5520 RETURN
|