tilerocket.bmx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. ' Ugly -- just playing around!
  2. Global FlameList:TList = New TList
  3. Global ShotList:TList = New TList
  4. Type Flame
  5. Field x#, y#
  6. Field image
  7. Field ALPHA#
  8. Field scale#
  9. Field ys#
  10. End Type
  11. Type Shot
  12. Field x#, y#
  13. Field xs#, ys#
  14. Field ALPHA#
  15. End Type
  16. Graphics 640, 480
  17. AutoImageFlags MASKEDIMAGE
  18. SetClsColor 16, 32, 64
  19. SetMaskColor 255, 0, 255
  20. player = LoadImage ("gfx/boing.png")
  21. MidHandleImage player
  22. flm = LoadImage ("gfx/flame.png")
  23. MidHandleImage flm
  24. sky = LoadImage ("gfx/sky.png")
  25. grass = LoadImage ("gfx/grass.png")
  26. rock = LoadImage ("gfx/rock.png")
  27. water = LoadImage ("gfx/water.png")
  28. MidHandleImage grass
  29. MidHandleImage rock
  30. MidHandleImage water
  31. x# = GraphicsWidth () / 2
  32. y# = GraphicsHeight () / 2
  33. speed# = 0
  34. playerscale# = 0.25
  35. ' Map tiles...
  36. MAPXS = 50
  37. MAPYS = 30
  38. Local map [MAPXS, MAPYS]
  39. For mapx = 0 To MAPXS - 1
  40. For mapy = 0 To MAPYS - 1
  41. Select Rand (0, 3)
  42. Case 0
  43. image = 0
  44. Case 1
  45. image = grass
  46. Case 2
  47. image = rock
  48. Case 3
  49. image = water
  50. End Select
  51. map [mapx, mapy] = image
  52. Next
  53. Next
  54. GW2 = GraphicsWidth () / 2
  55. GH2 = GraphicsHeight () / 2
  56. ShotSpeed# = 4
  57. Repeat
  58. mx = MouseX ()
  59. my = MouseY ()
  60. Cls
  61. SetBlend SOLIDBLEND
  62. TileImage sky
  63. ang# = ATan2 (my - GH2, mx - GW2)
  64. x = x + Cos (ang) * speed
  65. y = y + Sin (ang) * speed
  66. If KeyHit (KEY_SPACE)
  67. s:Shot = New Shot
  68. s.x = (x + Cos (ang) * (ImageWidth (player) * playerscale) / 2)
  69. s.y = (y + Sin (ang) * (ImageHeight (player) * playerscale)/ 2)
  70. s.xs = Cos (ang) * (speed + ShotSpeed)
  71. s.ys = Sin (ang) * (speed + ShotSpeed)
  72. s.ALPHA = 1
  73. ShotList.AddLast s
  74. EndIf
  75. If MouseDown (1)
  76. If speed < 10 Then speed = speed + 0.1
  77. If Rand (1, 100) > (100 - speed * 2.5)
  78. f:Flame = New Flame
  79. f.x = Rand (1, 8) + (x - Cos (ang) * (ImageWidth (player) * playerscale) / 2)
  80. f.y = Rand (1, 8) + (y - Sin (ang) * (ImageHeight (player) * playerscale)/ 2)
  81. f.ys = 0
  82. f.image = flm
  83. f.ALPHA = 1
  84. f.scale = 0.5
  85. FlameList.AddLast f
  86. EndIf
  87. EndIf
  88. SetBlend MASKBLEND
  89. SetRotation 0
  90. SetScale 1, 1
  91. For mapx = 0 To MAPXS - 1
  92. For mapy = 0 To MAPYS - 1
  93. If map [mapx, mapy]
  94. DrawImage map [mapx, mapy], mapx * 128 - x, mapy * 128 - y
  95. EndIf
  96. Next
  97. Next
  98. SetColor 255, 255, 255
  99. SetBlend ALPHABLEND
  100. Local p:Flame
  101. For p=EachIn FlameList
  102. p.ys = p.ys - 0.05
  103. p.y = p.y + p.ys
  104. SetAlpha p.ALPHA
  105. SetScale p.scale, p.scale
  106. SetRotation 0
  107. DrawImage p.image, GW2 + p.x - x, GH2 + p.y - y
  108. p.ALPHA = p.ALPHA - 0.01
  109. p.scale = p.scale + Rnd (0.0025, 0.05)
  110. If p.ALPHA < 0
  111. FlameList.remove p
  112. EndIf
  113. Next
  114. SetColor 255, 255, 0
  115. For s=EachIn ShotList
  116. s.x = s.x + s.xs
  117. s.y = s.y + s.ys
  118. SetAlpha s.ALPHA
  119. SetRotation 0
  120. SetScale 1, 1
  121. DrawRect GW2 + s.x - x, GH2 + s.y - y, 8, 8
  122. s.ALPHA = s.ALPHA - 0.01
  123. If s.ALPHA < 0
  124. ShotList.remove s
  125. EndIf
  126. Next
  127. SetBlend ALPHABLEND
  128. SetAlpha 0.25
  129. SetScale 0.25, 0.25
  130. SetColor 0, 0, 0
  131. sp2 = speed * 2
  132. DrawPointedImage player, GW2 + sp2, GH2 + sp2, mx + sp2, my + sp2
  133. SetColor 255, 255, 255
  134. SetBlend MASKBLEND
  135. SetScale 0.25, 0.25
  136. SetAlpha 1
  137. DrawPointedImage player, GW2, GH2, mx, my
  138. speed = speed - 0.075; If speed < 0 Then speed = 0
  139. SetRotation 0
  140. SetScale 1, 1
  141. SetColor 0, 0, 0
  142. DrawText "Hold left mouse button to move and hit space to fire...", 21, 21
  143. SetColor 255, 255, 255
  144. DrawText "Hold left mouse button to move and hit space to fire...", 20, 20
  145. Flip
  146. Until KeyHit (KEY_ESCAPE)
  147. End
  148. ' Assumes image is oriented 'upwards' by default -- fiddle with
  149. ' the "+ 90" part on the first line if not!
  150. Function DrawPointedImage (image, x#, y#, targetx#, targety# )
  151. ang# = ATan2 (targety - y, targetx - x) + 90
  152. SetRotation ang
  153. DrawImage image, x, y
  154. End Function