firepaint.bmx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. Rem
  2. Firepaint demo:
  3. Hold down mouse button to emit *FIRE*!
  4. EndRem
  5. Strict
  6. 'For minimal build...
  7. Rem
  8. Framework BRL.D3D7Max2D
  9. Import BRL.Basic
  10. Import BRL.System
  11. Import BRL.PNGLoader
  12. Import BRL.FreeAudioAudio
  13. Import BRL.WAVLoader
  14. End Rem
  15. Import "color.bmx"
  16. Incbin "stars.png"
  17. Incbin "player.png"
  18. Incbin "bullet.png"
  19. Incbin "shoot.wav"
  20. Const WIDTH=640,HEIGHT=480
  21. Const DEPTH=32,HERTZ=60
  22. Const GRAVITY#=.15,SPARKS_PER_FRAME=55
  23. Global sparks:TList=New TList
  24. Global bullets:TList=New TList
  25. Type TEntity
  26. Field link:TLink
  27. Method remove()
  28. link.remove
  29. End Method
  30. Method AddLast( list:TList )
  31. link=list.AddLast( Self )
  32. End Method
  33. Method Update() Abstract
  34. End Type
  35. Type TSpark Extends TEntity
  36. Field x#,y#,xs#,ys#
  37. Field color[3],rot#,rots#
  38. Method Update()
  39. ys:+GRAVITY
  40. x:+xs
  41. y:+ys
  42. If x<0 Or x>=WIDTH Or y>=HEIGHT
  43. remove
  44. Return
  45. EndIf
  46. rot=rot+rots
  47. SetHandle 8,8
  48. SetRotation rot#
  49. SetAlpha 1-y/HEIGHT
  50. SetColor color[0],color[1],color[2]
  51. DrawRect x,y,17,17
  52. SetHandle 0,0
  53. End Method
  54. Function CreateSpark:TSpark( x#,y#,color[] )
  55. Local spark:TSpark=New TSpark
  56. Local an#=Rnd(360),sp#=Rnd(3,5)
  57. spark.x=x
  58. spark.y=y
  59. spark.xs=Cos(an)*sp
  60. spark.ys=Sin(an)*sp
  61. spark.rots=Rnd(-15,15)
  62. spark.color=color
  63. spark.AddLast sparks
  64. Return spark
  65. End Function
  66. End Type
  67. Type TBullet Extends TEntity
  68. Field x#,y#,ys#
  69. Field rot#,img:TImage
  70. Method Update()
  71. ys:-.01
  72. y:+ys
  73. If y<0
  74. remove
  75. Return
  76. EndIf
  77. rot:+3
  78. SetRotation rot
  79. DrawImage img,x,y
  80. End Method
  81. Function CreateBullet:TBullet( x#,y#,img:TImage )
  82. Local bullet:TBullet=New TBullet
  83. bullet.x=x
  84. bullet.y=y
  85. bullet.ys=-1
  86. bullet.img=img
  87. bullet.AddLast bullets
  88. Return bullet
  89. End Function
  90. End Type
  91. Function UpdateEntities( list:TList )
  92. For Local entity:TEntity=EachIn list
  93. entity.Update
  94. Next
  95. End Function
  96. Graphics WIDTH,HEIGHT,DEPTH,HERTZ
  97. AutoMidHandle True
  98. Local fire:TSound=LoadSound( "incbin::shoot.wav" )
  99. Local dude:TImage=LoadImage( "incbin::player.png" ),dude_x=WIDTH/2,dude_y=HEIGHT-30
  100. Local bull:TImage=LoadImage( "incbin::bullet.png" ),bull_x,bull_y
  101. Local stars:TImage=LoadImage( "incbin::stars.png" ),stars_x,stars_y
  102. Local show_debug,color_rot#
  103. While Not KeyHit( KEY_ESCAPE )
  104. Cls
  105. stars_y:+1
  106. SetBlend MASKBLEND
  107. TileImage stars,stars_x,stars_y
  108. TileImage stars,stars_x+7,stars_y*2
  109. TileImage stars,stars_x+7,stars_y*3
  110. If KeyDown( KEY_LEFT )
  111. dude_x:-5
  112. Else If KeyDown( KEY_RIGHT )
  113. dude_x:+5
  114. EndIf
  115. SetBlend MASKBLEND
  116. DrawImage dude,dude_x,dude_y
  117. If KeyHit( KEY_SPACE )
  118. PlaySound fire
  119. TBullet.CreateBullet dude_x,dude_y-16,bull
  120. EndIf
  121. If MouseDown(1)
  122. color_rot:+1.5
  123. color_rot:Mod 360
  124. Local color:TRGBColor=HSVColor( color_rot,1,1 ).RGBColor()
  125. Local rgb[]=[Int(color.Red()*255),Int(color.Green()*255),Int(color.Blue()*255)]
  126. For Local k=1 To SPARKS_PER_FRAME
  127. TSpark.CreateSpark MouseX(),MouseY(),rgb
  128. Next
  129. EndIf
  130. SetBlend MASKBLEND
  131. UpdateEntities bullets
  132. SetRotation 0
  133. SetBlend LIGHTBLEND
  134. UpdateEntities sparks
  135. SetAlpha 1
  136. SetRotation 0
  137. SetColor 255,255,255
  138. If KeyHit( Asc("D") ) show_debug=1-show_debug
  139. If show_debug
  140. DrawText "MemAlloced="+GCMemAlloced(),0,0
  141. EndIf
  142. Flip
  143. Wend