Friday, December 13, 2013

Petit Computer Journal #29

A Simple Sprite Game

I've always said that writing a computer program is pretty easy if you know what you're doing. The question is, how easy can it be? I've written a version of Snakes and Ladders game in under 10 minutes. How quickly and easily can I write a sprite based game? Certainly, not too difficult.

I'm curious as to just how easy it is to write one. Certainly, there is the control. I settled for Up-Down-Fire, which is a variation of Left-Right-Fire. I was hoping for a single screen challenge program, and I managed to do it. However, it isn't fun at all. Also, it turns out that I don't need the Up-Down movement at all. Just sit there and hit the fire button!

  1. CLS:Y=0:A=256:C=128:S=0
  2. SPSET 1,96,0,0,0,0:T=3600
  3. SPSET 2,40,0,0,0,0
  4. SPOFS 2,-16,0,0:SPANIM 2,2,15
  5. SPSET 10,13,3,0,0,0
  6. @LOOP
  7. T=T-1:IF T<0 THEN END
  8. VSYNC 1:B=BUTTON(0):DX=0:DY=0
  9. LOCATE 0,0:?"S=";S,"T=";T;" "
  10. IF SPHIT(10) THEN S=S+1:BEEP
  12. IF (B AND 16) THEN GOSUB @FR
  13. IF !(B AND 3) GOTO @LOOP
  14. DY=(B AND 3)*2-3
  15. Y=Y+DY:IF Y<0 THEN Y=Y+192
  16. Y=Y%192:SPOFS 1,0,Y,0
  17. GOTO @LOOP
  18. @FR
  19. SPOFS 2,0,Y,0:SPOFS 2,A,Y,C/2
  20. RETURN
  21. @MM
  22. SPOFS 10,99+RND(99),-20,0
  23. SPOFS 10,99+RND(99),2*C,C
  24. RETURN

It's all very well and good for a single screen challenge, but I was curious as to how much better it would be, had it been a better fleshed out game. So, forget about the single screen challenge and just do better!

  1. CLS:Y=0:A=256:C=128:S=0
  2. BGFILL 0,0,0,63,63,9,8,0,0
  3. FOR I=1 TO 32
  4. BGPUT 0,RND(64),RND(64),32,8,0,0
  5. NEXT
  6. SPSET 1,96,0,0,0,0
  7. SPSET 2,40,0,0,0,0
  8. SPOFS 2,-16,0,0:SPANIM 2,2,15
  9. FOR I=10 TO 70
  10. SPSET I,13,3,0,0,0
  11. SPOFS I,99,-50,0
  12. NEXT
  13. @INIT
  14. BGMPLAY 23
  15. T=10800:S=0
  16. @LOOP
  18. IF !BGCHK(0) THEN BGOFS 0,RND(512),RND(512),360
  19. T=T-1:M=FLOOR(T/180):IF T<0 THEN GOTO @END
  20. VSYNC 1:B=BUTTON(0):DX=0:DY=0
  21. LOCATE 0,0:?"$=";S,"TIME=";M;"   ","HI $=";HC;"   "
  22. FOR I=10 TO 70-M
  25. NEXT
  26. IF (B AND 16) THEN GOSUB @FR
  27. IF !(B AND 3) GOTO @LOOP
  28. DY=(B AND 3)*2-3
  29. Y=Y+DY:IF Y<0 THEN Y=Y+192
  30. Y=Y%192:SPOFS 1,0,Y,0
  31. GOTO @LOOP
  32. @FR
  33. SPOFS 2,0,Y,0:SPOFS 2,A,Y,C/2
  34. RETURN
  35. @MM
  36. SPCHR I,13
  37. SPOFS I,99+RND(99),-20+256*RND(2),0
  38. SPOFS I,99+RND(99),-20+256*RND(2),99+RND(C)
  39. RETURN
  40. @HIT
  41. SPCHR I,248
  42. SPANIM I,8,6,1
  43. RETURN
  44. @END
  45. BGMPLAY 6
  46. WAIT 360
  47. FOR I=0 TO 16:I=BUTTON(0):NEXT
  48. GOTO @INIT

So far, I'm using standard graphics. It's very convenient that the graphics are all built-in. However, there is always a way to have custom made graphic. I won't list the source code, but check out the QR made for this game.

No comments:

Post a Comment