da ich ja noch ein anfänger bin weiss ich nun nicht wie ich die schlange um ein pixel erweitern kann und das dann,wenn man sich in eine richtung bewegt dass er dann die typische snake bewegung macht und den schwanz immer beim knick mit nimmt.
ich hoffe ihr habt eine gute lösung für mein problem.
Code: Alles auswählen
OpenWindow(0, 50,50, 600, 400, "Box", #PB_Window_SystemMenu |#PB_Window_MaximizeGadget |#PB_Window_MinimizeGadget )
InitKeyboard()
InitSprite()
OpenWindowedScreen(WindowID(0), 0, 0,600,400, 1, 1, 20)
CreateSprite(0,5,5)
StartDrawing(SpriteOutput(0))
Box(0,0,5,5,RGB(0,0,250))
StopDrawing()
CreateSprite(1,5,5)
StartDrawing(SpriteOutput(1))
Box(0,0,5,5,RGB(250,250,250))
StopDrawing()
score=0
speed=1
pos_x=Random(250)
pos_y=Random(250)
Repeat
Repeat
Event = WaitWindowEvent(10)
If Event = #PB_Event_CloseWindow
EXIT = 1
EndIf
Until Event = #Null
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Right)
x=x+speed
If x>=612
x=-12
EndIf
EndIf
If KeyboardPushed(#PB_Key_Left)
x=x-speed
If x<=-12
x=612
EndIf
EndIf
If KeyboardPushed(#PB_Key_Down)
y=y+speed
If y>=412
y=-12
EndIf
EndIf
If KeyboardPushed(#PB_Key_Up)
y=y-speed
If y<=-12
y=412
EndIf
EndIf
ClearScreen(0)
DisplaySprite(0,x,y)
DisplaySprite(1,pos_x,pos_y)
StartDrawing( ScreenOutput() )
DrawText( 400,2, "Score : "+Str(score) )
StopDrawing()
FlipBuffers()
If SpriteCollision(0,x,y,1,pos_x,pos_y)=1
score=score+1
pos_x=Random(250)
pos_y=Random(250)
EndIf
Until EXIT = 1