Problem mit schleifen *Erledigt*
Übersicht

![]() |
BlitzardBetreff: Problem mit schleifen *Erledigt* |
![]() Antworten mit Zitat ![]() |
---|---|---|
Also ich hab mal wieder en problem des is etwas komplexer.
Also: Ich habe einen 2d spaceshooter geschrieben und das menü mithilfe von functionen gelöst . D.h ich habe einmal meine Hauptschleife dan des Menü und meine Credits Alle sind in Function untergebracht. So also ich bin im Menü und klick auf Newgame so dann startt die Hauptschleife auch wunderbar aber ich möcht einfach mal neu anfangen klick auf esc und land wieder im Menü und klick wieder auf den button start aber dann seh ich des mein game genau da is wo ich es es letzte mal verlassen hab . Genauso isses bei den credits. Ich hab auch schon verschiedene sachen wie exit und End ausprobiert komm aber auf keine lösung^^ PS: Muss leider meinen ganzen code posten da ich nich genau weiß wo das problem liegt. Code: [AUSKLAPPEN] AppTitle "Star-Ranger" Graphics 1024,768,16,2 SetBuffer BackBuffer() SeedRnd MilliSecs() Dim Gegner(8,3) Dim GegnerTot(5,1) Dim FeindSch(100,2) Dim Sch(100,2) Include "load.bb" MaskImage GegnerImage ,255,0,255 MaskImage Schiff ,255,0,255 MaskImage Schuss ,255,0,255 MaskImage GegnerSch ,255,0,255 MaskImage HudSchrift ,255,0,255 MaskImage Energie ,255,0,255 MaskImage Laser,255,0,255 MaskImage SchiffKoli ,255,0,255 Global X#=300 Global Y#=700 Global gegner_x = Rand(100,700 ) Global gegner_y = 0 Global max_live = 300 Global current_live = 300 Global live_points Global max_laser = 100 Global current_laser# = 100 Global laser_points Global game = 1 Global Credits = 800 Global Frame# = 0 Global maus = MouseHit(1) Function status_bar() ;live Color 96,0,0 Rect 938,100,80,10 For live_bar = 0 To live_points Color 160,0,0 Rect 938,100,live_points,10 Next ;laser Color 0,0,120 Rect 938,170,80,10 For laser_bar = 0 To laser_points Color 0,0,255 Rect 938,170,laser_points,10 Next End Function Repeat Cls If game = 1 Then Menü() If game = 2 Then Hauptschleife() If game = 3 Then Credits() Flip Until KeyHit(1) Function Hauptschleife() Repeat Cls If laser_pointsr > 100 Then laser_points = 100 If current_laser > 100 Then current_laser = 100 current_laser = current_laser + 0.2 ;--------------------------------------------- I = I + 2 If I=200000 Then I=0 TileBlock Hinter,0,I ;--------------------------------------------- If KeyDown(203) X=X-2 If KeyDown(205) X=X+2 If KeyDown(205) Then X = X+4 Frame = (Frame +0.5) Mod 8 ;Else ;Frame = 3 EndIf If KeyDown(203) Then X = X-4 Frame = (Frame -0.5) Mod 7 ;Else ;Frame = 3 EndIf If Not KeyDown(203) Or KeyDown(205) Then Frame = 3 If Frame > 6 Then Frame = 6 If Frame < 0 Then Frame = 0 If KeyDown(200) Then Y = Y-4 If KeyDown(208) Then Y = Y+4 ;--------------------------------------------- For P = 1 To 5 ;--------------------------------------------- If X>850 Then X=850 If X<0 Then X=0 If Y>650 Then Y=650 If Y<0 Then Y=0 ;--------------------------------------------- ;--------------------------------------------- If KeyHit(57) And laser_points > 10 Then Schuss2 = Schuss2 + 1 If Schuss2 = 21 Then Schuss2 = 1 Sch(Schuss2,0) = 1 Sch(Schuss2,1) = X+29 Sch(Schuss2,2) = Y PlaySound(SchussSound) current_laser = current_laser - 10 EndIf For S = 1 To 100 If Sch(S,1) < 0 Then Sch(S,0) = 0 If Sch(S,0) = 1 Then DrawImage Schuss, Sch(S,1), Sch(S,2) Sch(S,2) = Sch(S,2) - 10 EndIf Next ;--------------------------------------------- ;--------------------------------------------- ;------------------Feindschuss--------------------------- For P = 1 To 5 For O = 1 To 10 Entfernung = O+1 If Y>Gegner(P,2) And Gegner(P,1) = X+Entfernung Then Schuss3 = Schuss3 + 1 If Schuss3 = 2 Then Schuss3 = 1 FeindSch(Schuss3,0) = 1 FeindSch(Schuss3,1) = Gegner(P,1) FeindSch(Schuss3,2) = Gegner(P,2) EndIf Next;For P For J = 1 To 100 If FeindSch(J,1) < 0 Then FeindSch(J,0) = 0 If FeindSch(J,0) = 1 Then DrawImage GegnerSch , FeindSch(J,1)+9, FeindSch(J,2) FeindSch(J,2) = FeindSch(J,2) +5 EndIf Next ; For J Next ;---------------------------------------------- ;--------------------------------------------- For K = 1 To 5 If Gegner(K,0) = 0 Then Gegner(K,0) = Rand(100,400) Gegner(K,1) = Rand(100,1024) Gegner(K,2) = Rand(-100,0) EndIf If Gegner(K,0) <> -1 Then Gegner(K,2) = Gegner(K,2) + 2 gegner_x = 391 + Cos( Gegner(K,1) ) * Gegner(K,0) And Gegner(K,2) = Gegner(K,2) + 4 EndIf Gegner(K,2) = Gegner(K,2) + 1 If Gegner(K,2) > 768 Then Gegner(K,0) = 0 DrawImage GegnerImage ,Gegner(K,1) ,Gegner(K,2) DrawImage Gegnerimage , Gegner(3,1),Gegner(3,2) ;--------------------------------------------- For G = 1 To 100 If FeindSch(G,1) < 0 Then FeindSch(G,0) = 0 If ImagesOverlap (GegnerImage, Gegner(K,1), Gegner(K,2), Schuss, Sch(G,1), Sch(G,2)) Then Gegner(K,0) = -1 EndIf Next ; For G Next ; For K ;--------------------------------------------- ;--------------------------------------------- DrawImage Hud,930,0 DrawImage HudSchrift ,938,0 DrawImage Energie ,940,70 DrawImage Laser ,940,130 live_points = current_live * 80 / max_live laser_points = current_laser * 80 / max_laser If ImagesCollide(GegnerSch , FeindSch(1,1) , FeindSch(1,2),0, Schiff, X ,Y,0) Then current_live = current_live -10 DrawImage SchiffKoli ,X,Y,Frame Else DrawImage Schiff ,X,Y,Frame EndIf status_bar() ;--------------------------------------------- ;Hud(ende) ;Explosion For R = 1 To 5 If Gegner(R,0) = -1 Then If GegnerTot(R,1) + 70 < MilliSecs() Then GegnerTot(R,0) = GegnerTot(R,0) + 1 GegnerTot (R,1) = MilliSecs() If GegnerTot(R,0) = 6 Then GegnerTot(R,0) = 0 GegnerTot(R,1) = 0 Gegner(R,0) = 0 EndIf EndIf DrawImage Explosion ,Gegner(R,1)-5 ,Gegner(R,2)-5 ,GegnerTot(R,0) EndIf ;--------------------------------------------- Next ;For R Next ;Explosion(ende) If KeyHit(1) Then Exit : End Flip Until KeyHit(1) End Function Function Menü() Repeat Cls MX = MouseX() MY = MouseY() If MouseHit(1) Then If ImagesOverlap(NewGame,400,200,Pointer,MX,MY) Then Hauptschleife() If ImagesOverlap(Credits1,400,300,Pointer,MX,MY) Then Credits() If ImagesOverlap(Ende,400,400,Pointer,MX,MY) Then End EndIf TileBlock Hinter,0,0 If ImagesCollide(NewGame,400,200,0,Pointer,MX,MY,0) Then DrawImage NewGameover,400,200 Else DrawImage NewGame,400,200 EndIf If ImagesCollide(Credits1,400,300,0,Pointer,MX,MY,0) Then DrawImage Creditsover1,400,300 Else DrawImage Credits1,400,300 EndIf If ImagesCollide(Ende,400,400,0,Pointer,MX,MY,0) Then DrawImage Endeover,400,400 Else DrawImage Ende,400,400 EndIf DrawImage Pointer,MX,MY Flip Until KeyHit(1) End Function Function Credits() Repeat Cls TileBlock Hinter,0,0 SetFont font If KeyHit(1) Then Menü() Credits = Credits - 1 Text 430,Credits, "Space Ranger" Text 395,Credits+50 ,"Ein Spiel von Thomas I." Text 385,Credits+100 , "Programmierer: Thomas I." Text 430,Credits+150 , "Idee: Thomas I." Text 160,Credits+200, "Grafiken und Sounds: Alles freie Sound und Grafiken da ich net sehr talletiert bin :P" Text 30,Credits+250, "Ganz Großen dank ans Blitzforum, An den Blitz-Chat (chat-blitz.de) und natürlich an ICETRUCK für die tollen Grafiken" Text 70 , Credits + 300, "Wer Kontakt aufnehemn möchte macht dies bitte unter ICQ:313-671-234 oder kommt zu mir nach Hause^^" Flip Until Hallo = 1 End Function ;Programm Ende |
||
User posted image |
- Zuletzt bearbeitet von Blitzard am Do, Feb 16, 2006 17:57, insgesamt einmal bearbeitet
totonak5 |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
ich hab mir den code jetzt zwar nicht genau durchgesehen aber du musst alle variablen auf 0 zurücksetzen. | ||
Just for Fun!
Jesus loves U! |
![]() |
aMulSieger des Minimalist Compo 01/13 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ohne den Code gelesen zu haben:
Wahrscheinlich benutzt du globale Variablen. Wenn dem so ist, musst du sie natürlich auf 0 (oder was auch immer) zurücksetzen, sobald ein neues Spiel gestartet wird/die Credits aufgerufen werden. Hoffe ich konnte helfen. MfG EDIT: da war wer schneller ![]() |
||
Panic Pong - ultimate action mashup of Pong and Breakout <= aktives Spiele-Projekt, Downloads mit vielen bunten Farben!
advASCIIdraw - the advanced ASCII art program <= aktives nicht-Spiele-Projekt, must-have für ASCII/roguelike/dungeon-crawler fans! Alter BB-Kram: ThroughTheAsteroidBelt - mit Quelltext! | RGB-Palette in 32²-Textur / Farbige Beleuchtung mit Dot3 | Stereoskopie in Blitz3D | Teleport-Animation Screensaver |
![]() |
Blitzard |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ok danke für die schnellen Antworten ohh man bin ich blöd da hätt ich auch selbst druffkomme könen . ^^ ![]() ![]() ![]() |
||
User posted image |
![]() |
Blitzard |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ok mit den credits funtzt es aber mit den gegner net
ich hab des so gemacht If KeyHit(1) Then X#=300 Y#=700 gegner_x = Rand(100,700 ) gegner_y = 0 Gegner(R,0 ) = 5 Gegner(R,1 ) = 0 Gegner(R,2 ) = 0 EndIf |
||
User posted image |
totonak5 |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Blitzard hat Folgendes geschrieben: Ok mit den credits funtzt es aber mit den gegner net
nein, es "funzt" nicht: es funktioniert! ![]() |
||
Just for Fun!
Jesus loves U! |
![]() |
Blitzard |
![]() Antworten mit Zitat ![]() |
---|---|---|
Also der post war ja jetzt mal unproduktiev könntest du vllt. es nächste mal was produktiveres zum thema beitrage ![]() ![]() ![]() |
||
User posted image |
![]() |
aMulSieger des Minimalist Compo 01/13 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Seh grad, wie du das mit der Schleife machst.
Wenn es dir nicht zuviel Arbeit ist den Code umzuschreiben, würde ich dir empfehlen es so zu machen: Code: [AUSKLAPPEN] repeat ;menü if newgame_press then game() if credits_press then credits() if end_press or keyhit(1) ende=1 until ende function game() ;game end function function credits() ;credits end function() So kannst du nämlich die Variablen im Spiel und in den Credits einfach in der function als Local definieren, dann werden sie automatisch zurückgesetzt. z.B. so: Code: [AUSKLAPPEN] function game() X#=300 Y#=700 gegner_x = Rand(100,700 ) gegner_y = 0 Gegner(R,0 ) = 5 Gegner(R,1 ) = 0 Gegner(R,2 ) = 0 ;game end function So hab ich meinen Moorhuhnklon programiert, und es hat hervorragend geklappt ![]() |
||
Panic Pong - ultimate action mashup of Pong and Breakout <= aktives Spiele-Projekt, Downloads mit vielen bunten Farben!
advASCIIdraw - the advanced ASCII art program <= aktives nicht-Spiele-Projekt, must-have für ASCII/roguelike/dungeon-crawler fans! Alter BB-Kram: ThroughTheAsteroidBelt - mit Quelltext! | RGB-Palette in 32²-Textur / Farbige Beleuchtung mit Dot3 | Stereoskopie in Blitz3D | Teleport-Animation Screensaver |
![]() |
Blitzard |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ähhm ich hab die varis als loacal vor die shleife in der funktion gesetzt
Code: [AUSKLAPPEN] Function Hauptschleife() X#=300 Y#=700 gegner_x = Rand(100,700 ) gegner_y = 0 Gegner(R,0 ) = 5 Gegner(R,1 ) = 0 Gegner(R,2 ) = 0 Repeat Aber es wird nix zurückgesetzt ![]() ![]() ![]() ![]() |
||
User posted image |
![]() |
aMulSieger des Minimalist Compo 01/13 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Oh, hab ich nich gesehn ![]() Aber vieleicht liegts daran: Code: [AUSKLAPPEN] Global max_live = 300 Global current_live = 300 Global live_points Global max_laser = 100 Global current_laser# = 100 Global laser_points Global game = 1 Global Credits = 800 Global Frame# = 0 Global maus = MouseHit(1) ? |
||
Panic Pong - ultimate action mashup of Pong and Breakout <= aktives Spiele-Projekt, Downloads mit vielen bunten Farben!
advASCIIdraw - the advanced ASCII art program <= aktives nicht-Spiele-Projekt, must-have für ASCII/roguelike/dungeon-crawler fans! Alter BB-Kram: ThroughTheAsteroidBelt - mit Quelltext! | RGB-Palette in 32²-Textur / Farbige Beleuchtung mit Dot3 | Stereoskopie in Blitz3D | Teleport-Animation Screensaver |
![]() |
Blitzard |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ne an denen liegts wohl kaum warum denn auch ?? | ||
User posted image |
![]() |
aMulSieger des Minimalist Compo 01/13 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Vieleicht daran:
Code: [AUSKLAPPEN] Dim Gegner(8,3) Dim GegnerTot(5,1) Dim FeindSch(100,2) Dim Sch(100,2) Wenn nich poste am besten nochmal deinen akktuellen Code... |
||
Panic Pong - ultimate action mashup of Pong and Breakout <= aktives Spiele-Projekt, Downloads mit vielen bunten Farben!
advASCIIdraw - the advanced ASCII art program <= aktives nicht-Spiele-Projekt, must-have für ASCII/roguelike/dungeon-crawler fans! Alter BB-Kram: ThroughTheAsteroidBelt - mit Quelltext! | RGB-Palette in 32²-Textur / Farbige Beleuchtung mit Dot3 | Stereoskopie in Blitz3D | Teleport-Animation Screensaver |
![]() |
Blitzard |
![]() Antworten mit Zitat ![]() |
---|---|---|
Code:
AppTitle "Star-Ranger" Graphics 1024,768,16,2 SetBuffer BackBuffer() SeedRnd MilliSecs() Dim Gegner(8,3) Dim GegnerTot(5,1) Dim FeindSch(100,2) Dim Sch(100,2) Include "load.bb" MaskImage GegnerImage ,255,0,255 MaskImage Schiff ,255,0,255 MaskImage Schuss ,255,0,255 MaskImage GegnerSch ,255,0,255 MaskImage HudSchrift ,255,0,255 MaskImage Energie ,255,0,255 MaskImage Laser,255,0,255 MaskImage SchiffKoli ,255,0,255 Global max_live = 300 Global current_live = 300 Global live_points Global max_laser = 100 Global current_laser# = 100 Global laser_points Global Frame# = 0 Function status_bar() ;live Color 96,0,0 Rect 938,100,80,10 For live_bar = 0 To live_points Color 160,0,0 Rect 938,100,live_points,10 Next ;laser Color 0,0,120 Rect 938,170,80,10 For laser_bar = 0 To laser_points Color 0,0,255 Rect 938,170,laser_points,10 Next End Function Repeat Cls Menü() Flip Until KeyHit(1) Function Hauptschleife() X#=300 Y#=700 gegner_x = Rand(100,700 ) gegner_y = 0 Gegner(R,0 ) = 5 Gegner(R,1 ) = 0 Gegner(R,2 ) = 0 Repeat Cls If laser_pointsr > 100 Then laser_points = 100 If current_laser > 100 Then current_laser = 100 current_laser = current_laser + 0.2 ;--------------------------------------------- I = I + 2 If I=200000 Then I=0 TileBlock Hinter,0,I ;--------------------------------------------- If KeyDown(203) X=X-2 If KeyDown(205) X=X+2 If KeyDown(205) Then X = X+4 Frame = (Frame +0.5) Mod 8 ;Else ;Frame = 3 EndIf If KeyDown(203) Then X = X-4 Frame = (Frame -0.5) Mod 7 ;Else ;Frame = 3 EndIf If Not KeyDown(203) Or KeyDown(205) Then Frame = 3 If Frame > 6 Then Frame = 6 If Frame < 0 Then Frame = 0 If KeyDown(200) Then Y = Y-4 If KeyDown(208) Then Y = Y+4 ;--------------------------------------------- For P = 1 To 5 ;--------------------------------------------- If X>850 Then X=850 If X<0 Then X=0 If Y>650 Then Y=650 If Y<0 Then Y=0 ;--------------------------------------------- ;--------------------------------------------- If KeyHit(57) And laser_points > 10 Then Schuss2 = Schuss2 + 1 If Schuss2 = 21 Then Schuss2 = 1 Sch(Schuss2,0) = 1 Sch(Schuss2,1) = X+29 Sch(Schuss2,2) = Y PlaySound(SchussSound) current_laser = current_laser - 10 EndIf For S = 1 To 100 If Sch(S,1) < 0 Then Sch(S,0) = 0 If Sch(S,0) = 1 Then DrawImage Schuss, Sch(S,1), Sch(S,2) Sch(S,2) = Sch(S,2) - 10 EndIf Next ;--------------------------------------------- ;--------------------------------------------- ;------------------Feindschuss--------------------------- For P = 1 To 5 For O = 1 To 10 Entfernung = O+1 If Y>Gegner(P,2) And Gegner(P,1) = X+Entfernung Then Schuss3 = Schuss3 + 1 If Schuss3 = 2 Then Schuss3 = 1 FeindSch(Schuss3,0) = 1 FeindSch(Schuss3,1) = Gegner(P,1) FeindSch(Schuss3,2) = Gegner(P,2) EndIf Next;For P For J = 1 To 100 If FeindSch(J,1) < 0 Then FeindSch(J,0) = 0 If FeindSch(J,0) = 1 Then DrawImage GegnerSch , FeindSch(J,1)+9, FeindSch(J,2) FeindSch(J,2) = FeindSch(J,2) +5 EndIf Next ; For J Next ;---------------------------------------------- ;--------------------------------------------- For K = 1 To 5 If Gegner(K,0) = 0 Then Gegner(K,0) = Rand(100,400) Gegner(K,1) = Rand(100,1024) Gegner(K,2) = Rand(-100,0) EndIf If Gegner(K,0) <> -1 Then Gegner(K,2) = Gegner(K,2) + 2 gegner_x = 391 + Cos( Gegner(K,1) ) * Gegner(K,0) And Gegner(K,2) = Gegner(K,2) + 4 EndIf Gegner(K,2) = Gegner(K,2) + 1 If Gegner(K,2) > 768 Then Gegner(K,0) = 0 DrawImage GegnerImage ,Gegner(K,1) ,Gegner(K,2) DrawImage Gegnerimage , Gegner(3,1),Gegner(3,2) ;--------------------------------------------- For G = 1 To 100 If FeindSch(G,1) < 0 Then FeindSch(G,0) = 0 If ImagesOverlap (GegnerImage, Gegner(K,1), Gegner(K,2), Schuss, Sch(G,1), Sch(G,2)) Then Gegner(K,0) = -1 EndIf Next ; For G Next ; For K ;--------------------------------------------- ;--------------------------------------------- DrawImage Hud,930,0 DrawImage HudSchrift ,938,0 DrawImage Energie ,940,70 DrawImage Laser ,940,130 live_points = current_live * 80 / max_live laser_points = current_laser * 80 / max_laser If ImagesCollide(GegnerSch , FeindSch(1,1) , FeindSch(1,2),0, Schiff, X ,Y,0) Then current_live = current_live -10 DrawImage SchiffKoli ,X,Y,Frame Else DrawImage Schiff ,X,Y,Frame EndIf status_bar() ;--------------------------------------------- ;Hud(ende) ;Explosion For R = 1 To 5 If Gegner(R,0) = -1 Then If GegnerTot(R,1) + 70 < MilliSecs() Then GegnerTot(R,0) = GegnerTot(R,0) + 1 GegnerTot (R,1) = MilliSecs() If GegnerTot(R,0) = 6 Then GegnerTot(R,0) = 0 GegnerTot(R,1) = 0 Gegner(R,0) = 0 EndIf EndIf DrawImage Explosion ,Gegner(R,1)-5 ,Gegner(R,2)-5 ,GegnerTot(R,0) EndIf ;--------------------------------------------- Next Next ;For R ;Explosion(ende) Flip Until KeyHit(1) End Function Function Menü() Repeat Cls MX = MouseX() MY = MouseY() If MouseHit(1) Then If ImagesOverlap(NewGame,400,200,Pointer,MX,MY) Then Hauptschleife() If ImagesOverlap(Credits1,400,300,Pointer,MX,MY) Then Credits() If ImagesOverlap(Ende,400,400,Pointer,MX,MY) Then End EndIf TileBlock Hinter,0,0 If ImagesCollide(NewGame,400,200,0,Pointer,MX,MY,0) Then DrawImage NewGameover,400,200 Else DrawImage NewGame,400,200 EndIf If ImagesCollide(Credits1,400,300,0,Pointer,MX,MY,0) Then DrawImage Creditsover1,400,300 Else DrawImage Credits1,400,300 EndIf If ImagesCollide(Ende,400,400,0,Pointer,MX,MY,0) Then DrawImage Endeover,400,400 Else DrawImage Ende,400,400 EndIf DrawImage Pointer,MX,MY Flip Until KeyHit(1) End Function Function Credits() Credits = 800 Repeat Cls TileBlock Hinter,0,0 SetFont font Credits = Credits - 1 Text 430,Credits, "Space Ranger" Text 395,Credits+50 ,"Ein Spiel von Thomas I." Text 385,Credits+100 , "Programmierer: Thomas I." Text 430,Credits+150 , "Idee: Thomas I." Text 160,Credits+200, "Grafiken und Sounds: Alles freie Sound und Grafiken da ich net sehr talletiert bin ![]() Text 30,Credits+250, "Ganz Großen dank ans Blitzforum, An den Blitz-Chat (chat-blitz.de) und natürlich an ICETRUCK für die tollen Grafiken" Text 70 , Credits + 300, "Wer Kontakt aufnehemn möchte macht dies bitte unter ICQ:313-671-234 oder kommt zu mir nach Hause^^" If KeyHit(1) Then Credits = 800 Flip Until KeyHit(1) End Function ;Programm Ende |
||
User posted image |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group