| Schönen Guten Abend an alle, 
 wie schön die Überschrift erahnen lässt möchte ich mir ein paar möglichkeiten zeigenlassen wie ich meinen Code beschleunigen kann da bereits ab 12 Objekten (=Inf Type) die Geschwindigkeit deutlich vermindert wird.
 
 Wer den Code ausprobieren will:
 
 Linke Maustaste = Schießen
 Mittlere Maustaste = 20 Inf Objekte erstellen
 Rechte Maustaste = Alle Inf Objekte löschen
 B = "kaufenmenü" wird Benötigt um mit
 + (auf dem Ziffernblock) = Waffe wechseln
 Esc = beenden
 
 Ich habe das Startgeld auf 20000 gestellt zum ausprobieren.
 
 Hoffe auf viele Hilfreiche antworten.
 
 P.S. wenn die rote Linie mit den Inf Objekten in Kontakt kommt verliert man Leben, links in der Mitte wird das Leben angezeigt (1000 Startwert)
 
 
 BlitzBasic:  [AUSKLAPPEN]  [EINKLAPPEN]
 Graphics 1024, 768,0,2SetBuffer BackBuffer()
 
 
 Type Inf
 Field xpos
 Field ypos
 Field leben
 Field speed
 Field xbeweg
 Field ybeweg
 End Type
 
 
 Type schuss
 Field x_Pos#
 Field y_Pos#
 Field winkel#
 End Type
 
 
 Global Spielerleben = 1000
 Global killed = 0
 Global Cash% = 20000
 Global s.schuss
 Global a.Inf
 Global trigger = 0
 Global revolver = 1
 Global Sharpsh = 0
 Global MG = 0
 Global Schrot = 0
 Global aktuellewaffe = 1
 
 
 Repeat
 Cls
 
 gegner()
 schuss()
 Turm()
 
 
 If KeyHit(48) Then kaufen()
 Waffewechsel()
 
 
 
 Flip
 Until KeyHit(1)
 End
 
 
 
 Function kaufen()
 Cls
 Color 255,255,255
 Rect 100,100, 824,524
 fntArial=LoadFont("Arial",24,True,False,True)
 SetFont fntArial
 Color 0,0,0
 Text 400,100, "Dorena's Waffenlager"
 fntArial=LoadFont("Arial",18,True,False,False)
 SetFont fntArial
 Text 600, 300, "Aktuelles Guthaben: " + cash%+" Euro"
 FreeFont fntArial
 
 Text 100, 300, "Scharfschützengewehr, Kosten: 1000 Euro, Kennziffer 1"
 Text 100, 320, "Maschienengewehr MG 40, Kosten: 1500 Euro, Kennziffer 2"
 Text 100, 340, "Schrotflinte, Kosten: 1500 Euro, Kennziffer 3"
 Text 100, 500, "Zum Abrechen: A"
 FlushKeys
 Locate 100,400
 
 fntArial=LoadFont("Arial",18,True,False,False)
 SetFont fntArial
 BuyAuswahl$ = Input$("Bitte hier Ihre Wahl: ")
 FreeFont fntArial
 If BuyAuswahl$ = "a" Then Return
 If BuyAuswahl$ = 1 Then
 If Cash% < 1000 Then
 FlushKeys
 Cls
 Color 255,255,255
 fntArial=LoadFont("Arial",18,True,False,False)
 SetFont fntArial
 Text 25, 300, "Aktuelles Guthaben beträgt weniger als 1000 Euro es Reicht nicht aus für dieses Scharfschützengewehr! Beliebige Taste zum Fortfahren"
 WaitKey
 FreeFont fntArial
 kaufen()
 ElseIf Cash% >= 1000 Then
 Sharpsh = 1
 Cash%= Cash% -1000
 EndIf
 EndIf
 
 If BuyAuswahl$ = 2 Then
 If Cash% < 1500 Then
 FlushKeys
 Cls
 Color 255,255,255
 fntArial=LoadFont("Arial",18,True,False,False)
 SetFont fntArial
 Text 80, 300, "Aktuelles Guthaben beträgt weniger als 1500 Euro es Reicht nicht aus für diese MG! Beliebige Taste zum Fortfahren"
 WaitKey
 FreeFont fntArial
 kaufen()
 ElseIf Cash% >= 1500 Then
 MG = 1
 Cash%= Cash% -1500
 EndIf
 EndIf
 
 If BuyAuswahl$ = 3 Then
 If Cash% < 1500 Then
 FlushKeys
 Cls
 Color 255,255,255
 fntArial=LoadFont("Arial",18,True,False,False)
 SetFont fntArial
 Text 35, 300, "Aktuelles Guthaben beträgt weniger als 1500 Euro es Reicht nicht aus für diese Schrotflinte! Beliebige Taste zum Fortfahren"
 WaitKey
 FreeFont fntArial
 kaufen()
 ElseIf Cash% >= 1500 Then
 Schrot = 1
 Cash%= Cash% -1500
 EndIf
 EndIf
 
 
 
 
 FlushKeys
 
 End Function
 
 
 
 
 Function Waffewechsel()
 
 If KeyHit(78) Then
 If aktuellewaffe = 1 Then
 If sharpsh = 1 Then
 aktuellewaffe = 2
 ElseIf sharpsh = 0 Then
 If MG = 1 Then
 aktuellewaffe = 3
 ElseIf MG = 0 Then
 If Schrot = 1 Then
 Aktuellewaffe = 4
 ElseIf Schrot = 0 Then
 Aktuellewaffe = 1
 EndIf
 EndIf
 EndIf
 
 
 ElseIf aktuellewaffe = 2 Then
 If MG = 1 Then
 aktuellewaffe=3
 ElseIf MG = 0 Then
 If Schrot = 1 Then
 aktuellewaffe = 4
 ElseIf Schrot = 0 Then
 aktuellewaffe = 1
 EndIf
 EndIf
 ElseIf aktuellewaffe = 3 Then
 If schrot = 1 Then
 aktuellewaffe = 4
 ElseIf schrot = 0 Then
 aktuellewaffe = 1
 EndIf
 ElseIf aktuellewaffe = 4 Then
 aktuellewaffe= 1
 
 EndIf
 EndIf
 
 
 
 
 End Function
 
 
 
 
 
 
 
 
 Function schuss()
 x1= MouseX()
 y1= MouseY()
 
 w# = ATan2(x1-505,y1-205)
 
 
 If  aktuellewaffe = 1 Then
 Text 0,0, "Waffe: Revolver"
 EndIf
 If  aktuellewaffe = 2 Then
 Text 0,0, "Waffe: Scharfschützengewehr"
 EndIf
 If  aktuellewaffe = 3 Then
 Text 0,0, "Waffe: MG"
 EndIf
 If aktuellewaffe = 4 Then
 Text 0,0, "Waffe: Schrotflinte"
 EndIf
 
 
 
 If MouseHit(1) Then
 If aktuellewaffe = 1 Then
 s = New schuss
 s\x_Pos#= 505
 s\y_Pos#= 205
 s\winkel# = w#
 Color 255,255,0
 
 ElseIf aktuellewaffe = 2 Then
 s = New schuss
 s\x_Pos#= 505
 s\y_Pos#= 205
 s\winkel# = w#
 Color 255,255,0
 
 ElseIf aktuellewaffe = 4 Then
 
 For i= 1 To 10
 s = New schuss
 s\x_Pos#= 505
 s\y_Pos#= 205
 s\winkel# = w#+ Rnd(-40,40)
 Color 0,0,255
 
 Next
 
 EndIf
 EndIf
 
 If MouseDown(1) Then
 If aktuellewaffe = 3 Then
 trigger = trigger +1
 
 If trigger = 7 Then
 
 s = New schuss
 s\x_Pos#= 505
 s\y_Pos#= 205
 s\winkel# = w# + Rnd(-0.3,0.3)
 Color 255,255,0
 trigger = 0
 EndIf
 EndIf
 EndIf
 
 
 
 
 For s = Each schuss
 
 For a = Each Inf
 
 
 
 If LinesIntersect(s\x_Pos,s\y_Pos,s\x_Pos+Sin(s\winkel#)*10,s\y_Pos+Cos(s\winkel#)*10,a\xpos,a\ypos,a\xpos+10,a\ypos+10) Then
 If aktuellewaffe = 1 Then
 a\leben = a\leben - 20
 EndIf
 
 If aktuellewaffe = 2 Then
 a\leben =  a\leben - 100
 EndIf
 
 If aktuellewaffe = 3 Then
 a\leben =a\leben -30
 EndIf
 
 If aktuellewaffe= 4 Then
 a\leben =a\leben -15
 EndIf
 EndIf
 
 If LinesIntersect(s\x_Pos,s\y_Pos,s\x_Pos+Sin(s\winkel#)*10,s\y_Pos+Cos(s\winkel#)*10,a\xpos,a\ypos+10,a\xpos+10, a\ypos) Then
 
 If aktuellewaffe = 1 Then
 a\leben = a\leben - 20
 EndIf
 
 If aktuellewaffe = 2 Then
 a\leben =  a\leben - 100
 EndIf
 
 If aktuellewaffe = 3 Then
 a\leben =a\leben -30
 EndIf
 
 If aktuellewaffe= 4 Then
 a\leben =a\leben -15
 EndIf
 EndIf
 
 
 
 
 If a\Leben <= 0 Then
 Cash% = Cash% + a\speed * 100
 Delete a
 killed=killed +1
 EndIf
 
 
 Next
 
 If aktuellewaffe = 1
 Line s\x_Pos,s\y_Pos,s\x_Pos+Sin(s\winkel#)*10,s\y_Pos+Cos(s\winkel#)*10
 s\x_Pos#= s\x_Pos#+ Sin(s\winkel#) * 20
 s\y_Pos#= s\y_Pos#+ Cos(s\winkel#) * 20
 EndIf
 If aktuellewaffe = 2
 Line s\x_Pos,s\y_Pos,s\x_Pos+Sin(s\winkel#)*20,s\y_Pos+Cos(s\winkel#)*20
 s\x_Pos#= s\x_Pos#+ Sin(s\winkel#) * 20
 s\y_Pos#= s\y_Pos#+ Cos(s\winkel#) * 20
 EndIf
 
 If aktuellewaffe = 3
 Line s\x_Pos,s\y_Pos,s\x_Pos+Sin(s\winkel#)*10,s\y_Pos+Cos(s\winkel#)*10
 s\x_Pos#= s\x_Pos#+ Sin(s\winkel#) * 20
 s\y_Pos#= s\y_Pos#+ Cos(s\winkel#) * 20
 EndIf
 
 If aktuellewaffe = 4
 Line s\x_Pos,s\y_Pos,s\x_Pos+Sin(s\winkel#)*1,s\y_Pos+Cos(s\winkel#)*1
 s\x_Pos#= s\x_Pos#+ Sin(s\winkel#) * 20
 s\y_Pos#= s\y_Pos#+ Cos(s\winkel#) * 20
 EndIf
 
 
 
 Next
 
 Text 300, 0, "Cash: "+Cash%
 Text 0,20,"Getötet: " + killed
 Color 255,255,255
 
 End Function
 
 
 
 
 
 
 Function Turm()
 x1= MouseX()
 y1= MouseY()
 
 Oval 500, 200, 12, 12 ,1
 
 
 Color 255,0,0
 Line 505,205,x1, y1
 
 For a = Each Inf
 If linesintersect(a\xpos,a\ypos,a\xpos+10,a\ypos+10,505,205,x1, y1) Then
 Spielerleben = Spielerleben - 10
 EndIf
 
 If linesintersect(a\xpos,a\ypos+10,a\xpos+10, a\ypos,505,205,x1, y1) Then
 Spielerleben = Spielerleben -10
 EndIf
 
 
 Next
 
 Color 255,255,255
 
 If spielerleben =< 0 Then
 Cls
 
 FlushKeys
 
 fntArial=LoadFont("Arial",24,True,False,True)
 
 SetFont fntArial
 
 Text 400,100, "Verloren!!!!!!!!!!!!!!!!!!"
 Flip
 WaitKey
 
 End
 EndIf
 
 Text 0,600, spielerleben
 
 
 
 For s = Each schuss
 If s\x_pos <= 0 Then
 Delete s
 ElseIf s\x_pos >= 1024 Then
 Delete s
 ElseIf s\y_pos <= 0 Then
 Delete s
 ElseIf s\y_pos >= 768 Then
 Delete s
 EndIf
 Next
 End Function
 
 
 
 
 
 
 
 
 Function Gegner()
 
 If MouseHit(3) Then
 For t = 1 To 20
 a.Inf = New Inf
 a\xpos# = Rnd(0,1024)
 a\ypos# = Rnd(0,768)
 a\leben = 100
 a\speed = Rnd(1,3)
 a\xbeweg = Rnd(0,1)
 a\ybeweg = Rnd(0,1)
 Next
 End If
 
 If MouseHit(2) Then
 Delete Each Inf
 End If
 
 For a.Inf = Each Inf
 Line a\xpos,a\ypos,a\xpos+10,a\ypos+10
 Line a\xpos,a\ypos+10,a\xpos+10, a\ypos
 
 If a\xpos >= 1024 Then
 a\xbeweg = 1
 ElseIf a\xpos =< 0  Then
 a\xbeweg = 0
 EndIf
 
 If a\ypos >= 768 Then
 a\ybeweg = 1
 ElseIf a\ypos =< 0  Then
 a\ybeweg = 0
 EndIf
 
 
 If a\xbeweg = 0 Then
 a\xpos = a\xpos + a\speed
 ElseIf a\xbeweg = 1 Then
 a\xpos = a\xpos - a\speed
 EndIf
 
 If a\ybeweg = 0 Then
 a\ypos = a\ypos + a\speed
 ElseIf a\ybeweg = 1 Then
 a\ypos = a\ypos - a\speed
 EndIf
 
 
 
 Text a\xpos-70,a\ypos+10, "Health: " + a\leben +" Speed: "+a\speed
 
 Next
 
 
 
 End Function
 
 
 
 
 
 
 
 
 
 Function LinesIntersect(ax#, ay#, bx#, by#, cx#, cy#, dx#, dy#)
 rn# = (ay#-cy#)*(dx#-cx#) - (ax#-cx#)*(dy#-cy#)
 rd# = (bx#-ax#)*(dy#-cy#) - (by#-ay#)*(dx#-cx#)
 If rd# = 0
 Return False
 Else
 sn# = (ay#-cy#)*(bx#-ax#) - (ax#-cx#)*(by#-ay#)
 intersection_ab# = rn# / rd#
 intersection_cd# = sn# / rd#
 intersection_x#  = ax# + intersection_ab#*(bx#-ax#)
 intersection_y#  = ay# + intersection_ab#*(by#-ay#)
 
 If intersection_ab#>0 And intersection_ab#<1 And intersection_cd#>0 And intersection_cd#<1 Then Return True
 EndIf
 End Function
 |