March 02, 2021, 02:33:54 PM

Author Topic: [bmx] Color Cycling and Procedural Critters by zoqfotpik [ 1+ years ago ]  (Read 626 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Color Cycling and Procedural Critters
Author : zoqfotpik
Posted : 1+ years ago

Description : There are two main features in this little demo.  One is a sort of fake color field effect.  Back in the old days, it was easier to directly address hardware to do things like cycle palettes.  Now we have to do it in software since we don't have hardware palette addressing.  One way is by using grabimage to clip chunks of color field and then draw them as sprites.  There are lots of other fun things you could do with this.

The other part of this demo is randomly generated enemies for a game like Galaxians or Space Invaders.


Code :
Code: BlitzMax
  1. Global GFXHEIGHT=480
  2. Global GFXWIDTH=640
  3. Global maxstars=1000
  4. Graphics GFXWIDTH, GFXHEIGHT
  5. SetMaskColor 255,255,0
  6. Global critterlist:TList=New TList
  7. Global critterlist2:TList = New TList
  8.  
  9. SetScale 2,2
  10. SetColor 0,0,0
  11. DrawRect 100,100,100,100
  12. SetColor 255,255,0
  13. DrawText "WILDLY INTERESTING COPPER EFFECTS",000,130
  14. myimage:TImage = CreateImage(1000,75,1)
  15. Global ticks
  16.  
  17. GrabImage myimage, 000,100
  18.  
  19. SetScale 1,1
  20. SetBlend solidblend
  21. For i = 1 To 10
  22. Local s:proceduralpic = New proceduralpic
  23. s.randcolors()
  24. s.initgrid()
  25. s.x = 68*i
  26. s.y = 120
  27. ListAddLast critterlist,s
  28. Next
  29.  
  30. For i = 1 To 10
  31. s:proceduralpic = New proceduralpic
  32. s.randcolors()
  33. s.initgrid()
  34. s.x = 68*i-64
  35. s.y = 240
  36. ListAddLast critterlist2,s
  37. Next
  38.  
  39. Type Tstar
  40. Field x,y,vx,vy,size:Int
  41. Field alpha:Float
  42. Method update()
  43.         x=x+vx
  44.         y = y + vy
  45.         If x < 0 x = GFXWIDTH
  46. End Method
  47. Method draw()
  48.         SetColor 255,255,255
  49.         SetAlpha alpha
  50.         Plot x,y
  51.         'DrawRect x,y, size,size
  52. End Method
  53. End Type
  54.  
  55. Type Tstarfield
  56. Global star_list:TList = New TList
  57. Function init(num_stars)
  58. For Local i = 1 To num_stars
  59.         s:Tstar = New Tstar
  60.         s.x = Rand(GFXWIDTH)
  61.         s.y = Rand(GFXHEIGHT)
  62.         s.vx = (Rand(5)+Rnd())*-1
  63.         s.vy = 0
  64.         s.size=Rand(3)
  65.         s.alpha = Rnd()+.5
  66.         ListAddLast(star_list,s)
  67. Next
  68. End Function
  69. Method update()
  70.         For s:tstar=EachIn star_list
  71.         s.update()
  72.         SetBlend alphablend
  73.         s.draw()
  74.         Next
  75. End Method
  76. End Type
  77.  
  78. Type Tcolor
  79.         Field r#, g#, b#
  80. End Type
  81.  
  82.        
  83. Global mystarfield:TStarfield = New TStarfield
  84. myStarfield.init(MAXSTARS)
  85.  
  86. While KeyDown(key_escape)=0
  87.  
  88. For Local thiscritter:proceduralpic = EachIn critterlist
  89. If thiscritter.x < -32
  90. thiscritter.x = 640
  91. thiscritter.randcolors()
  92. thiscritter.initgrid()
  93. EndIf
  94. Next
  95.  
  96. For thiscritter:proceduralpic = EachIn critterlist2
  97. If thiscritter.x > 640
  98. thiscritter.x = -32
  99. thiscritter.randcolors()
  100. thiscritter.initgrid()
  101. EndIf
  102. Next
  103.  
  104.  
  105. Cls
  106. ticks = ticks + 1
  107. SetScale 1,1
  108.  
  109. SetBlend solidblend
  110.  
  111.  
  112. copperblock (170,230,ticks)
  113.  
  114.  
  115. SetColor 255,255,255
  116.  
  117. SetBlend maskblend
  118. SetScale 2,2
  119. DrawImage myimage,0-Sin(ticks)*210-210,115
  120. SetScale 1,1
  121.  
  122. mystarfield.update()
  123. copperblock (300,400,ticks+20)
  124. copperblock 25,65,ticks-20
  125.  
  126. SetBlend solidblend
  127. For thiscritter:proceduralpic = EachIn critterlist
  128. thiscritter.x = thiscritter.x - 5
  129. thiscritter.y = 120+Sin(thiscritter.x*10)*3
  130. thiscritter.draw()
  131. Next
  132.  
  133. For thiscritter:proceduralpic = EachIn critterlist2
  134. thiscritter.x = thiscritter.x + 5
  135. thiscritter.y = 240+Sin(thiscritter.x*10)*3
  136. thiscritter.draw()
  137. Next
  138.  
  139. Flip
  140. Wend
  141.  
  142.  
  143. Function waveline(x1, x2, y, frequency#, amplitude#)
  144. For Local i = x1 To x2 Step 2
  145. myy=y+Sin(i*frequency)*amplitude
  146. DrawRect i, myy, 2,2
  147. Next
  148. End Function
  149.  
  150. Function copperblock(starty, endy,timestep)
  151. For i = starty To endy Step 2
  152. SetColor Abs(Sin(i*20+timestep*20)*255), Abs(Tan(i*5+timestep*2)*50),Abs(Cos(i*5+timestep*20)*255)
  153. waveline 0,640,i, Sin(timestep)*5, Cos(timestep)*20
  154. Next
  155. End Function
  156.  
  157. '---------------------------------
  158. Type color
  159. '---------------------------------
  160. Field r:Int, g:Int, b:Int
  161.  
  162. Method SetmyColor(myr,myg,myb)
  163.         r=myr
  164.         g=myg
  165.         b=myb
  166. End Method
  167.  
  168. Method randcolor()
  169.         r=Rand(100,255)
  170.         g=Rand(100,255)
  171.         b=Rand(100,255)
  172. End Method
  173.  
  174. Method thiscolor()
  175.         SetColor r,g,b
  176. End Method
  177. End Type
  178.  
  179.  
  180. '---------------------------------
  181. Type proccritter
  182. '---------------------------------
  183. Field x, y, vx, vy, angle
  184.  
  185. Field primarycolor:color=New color
  186. Field secondarycolor:color=New color
  187.  
  188. Method update()
  189. End Method
  190. Method draw()
  191. End Method
  192. End Type
  193.  
  194. '--------------------------------
  195. Type proceduralpic Extends proccritter
  196. '--------------------------------
  197. Field grid[8,8]
  198. Field myimage = CreateImage(32,32)
  199.  
  200. Method randcolors()
  201.         primarycolor.randcolor()
  202.         secondarycolor.randcolor()
  203. End Method
  204.  
  205. Method initgrid()
  206.  
  207.         For myx = 0 To 7
  208.         For myy = 0 To 7
  209.         grid[myx,myy]=0
  210.         Next
  211.         Next
  212.        
  213.        
  214.         For i = 1 To 25
  215.                 xrand = Rand(0,3)
  216.                 yrand = Rand(0,7)
  217.        
  218.                 celltype = Rand(2)
  219.                 grid[xrand,yrand]=celltype
  220.                 grid[7-xrand,yrand]=celltype
  221.                
  222.         Next
  223.         Cls
  224.        
  225.         For myy = 0 To 7
  226.                 For myx = 0 To 7
  227.                                                
  228.                         SetColor(0,0,0)
  229.                         If grid[myx, myy]=1
  230.                                 primarycolor.thiscolor()
  231.                         Else If grid [myx, myy]=2
  232.                                 secondarycolor.thiscolor()
  233.                         EndIf
  234.                        
  235.                         DrawRect (100+myx*4), (100+myy*4), 3, 3
  236.                 Next
  237.         Next
  238.         SetColor 255,255,255
  239.         GrabImage myimage,100,100
  240.        
  241. End Method
  242.  
  243. Method draw()
  244.         SetColor 150,150,150
  245.         DrawImage myimage, x+2,y+2
  246.         SetColor 255,255,255
  247.         DrawImage myimage, x, y
  248.        
  249. End Method
  250.  
  251. Method update()
  252. End Method
  253.  
  254. End Type


Comments :


virtlands(Posted 1+ years ago)

 Hi, zoqfotpik, these are quite nice.  I like the "Critters" one the best. The files are actually *.BMX files .Color Cycling and Procedural Critters :: <font class="tiny"> <a href="http://uploadingit.com/file/xnrveey7fjoc93mk/Color Cycling and Procedural Critters_3089.bmx" target="_blank">http://uploadingit.com/file/xnrveey7fjoc93mk/Color%20Cycling%20and%20Procedural%20Critters_3089.bmx[/url] </font>RTS Drag Effect :: <font class="tiny"> <a href="http://uploadingit.com/file/dmoxb7q8pplmotpz/RTS Drag Select_3088.bmx" target="_blank">http://uploadingit.com/file/dmoxb7q8pplmotpz/RTS%20Drag%20Select_3088.bmx[/url] </font>Image Recursion :: <font class="tiny"> <a href="http://uploadingit.com/file/kv2u1husmv3ulyob/Image Recursion_3087.bmx" target="_blank">http://uploadingit.com/file/kv2u1husmv3ulyob/Image%20Recursion_3087.bmx[/url] </font>[ shown are screenshots for Color Cycling and Procedural Critters & RTS Drag Effect ][img]imagizer.imageshack.us/a/img12/255/ggek.html">  [img]imagizer.imageshack.us/a/img802/8319/y4bf.html">


zoqfotpik(Posted 1+ years ago)

 Thank you.  I'd love to see some games written using the procedural critters, they are perfect for all sorts of old style retro games.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal