Post by bplus on Jul 1, 2024 9:50:05 GMT -5
This mod of the Snake Game brings out an aspect of the "game" that you don't normally get to experience from the standard version. ie know what it's like to fill the whole screen or field or garden with snake. The game is usually about attempting to NOT walk into wall or snake body while attempting to hit the square with the apple in it. Who can last that long?
Here you move step by step with keypresses so if you crash into wall or snake body it's your own dang fault!
This is set for a 4x4 little garden or field to run the snake in. You are done, the screen will freeze when you try to eat the apple from the last empty space available, you "won" at that point. The screen freezes because there is no empty place to put the next apple.
The Black circle is the snake head, the red circle is the apple of course
Change Const sps to something bigger (designed for up to 20x20) when ready for a bigger garden/field.
Here you move step by step with keypresses so if you crash into wall or snake body it's your own dang fault!
This is set for a 4x4 little garden or field to run the snake in. You are done, the screen will freeze when you try to eat the apple from the last empty space available, you "won" at that point. The screen freezes because there is no empty place to put the next apple.
The Black circle is the snake head, the red circle is the apple of course
Change Const sps to something bigger (designed for up to 20x20) when ready for a bigger garden/field.
_Title "Walk the Snake Yourself, b+ mod 2024-06-30"
' mod 2024-06-30 I don't like the snake moving without being told
' this will fix that and now if you crash into wall you die you dummy! LOL
' oh also fix the apple so it's never on snake body
Option _Explicit
Const sps = 4 ' cells per row or column !!!! < try 4 cells for quick garden fill!!!
Const sq = 20 ' pixels per cell
Const xmax = sps * sq, ymax = xmax
Screen _NewImage(400, 400, 12)
Dim px, py, ax, ay, tail, i, keypress$, crash, moved
Dim trailX(1000), trailY(1000)
px = 0 ' snake head
py = 0
ax = 2 ' apple food
ay = 2
tail = 1 ' how long snake is
trailX(0) = px
trailY(0) = py
Do ' update display first, get key and then update game
Line (0, 0)-(xmax, ymax), 6, BF ' clear garden 6
For i = 0 To tail - 1 'show snake
If i = 0 Then
Circle (trailX(i) * sq + .5 * sq, trailY(i) * sq + .5 * sq), .5 * sq, 0
Paint (trailX(i) * sq + .5 * sq, trailY(i) * sq + .5 * sq), 0, 0
Else
Line (trailX(i) * sq + 2, trailY(i) * sq + 2)-Step(sq - 4, sq - 4), (i Mod 4) + 7, BF
End If
Next
Circle (ax * sq + .5 * sq, ay * sq + .5 * sq), .5 * sq, 4 ' show apple
Paint (ax * sq + .5 * sq, ay * sq + .5 * sq), 4, 4
_Display
_Limit 30
moved = 0 ' this walks snake step by step with arrow keys no stupid timing required
keypress$ = InKey$
If keypress$ = Chr$(0) + Chr$(72) Then 'up
py = py - 1: moved = 1
ElseIf keypress$ = Chr$(0) + Chr$(80) Then 'down
py = py + 1: moved = 1
ElseIf keypress$ = Chr$(0) + Chr$(77) Then 'right
px = px + 1: moved = 1
ElseIf keypress$ = Chr$(0) + Chr$(75) Then 'left
px = px - 1: moved = 1
ElseIf keypress$ = "q" Or keypress$ = Chr$(27) Then
End '>>>>>>>> here is quit or escape clause!!!!
End If
_KeyClear
If moved Then
' check for wall crashes
If px < 0 Then crash = 1
If px > sps - 1 Then crash = 1
If py < 0 Then crash = 1
If py > sps - 1 Then crash = 1
For i = 0 To tail - 1 ' check for snake crashes into self
If px = trailX(i) And py = trailY(i) Then crash = 2: Exit For
Next
If crash Then
If crash = 1 Then
_PrintString (84, 192), "Crashed into wall - GAME OVER!"
Else
_PrintString (54, 192), "Snake crashed into self - GAME OVER!"
End If
_Display
End
End If
If ax = px And ay = py Then ' snake eats apple and grows
tail = tail + 1
GoSub update_snake
newapple:
ax = Int(Rnd * sps) ' set new place for apple
ay = Int(Rnd * sps)
For i = 0 To tail - 1 ' check update apple
If ax = trailX(i) And ay = trailY(i) Then GoTo newapple
Next
Else
GoSub update_snake
End If
End If
Loop
update_snake:
For i = tail - 1 To 1 Step -1
trailX(i) = trailX(i - 1): trailY(i) = trailY(i - 1)
Next
trailX(0) = px
trailY(0) = py
Return