Part of the source code to a pretty darn clever bit of Scratch programming that I was trying to figure out how it had been done. Man, Scratch is infuriatingly limited as a language, but in the very best addictive sort of way.
edit: I have no idea why this was in my clipboard, though...
Code:
Project: Snake
Author: ernestpazera
Scratch: 1.1
Notes:
Eat the red pellets, and don't touch the walls or your own tail. Use the arrow keys to navigate. When the game is over, hit the space bar to set up a new game. While playing, you get one point each time you eat the last red pellet on the screen. If you take too long (15 seconds), two penalty pellets will appear, and you will get no score for eating them (although the snake will still grow).
Update 6/2/2007: Added sounds and a visible time left timer so that a player can see how much time remains before penaly pellets will show up.
Totals:
Sprites: 3
Stacks: 13
Unique costumes: 26
Unique sounds: 5
--------
Sprite: Stage
Costumes (1):
Background (480x360)
Sounds (2):
move (0:00:00)
penalty (0:00:05)
Stacks (8):
when space key pressed
if game_state = 0
broadcast "reset_game" and wait
end when up arrow key pressed
if game_state = 1 and not snake_direction = 2
set snake_direction to 0
play sound "move"
end when left arrow key pressed
if game_state = 1 and not snake_direction = 1
set snake_direction to 3
play sound "move"
end when green flag clicked
broadcast "reset_game" and wait
forever
if game_state = 1
broadcast "do_game_loop" and wait
end when down arrow key pressed
if game_state = 1 and not snake_direction = 0
set snake_direction to 2
play sound "move"
end when right arrow key pressed
if game_state = 1 and not snake_direction = 3
set snake_direction to 1
play sound "move"
end when I receive "reset_game"
clear
set score to 0
set pellet_count to 0
set snake_actual_length to 0
set snake_final_length to 4
set snake_direction to -1
broadcast "reset_head" and wait
broadcast "reset_tail" and wait
broadcast "create_pellet" and wait
set game_state to 1
end when I receive "do_game_loop"
if snake_direction = -1
reset timer
if timer > 15
reset timer
broadcast "create_pellet" and wait
broadcast "create_pellet" and wait
play sound "penalty"
broadcast "update_head" and wait
if game_state = 1
broadcast "update_tail" and wait
set time left to 15 - timer
end
--------
Sprite: Tail
Costumes (13):
blank (12x12)
clear (12x12)
feeler_east (12x12)
feeler_north (12x12)
feeler_south (12x12)
feeler_west (12x12)
feeler_bulge (12x12)
bulge (12x12)
east (12x12)
north (12x12)
south (12x12)
tail (12x12)
west (12x12)
Sounds (1):
pop (0:00:00)
Stacks (2):
when I receive "reset_tail"
set east to 0
set north to 0
set south to 0
set west to 0
set pellet to 0
go to x: -66 y: -6
switch to costume "blank"
end when I receive "update_tail"
repeat until not snake_actual_length > snake_final_length
change snake_actual_length by -1
set east to 0
set north to 0
set south to 0
set west to 0
switch to costume "feeler_east"
if touching color c[00FF00]?
change east by 1
switch to costume "feeler_north"
if touching color c[00FF00]?
change north by 1
switch to costume "feeler_south"
if touching color c[00FF00]?
change south by 1
switch to costume "feeler_west"
if touching color c[00FF00]?
change west by 1
switch to costume "clear"
stamp
if east = 1
set east to 0
set north to 0
set south to 0
set west to -1
change x by 12
else
if north = 1
set east to 0
set north to 0
set south to -1
set west to 0
change y by 12
else
if south = 1
set east to 0
set north to -1
set south to 0
set west to 0
change y by -12
else
if west = 1
set east to -1
set north to 0
set south to 0
set west to 0
change x by -12
switch to costume "feeler_east"
if touching color c[00FF00]?
change east by 1
switch to costume "feeler_north"
if touching color c[00FF00]?
change north by 1
switch to costume "feeler_south"
if touching color c[00FF00]?
change south by 1
switch to costume "feeler_west"
if touching color c[00FF00]?
change west by 1
set pellet to 0
switch to costume "feeler_bulge"
if touching color c[00FF00]?
change pellet by 1
if pellet = 1
switch to costume "bulge"
else
switch to costume "tail"
stamp
if east = 1
switch to costume "east"
stamp
if north = 1
switch to costume "north"
stamp
if south = 1
switch to costume "south"
stamp
if west = 1
switch to costume "west"
stamp
switch to costume "blank"
end
--------
Sprite: Head
Costumes (9):
blank (12x12)
bulge (12x12)
east (12x12)
feeler_tail (12x12)
head (12x12)
north (12x12)
south (12x12)
tail (12x12)
west (12x12)
Sounds (2):
gameover (0:00:05)
eat (0:00:00)
Stacks (2):
when I receive "update_head"
if game_state = 1 and not snake_direction = -1
if pellet = 1
switch to costume "bulge"
else
switch to costume "tail"
stamp
if snake_direction = 0
switch to costume "north"
stamp
else
if snake_direction = 1
switch to costume "east"
stamp
else
if snake_direction = 2
switch to costume "south"
stamp
else
if snake_direction = 3
switch to costume "west"
stamp
if north = 1
switch to costume "north"
stamp
if east = 1
switch to costume "east"
stamp
if south = 1
switch to costume "south"
stamp
if west = 1
switch to costume "west"
stamp
if snake_direction = 0
set east to 0
set north to 0
set south to 1
set west to 0
change y by 12
else
if snake_direction = 1
set east to 0
set north to 0
set south to 0
set west to 1
change x by 12
else
if snake_direction = 2
set east to 0
set north to 1
set south to 0
set west to 0
change y by -12
else
if snake_direction = 3
set east to 1
set north to 0
set south to 0
set west to 0
change x by -12
switch to costume "feeler_tail"
set pellet to 0
if touching color c[00FF00]? or touching color c[0000FF]?
set game_state to 0
play sound "gameover"
else
if touching color c[FF0000]?
play sound "eat"
reset timer
change pellet_count by -1
change snake_final_length by 2
set pellet to 1
if pellet_count = 0
broadcast "create_pellet" and wait
change score by 1
switch to costume "head"