I did say stick man would be back!
I have had a game idea for a while which would be a good fit for the stickman from Lucky Egg. It's called 'Cash Grab' and some of the code and the GFX could be reused but I needed up and down movement for the game. Once I had this coded I realised this could be a useful little example for someone learning Dragon/Coco basic so here it is. Oh yes, I wanted it to have joystick control too so I added this and backported it to Lucky Egg too.
Code is below but you can also find it on Github.
In the next blog post, we'll take a look at interacting with objects on screen.
10 DIMH(16),I(16),A(1),B(1),X,Y,V,W 20 FORI=0TO15:H(I)=I*16:NEXT 30 REM SET UP GRAPHICS 40 PMODE0,1:PCLS:SCREEN1,1 50 GET(0,0)-(15,15),B 60 FORL=0TO7:READD:POKE1536+(L*16),D:NEXT 70 GET(0,0)-(15,15),A 80 REM SET STARTING POSITION 90 X=8:Y=5:V=1:W=1 100 PCLS:GOTO210 110 REM GAME LOOP 120 A$=INKEY$:IFA$="P"THENX=X+1ELSEIFA$="O"THENX=X-1 130 IFA$="Q"THENY=Y-1ELSEIFA$="A"THENY=Y+1 140 J=JOYSTK(0):IFJ=0THENX=X-1ELSEIFJ=63THENX=X+1 150 J=JOYSTK(1):IFJ=0THENY=Y-1ELSEIFJ=63THENY=Y+1 160 IFX<0THENX=0 170 IFX>15THENX=15 180 IFY<1THENY=1 190 IFY>11THENY=11 200 IF X=V AND Y=W THEN 120 210 PUT(H(X),H(Y))-(H(X)+15,H(Y)+15),A,PSET:PUT(H(V),H(W))-(H(V)+15,H(W)+15),B,PSET:V=X:W=Y 220 GOTO 120 : REM CONTINUE LOOP 230 REM STICK MAN 240 DATA24,60,24,126,24,24,36,66 250 REM
No comments:
Post a Comment