2D Starfield Warp von walski |
In der Hoffnung, dass es das diesmal hier noch nicht gab: Inspieriert von WarBlades (nem lustigen 2D Freeware Shooter ala R-Type) hab ich mich mal an ein "warpbares" Starfield gemacht: [code:1:f96892a65f] ;A little warp effekt :) Const ScreenW=1024,ScreenH=768 Const StarCount=500 Type Stars Field x,y Field Intensity# Field WarpStar Field TookOut End Type SeedRnd MilliSecs() For i=1 To StarCount Star.Stars = New Stars Starx=Rand(0,ScreenW) Stary=Rand(0,ScreenH) StarIntensity=Rnd(0.0001,1) If i<=200 Then StarWarpStar=1 Next Graphics ScreenW,ScreenH,32,1 SetBuffer BackBuffer() timer=CreateTimer(100) Trail#=1 Speed# = 5 WarpPhase = 0 While Not KeyDown(1) WaitTimer timer Cls LockBuffer BackBuffer() For Star = Each Stars If WarpPhase<>0 And (Not StarWarpStar=1) Then Goto NStar For i=1 To Trail If Stary>i Then Light=Ceil(255*StarIntensity)/(i/((Trail/10)+1)) WritePixelFast Starx,Stary-i,RGB2Hex(Light,Light,Light) EndIf Next .NStar Stary=Stary+Ceil(Speed*StarIntensity) If Stary>ScreenH Then stary=1 starx=Rand(0,ScreenW) EndIf Next If KeyHit(57) And (Not WarpPhase) Then WarpPhase=1 If WarpPhase If WarpPhase>150 And WarpPhase < 300 Trail=Trail+.8 Speed=Speed +.2 ElseIf WarpPhase>650 And WarpPhase <800 Trail=Trail-.8 Speed=Speed-.2 EndIf If WarpPhase < 300 Then i=0 For Star = Each Stars If StarWarpStar=0 And StarTookOut=0 Then Light=255 WritePixelFast Starx,Stary,RGB2Hex(Light,Light,Light) StarTookOut=1 i=i+1 EndIf If i>Ceil(StarCount/300) Then Exit Next i=1 For Star = Each Stars If StarWarpStar=0 And StarTookOut=0 Then Light=Ceil(255*StarIntensity)/(i/((Trail/10)+1)) WritePixelFast Starx,Stary-i,RGB2Hex(Light,Light,Light) EndIf Next EndIf If WarpPhase > 800 Then i=0 For Star = Each Stars If StarWarpStar=0 And StarTookOut=1 Then Light=255 WritePixelFast Starx,Stary,RGB2Hex(Light,Light,Light) StarTookOut=0 i=i+1 EndIf If i>Ceil(StarCount/300) Then Exit Next i=1 For Star = Each Stars If StarWarpStar=0 And StarTookOut=0 Then Light=Ceil(255*StarIntensity)/(i/((Trail/10)+1)) WritePixelFast Starx,Stary-i,RGB2Hex(Light,Light,Light) EndIf Next EndIf WarpPhase=WarpPhase+1 If WarpPhase >1099 Then WarpPhase =0 For Star = Each Stars StarTookOut=0 Next EndIf EndIf UnlockBuffer BackBuffer() Flip Wend Function RGB2Hex(R,G,B) Return 255*$1000000 + r*$10000 + g*$100 + b End Function [/code:1:f96892a65f] Einziges Problem noch zur Zeit: Ich will aus Performance-Gründen nur 200 Sterne "warpen" und der Übergang (im Moment verschwinden die überzähligen Sterne nach und nach und kommen am Ende genauso wieder) ist wirklich hässlich! Ach ja, mit SPACE warpt man. Have Fun walski |
von ??? |
Gefällt mir :) |
von walski |
So, hier mal ein abgeänderter Code. Diesmal werden die überflüssigen Sterne einfach weiterhin gezeichnet, allerdings ohne den Schweif. Ich hoffe das sieht besser aus. [code:1:37a1c2ab37] ;A little warp effekt :) Const ScreenW=1024,ScreenH=768 Const StarCount=500 Type Stars Field x,y Field Intensity# Field WarpStar Field TookOut End Type SeedRnd MilliSecs() For i=1 To StarCount Star.Stars = New Stars Starx=Rand(0,ScreenW) Stary=Rand(0,ScreenH) StarIntensity=Rnd(0.0001,1) If i<=200 Then StarWarpStar=1 Next Graphics ScreenW,ScreenH,32,1 SetBuffer BackBuffer() timer=CreateTimer(100) Trail#=1 Speed# = 5 NWarpSpeed=5 WarpPhase = 0 While Not KeyDown(1) WaitTimer timer Cls LockBuffer BackBuffer() For Star = Each Stars If WarpPhase<>0 And (Not StarWarpStar=1) Then Light=Ceil(255*StarIntensity) WritePixelFast Starx,Stary,RGB2Hex(Light,Light,Light) Stary=Stary+Ceil(NWarpSpeed*StarIntensity) Else For i=1 To Trail If Stary>i Then Light=Ceil(255*StarIntensity)/(i/((Trail/10)+1)) WritePixelFast Starx,Stary-i,RGB2Hex(Light,Light,Light) EndIf Next Stary=Stary+Ceil(Speed*StarIntensity) EndIf If Stary>ScreenH Then stary=1 starx=Rand(0,ScreenW) EndIf Next If KeyHit(57) And (Not WarpPhase) Then WarpPhase=1 If WarpPhase If WarpPhase<150 Trail=Trail+.8 Speed=Speed +.2 ElseIf WarpPhase>300 Trail=Trail-.8 Speed=Speed-.2 EndIf WarpPhase=WarpPhase+1 If WarpPhase >449 Then WarpPhase =0 For Star = Each Stars StarTookOut=0 Next EndIf EndIf UnlockBuffer BackBuffer() Flip Wend Function RGB2Hex(R,G,B) Return 255*$1000000 + r*$10000 + g*$100 + b End Function [/code:1:37a1c2ab37] walski |
von ??? |
sieht auf jeden fall besser aus... sonst mach es doch so, das nur die hintere schicht nicht gewarpt wird... die sieht man sowieso kaum... |
von walski |
O.k. gute Idee. [code:1:9f078153d5] ;A little warp effekt :) Const ScreenW=1024,ScreenH=768 Const StarCount=500 Type Stars Field x,y Field Intensity# Field WarpStar Field TookOut End Type SeedRnd MilliSecs() For i=1 To StarCount Star.Stars = New Stars Starx=Rand(0,ScreenW) Stary=Rand(0,ScreenH) StarIntensity=Rnd(0.0001,1) If StarIntensity>0.5 Then StarWarpStar=1 Next Graphics ScreenW,ScreenH,32,1 SetBuffer BackBuffer() timer=CreateTimer(60) Trail#=1 Speed# = 5 WarpPhase = 0 While Not KeyDown(1) WaitTimer timer Cls LockBuffer BackBuffer() For Star = Each Stars If WarpPhase<>0 And (Not StarWarpStar=1) Then Light=Ceil(255*StarIntensity) WritePixelFast Starx,Stary,RGB2Hex(Light,Light,Light) Stary=Stary+Ceil(Speed*StarIntensity) Else For i=1 To Trail If Stary>i Then Light=Ceil(255*StarIntensity)/(i/((Trail/10)+1)) WritePixelFast Starx,Stary-i,RGB2Hex(Light,Light,Light) EndIf Next Stary=Stary+Ceil(Speed*StarIntensity) EndIf If Stary>ScreenH Then stary=1 starx=Rand(0,ScreenW) EndIf Next If KeyHit(57) And (Not WarpPhase) Then WarpPhase=1 If WarpPhase If WarpPhase<150 Trail=Trail+.8 Speed=Speed +.2 ElseIf WarpPhase>300 Trail=Trail-.8 Speed=Speed-.2 EndIf WarpPhase=WarpPhase+1 If WarpPhase >449 Then WarpPhase =0 Trail=1 EndIf EndIf UnlockBuffer BackBuffer() Flip If KeyHit(14) Then While Not KeyHit(14) Wend EndIf Wend Function RGB2Hex(R,G,B) Return 255*$1000000 + r*$10000 + g*$100 + b End Function [/code:1:9f078153d5] Ich denke so kann mans lassen :) walski [EDIT] Code dank ViciouS nocheinmal verbessert. [/EDIT] |
von ??? |
aber schneller werden könnten die weit entfernten sterne trotzdem, das ist sonst irgendwie unlogisch ^^ |
von ??? |
sieht cool aus .... muss man dich loben !!! r3sp3kt *g* ( nein ich bin kein scheiss CS sprachen arschloch ^^ ) |
von walski |
@ ViciouS: hm hm... ok moment. Hab den Code oben so geändert. Jetzt sieht es wirkloich cool aus! @Joke: Danke! So, ich fange grad mein nächstes "Projekt" für den ShowCase an :) Mal sehn ob euch das auch gefällt *g walski [/code] |
von ??? |
jo jetzt siehts richtig geil aus... darf man das in seinen shootern einsetzten?? |
von walski |
Klar! Wenn du willst kannst mir ja Credits geben. Wenn nicht, dann eben nicht :) Aber sag mir dann wenn der Shooter spielbar ist wenigstens ma bescheid :) Ich will den dann ma zocken! *g walski |