Krater auf Terrain erzeugen von ??? |
Granatenwerfer erzeugt Krater auf Terrain. [code:1:8493643065] ; coded by norc of CSP Graphics3D 640,480,16,1 SetBuffer BackBuffer() Collisions 1,2,2,3 Collisions 2,1,1,1 Collisions 3,2,2,1 ; for bullets > enviroment check player=CreatePivot() PositionEntity player,-15,2,-30 EntityRadius player,.6 EntityType player,1 camera=CreateCamera( player ) CameraRange camera,.1,200 CameraClsColor camera,50,100,100 PositionEntity camera,0,1,0 TranslateEntity camera,0,2,0 ; eyes height CameraFogMode camera,1 CameraRange camera,.1,50 CameraFogColor camera,50,100,100 CameraFogRange camera,20,55 light=CreateLight() ;-------------------------------------------------------------terrain-test mesh=CreateTerrain(128) terrscale#=2.0 terrxz#=64 ScaleEntity mesh,terrscale#,3,terrscale# PositionEntity mesh,-terrxz#,0,-terrxz# TranslateEntity mesh,0,-10,0 testtex=CreateTexture(128,128) SetBuffer TextureBuffer(testtex) Color 200,200,0 Rect 0,0,128,128,1 For i=0 To 10000 ; draw 10001 dots on a texture created on the fly red=Rand(120,150) green=red+Rand(180-(red)) Color red,green,0 Plot Rand(0,129),Rand(0,129) Next SetBuffer BackBuffer() ScaleTexture testtex,512,512 tex2=CreateTexture(128,128) CopyRect 0,0,128,128,0,0,TextureBuffer(testtex),TextureBuffer(tex2) ;ScaleTexture tex2,4,4 EntityTexture mesh,testtex,0,0 EntityTexture mesh,tex2,0,1 TerrainShading mesh,1 ;eo terrain init EntityType mesh,2 sp#=.5 ey#=EntityY(player) ; dummy gun gun=CreateCube(camera):ScaleEntity gun,1,1,10 PositionEntity gun,.3,-.2,.5 RotateEntity gun,0,5,20 ScaleEntity gun,.15,.15,.5 EntityParent gun,camera EntityRadius gun,1 EntityOrder gun,-1 EntityColor gun,170,170,170 ; ;create bullets maxbull=100 ; max. number of bullets active currbull=0 bulletspeed#=3.0 reload_after=30 Dim bullet(maxbull),bulljob(maxbull),mustset(maxbull),bullet_gravity#(i) ; bullets array, bullet job flag array, collision reset flag array For i=0 To maxbull bullet(i)=CreateCylinder() ; << HideEntity bullet(i) EntityType bullet(i),3 EntityRadius bullet(i),.05 ScaleEntity bullet(i),.2,.2,.5 RotateMesh bullet(i),90,0,0 Next ; so now we have bullet(0) to bullet(100) - these are 101 bullets boom=CreateSphere() ; used as a impact sign EntityAlpha boom,0.5 p_angle#=0 ; player angle at start reloading=0 ; ----------------------------------------MAINLOOP---------------------------------------- While Not KeyHit(1) If KeyHit(17) wire=1-wire WireFrame wire EndIf p_angle#=(p_angle#-mxs#) ; angle... If p_angle#>360 Then p_angle#=p_angle#-360 p_smooth_angle#=p_smooth_angle#-360 EndIf If p_angle#<0 Then p_angle#=p_angle#+360 p_smooth_angle#=p_smooth_angle#+360 EndIf c_angle#=(c_angle#+mys#) If c_angle#>360 Then c_angle#=c_angle#-360 c_smooth_angle#=c_smooth_angle#-360 EndIf If c_angle#<0 Then c_angle#=c_angle#+360 c_smooth_angle#=c_smooth_angle#+360 EndIf p_smooth_angle#=p_smooth_angle#-((p_smooth_angle#-p_angle#)/2.5) c_smooth_angle#=c_smooth_angle#-((c_smooth_angle#-c_angle#)/2.5) RotateEntity player,0,p_smooth_angle#,0 RotateEntity camera,c_smooth_angle#,0,0 If KeyDown(200) Then MoveEntity player,0,0,sp If KeyDown(208) Then MoveEntity player,0,0,-sp If KeyHit(57)=1 jump#=4.0 EndIf If jump#>.1 TranslateEntity player,0,jump#,0 jump=jump*.7 EndIf ; fire If MouseDown(1)=1 And MilliSecs()>=time_for_a_bullet time_for_a_bullet=MilliSecs()+133 mag=mag+1 If mag>=reload_after Then ; need to reload? time_for_a_bullet=MilliSecs()+1000 ; reload - no fire for 1 second mag=0 reloading=1 Else reloading=0 EndIf ; launch bullet, probably play a gun sound EntityType bullet(currbull),0 ; force no collision to position at the guns xyz bullet_gravity#(currbull)=0 mustset(currbull)=1; remember this PositionEntity bullet(currbull),EntityX(gun,1),EntityY(gun,1),EntityZ(gun,1),1 RotateEntity bullet(currbull),EntityPitch(gun,1),EntityYaw(gun,1),EntityRoll(gun,1),1 MoveEntity bullet(currbull),0,0,-1.8 ShowEntity bullet(currbull) bulljob(currbull)=1 currbull=currbull+1 If currbull>maxbull Then currbull=0 EndIf EndIf If MilliSecs()>=time_for_a_bullet reloading=0 ; end reload phase anyway EndIf ; bullets in the air? For i=0 To maxbull If bulljob(i)<>0 ; is this bullet flying? If mustset(i)=1 EntityType bullet(i),3 ; re-enable collison if required mustset(i)=0 EndIf MoveEntity bullet(i),0,0,bulletspeed# TranslateEntity bullet(i),0,-bullet_gravity#(i),0 If bullet_gravity#(i)<3 bullet_gravity#(i)=(bullet_gravity#(i)+.1)*1.1 EndIf If CountCollisions(bullet(i))>0 hit_here=CollisionEntity(bullet(i),1) ; bullet hit wich entity? If hit_here<>0 ; did you hit a lame multyplayer mesh? hit_here has its entity handle (that mesh needs EntityType 2) ; probalby play impact sound, start a particle effect ... boomx#=CollisionX(bullet(i),1) boomy#=CollisionY(bullet(i),1) boomz#=CollisionZ(bullet(i),1) bulljob(i)=0 ; deactivate bullet EntityType bullet(i),0 ; collison off HideEntity bullet(i) ;impact happened Right here: (using a sphere to mark this point temporary - could be exlosion...) PositionEntity boom,boomx#,boomy#,boomz#,1 ; mache KRATER x#=EntityX(player) z#=EntityZ(player) xdis#=Abs(x-boomx) zdis#=Abs(z-boomz) If Sqr((xdis*xdis)+(zdis*zdis))>5 tboomx#=(boomx#+terrxz#)/terrscale# tboomz#=(boomz#+terrxz#)/terrscale# For i2=0 To 360 Step 30 ModifyTerrain mesh,tboomx#+Sin(i2)*1.5,tboomz#+Cos(i2)*1.5,Rnd(.5,.8) Next msg$="" Else msg$="You have just bombed yourself, silly boy!" EndIf ;ModifyTerrain mesh,tboomx#,tboomz#,Rnd(.5,.8) EndIf EndIf If EntityDistance(bullet(i),gun)>100; bullet far away? HideEntity bullet(i) bulljob(i)=0 ; deactivate bullet EntityType bullet(i),0 ; collison off EndIf EndIf Next If EntityCollided(player,2)=0 ; gravity system If EntityY(player)>-10 ; prevent falling trough terrain TranslateEntity player,0,-gravity#,0 gravity#=(gravity#+.1)*1.2 Else PositionEntity player,EntityX(player),0,EntityZ(player) gravity#=0 EndIf Else gravity#=0 EndIf UpdateWorld RenderWorld Color 255,255,255 Text 0,16,"Triangles Rendered:"+TrisRendered() Text 0,32,"Camera Position: "+EntityX(camera,1)+" "+EntityY(camera,1)+" "+EntityZ(camera,1) If reloading=1 Then Text GraphicsWidth()/2,GraphicsHeight()/2,"RELOADING",1,1 Color 255,0,0 If msg$<>"" Then Text 0,48,msg$ mxs#=MouseXSpeed()/4.0 mys#=MouseYSpeed()/4.0 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 Flip Wend End [/code:1:8493643065] |
von ??? |
Sie denken wahrscheinlich, dass ich nu meckern kann. Aber ich meinte eher ein Krater nach innen. Trotzdem: GUT GEMACHT! Vieleicht war das Wort Krater ein kleines bisschen falsch benutzt. |
von ??? |
Je länger ich mir diesen Code und (das Programm) ansehe, umso besser gefällt er mir! |
von ??? |
*grummel* Würds mir ja auch gern mal angucken.... bekomme aber ne Fehlermeldung und kann das Problem net lokalisieren. :x |
von ??? |
Schalt Debugger an! |
von ??? |
Natürlich kann der Krater auch gegen innen sein. Wenn du für das Terrain eine Heightmap lädst, musst du den Krater eh RELATIV zur aktuellen Höhe eindrücken. Da fragst du dann erst nach der Terrainheight(), ziehst rnd(.1,.2) ab (passt auf, dass der Wert nicht unter Null geht) und benutzt dann Modifyterrain mit dieser Summe wie beschrieben. Kannst auch 2 Kreise machen, aussen nach oben, innen nach unten. Das wär dann ziemlich realistisch. |