starfieldpong.bmx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. Strict
  2. Const WIDTH=640,HEIGHT=480,DEPTH=32
  3. Const Star_Count = 1000 ' Stars Count
  4. Const MAX_SIZE = 12 ' Maximum starts
  5. Const MAX_ROTSPD# = 1.5 ' How much rotation goin on
  6. Global Delta_X#,Delta_Y#, Delta_Ang#=0 ,tick#=0
  7. Type TEntity
  8. Field x#,y#
  9. Method Update() Abstract
  10. EndType
  11. Type Star Extends TEntity
  12. Field s#
  13. Field size#
  14. Field col#,alp#
  15. Field rot#
  16. Field tcol[3]
  17. Field vtype
  18. Method Update()
  19. Local cs# , sn#
  20. Local tx# , ty#
  21. x:+ ( x-319.99999 ) / s
  22. y:+ ( y-239.99999 ) / s
  23. x=x-320
  24. y=y-240
  25. cs = Cos(Delta_Ang)
  26. sn = Sin(Delta_Ang)
  27. tx = x
  28. ty = y
  29. x = tx * cs - ty * sn
  30. y = tx * sn + ty * Cs
  31. x=x +320
  32. y=y +240
  33. 'Pitch Horiz and Verti
  34. x = x + Delta_X / s
  35. y = y + Delta_Y / s
  36. If x<0 Or x>WIDTH
  37. x=Rnd(WIDTH)
  38. alp=0
  39. EndIf
  40. If y<0 Or y>HEIGHT
  41. y=Rnd(HEIGHT)
  42. alp=0
  43. EndIf
  44. If alp<1
  45. alp = alp + .05
  46. EndIf
  47. SetBlend LIGHTBLEND
  48. SetRotation rot
  49. SetAlpha alp
  50. rot=rot+5
  51. SetColor tcol[0],tcol[1],tcol[2]
  52. Select vtype
  53. Case 0
  54. SetHandle size*.5,.5
  55. DrawRect x,y,size,1
  56. SetHandle .5,size*.5
  57. DrawRect x,y,1,size
  58. SetHandle 0,0
  59. Case 1
  60. SetHandle size*.5,size*.5
  61. DrawRect x,y,size,size
  62. SetHandle 0,0
  63. End Select
  64. End Method
  65. Function CreateStar:Star()
  66. Local s:Star = New Star
  67. Local r =Rand(128)
  68. s.x=Rnd(640)
  69. s.y=Rnd(480)
  70. s.s=Rnd(150,250)
  71. s.tcol=[r,r,r]
  72. s.size = Rnd(1,MAX_SIZE)
  73. s.vtype = Rnd(1)
  74. Return s
  75. EndFunction
  76. End Type
  77. Function UpdateEntities( list:TList )
  78. Delta_X = 400*Cos(tick)
  79. Delta_Y = 400*Sin(tick)
  80. Delta_Ang = MAX_ROTSPD*Cos( tick )
  81. tick=tick+.5
  82. Local c:TEntity
  83. For c=EachIn list
  84. c.Update
  85. Next
  86. End Function
  87. Graphics WIDTH,HEIGHT,DEPTH
  88. HideMouse
  89. Local StarList:TList = New TList
  90. Local a
  91. Local px1#=30,py1#
  92. Local px2#=WIDTH-30,py2#
  93. Local bx#=WIDTH/2, by#=HEIGHT/2
  94. Local bdx#=Rnd(-8,4)
  95. Local bdy#=3
  96. Local sc1,sc2
  97. For a= 0 To Star_Count-1
  98. StarList.AddLast( star.CreateStar() )
  99. Next
  100. While Not KeyHit( KEY_ESCAPE )
  101. Cls
  102. UpdateEntities StarList
  103. py1=MouseY()
  104. If py1<40 py1=40
  105. If py1>HEIGHT-40 py1=HEIGHT-40
  106. SetBlend SOLIDBLEND
  107. SetColor 255,0,0
  108. SetRotation 0
  109. SetHandle 5,40
  110. DrawRect px1,py1,10,80
  111. DrawRect px2,py2,10,80
  112. SetHandle 0,0
  113. SetColor 0,0,255
  114. SetHandle 2.5,2.5
  115. DrawRect bx,by,5,5
  116. SetHandle 0,0
  117. bx=bx+bdx
  118. by=by+bdy
  119. If by<3 bdy=-bdy
  120. If by>HEIGHT-3 bdy=-bdy
  121. 'check players paddle
  122. If bx<px1+10
  123. If by>py1-40 And by<py1+40
  124. bdx=-bdx*Rnd(1.1,1.2)
  125. bdy=-bdy+Rnd(-1,1)
  126. EndIf
  127. EndIf
  128. If bx>px2-10 And bx<px2+10
  129. If by>py2-40 And by<py2+40
  130. bdx=-bdx*Rnd(1.1,1.2)
  131. bdy=-bdy+Rnd(-1,1)
  132. EndIf
  133. EndIf
  134. If bx>WIDTH-3 Or bx<3
  135. bdx= Rnd(-8,8)
  136. bdy= Rnd(-8,8)
  137. If bx>Width-3
  138. sc1:+1
  139. Else
  140. sc2:+1
  141. EndIf
  142. bx=width/2
  143. by=height/2
  144. EndIf
  145. If py2<by
  146. If py2<HEIGHT-40
  147. py2=py2+3
  148. EndIf
  149. EndIf
  150. If py2>by
  151. If py2>40
  152. py2=py2-3
  153. EndIf
  154. EndIf
  155. DrawText sc1,width/2-40,0
  156. DrawText sc2,width/2+40,0
  157. Flip
  158. Wend