setscreen ("graphics:640;480")
var snake_length : int
snake_length := 4
proc orange_grid
var orange_x_ar, orange_y_ar : array 1 .. 19 of int
var count : int
count := 0
for pick_x : 139 .. 499 by 20
count += 1
orange_x_ar (count) := pick_x
end for
count := 0
for pick_y : 59 .. 419 by 20
count += 1
orange_y_ar (count) := pick_y
end for
end orange_grid
proc snake_up (var x, y : int)
if whatdotcolor (x, y + 20) not= 7 then
y += 20
drawfillbox (x - 10, y, x + 10, y - 30, 0)
drawfilloval (x, y, 10, 10, 12)
drawfilloval (x - 4, y + 4, 2, 2, green)
drawfilloval (x + 4, y + 4, 2, 2, green)
drawfilloval (x, y - 20, 10, 10, 12) %Snake following
end if
end snake_up
proc snake_down (var x, y : int)
if whatdotcolor (x, y - 20) not= 7 then
y -= 20
drawfillbox (x - 10, y, x + 10, y + 30, 0)
drawfilloval (x, y, 10, 10, 12)
drawfilloval (x - 4, y - 4, 2, 2, green)
drawfilloval (x + 4, y - 4, 2, 2, green)
drawfilloval (x, y + 20, 10, 10, 12) %Snake following
end if
end snake_down
proc snake_left (var x, y : int)
if whatdotcolor (x - 20, y) not= 7 then
x -= 20
drawfillbox (x, y - 10, x + 30, y + 10, 0)
drawfilloval (x, y, 10, 10, 12)
drawfilloval (x - 4, y + 4, 2, 2, green)
drawfilloval (x - 4, y - 4, 2, 2, green)
drawfilloval (x + 20, y, 10, 10, 12) %Snake following
end if
end snake_left
proc snake_right (var x, y : int)
if whatdotcolor (x + 20, y) not= 7 then
x += 20
drawfillbox (x, y - 10, x - 30, y + 10, 0)
drawfilloval (x, y, 10, 10, 12)
drawfilloval (x + 4, y + 4, 2, 2, green)
drawfilloval (x + 4, y - 4, 2, 2, green)
drawfilloval (x - 20, y, 10, 10, 12) %Snake following
end if
end snake_right
proc draw_orange (var x, y : int)
var orange_x, orange_y : int
var count : int
orange_grid
randint (orange_x, 1, 19)
randint (orange_y, 1, 19)
%draws orange
drawfilloval (orange_x_ar (orange_x), orange_y_ar (orange_y), 10, 10, 41)
end draw_orange
proc orange_hit (var orange_x, orange_y, x, y : int)
orange_grid
if orange_x_ar (2) = x and orange_y_ar (2) = y then %if snake gets orange
put "SCORE"
draw_orange (x, y)
end if
end orange_hit
%boundaries
drawfillbox (115, 40, 128, 440, 7) %left wall
drawfillbox (120, 430, 520, 440, 7) %top wall
drawfillbox (511, 40, 520, 440, 7) %right wall
drawfillbox (114, 35, 520, 48, 7) %bottom wall
var x, y : int
var orange_x, orange_y : int
var key : string (1)
var move : string
var count : int
var erase_x, erase_y : array 1 .. 1000 of int
x := maxx div 2
y := maxy div 2
count := 0
move := "NONE"
draw_orange (x, y)
loop
getch (key)
loop
count += 1
erase_x (count) := x
erase_y (count) := y
if key = KEY_UP_ARROW then
if move not= "DOWN" then
snake_up (x, y)
move := "UP"
elsif move = "DOWN" then
snake_down (x, y)
end if
elsif key = KEY_DOWN_ARROW then
if move not= "UP" then
snake_down (x, y)
move := "DOWN"
elsif move = "UP" then
snake_up (x, y)
end if
elsif key = KEY_LEFT_ARROW then
if move not= "RIGHT" then
snake_left (x, y)
move := "LEFT"
elsif move = "RIGHT" then
snake_right (x, y)
end if
elsif key = KEY_RIGHT_ARROW then
if move not= "LEFT" then
snake_right (x, y)
move := "RIGHT"
elsif move = "LEFT" then
snake_left (x, y)
end if
end if
delay (150)
if count >= snake_length then
drawfilloval (erase_x (count - snake_length + 1), erase_y (count - snake_length + 1), 10, 10, 0)
end if
orange_hit (orange_x, orange_y, x, y)
exit when hasch
end loop
end loop
|