ps : actu, il se dirige, ne meurt pas en se mordant, plante si on sort de l'ecran, et aucune option n'est codé (mais ca va venir)
Code : Tout sélectionner
InitSprite()
InitKeyboard()
dw=1024
dh=768
dc=32
If OpenScreen(dw,dh,dc,"SPH_Snake")=0
End
EndIf
StartDrawing(ScreenOutput())
MemVideo = DrawingBuffer()
dbp=DrawingBufferPitch()
dbpf=DrawingBufferPixelFormat()
;1= #PB_PixelFormat_8Bits ; 1 bytes per pixel, palletized
;2= #PB_PixelFormat_15Bits ; 2 bytes per pixel
;3= #PB_PixelFormat_16Bits ; 2 bytes per pixel
;4= #PB_PixelFormat_24Bits_RGB ; 3 bytes per pixel (RRGGBB)
;5= #PB_PixelFormat_24Bits_BGR ; 3 bytes per pixel (BBGGRR)
;6= #PB_PixelFormat_32Bits_RGB ; 4 bytes per pixel (RRGGBB)
;7= #PB_PixelFormat_32Bits_BGR ; 4 bytes per pixel (BBGGRR)
StopDrawing()
;End
;Dim p(dh-1,dw-1)
Dim p(dh-1,dbp/4-1)
;Points blancs aux 4 coins
p(0,0)=RGB(255,255,255)
p(0,dw-1)=RGB(255,255,255)
p(dh-1,dw-1)=RGB(255,255,255)
p(dh-1,0)=RGB(255,255,255)
;Points de couleur en retrait
p(5,5)=RGB(255,0,255)
p(5,dw-6)=RGB(255,0,255)
p(dh-6,dw-6)=RGB(255,0,255)
p(dh-6,5)=RGB(255,0,255)
;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;
xx=dw/2
yy=dh/2
longueur=50
Dim sx(2000)
Dim sy(2000)
Dim sc(2000)
For i=0 To longueur
sx(i)=xx
sy(i)=yy
r=Random(100)+50
sc(i)=RGB(r,r,r) ; le corps du snake gris
Next
sc(0)=RGB(255,255,255) ; la tete du snake blanche
sens=0
xxx=0
yyy=0
vitesse=3
vitesse_actu=0
;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GOOOOOO
Repeat
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up) And sens<>1
sens=1
xxx=0
yyy=-1
EndIf
If KeyboardPushed(#PB_Key_Left) And sens<>2
sens=2
xxx=-1
yyy=0
EndIf
If KeyboardPushed(#PB_Key_Down) And sens<>1
sens=1
xxx=0
yyy=1
EndIf
If KeyboardPushed(#PB_Key_Right) And sens<>2
sens=2
xxx=1
yyy=0
EndIf
vitesse_actu+1
If vitesse_actu=vitesse
vitesse_actu=0
If sens<>0 ; on bouge le snake
For i=longueur To 1 Step -1
sx(i)=sx(i-1)
sy(i)=sy(i-1)
Next
sx(0)+xxx
sy(0)+yyy
;If Random(30):End:EndIf
EndIf
EndIf
;affichage
StartDrawing(ScreenOutput())
MemVideo = DrawingBuffer()
For u=0 To dh-1
CopyMemory(@p(u,0), MemVideo+DrawingBufferPitch()*u,dw*4)
Next
;MemVideo = DrawingBuffer()
;CopyMemory(@p(), MemVideo, dh*dbp)
;;; on dessine le snake par dessus :
For i=longueur To 0 Step -1
Plot(sx(i),sy(i),sc(i))
Next
;;;
StopDrawing()
FlipBuffers()
;Delay(1)
Until KeyboardPushed(#PB_Key_Escape)