Friday, September 13, 2013

Petit Computer Journal #17

WITCH

I wrote WITCH to showcase the SPRITE capabilities of Petit Computer. There are lots of people who doesn't know how to use sprites. In fact, Petit Computer sprites are so powerful, you can easily replicate old games.

So here is the WITCH program that is purposely SPRITE heavy. There are certain techniques where I could have done it traditionally, but chose to implement it using a sprite instead. Notably, there is a TIMER sprite, where the sole purpose is to spread the bullets so that they don't trip over one another.

I chose the firing of the fireball using stylus because somebody was asking the way to do it. He was wondering about how to fire the bullet in the direction of the stylus, without stopping at the point of the stylus. In my solution, I also took care of the speed of the bullets. Done carelessly, the bullets may have different speed.

'THE WITCH AND THE UNDEAD
'A SPRITE EXERCISE

'1. WITCH
'2. FIREBALL
'3. UNDEAD FALLING
'4. UNDEAD WALKING
'5. UNDEAD HIT
'6. WITCH HIT
'7. EXTRAS

@INIT
H=100:'HEALTH
NUMZ=1:'CURRENT NUM OF ENEMY
MAXZ=20:'MAXNUM OF ENEMY
SCORE=0

ACLS
PNLTYPE "OFF"
SPSET 1,108,1,0,0,0:'WITCH
SPCOL 1,0,0,16,16,FALSE
SPOFS 1,120,170

'BULLET
FOR I=2 TO 9
SPSET I,142,0,0,0,0
SPANIM I,2,10,0
SPOFS I,30,180,I*90
SPCOL I,0,0,16,16,FALSE,2
NEXT

'CURSOR
SPSET 10,253,1,0,0,0
SPCOL 10,0,0,16,16,FALSE,0

'TIMER
SPSET 11,3,1,0,0,0
SPCOL 11,0,0,16,16,FALSE,0
SPOFS 11,200,200

'UNDEAD
FOR I=20 TO 20+MAXZ
SPSET I,130,RND(16),0,0,0
SPANIM I,2,20,0
SPOFS I,200,-300
SPCOL I,0,0,16,16,FALSE,1+2
NEXT



@MAINLOOP
VSYNC 1:X=TCHX:Y=TCHY:S=TCHST:B=BUTTON(0)
LOCATE 0,0:?"HEALTH=";H;"   ":?"SCORE=";SCORE
SPOFS 10,X,Y
GOSUB @FIREBALL
GOSUB @ENEMY

IF SPHIT(1) THEN H=H-1:BEEP 37
IF B AND 4 THEN DX=-8: GOSUB @MOVE
IF B AND 8 THEN DX=8:GOSUB @MOVE
'IF B AND 16 GOTO @END
IF H<=0 GOTO @END
GOTO @MAINLOOP

@MOVE
SPREAD(1),SX,SY
IF SX+DX>0 AND SX+DX<240 THEN SPOFS 1,SX+DX,SY,8
RETURN

@ENEMY
SPREAD(1),SX,SY
FOR I=20 TO 20+NUMZ
SPREAD(I),ZX,ZY
IF (1 AND SPCHK(i)) GOTO @ENEMY2
IF ZY>SY THEN SPOFS I,SX,SY,SPEED:GOTO @ENEMY2
SPEED=(50000-SCORE)/100:IF SPEED<60 THEN SPEED=60
SPOFS I,RND(255),0
SPOFS I,RND(255),SY+1,SPEED
@ENEMY2
NEXT
RETURN

@FIREBALL
FOR I=2 TO 9
IF SPHIT(I) THEN GOSUB @HITZ
IF !(1 AND SPCHK(I)) THEN SPOFS I,I*18,300
IF S==1 AND !(1 AND SPCHK(11) THEN @SHOOT
NEXT
RETURN

@HITZ
BEEP 14
SPOFS I,80,0
SPOFS SPHITNO,30,-150
SCORE=SCORE+FLOOR(SQR((SPHITX-SX)*(SPHITX-SX)+(SPHITY-SY)*(SPHITY-SY))/3)
NUMZ=FLOOR(SCORE/1000)+1
IF NUMZ>MAXZ THEN NUMZ=MAXZ
RETURN

@SHOOT
CB=((CB+1)%8:CBS=CB+2
IF (1 AND SPCHK(CBS)) GOTO @SHOOT2
BEEP 10:SCORE=SCORE-1:IF SCORE<0 THEN SCORE=0
SPREAD(1),SX,SY
A=ATAN((X-SX),(Y-SY))
SPOFS CBS,SX,SY
SPOFS CBS,SX+300*SIN(A),SY+300*COS(A),150
SPOFS 11,250,250,20
@SHOOT2
RETURN

@END
CLS:?"GAMEOVER"
BGMPLAY 6
WAIT 60
END

No comments:

Post a Comment