Author Topic: Infamous Bouncing Ball(s) Type-in from book Working Graphics on cpc464/664  (Read 964 times)

0 Members and 1 Guest are viewing this topic.

Offline Z|G

  • CPC464
  • **
  • Posts: 22
  • Country: af
    • Awards
Currently reading, Working Graphics on the Amstrad cpc464-664 by Mike James - Kay Ewbank - S.M.Gee *highly recommended*

Which can be found http://www.cpcwiki.eu/index.php/Working_Graphics_on_the_Amstrad_CPC_464_%26_664


Thought this was a nice example.

Code: [Select]
20 MODE 1:BORDER 26   
30 PRINT"How many sprites ";
40 INPUT n%
50 CLS
60 GOSUB 1000
70 WHILE TIME-rtime<10000
80   GOSUB 2000
90   GOSUB 3000
100 t%=t%+1
110 WEND
120 END
1000 REM init
1010 DIM s$(n%),x(n%),y(n%),xv(n%),yv(n%)
1020 DIM xa(n%),ya(n%),px(n%),py(n%)
1030 FOR i%=1 TO n%
1040 s$(i%)=CHR$(231)
1050 x(i%)=INT(RND*37+2)
1060 y(i%)=INT(RND*22+2)
1070 px(i%)=x(i%)
1080 py(i%)=y(i%)
1090 xv(i%)=SGN(RND-0.5)
1100 yv(i%)=SGN(RND-0.5)
1110 xa(i%)=0
1120 ya(i%)=0
1130 NEXT i%
1140 rtime=TIME
1150 t%=0
1199 RETURN
2000 REM animate
2010 FOR i%=1 TO n%
2020 px(i%)=x(i%)
2030 py(i%)=y(i%)
2040 x(i%)=x(i%)+xv(i%)
2050 y(i%)=y(i%)+yv(i%)
2060 xa(i%)=0
2070 ya(i%)=0
2080 IF x(i%)<=1 THEN x(i%)=1:xa(i%)=-2*xv(i%)
2090 IF x(i%)>=40 THEN x(i%)=40:xa(i%)=-2*xv(i%)
2100 IF y(i%)<=1 THEN y(i%)=1:ya(i%)=-2*yv(i%)
2110 IF y(i%)>=25 THEN y(i%)=25:ya(i%)=-2*yv(i%)
2120 xv(i%)=xv(i%)+xa(i%)
2130 yv(i%)=yv(i%)+ya(i%)
2140 NEXT i%
2999 RETURN
3000 FOR i%=1 TO n%
3010  LOCATE px(i%),py(i%)
3020  PRINT SPC(1);
3030  LOCATE x(i%),y(i%)
3040  PRINT s$(i%);
3050 NEXT i%
3999 RETURN

Note: Just in case you do not know, You can cut'n'paste this into winape. right click on screen then file->paste
« Last Edit: 19:57, 31 May 21 by Z|G »
like
0
No reactions
1xCPC6128, 1xTandy Model 4, 1xC64 (IN BOX)

Offline Z|G

  • CPC464
  • **
  • Posts: 22
  • Country: af
    • Awards
Slowly going through the book, adding type-ins as I see fit.
Not sure why this scrolls right, to left and up one line. but still kinda nice effect. be way cooler to just scroll right to left..??





Code: [Select]
10 s%=0
20 d%=s% MOD 256
30 r%=13
40 GOSUB 1000
50 s%=s%+1
60 FOR j=1 TO 100:NEXT j
70 GOTO 20
80 GOTO 20
1000 OUT &BC00,r%
1010 OUT &BD00,d%
1020 RETURN
like
0
No reactions
1xCPC6128, 1xTandy Model 4, 1xC64 (IN BOX)

Offline Animalgril987

  • Supporter
  • CPC6128
  • *
  • Posts: 230
  • Country: gb
    • Awards
The OUT commands alter values in the CRTC register 13 (Display start Address)
like
0
No reactions

Offline Z|G

  • CPC464
  • **
  • Posts: 22
  • Country: af
    • Awards



Thought this was cool. Advanced peeps can skip it. (nothing new here)

Code: [Select]
10 REM EXAMPLE: ROTATE A SHAPE
20 REM ABOUT A POINT
30 MODE 1
40 DEG
50 orgX=300:orgY=200:theta=0
60 INPUT"Enter angle of rotation (degrees)";angle
70 number=INT(360/angle)
80 CLS
90 FOR N%= l TO number   
100 MOVE orgX,orgY
110 RESTORE
120 FOR K=1 TO 4
130 READ X,Y   
140 GOSUB 10000
150 DRAWR X,Y
160 NEXT 
170 theta=theta+angle
180 NEXT
190 END 
200 '
210 REM DATA FOR RECTANGLE SHAPE
220 DATA 150,0
230 DATA 0,75
240 DATA -150,0
250 DATA 0,-75
260 '
9999 REM ROTATION SUBROUTINE
10000 X1=X*COS(theta)-Y*SIN(theta)
10010 Y1=X*SIN(theta)+Y*COS(theta)
10020 X=X1:Y=Y1
10030 RETURN


Colour mapping? The illusion of movement?


Code: [Select]
10 MODE 1
20 GOSUB 1000
30 GOSUB 2000
40 END
1000 REM ? frame
1010 FOR x=1 TO 40 STEP 4
1020 LOCATE x,1
1030 PEN 1
1040 PRINT STRING$(2,143);
1050 PEN 2
1060 PRINT STRING$(2,143);
1070 LOCATE x,24
1080 PEN 1
1090 PRINT STRING$(2,143);     
1100 PEN 2
1110 PRINT STRING$(2,143);
1120 NEXT x
1130 FOR y=2 TO 23
1140 PEN y2 MOD 2+1
1150 LOCATE 1,y
1160 PRINT CHR$(143);
1170 LOCATE 40,y
1180 PEN (y2+1) MOD 2 +1
1190 PRINT CHR$(143);
1200 NEXT y
1210 RETURN
2000 INK 1,6,26
2010 INK 2,26,6
2020 SPEED INK 8,8 ' change these for different effects
2030 RETURN
« Last Edit: 21:43, 02 June 21 by Z|G »
like
0
No reactions
1xCPC6128, 1xTandy Model 4, 1xC64 (IN BOX)