snake (Pause und Kollision)
Übersicht

![]() |
MikeDeeBetreff: snake (Pause und Kollision) |
![]() Antworten mit Zitat ![]() |
---|---|---|
Melde mich auch mal wieder zu Wort,
Ich hab ein kleines Snakeclone nach einer Tutorial in diesem Forum gemacht, bloß die Kollision funktioniert nicht (hab das mit der Kollison auch nicht 100% verstanden) Und ausserdem hatte ich auch eine (sehr) einfache Pause funktion eingebaut, bei der aber der Schwanz gelöscht wird (was ich natürlich nicht will) Pause geht per Leertaste, die Restliche Steuerung dürfte logisch sein Code: [AUSKLAPPEN] Graphics 640,480,16,2
SetBuffer BackBuffer() SeedRnd MilliSecs() Global xhead = 15 Global yhead = 15 Global xplus = 0 Global yplus = 0 Global xeat = Rand(0,63) Global yeat = Rand(0,47) Type TTeil Field x Field y End Type For i = 0 To 50 Teil.TTeil = New TTeil Teil\x = xhead Teil\y = yhead Next ;Hauptschleife Repeat Cls ;Tastenpruefung If KeyHit(200) And yplus = 0 Then xplus = 0 yplus = -1 EndIf If KeyHit(203) And xplus = 0 Then xplus = -1 yplus = 0 EndIf If KeyHit(205) And xplus = 0 Then xplus = 1 yplus = 0 EndIf If KeyHit(208) And yplus = 0 Then xplus = 0 yplus = 1 EndIf If KeyHit(57) Then xplus = 0 yplus = 0 EndIf If xplus = 0 And yplus = 0 Then eating = 1 EndIf ;Bewegung If MilliSecs() - letztebewegung > 50 Then letztebewegung = MilliSecs() xhead = xhead + xplus yhead = yhead + yplus EndIf If xhead < 0 Then xhead = 63 If xhead > 63 Then xhead = 0 If yhead < 0 Then yhead = 47 If yhead > 47 Then yhead = 0 ;essen If xhead = xeat And yhead = yeat Then xeat = Rand(0,63) yeat = Rand(0,47) eating = 1 punkt = punkt + 1 Else eating = 0 EndIf ;schwanz Teil.TTeil = New TTeil Teil\x = xhead Teil\y = yhead If eating = 0 Then Delete First TTeil EndIf ;zeichnen ;schwanz For Teil.TTeil = Each TTeil Color 127,127,127 Rect Teil\x*10,Teil\y*10,10,10,1 ;kollision If xheat = Teil\x And yhead = Teil\y And (Teil<>Last TTeil) Then Cls Color 255,255,255 Text 320,240,"GAME OVER",1,1 Flip FlushKeys WaitKey End EndIf Next ;kopf Color 255,255,255 Rect xhead*10,yhead*10,10,10,1 ;essen Color 255,255,0 Rect xeat*10,yeat*10,10,10,1 ;punkte Color 255,255,255 Text 0,0,"punkte"+Chr$(58) + punkt Flip Until KeyHit(1) End |
||
Nicht wenige benutzen die Anonymität des Internets um berühmt zu werden. |
![]() |
sheldon |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ich würde per Leertaste "pause" auf 1 setzen und dann in der Hauptschleife noch eine Schleife machen. Während pause auf 1 ist, abfragen, ob Leertatse gedrückt wurde, wenn ja, "pause" auf 0 setzen. | ||
![]() |
SpionAtom |
![]() Antworten mit Zitat ![]() |
---|---|---|
Zeile 83:
Code: [AUSKLAPPEN] If eating = 0 And (xplus + yplus <> 0) Then
Delete First TTeil EndIf Wenn keine Bewegung stattfindet - also xplus und yplus beide nicht null sind, dann wird das letzte Teilstück nicht gelöscht. Und das mit der Variable eating rall ich nicht. |
||
os: Windows 10 Home cpu: Intel Core i7 6700K 4.00Ghz gpu: NVIDIA GeForce GTX 1080 |
![]() |
MikeDee |
![]() Antworten mit Zitat ![]() |
---|---|---|
eating bezieht sich auf das
;schwanz Teil.TTeil = New TTeil Teil\x = xhead Teil\y = yhead If eating = 0 Then Delete First TTeil EndIf |
||
Nicht wenige benutzen die Anonymität des Internets um berühmt zu werden. |
![]() |
SpionAtom |
![]() Antworten mit Zitat ![]() |
---|---|---|
Und hab noch was vergessen:
Code: [AUSKLAPPEN] If (xplus + yplus <> 0) Then
Teil.TTeil = New TTeil Teil\x = xhead Teil\y = yhead End If If eating = 0 And (xplus + yplus <> 0) Then Delete First TTeil EndIf Wenn kein Teilstück gelöscht wird, darf natürlich auch keins hinzugefügt werden. |
||
os: Windows 10 Home cpu: Intel Core i7 6700K 4.00Ghz gpu: NVIDIA GeForce GTX 1080 |
![]() |
MikeDee |
![]() Antworten mit Zitat ![]() |
---|---|---|
zurzeit sieht es so aus:
Code: [AUSKLAPPEN] Graphics 640,480,16,2
SetBuffer BackBuffer() SeedRnd MilliSecs() Global xhead = 15 Global yhead = 15 Global xplus = 0 Global yplus = 0 Global xeat = Rand(0,63) Global yeat = Rand(0,47) Type TTeil Field x Field y End Type For i = 0 To 50 Teil.TTeil = New TTeil Teil\x = xhead Teil\y = yhead Next ;Hauptschleife Repeat Cls ;Tastenpruefung If KeyHit(200) And yplus = 0 Then xplus = 0 yplus = -1 EndIf If KeyHit(203) And xplus = 0 Then xplus = -1 yplus = 0 EndIf If KeyHit(205) And xplus = 0 Then xplus = 1 yplus = 0 EndIf If KeyHit(208) And yplus = 0 Then xplus = 0 yplus = 1 EndIf If KeyHit(57) Then xplus = 0 yplus = 0 EndIf If xplus = 0 And yplus = 0 Then eating = 1 EndIf ;Bewegung If MilliSecs() - letztebewegung > 50 Then letztebewegung = MilliSecs() xhead = xhead + xplus yhead = yhead + yplus EndIf If xhead < 0 Then xhead = 63 If xhead > 63 Then xhead = 0 If yhead < 0 Then yhead = 47 If yhead > 47 Then yhead = 0 ;essen If xhead = xeat And yhead = yeat Then xeat = Rand(0,63) yeat = Rand(0,47) eating = 1 punkt = punkt + 1 Else eating = 0 EndIf ;schwanz Teil.TTeil = New TTeil Teil\x = xhead Teil\y = yhead If eating = 0 Then Delete First TTeil EndIf ;zeichnen ;schwanz For Teil.TTeil = Each TTeil Color 127,127,127 Rect Teil\x*10,Teil\y*10,10,10,1 ;kollision If xheat = Teil\x And yhead = Teil\y And (Teil<>Last TTeil) Then Cls Color 255,255,255 Text 320,240,"GAME OVER",1,1 Flip FlushKeys WaitKey End EndIf Next ;kopf Color 255,255,255 Rect xhead*10,yhead*10,10,10,1 ;essen Color 255,255,0 Rect xeat*10,yeat*10,10,10,1 ;punkte Color 255,255,255 Text 0,0,"punkte"+Chr$(58) + punkt Flip Until KeyHit(1) End Kollision grieg ich immernoch nicht hin und je schneller die schlange ist, desto kürzer wird sie o.O |
||
Nicht wenige benutzen die Anonymität des Internets um berühmt zu werden. |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group