Ein Beispiel, dass ich für einen Thread schrieb, es aber den Interessierten dieser Welt nicht vorenthalten möchte
Es geht nur darum, einen Punkt zu zeichnen, der eine Leuchtspur hinter sich herzieht.
Das ganze ist aus den nativen Zeichenroutinen Blitzbasics zusammengebaut, daher wohl vor allem bei großen Mengen solcher Punkte und natürlich vor allem bei vielen, langen Leuchtspuren nicht sehr perfomant. Außerdem ist es hässlich, zeigt aber wohl doch, wie das soetwas rein methodisch aufgebaut sein kann.
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN]
Type particle
Field x# Field y# Field direction Field speed# Field r Field g Field b Field rFade Field gFade Field bFade End Type
Type shot
Field particle.particle Field lastParticle End Type
Const key_esc = 1
Const mouse_lb = 1
Const screenmode_fullscreen = 1 Const screenmode_windowed = 2
Const screen_width = 800 Const screen_height = 600
Const screen_depth = 32
Const screen_mode = screenmode_windowed
Const shot_speed# = 4
Const shot_r = 255 Const shot_g = 255 Const shot_b = 0
Const shot_rFade = 0 Const shot_gFade = 0 Const shot_bFade = 0
Const shot_particle_timer = 1
Const shot_particle_r = 200 Const shot_particle_g = 200 Const shot_particle_b = 200
Const shot_particle_rFade = 4 Const shot_particle_gFade = 4 Const shot_particle_bFade = 4
Graphics screen_width,screen_height,screen_depth,screen_mode SetBuffer BackBuffer()
Local timer
timer = CreateTimer( 100 )
Local mouse_x,mouse_y
While Not KeyHit( key_esc )
Cls WaitTimer( timer ) mouse_x = MouseX() mouse_y = MouseY() If MouseHit( mouse_lb ) emitShot( screen_width / 2,screen_height / 2,( -1 * ( ATan2( mouse_x - ( screen_width / 2 ), mouse_y - ( screen_height / 2 ) ) + 360 ) Mod 360 ) + 90 ) EndIf handleShots() handleParticles() Flip 0
Wend
End
Function emitParticle.particle( x,y,direction,speed#,r,g,b,rFade = 0,gFade = 0,bFade = 0 )
Local tParticle.particle tParticle = New particle tParticle\x = Float( x ) tParticle\y = Float( y ) tParticle\direction = direction tParticle\speed = speed tParticle\r = r tParticle\g = g tParticle\b = b tParticle\rFade = rFade tParticle\gFade = gFade tParticle\bFade = bFade Return tParticle End Function
Function emitShot( x,y,direction )
Local tShot.shot tShot = New shot tShot\particle = emitParticle( x,y,direction,shot_speed,shot_r,shot_g,shot_b,shot_rFade,shot_gFade,shot_bFade ) tShot\lastParticle = 0 End Function
Function handleShots()
Local tShot.shot For tShot.shot = Each shot If tShot\particle <> Null Then tShot\lastParticle = tShot\lastParticle + 1 If tShot\lastParticle >= shot_particle_timer Then tShot\lastParticle = 0 emitParticle( tShot\particle\x + Cos( tShot\particle\direction ) * ( -1 * tShot\particle\speed ),tShot\particle\y + Sin( tShot\particle\direction ) * ( -1 * tShot\particle\speed ),0,0,shot_particle_r,shot_particle_g,shot_particle_b,shot_particle_rFade,shot_particle_gFade,shot_particle_bFade ) EndIf
Else Delete tShot EndIf Next
End Function
Function handleParticles()
Local tParticle.particle Local curBuffer curBuffer = GraphicsBuffer() LockBuffer curBuffer For tParticle = Each particle tParticle\x = tParticle\x + Cos( tParticle\direction ) * tParticle\speed tParticle\y = tParticle\y + Sin( tParticle\direction ) * tParticle\speed tParticle\r = tParticle\r - tParticle\rFade tParticle\g = tParticle\g - tParticle\gFade tParticle\b = tParticle\b - tParticle\bFade If tParticle\x >= 0 And tParticle\x < screen_width And tParticle\y >= 0 And tParticle\y < screen_height And ( tParticle\r > 0 Or tParticle\b > 0 Or tParticleg > 0 ) And ( tParticle\r < 255 Or tParticle\g < 255 Or tParticle\b < 255 ) Then WritePixelFast tParticle\x,tParticle\y,argb( tParticle\r,tParticle\g,tParticle\b ),curBuffer Else Delete tParticle EndIf Next UnlockBuffer curBuffer End Function Function argb( r,g,b )
Return 255 * $1000000 + r * $10000 + g * $100 + b End Function
walski
|