Snake
Übersicht

![]() |
Eingeproggt |
![]() Antworten mit Zitat ![]() |
---|---|---|
Sry, TedY, aber ich glaub du hast Shark falsch verstanden. Das war schon gut, was er machte. Außerdem kann man wegen FlushKeys am Ende nimma beenden. Änder es grad wieder um.
EDIT: So. Jetzt is Sharks Verion von der Spielfeldbegrenzung drin und TedYs Seinabfrage mit meinem "Velroren" geht auch. Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" Const schlange_speed% = 1 SetFont LoadFont("Arial",48,1,0,0) SeedRnd MilliSecs() Global temp,cur Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Local Schwanz.Schwanz Local Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_Anzahl=10 Local timer=CreateTimer(50) Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y While Not KeyHit(1) WaitTimer timer Cls Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=10 Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select If KeyHit(200) Then Kopf_richtung=4 If KeyHit(208) Then Kopf_richtung=3 If KeyHit(203) Then Kopf_richtung=2 If KeyHit(205) Then Kopf_richtung=1 For Schwanz.Schwanz=Each Schwanz Rect Schwanz\x,Schwanz\y,10,10,0 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 Color 255,0,0 For Ein.Stein=Each Stein Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Verloren!",1,1 FlushKeys() Flip 0 WaitKey() End EndIf EndIf Next Flip 0 Wend End Der nächste, der sich dran versucht könnte ja mal Äpfel einzubinden^^ |
||
Gewinner des BCC 18, 33 und 65 sowie MiniBCC 9 |
TeDy14Gast |
![]() Antworten mit Zitat |
|
---|---|---|
Ja aber jetzt ist es doch möglich aus dem Spielfeld zu gehen...
Nur der schwanz kommt halt nicht mehr mit Oder sehe ich da wieder etwas falsch ? |
||
![]() |
Eingeproggt |
![]() Antworten mit Zitat ![]() |
---|---|---|
Probiers aus ![]() |
||
Gewinner des BCC 18, 33 und 65 sowie MiniBCC 9 |
TeDy14Gast |
![]() Antworten mit Zitat |
|
---|---|---|
Achso jetzt versteh ichs ^^
Jetzt mit Äpfel und ein paar fehler behoben Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" Const schlange_speed% = 1 SetFont LoadFont("Arial",48,1,0,0) SeedRnd MilliSecs() Global temp,cur Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y End Type Local Apfel.Apfel For Ap=0 To 9 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Next Local Schwanz.Schwanz Local Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local timer=CreateTimer(50) Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y While Not KeyHit(1) WaitTimer timer Cls Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select If KeyHit(200) Then Kopf_richtung=4 If KeyHit(208) Then Kopf_richtung=3 If KeyHit(203) Then Kopf_richtung=2 If KeyHit(205) Then Kopf_richtung=1 For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,0 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 For Apfel.Apfel=Each Apfel Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Schwanz_laenge=Schwanz_laenge+15 Delete Apfel EndIf EndIf Next For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Verloren!",1,1 FlushKeys() Flip 0 WaitKey() End EndIf EndIf Next Flip 0 Wend End |
||
![]() |
Der Eisvogel |
![]() Antworten mit Zitat ![]() |
---|---|---|
So jetzt ist nicht nur noch ein Stein im Spiel, sondern 10.
Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" Const schlange_speed% = 1 SetFont LoadFont("Arial",48,1,0,0) SeedRnd MilliSecs() Global temp,cur Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y End Type Local Apfel.Apfel For Ap=0 To 9 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Next Local Schwanz.Schwanz Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Next Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local timer=CreateTimer(50) Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y While Not KeyHit(1) WaitTimer timer Cls Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select If KeyHit(200) Then Kopf_richtung=4 If KeyHit(208) Then Kopf_richtung=3 If KeyHit(203) Then Kopf_richtung=2 If KeyHit(205) Then Kopf_richtung=1 For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,0 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 For Apfel.Apfel=Each Apfel Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Schwanz_laenge=Schwanz_laenge+15 Delete Apfel EndIf EndIf Next For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Verloren!",1,1 FlushKeys() Flip 0 WaitKey() End EndIf EndIf Next Flip 0 Wend End |
||
Ungarische Notation kann nützlich sein.
BlitzMax ; Blitz3D Win 7 Pro 64 Bit ; Intel Core i7-860 ; 8 GB Ram ; ATI HD 5750 1 GB Projekte: Window-Crasher Ich liebe es mit der WinAPI zu spielen. |
TeDy14Gast |
![]() Antworten mit Zitat |
|
---|---|---|
Und jetzt gibts Punkte ^^
Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" Const schlange_speed% = 1 SetFont LoadFont("Arial",48,1,0,0) SeedRnd MilliSecs() Global temp,cur Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y End Type Local Apfel.Apfel For Ap=0 To 9 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Next Local Schwanz.Schwanz Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Next Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local timer=CreateTimer(50) Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y Local Punkte While Not KeyHit(1) WaitTimer timer Cls Text 10,10,"Punkte : "+Punkte Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select If KeyHit(200) Then Kopf_richtung=4 If KeyHit(208) Then Kopf_richtung=3 If KeyHit(203) Then Kopf_richtung=2 If KeyHit(205) Then Kopf_richtung=1 For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,0 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 For Apfel.Apfel=Each Apfel Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Schwanz_laenge=Schwanz_laenge+15 Punkte=Punkte+1 Delete Apfel EndIf EndIf Next For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Verloren!",1,1 FlushKeys() Flip 0 WaitKey() End EndIf EndIf Next Flip 0 Wend End |
||
![]() |
Der Eisvogel |
![]() Antworten mit Zitat ![]() |
---|---|---|
Da fehlt doch noch was...
Hmm...? Ah,stimmt es gibt noch keine Leben, jetzt aber. Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" Const schlange_speed% = 1 SetFont LoadFont("Arial",48,1,0,0) SeedRnd MilliSecs() Global temp,cur Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y End Type Local Apfel.Apfel For Ap=0 To 9 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Next Local Schwanz.Schwanz Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Next Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local timer=CreateTimer(50) Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y Local Leben=5 Local Punkte While Not KeyHit(1) WaitTimer timer Cls Text 10,10,"Leben: "+Leben Text 10,60,"Punkte: "+Punkte Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select If KeyHit(200) Then Kopf_richtung=4 If KeyHit(208) Then Kopf_richtung=3 If KeyHit(203) Then Kopf_richtung=2 If KeyHit(205) Then Kopf_richtung=1 For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,0 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 For Apfel.Apfel=Each Apfel Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Schwanz_laenge=Schwanz_laenge+15 Punkte=Punkte+1 Delete Apfel EndIf EndIf Next For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Leben verloren!",1,1 Text 400,350,"Taste drücken.",1,1 Leben=Leben-1 Kopf\x=kopf_x Kopf\y=kopf_y FlushKeys() Flip 0 WaitKey() If Leben=<-1 Then End EndIf EndIf EndIf Next Flip 0 Wend End EDIT: Ich hab eben noch eine Änderung vorgenommen. Wenn die Schlang nach Links läuft, dann sie nur noch nach Oben und Unten, früher war es so das sie dann auch nach Rechts konnte. Wenn die sei dann nach Oben läuft, kann sie nur nach Rechts und Links. Das Gleiche gilt für Rechts und Unten auch, mit den entsprechenden Richtungen. Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" Const schlange_speed% = 1 SetFont LoadFont("Arial",48,1,0,0) SeedRnd MilliSecs() Global temp,cur Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y End Type Local Apfel.Apfel For Ap=0 To 9 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Next Local Schwanz.Schwanz Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Next Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local timer=CreateTimer(50) Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y Local Leben=5 Local Punkte While Not KeyHit(1) WaitTimer timer Cls Text 10,10,"Leben: "+Leben Text 10,60,"Punkte: "+Punkte Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select If KeyHit(200) And (Kopf_richtung=1 Or Kopf_richtung=2) Then Kopf_richtung=4 If KeyHit(208) And (Kopf_richtung=1 Or Kopf_richtung=2) Then Kopf_richtung=3 If KeyHit(203) And (Kopf_richtung=3 Or Kopf_richtung=4) Then Kopf_richtung=2 If KeyHit(205) And (Kopf_richtung=3 Or Kopf_richtung=4) Then Kopf_richtung=1 For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,0 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 For Apfel.Apfel=Each Apfel Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Schwanz_laenge=Schwanz_laenge+15 Punkte=Punkte+1 Delete Apfel EndIf EndIf Next For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Leben verloren!",1,1 Text 400,350,"Taste drücken.",1,1 Leben=Leben-1 Kopf\x=kopf_x Kopf\y=kopf_y FlushKeys() Flip 0 WaitKey() If Leben=<-1 Then End EndIf EndIf EndIf Next Flip 0 Wend End |
||
Ungarische Notation kann nützlich sein.
BlitzMax ; Blitz3D Win 7 Pro 64 Bit ; Intel Core i7-860 ; 8 GB Ram ; ATI HD 5750 1 GB Projekte: Window-Crasher Ich liebe es mit der WinAPI zu spielen. |
Shark |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
So falls 10 Äpfel gefuttert wurden, dann gibt es wieder 10 Äpfel ![]() Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" Const schlange_speed% = 3 SetFont LoadFont("Arial",48,1,0,0) SeedRnd MilliSecs() Global temp,cur Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y End Type Local Apfel.Apfel Global Apfelanzahl = 10 For anzahl=0 To Apfelanzahl-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Next Local Schwanz.Schwanz Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Next Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=3 Local timer=CreateTimer(50) Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y Local Leben=5 Local Punkte While Not KeyHit(1) WaitTimer timer Cls Text 10,10,"Leben: "+Leben Text 10,60,"Punkte: "+Punkte Text 10,90,"Anzahl: "+Apfelanzahl Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select If KeyHit(200) And (Kopf_richtung=1 Or Kopf_richtung=2) Then Kopf_richtung=4 If KeyHit(208) And (Kopf_richtung=1 Or Kopf_richtung=2) Then Kopf_richtung=3 If KeyHit(203) And (Kopf_richtung=3 Or Kopf_richtung=4) Then Kopf_richtung=2 If KeyHit(205) And (Kopf_richtung=3 Or Kopf_richtung=4) Then Kopf_richtung=1 For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,1 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 For Apfel.Apfel=Each Apfel Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Schwanz_laenge=Schwanz_laenge+4 Punkte=Punkte+1 Apfelanzahl = Apfelanzahl - 1 Delete Apfel EndIf EndIf Next If Apfelanzahl <=0 Then For i=0 To 9 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Next Apfelanzahl = 10 EndIf For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Leben verloren!",1,1 Text 400,350,"Taste drücken.",1,1 Leben=Leben-1 Kopf\x=kopf_x Kopf\y=kopf_y FlushKeys() Flip 0 WaitKey() If Leben=<-1 Then End EndIf EndIf EndIf Next Flip 0 Wend End |
||
![]() |
Der Eisvogel |
![]() Antworten mit Zitat ![]() |
---|---|---|
Also, folgendes habe ich vollbracht:
![]() ![]() ![]() Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" Local schlange_speed = 1 SetFont LoadFont("Arial",48,1,0,0) SeedRnd MilliSecs() Global temp,cur Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y Field typ End Type Local Apfel.Apfel Global Apfelanzahl = 10 For anzahl=0 To Apfelanzahl-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Apfel\typ=Rand(-2,2) Next Local Schwanz.Schwanz Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Next Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local timer=CreateTimer(50) Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y Local Leben=5 Local Punkte While Not KeyHit(1) WaitTimer timer Cls Text 10,10,"Leben: "+Leben Text 10,60,"Punkte: "+Punkte Text 10,110,"Anzahl: "+Apfelanzahl Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select If KeyHit(200) And (Kopf_richtung=1 Or Kopf_richtung=2) Then Kopf_richtung=4 If KeyHit(208) And (Kopf_richtung=1 Or Kopf_richtung=2) Then Kopf_richtung=3 If KeyHit(203) And (Kopf_richtung=3 Or Kopf_richtung=4) Then Kopf_richtung=2 If KeyHit(205) And (Kopf_richtung=3 Or Kopf_richtung=4) Then Kopf_richtung=1 For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,1 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 For Apfel.Apfel=Each Apfel Color 0,255,0 Select Apfel\typ Case -2 Color 255,0,0 Rect Apfel\x,Apfel\y,10,10 Case -1 Color 255,150,0 Rect Apfel\x,Apfel\y,10,10 Case 0 Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 Case 1 Color 0,150,255 Rect Apfel\x,Apfel\y,10,10 Case 2 Color 0,0,255 Rect Apfel\x,Apfel\y,10,10 End Select If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Schwanz_laenge=Schwanz_laenge+10 Punkte=Punkte+1 Select Apfel\typ Case -2 Punkte=Punkte-10 Case -1 Punkte=Punkte-1 Case 0 Punkte=Punkte Case 1 Punkte=Punkte+1 Case 2 Punkte=Punkte+10 End Select If Punkte<0 Then Punkte=0 Apfelanzahl = Apfelanzahl - 1 Delete Apfel EndIf EndIf Next If Apfelanzahl <=0 Then schlange_speed=schlange_speed+1 Apfelanzahl = 10 For i=0 To 9 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Next Delay 1000 EndIf For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Leben verloren!",1,1 Text 400,350,"Taste drücken.",1,1 Leben=Leben-1 Kopf\x=kopf_x Kopf\y=kopf_y FlushKeys() Flip 0 WaitKey() If Leben=<-1 Then End EndIf EndIf EndIf Next Flip 0 Wend End |
||
Ungarische Notation kann nützlich sein.
BlitzMax ; Blitz3D Win 7 Pro 64 Bit ; Intel Core i7-860 ; 8 GB Ram ; ATI HD 5750 1 GB Projekte: Window-Crasher Ich liebe es mit der WinAPI zu spielen. |
Shark |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
![]() ![]() Edit: Kein missen, sondern miese ![]() Was ich damit sagen wollte ist, dass es nix bringt die Äpfel zu differenzieren, wenn man doch ey alle sammeln muss... Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" SetFont LoadFont("Arial",36,1,0,0) SeedRnd MilliSecs() ;Variable Global temp,cur Global Apfelanzahl = 10 Local Leben=5 Local Punkte Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local schlange_speed=1 Local timer=CreateTimer(50) Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y Field typ End Type ;Anfangs Äpfel werden generiert Local Apfel.Apfel For anzahl=0 To Apfelanzahl-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Apfel\typ=Rand(-2,2) Next ;Steine werden generiert Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Next ;Schwanz wird gebildet Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y ;Hauptschleife While Not KeyHit(1) WaitTimer timer Cls Text 10,10,"Leben: "+Leben Text 10,60,"Punkte: "+Punkte Text 10,110,"Anzahl: "+Apfelanzahl Local Schwanz.Schwanz Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge ;Bewegung der Schlange Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select ;Richtungsänderung der Schlange If KeyHit(200) And (Kopf_richtung<>3) Then Kopf_richtung=4 If KeyHit(208) And (Kopf_richtung<>4) Then Kopf_richtung=3 If KeyHit(203) And (Kopf_richtung<>1) Then Kopf_richtung=2 If KeyHit(205) And (Kopf_richtung<>2) Then Kopf_richtung=1 ;Schlange wird gezeichnet For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,1 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 ;Verschiedene Äpfel For Apfel.Apfel=Each Apfel Color 0,255,0 Select Apfel\typ Case -2 Color 255,0,0 Rect Apfel\x,Apfel\y,10,10 Case -1 Color 255,150,0 Rect Apfel\x,Apfel\y,10,10 Case 0 Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 Case 1 Color 0,150,255 Rect Apfel\x,Apfel\y,10,10 Case 2 Color 0,0,255 Rect Apfel\x,Apfel\y,10,10 End Select ;Kollision mit Apfel If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Schwanz_laenge=Schwanz_laenge+10 Punkte=Punkte+1 Select Apfel\typ Case -2 Punkte=Punkte-10 Case -1 Punkte=Punkte-1 Case 0 Punkte=Punkte Case 1 Punkte=Punkte+1 Case 2 Punkte=Punkte+10 End Select If Punkte<0 Then Punkte=0 Apfelanzahl = Apfelanzahl - 1 Delete Apfel EndIf EndIf Next ;Falls keine Äpfel mehr da sind If Apfelanzahl <=0 Then schlange_speed=schlange_speed+1 Apfelanzahl = 10 For i=0 To 9 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Next ;Delay 1000 EndIf ;Kollision mit Stein For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Leben verloren!",1,1 Text 400,350,"Taste drücken.",1,1 Leben=Leben-1 Kopf\x=kopf_x Kopf\y=kopf_y FlushKeys() Flip 0 WaitKey() If Leben=<-1 Then End EndIf EndIf EndIf Next Flip 0 Wend End |
||
- Zuletzt bearbeitet von Shark am Di, Jan 29, 2008 20:43, insgesamt einmal bearbeitet
![]() |
Der Eisvogel |
![]() Antworten mit Zitat ![]() |
---|---|---|
Was meinst du mit "missen"
Das können wir über ICQ Regeln, falls du ICQ hast: 330291637 Ansonsten dann halt hier. [EDIT1] Also, meine Antwort auf die Frage von Shark: Der nächste der dem Code was hinzufügt könnte es so machen das die Miesen Äpfel nicht eingesammelt werden müssen um 10 (oder mehr) neue Äpfel zu bekommen, sondern nur die Äpfel die einem was bringen (grün,hellblau,dunkelblau) und wenn alle guten eingesammelt sind, alle noch bestehenden (miesen) Äpfel gelöscht werden. [/EDIT1] [EDIT2] Hier ist der Code so wie er beim ersten EDIT beschrieben wurde: Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" SetFont LoadFont("Arial",36,1,0,0) SeedRnd MilliSecs() ;Variable Global temp,cur Global Apfelanzahl = 10 Global Apfelanzahl_mies = 5 Local Leben=5 Local Punkte Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local schlange_speed=1 Local timer=CreateTimer(50) Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y Field typ End Type ;Anfangs Äpfel werden generiert Local Apfel.Apfel For anzahl=0 To Apfelanzahl-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Apfel\typ=Rand(0,2) Next For anzahl=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Apfel\typ=Rand(-2,-1) Next ;Steine werden generiert Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Next ;Schwanz wird gebildet Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y ;Hauptschleife While Not KeyHit(1) WaitTimer timer Cls Text 10,10,"Leben: "+Leben Text 10,60,"Punkte: "+Punkte Text 10,110,"Anzahl: "+Apfelanzahl Local Schwanz.Schwanz Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge ;Bewegung der Schlange Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select ;Richtungsänderung der Schlange If KeyHit(200) And (Kopf_richtung<>3) Then Kopf_richtung=4 If KeyHit(208) And (Kopf_richtung<>4) Then Kopf_richtung=3 If KeyHit(203) And (Kopf_richtung<>1) Then Kopf_richtung=2 If KeyHit(205) And (Kopf_richtung<>2) Then Kopf_richtung=1 ;Schlange wird gezeichnet For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,1 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 ;Verschiedene Äpfel For Apfel.Apfel=Each Apfel Color 0,255,0 Select Apfel\typ Case -2 Color 255,0,0 Rect Apfel\x,Apfel\y,10,10 Case -1 Color 255,150,0 Rect Apfel\x,Apfel\y,10,10 Case 0 Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 Case 1 Color 0,150,255 Rect Apfel\x,Apfel\y,10,10 Case 2 Color 0,0,255 Rect Apfel\x,Apfel\y,10,10 End Select ;Kollision mit Apfel If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Schwanz_laenge=Schwanz_laenge+10 Select Apfel\typ Case -2 Punkte=Punkte-10 Case -1 Punkte=Punkte-1 Case 0 Punkte=Punkte Apfelanzahl = Apfelanzahl - 1 Case 1 Punkte=Punkte+1 Apfelanzahl = Apfelanzahl - 1 Case 2 Punkte=Punkte+10 Apfelanzahl = Apfelanzahl - 1 End Select If Punkte<0 Then Punkte=0 Delete Apfel EndIf EndIf Next ;Falls keine Äpfel mehr da sind If Apfelanzahl <=0 Then For Apfel.Apfel=Each Apfel Delete Apfel.Apfel Next schlange_speed=schlange_speed+1 Apfelanzahl = 10 Apfelanzahl_mies = Apfelanzahl_mies+1 For i=0 To Apfelanzahl-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Apfel\typ=Rand(0,2) Next For i=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Apfel\typ=Rand(-2,-1) Next Delay 1000 EndIf ;Kollision mit Stein For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Leben verloren!",1,1 Text 400,350,"Taste drücken.",1,1 Leben=Leben-1 Kopf\x=kopf_x Kopf\y=kopf_y FlushKeys() Flip 0 WaitKey() If Leben=<-1 Then End EndIf EndIf EndIf Next Flip 0 Wend End [/EDIT2] |
||
Ungarische Notation kann nützlich sein.
BlitzMax ; Blitz3D Win 7 Pro 64 Bit ; Intel Core i7-860 ; 8 GB Ram ; ATI HD 5750 1 GB Projekte: Window-Crasher Ich liebe es mit der WinAPI zu spielen. |
Shark |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
![]() ![]() Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" SetFont LoadFont("Arial",24,1,0,0) SeedRnd MilliSecs() ;Variable Global temp,cur Global Apfelanzahl = 10 Global Apfelanzahl_mies = 5 Local Leben=5 Local Punkte Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local schlange_speed=1 Local level=1 Local timer=CreateTimer(50) Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y Field typ End Type ;Anfangs Äpfel werden generiert Local Apfel.Apfel For anzahl=0 To Apfelanzahl-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Apfel\typ=Rand(-2,2) Next For anzahl=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Apfel\typ=Rand(-2,-1) Next ;Steine werden generiert Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Next ;Schwanz wird gebildet Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y ;Hauptschleife While Not KeyHit(1) WaitTimer timer Cls Text ((screen_w%/4)*1),10,"Leben: "+Leben Text ((screen_w%/4)*2),10,"Punkte: "+Punkte Text ((screen_w%/4)*3),10,"Level: "+level Local Schwanz.Schwanz Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge ;Bewegung der Schlange Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select ;Richtungsänderung der Schlange If KeyHit(200) And (Kopf_richtung<>3) Then Kopf_richtung=4 If KeyHit(208) And (Kopf_richtung<>4) Then Kopf_richtung=3 If KeyHit(203) And (Kopf_richtung<>1) Then Kopf_richtung=2 If KeyHit(205) And (Kopf_richtung<>2) Then Kopf_richtung=1 ;Schlange wird gezeichnet For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,1 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 ;Verschiedene Äpfel For Apfel.Apfel=Each Apfel Color 0,255,0 Select Apfel\typ Case -2 Color 255,0,0 Rect Apfel\x,Apfel\y,10,10 Case -1 Color 255,150,0 Rect Apfel\x,Apfel\y,10,10 Case 0 Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 Case 1 Color 0,150,255 Rect Apfel\x,Apfel\y,10,10 Case 2 Color 0,0,255 Rect Apfel\x,Apfel\y,10,10 End Select ;Kollision mit Apfel If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Schwanz_laenge=Schwanz_laenge+10 Punkte=Punkte+1 Select Apfel\typ Case -2 Punkte=Punkte-10 Case -1 Punkte=Punkte-1 Case 0 Apfelanzahl = Apfelanzahl - 1 Case 1 Punkte=Punkte+1 Apfelanzahl = Apfelanzahl - 1 Case 2 Punkte=Punkte+10 Apfelanzahl = Apfelanzahl - 1 End Select If Punkte<0 Then Punkte=0 Delete Apfel EndIf EndIf Next ;Falls keine Äpfel mehr da sind If Apfelanzahl <=0 Then schlange_speed=schlange_speed+1 Apfelanzahl = 10 For i=0 To Apfelanzahl -1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Next Apfelanzahl_mies = Apfelanzahl_mies+1 For i=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%) Apfel\y=Rand(0,screen_h%) Apfel\typ=Rand(-2,-1) Next level = level + 1 ;Delay 1000 EndIf ;Kollision mit Stein For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Leben verloren!",1,1 Text 400,350,"Taste drücken.",1,1 Leben=Leben-1 Kopf\x=kopf_x Kopf\y=kopf_y For schwanz.schwanz = Each schwanz If Handle(schwanz) <> 1 Then ; 1 = Kopf Delete schwanz EndIf Next FlushKeys() Flip 0 WaitKey() If Leben=<0 Then End EndIf EndIf EndIf Next Flip 0 Wend End |
||
![]() |
Der Eisvogel |
![]() Antworten mit Zitat ![]() |
---|---|---|
Neuer Code im Anmarsch.
Änderungen: ![]() ![]() ![]() ![]() Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" SetFont LoadFont("Arial",24,1,0,0) SeedRnd MilliSecs() ;Variable Global temp,cur Global Apfelanzahl = 10 Global Apfelanzahl_mies = 5 Local Leben=5 Local Punkte Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local schlange_speed=1 Local level=1 Local timer=CreateTimer(50) Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y Field typ End Type ;Anfangs Äpfel werden generiert Local Apfel.Apfel For anzahl=0 To Apfelanzahl-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%-10) Apfel\y=Rand(0,screen_h%-10) Apfel\typ=Rand(0,2) Next For anzahl=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%-10) Apfel\y=Rand(0,screen_h%-10) Apfel\typ=Rand(-2,-1) Next ;Steine werden generiert Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Next ;Schwanz wird gebildet Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y ;Hauptschleife While Not KeyHit(1) WaitTimer timer Cls Text ((screen_w%/4)*1),10,"Leben: "+Leben Text ((screen_w%/4)*2),10,"Punkte: "+Punkte Text ((screen_w%/4)*3),10,"Level: "+level Local Schwanz.Schwanz Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge ;Bewegung der Schlange Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select ;Richtungsänderung der Schlange If KeyHit(200) And (Kopf_richtung<>3) Then Kopf_richtung=4 If KeyHit(208) And (Kopf_richtung<>4) Then Kopf_richtung=3 If KeyHit(203) And (Kopf_richtung<>1) Then Kopf_richtung=2 If KeyHit(205) And (Kopf_richtung<>2) Then Kopf_richtung=1 ;Schlange wird gezeichnet For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,1 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 ;Verschiedene Äpfel For Apfel.Apfel=Each Apfel Color 0,255,0 Select Apfel\typ Case -2 Color 255,0,0 Rect Apfel\x,Apfel\y,10,10 Case -1 Color 255,150,0 Rect Apfel\x,Apfel\y,10,10 Case 0 Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 Case 1 Color 0,150,255 Rect Apfel\x,Apfel\y,10,10 Case 2 Color 0,0,255 Rect Apfel\x,Apfel\y,10,10 End Select ;Kollision mit Apfel If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Schwanz_laenge=Schwanz_laenge+10 Punkte=Punkte+1 Select Apfel\typ Case -2 Punkte=Punkte-10 Case -1 Punkte=Punkte-1 Case 0 Apfelanzahl = Apfelanzahl - 1 Case 1 Punkte=Punkte+1 Apfelanzahl = Apfelanzahl - 1 Case 2 Punkte=Punkte+10 Apfelanzahl = Apfelanzahl - 1 End Select If Punkte<0 Then Punkte=0 Delete Apfel EndIf EndIf Next ;Falls keine Äpfel mehr da sind If Apfelanzahl <=0 Then schlange_speed=schlange_speed+1 Apfelanzahl = 10 For i=0 To Apfelanzahl -1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%-10) Apfel\y=Rand(0,screen_h%-10) Apfel\typ=Rand(0,2) Next Apfelanzahl_mies = Apfelanzahl_mies+1 For i=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%-10) Apfel\y=Rand(0,screen_h%-10) Apfel\typ=Rand(-2,-1) Next level = level + 1 Schwanz_laenge=Schwanz_laenge/2 Kopf\x=kopf_x Kopf\y=kopf_y For schwanz.schwanz = Each schwanz If Handle(schwanz) <> 1 Then ; 1 = Kopf Delete schwanz EndIf Next Kopf_richtung=4 ;Delay 1000 EndIf ;Kollision mit Stein For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Leben verloren!",1,1 Text 400,350,"Taste drücken.",1,1 Leben=Leben-1 Kopf\x=kopf_x Kopf\y=kopf_y For schwanz.schwanz = Each schwanz If Handle(schwanz) <> 1 Then ; 1 = Kopf Delete schwanz EndIf Next Kopf_richtung=4 FlushKeys() Flip 0 WaitKey() If Leben=<0 Then End EndIf EndIf EndIf Next Flip 0 Wend End |
||
Ungarische Notation kann nützlich sein.
BlitzMax ; Blitz3D Win 7 Pro 64 Bit ; Intel Core i7-860 ; 8 GB Ram ; ATI HD 5750 1 GB Projekte: Window-Crasher Ich liebe es mit der WinAPI zu spielen. |
Shark |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
![]() ![]() Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" Local arial1 = LoadFont("Arial",24,1,0,0) Local arial2 = LoadFont("Arial",12,1,0,0) SetFont arial1 SeedRnd MilliSecs() ;Variable Global temp,cur Global Apfelanzahl = 10 Global Apfelanzahl_mies = 5 Local Leben=5 Local Punkte Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local schlange_speed=1 Local level=1 Local fps,fps_frames,fps_ms = MilliSecs() Local timer=CreateTimer(50) Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y Field typ End Type ;Anfangs Äpfel werden generiert Local Apfel.Apfel For anzahl=0 To Apfelanzahl-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%-10) Apfel\y=Rand(0,screen_h%-10) Apfel\typ=Rand(0,2) Next For anzahl=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%-10) Apfel\y=Rand(0,screen_h%-10) Apfel\typ=Rand(-2,-1) Next ;Steine werden generiert Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(80) * 10 Ein\y=Rand(60) * 10 Next ;Schwanz wird gebildet Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y ;Hauptschleife While Not KeyHit(1) WaitTimer timer Cls Text ((screen_w%/4)*1),10,"Leben: "+Leben Text ((screen_w%/4)*2),10,"Punkte: "+Punkte Text ((screen_w%/4)*3),10,"Level: "+level SetFont arial2 Text (20),(screen_h-20),"Fps: "+fps SetFont arial1 ;FPS-Routine fps_frames = fps_frames + 1 If MilliSecs()-fps_ms >= 1000 Then fps_ms = MilliSecs() fps = fps_frames fps_frames = 0 EndIf Local Schwanz.Schwanz Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge ;Bewegung der Schlange Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select ;Richtungsänderung der Schlange If KeyHit(200) And (Kopf_richtung<>3) Then Kopf_richtung=4 If KeyHit(208) And (Kopf_richtung<>4) Then Kopf_richtung=3 If KeyHit(203) And (Kopf_richtung<>1) Then Kopf_richtung=2 If KeyHit(205) And (Kopf_richtung<>2) Then Kopf_richtung=1 ;Schlange wird gezeichnet For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,1 If Schwanz\x < 0 Then Schwanz\x = screen_w If Schwanz\x > screen_w Then Schwanz\x = 0 If Schwanz\y < 0 Then Schwanz\y = screen_h If Schwanz\y > screen_h Then Schwanz\y = 0 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 ;Verschiedene Äpfel For Apfel.Apfel=Each Apfel Color 0,255,0 Select Apfel\typ Case -2 Color 255,0,0 Rect Apfel\x,Apfel\y,10,10 Case -1 Color 255,150,0 Rect Apfel\x,Apfel\y,10,10 Case 0 Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 Case 1 Color 0,150,255 Rect Apfel\x,Apfel\y,10,10 Case 2 Color 0,0,255 Rect Apfel\x,Apfel\y,10,10 End Select ;Kollision mit Apfel If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Punkte=Punkte+1 Select Apfel\typ Case -2 Punkte=Punkte-10 If Schwanz_laenge<>10 Schwanz_laenge=Schwanz_laenge-10 EndIf Case -1 Punkte=Punkte-1 If Schwanz_laenge<>10 Schwanz_laenge=Schwanz_laenge-10 EndIf Case 0 Apfelanzahl = Apfelanzahl - 1 Schwanz_laenge=Schwanz_laenge+10 Case 1 Punkte=Punkte+1 Apfelanzahl = Apfelanzahl - 1 Schwanz_laenge=Schwanz_laenge+10 Case 2 Punkte=Punkte+10 Apfelanzahl = Apfelanzahl - 1 Schwanz_laenge=Schwanz_laenge+10 End Select If Punkte<0 Then Punkte=0 Delete Apfel EndIf EndIf Next ;Falls keine Äpfel mehr da sind If Apfelanzahl <=0 Then schlange_speed=schlange_speed+1 Apfelanzahl = 10 For i=0 To Apfelanzahl -1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%-10) Apfel\y=Rand(0,screen_h%-10) Apfel\typ=Rand(0,2) Next Apfelanzahl_mies = Apfelanzahl_mies+1 For i=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%-10) Apfel\y=Rand(0,screen_h%-10) Apfel\typ=Rand(-2,-1) Next level = level + 1 Schwanz_laenge=Schwanz_laenge/2 Kopf\x=kopf_x Kopf\y=kopf_y For schwanz.schwanz = Each schwanz If Handle(schwanz) <> 1 Then ; 1 = Kopf Delete schwanz EndIf Next Kopf_richtung=4 ;Delay 1000 EndIf ;Kollision mit Stein For Ein.Stein=Each Stein Color 200,200,200 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Leben verloren!",1,1 Text 400,350,"Taste drücken.",1,1 Leben=Leben-1 Kopf\x=kopf_x Kopf\y=kopf_y For schwanz.schwanz = Each schwanz If Handle(schwanz) <> 1 Then ; 1 = Kopf Delete schwanz EndIf Next Kopf_richtung=4 FlushKeys() Flip 0 WaitKey() If Leben=<0 Then End EndIf EndIf EndIf Next Flip 0 Wend End |
||
![]() |
Der Eisvogel |
![]() Antworten mit Zitat ![]() |
---|---|---|
Änderungen:
![]() ![]() ![]() Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 SetBuffer BackBuffer() AppTitle "Snake" Local arial1 = LoadFont("Arial",24,1,0,0) Local arial2 = LoadFont("Arial",12,1,0,0) SetFont arial1 SeedRnd MilliSecs() ;Variable Global temp,cur Global Apfelanzahl = 10 Global Apfelanzahl_mies = 5 Local Leben=5 Local Punkte Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local schlange_speed=1 Local level=1 Local fps,fps_frames,fps_ms = MilliSecs() Local timer=CreateTimer(50) Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y Field typ End Type ;Anfangs Äpfel werden generiert Local Apfel.Apfel For anzahl=0 To Apfelanzahl-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%-30)+10 Apfel\y=Rand(0,screen_h%-80)+60 Apfel\typ=Rand(0,2) Next For anzahl=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x= Rand(0,screen_w%-30)+10 Apfel\y=Rand(0,screen_h%-80)+60 Apfel\typ=Rand(-2,-1) Next ;Steine werden generiert Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(0,screen_w%-30)+10 Ein\y=Rand(0,screen_h%-80)+60 Next ;Schwanz wird gebildet Local Kopf.Schwanz=New Schwanz Kopf\x=kopf_x Kopf\y=kopf_y ;Hauptschleife While Not KeyHit(1) WaitTimer timer Cls Color 255,255,255 Rect 0,50,800,549,1 Color 150,150,150 Rect 10,60,780,529 Color 255,0,0 Text ((screen_w%/4)*1),10,"Leben: "+Leben Text ((screen_w%/4)*2),10,"Punkte: "+Punkte Text ((screen_w%/4)*3),10,"Level: "+level ;SetFont arial2 ;Text (20),(screen_h-10),"Fps: "+fps ;SetFont arial1 ;FPS-Routine ;fps_frames = fps_frames + 1 ;If MilliSecs()-fps_ms >= 1000 Then ;fps_ms = MilliSecs() ;fps = fps_frames ;fps_frames = 0 ;EndIf Local Schwanz.Schwanz Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge ;Bewegung der Schlange Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select ;Richtungsänderung der Schlange If KeyHit(200) And (Kopf_richtung<>3) Then Kopf_richtung=4 If KeyHit(208) And (Kopf_richtung<>4) Then Kopf_richtung=3 If KeyHit(203) And (Kopf_richtung<>1) Then Kopf_richtung=2 If KeyHit(205) And (Kopf_richtung<>2) Then Kopf_richtung=1 ;Schlange wird gezeichnet For Schwanz.Schwanz=Each Schwanz Color 255,0,0 Rect Schwanz\x,Schwanz\y,10,10,1 If Schwanz\x < 10 Then Schwanz\x = screen_w-21 If Schwanz\x > screen_w-21 Then Schwanz\x = 10 If Schwanz\y < 60 Then Schwanz\y = screen_h-21 If Schwanz\y > screen_h-21 Then Schwanz\y = 60 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 ;Verschiedene Äpfel For Apfel.Apfel=Each Apfel Color 0,255,0 Select Apfel\typ Case -2 Color 255,0,0 Rect Apfel\x,Apfel\y,10,10 Case -1 Color 255,150,0 Rect Apfel\x,Apfel\y,10,10 Case 0 Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 Case 1 Color 0,150,255 Rect Apfel\x,Apfel\y,10,10 Case 2 Color 0,0,255 Rect Apfel\x,Apfel\y,10,10 End Select ;Kollision mit Apfel If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Punkte=Punkte+1 Select Apfel\typ Case -2 Punkte=Punkte-10 If Schwanz_laenge<>10 Schwanz_laenge=Schwanz_laenge-10 EndIf Case -1 Punkte=Punkte-1 If Schwanz_laenge<>10 Schwanz_laenge=Schwanz_laenge-10 EndIf Case 0 Apfelanzahl = Apfelanzahl - 1 Schwanz_laenge=Schwanz_laenge+10 Case 1 Punkte=Punkte+1 Apfelanzahl = Apfelanzahl - 1 Schwanz_laenge=Schwanz_laenge+10 Case 2 Punkte=Punkte+10 Apfelanzahl = Apfelanzahl - 1 Schwanz_laenge=Schwanz_laenge+10 End Select If Punkte<0 Then Punkte=0 Delete Apfel EndIf EndIf Next ;Falls keine Äpfel mehr da sind If Apfelanzahl <=0 Then schlange_speed=schlange_speed+1 Apfelanzahl = 10 For i=0 To Apfelanzahl -1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%-10) Apfel\y=Rand(0,screen_h%-10) Apfel\typ=Rand(0,2) Next Apfelanzahl_mies = Apfelanzahl_mies+1 For i=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x=Rand(0,screen_w%-10) Apfel\y=Rand(0,screen_h%-10) Apfel\typ=Rand(-2,-1) Next level = level + 1 Schwanz_laenge=Schwanz_laenge/2 Kopf\x=kopf_x Kopf\y=kopf_y For schwanz.schwanz = Each schwanz If Handle(schwanz) <> 1 Then ; 1 = Kopf Delete schwanz EndIf Next Kopf_richtung=4 ;Delay 1000 EndIf ;Kollision mit Stein For Ein.Stein=Each Stein Color 0,0,0 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Leben verloren!",1,1 Text 400,350,"Taste drücken.",1,1 Leben=Leben-1 Kopf\x=kopf_x Kopf\y=kopf_y For schwanz.schwanz = Each schwanz If Handle(schwanz) <> 1 Then ; 1 = Kopf Delete schwanz EndIf Next Kopf_richtung=4 FlushKeys() Flip 0 WaitKey() If Leben=<0 Then End EndIf EndIf EndIf Next Flip 0 Wend End |
||
Ungarische Notation kann nützlich sein.
BlitzMax ; Blitz3D Win 7 Pro 64 Bit ; Intel Core i7-860 ; 8 GB Ram ; ATI HD 5750 1 GB Projekte: Window-Crasher Ich liebe es mit der WinAPI zu spielen. |
Shark |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
![]() ![]() ![]() ![]() Code: [AUSKLAPPEN] Const screen_w%=800,screen_h%=600
Graphics screen_w,screen_h,32,2 ;SetBuffer BackBuffer() AppTitle "Snake" Local arial1 = LoadFont("Arial",24,1,0,0) Local arial2 = LoadFont("Arial",12,1,0,0) SetFont arial1 SeedRnd MilliSecs() ;Einstellen ob man fps haben will oder nicht Const fps_anzeige= True ; Wenn false dann wird sie nicht angezeigt! ;Variable Global temp,cur Global Apfelanzahl = 10 Global Apfelanzahl_mies = 5 Local Leben=5 Local pos_leben_x = ((screen_w%/4)*1+StringWidth("Leben: ")) Local Punkte Local pos_punkte_x = ((screen_w%/4)*2+StringWidth("Punkte: ")) Local kopf_x=400,kopf_y=300,Kopf_richtung=4 Local Schwanz_laenge=10 Local schlange_speed=1 Local level=1 Local pos_level_x = ((screen_w%/4)*3+StringWidth("Level: ")) Local fps,fps_frames,fps_ms = MilliSecs() Local timer=CreateTimer(50) ;Erstellen vom Hintergrund Global Background = CreateImage(screen_w,screen_h) SetBuffer ImageBuffer(Background) Color 255,255,255 Rect 0,50,screen_W,screen_h-51,1 Color 150,150,150 Rect 10,60,screen_W-20,screen_h-71 Color 255,0,0 Text ((screen_w%/4)*1),10,"Leben: " Text ((screen_w%/4)*2),10,"Punkte: " Text ((screen_w%/4)*3),10,"Level: " SetBuffer BackBuffer() Type Schwanz Field x Field y Field time End Type Type Stein Field x Field y End Type Type Apfel Field x Field y Field typ End Type ;Anfangs Äpfel werden generiert Local Apfel.Apfel For anzahl=0 To Apfelanzahl-1 Apfel.Apfel=New Apfel Apfel\x=Rand(1,(screen_w%/10)-2)*10 Apfel\y=Rand(6,(screen_h%/10)-8)*10 Apfel\typ=Rand(0,2) Next For anzahl=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x=Rand(1,(screen_w%/10)-2)*10 Apfel\y=Rand(6,(screen_h%/10)-8)*10 Apfel\typ=Rand(-2,-1) Next ;Steine werden generiert Local Ein.Stein For i=0 To 9 Ein.Stein=New Stein Ein\x=Rand(1,(screen_w%/10)-2)*10 Ein\y=Rand(6,(screen_h%/10)-8)*10 Next ;Schwanz wird gebildet Local Kopf.Schwanz=New Schwanz For ein.stein = Each stein kopf\x = kopf_x If kopf\x = ein\x Then While Not kopf\x = ein\x kopf\x = Rand(1,(screen_w%/10)-2)*10 Wend EndIf Kopf\y=kopf_y If kopf\y = ein\y Then While Not kopf\y = ein\y kopf\y = Rand(6,(screen_h%/10)-8)*10 Wend EndIf Next ;Hauptschleife While Not KeyHit(1) WaitTimer timer Cls DrawBlock Background,0,0 Color 255,0,0 Color 255,0,0 Text pos_leben_x,10,Leben Text pos_punkte_x,10,Punkte Text pos_level_x,10,level ;Fps Routine If fps_anzeige = True Then SetFont arial2 Text (10),(screen_h-13),"Fps: "+fps SetFont arial1 fps_frames = fps_frames + 1 If MilliSecs()-fps_ms >= 250 Then fps_ms = MilliSecs() fps = fps_frames *4 fps_frames = 0 EndIf EndIf Local Schwanz.Schwanz Schwanz.Schwanz=New Schwanz Schwanz\x=Kopf\x Schwanz\y=Kopf\y Schwanz\time=schwanz_laenge ;Bewegung der Schlange Select Kopf_richtung Case 1 Kopf\x=Kopf\x+schlange_speed Case 2 Kopf\x=Kopf\x-schlange_speed Case 3 Kopf\y=Kopf\y+schlange_speed Case 4 Kopf\y=Kopf\y-schlange_speed End Select ;Richtungsänderung der Schlange If KeyHit(200) And (Kopf_richtung<>3) Then Kopf_richtung=4 If KeyHit(208) And (Kopf_richtung<>4) Then Kopf_richtung=3 If KeyHit(203) And (Kopf_richtung<>1) Then Kopf_richtung=2 If KeyHit(205) And (Kopf_richtung<>2) Then Kopf_richtung=1 ;Schlange wird gezeichnet + Rand For Schwanz.Schwanz=Each Schwanz Rect Schwanz\x,Schwanz\y,10,10,1 If Schwanz\x < 10 Then Schwanz\x = screen_w-21 If Schwanz\x > screen_w-21 Then Schwanz\x = 10 If Schwanz\y < 60 Then Schwanz\y = screen_h-21 If Schwanz\y > screen_h-21 Then Schwanz\y = 60 Schwanz\time=Schwanz\time-1 If Schwanz\time=0 Then Delete Schwanz Next Color 255,255,255 Rect Kopf\x,Kopf\y,10,10,1 ;Verschiedene Äpfel For Apfel.Apfel=Each Apfel Color 0,255,0 Select Apfel\typ Case -2 Color 255,0,0 Rect Apfel\x,Apfel\y,10,10 Case -1 Color 255,150,0 Rect Apfel\x,Apfel\y,10,10 Case 0 Color 0,255,0 Rect Apfel\x,Apfel\y,10,10 Case 1 Color 0,150,255 Rect Apfel\x,Apfel\y,10,10 Case 2 Color 0,0,255 Rect Apfel\x,Apfel\y,10,10 End Select ;Kollision mit Apfel If Kopf\x>(Apfel\x-10) And Kopf\x<(Apfel\x+10) If Kopf\y>(Apfel\y-10) And Kopf\y<(Apfel\y+10) Punkte=Punkte+1 Select Apfel\typ Case -2 Punkte=Punkte-10 If Schwanz_laenge<>10 Schwanz_laenge=Schwanz_laenge-10 EndIf Case -1 Punkte=Punkte-1 If Schwanz_laenge<>10 Schwanz_laenge=Schwanz_laenge-10 EndIf Case 0 Apfelanzahl = Apfelanzahl - 1 Schwanz_laenge=Schwanz_laenge+10 Case 1 Punkte=Punkte+1 Apfelanzahl = Apfelanzahl - 1 Schwanz_laenge=Schwanz_laenge+10 Case 2 Punkte=Punkte+10 Apfelanzahl = Apfelanzahl - 1 Schwanz_laenge=Schwanz_laenge+10 End Select If Punkte<0 Then Punkte=0 Delete Apfel EndIf EndIf Next ;Falls keine Äpfel mehr da sind If Apfelanzahl <=0 Then schlange_speed=schlange_speed+1 Apfelanzahl = 10 For i=0 To Apfelanzahl -1 Apfel.Apfel=New Apfel Apfel\x=Rand(1,(screen_w%/10)-2)*10 Apfel\y=Rand(6,(screen_h%/10)-8)*10 Apfel\typ=Rand(0,2) Next Apfelanzahl_mies = Apfelanzahl_mies+1 For i=0 To Apfelanzahl_mies-1 Apfel.Apfel=New Apfel Apfel\x=Rand(1,(screen_w%/10)-2)*10 Apfel\y=Rand(6,(screen_h%/10)-8)*10 Apfel\typ=Rand(-2,-1) Next level = level + 1 Schwanz_laenge=Schwanz_laenge/2 Kopf\x=kopf_x Kopf\y=kopf_y For schwanz.schwanz = Each schwanz If Handle(schwanz) <> 1 Then ; 1 = Kopf Delete schwanz EndIf Next Kopf_richtung=4 ;Delay 1000 EndIf ;Kollision mit Stein For Ein.Stein=Each Stein Color 0,0,0 Rect Ein\x, Ein\y,10,10,1 If Kopf\x>(Ein\x-10) And Kopf\x<(Ein\x+10) Then If Kopf\y>(Ein\y-10) And Kopf\y<(Ein\y+10) Then Text 400,300,"Leben verloren!",1,1 Text 400,350,"Taste drücken.",1,1 Leben=Leben-1 Kopf\x=kopf_x Kopf\y=kopf_y For schwanz.schwanz = Each schwanz If Handle(schwanz) <> 1 Then ; 1 = Kopf Delete schwanz EndIf Next Kopf_richtung=4 FlushKeys() Flip 0 WaitKey() If Leben=<0 Then End EndIf EndIf EndIf Next Flip 0 Wend End |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group