Collidiertes Object entfernen. Wie?!

Übersicht BlitzMax, BlitzMax NG Beginners-Corner

Neue Antwort erstellen

 

Preakz

Betreff: Collidiertes Object entfernen. Wie?!

BeitragSo, Jun 24, 2012 18:29
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo allerseits... ich wollte mich mal erkundigen , ob einer von euch weiß wie man das "Collidierte Objekt" entfernt also removed. Habe das mit RemoveLast gemacht , aber das ist ja nicht das was ich möchte. Ich möchte ja nicht das letzte sondern das Aktuelle collidierte Object löschen. Hat jmd Vorschläge ?
Danke schonmal im vorraus Smile

Code: [AUSKLAPPEN]
Strict
Global Number_of_Tanks = 1000  'How many tanks to create?
Const RefreshRate = 300 'Hz = FPS
Global Live
HideMouse()
Type MoveObject
   Field X#,Y#
   Field Dir:Int
   Field R:Int, G:Int, B:Int
   Global DeltaTime:Float
   Global TimeDelay:Int ' Millisecs() returns int
   Function UpdateDeltaTime()
      DeltaTime = ( MilliSecs()- TimeDelay )*0.001'Delta Timer
      TimeDelay = MilliSecs()
   End Function
End Type


Type Me Extends MoveObject
   
   Global MeNumber = 0
   Global MeinCursor:TList
   Field Size:Int = 20
   
   Function Create()
      If Not MeinCursor MeinCursor = CreateList()
         Local NewMe:Me = New Me
         NewMe.SetupNew()
         MeinCursor.AddLast(NewMe)
         MeNumber:+1
   End Function
   
   Method Go()
      X = MouseX()
      Y = MouseY()
   End Method
   Method Draw()
      SetColor (R, G, B)
      DrawRect X, Y, Size, Size
   EndMethod   
   
   Method SetupNew()
      MoveMouse(0, 0)
      X = MouseX() ;Y = MouseY()
      R = Rnd(0, 255)
      G = Rnd(0, 255)
      B = Rnd(0, 255)
      
   End Method

End Type


Type Tank Extends MoveObject
   'Override the Speed Field in MoveObject
   Field Speed:Float = 200 / 1 ' Pixels / Seconds
   Field Size:Int = 1
   Global TankNumber=0 'The current number of tanks
   Global TankList:TList
   'Draw draws a rect at the tank's X,Y
   Method Draw()
      SetColor (R, G, B)
      DrawRect X, Y, Size, Size
      SetColor 255, 255, 255
   EndMethod
   'Go update the tank's movement
   Method Go()
      X:-Speed * Cos(Dir) * DeltaTime
      Y:-Speed * Sin(Dir) * DeltaTime
   EndMethod
   'Sets the starting values of the Tank
   Method SetupNew()
      
      X = (GraphicsWidth() / 2) ;Y = (GraphicsHeight() / 2)
      Speed:*Rnd(0.5, 1)
      R = Rnd(0, 255)
      G = Rnd(0, 255)
      B = Rnd(0, 255)
      
   End Method
   'This function Creates a new tank
   Function Create()'
   'Create a List if none exists
      If Not TankList TankList = CreateList()
      Local NewTank:Tank = New Tank
      NewTank.SetupNew()
      TankList.AddLast( NewTank )
      TankNumber:+1
      Live = Live + 1
   End Function
   
   Method DetectCollision()
      Local LastX, LastY, MR = 20'MR Short for MouseRadius
      Local TargetX:Int = X
      Local TargetY:Int = Y
      Local TR = Size'TR Short for TargetRadius
      If Distance(MouseX(), MouseY(), TargetX, TargetY) < TR + MR
         
         SetColor Rnd(0, 255), Rnd(0, 255), Rnd(0, 255)
         DrawText "COLLISION DETECTED!", (GraphicsWidth() / 2) - 90, (GraphicsWidth() / 2)
         Live = Live - 1
         Tank.TankList.RemoveLast
         TankNumber:-1
         
      EndIf
      LastX = MouseX() ;LastY = MouseY()
      
   End Method
End Type





'------ MAIN ------
Graphics 800, 600, 0, RefreshRate

For Local NrMe = 0 To 1
   Me.Create()
Next
For Local Nr = 1 To Number_of_Tanks
   Tank.Create()
Next
Delay 500
Tank.TimeDelay=MilliSecs()
While Not KeyDown(KEY_ESCAPE)
   
   If KeyDown(KEY_SPACE)
      Tank.Create()
   End If

   DrawText "Deine FPS: " + FPS.Calc(), 20, 40
   DrawText "Winkel: ", 20, 55
   DrawText "Mein Leben: " + Live, 20, 70
   MoveObject.UpdateDeltaTime()
   For Local T:Me = EachIn Me.MeinCursor
      T.Draw
      T.Go
   Next
   For Local T:Tank = EachIn Tank.TankList
      T.DetectCollision
      T.Dir = (ATan2(T.Y - MouseY(), T.X - MouseX()))
      T.Draw
      DrawText "Anzahl der Partikel : " + Tank.TankNumber, 20, 20
      T.Go'update      
   Next
   GameOver()
   Flip;Cls
Wend
'_____






Function GameOver()
   If Live <= 0 Then
      LoadFont("SpaceAge", 13, 0)
      SetColor (255, 0, 0)
      DrawText ("GAME OVER", MouseX() - 25, MouseY() + 20)
      DrawText ("Press Space to add new Enemies", MouseX() - 120, MouseY() + 35)
      If(KeyHit(KEY_SPACE))
         
      EndIf
   End If
End Function











' FPS_Counter <> Runs And displays the FPS
' --------------------------------------------
Type FPS
   Global Counter, Time, TFPS
   Function Calc%()
      Counter:+1
      If Time < MilliSecs()
      TFPS = Counter' <- Frames/Sec
      Time = MilliSecs() + 1000'Update
      Counter = 0
      EndIf
      Return TFPS
   EndFunction
EndType
' --------------------------------------------


Function Distance:Float(X1, Y1, X2, Y2)
Local DX# = X2 - X1
Local DY# = Y2 - Y1
Return Sqr( Dx*DX + Dy*Dy )
EndFunction

Xeres

Moderator

BeitragSo, Jun 24, 2012 18:37
Antworten mit Zitat
Benutzer-Profile anzeigen
Du scheinst
Code: [AUSKLAPPEN]
Tank.TankList.Remove(Self)
zu suchen.
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)
 

Preakz

BeitragSo, Jun 24, 2012 18:38
Antworten mit Zitat
Benutzer-Profile anzeigen
Dankeschön für die schnelle Antwort Smile

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group