colourback (green)
cls
var x, y : int := 20 % x and y of Pacman's centre
var dx, dy, x_temp, y_temp : int % direction Pacman moves
dx := 1 % Pacman will move to the right
dy := 0 % Pacman will not be going up or down
var mouth : int := 0 % size of mouth
var dir : int := 0 % mouth direction, 0=right, 90=up, etc.
drawfilloval (100, 100, 5, 5, white)
drawfilloval (200, 200, 5, 5, white)
drawfilloval (300, 300, 5, 5, white)
drawfilloval (190, 150, 5, 5, white)
drawfilloval (290, 199, 5, 5, white)
drawfilloval (389, 500, 5, 5, white)
drawfilloval (209, 340, 5, 5, white)
var box_x1, box_y1, box_x2, box_y2 : int
box_x1 := 300
box_x2 := 320
box_y1 := 0
box_y2 := 175
drawfillbox (box_x1, box_y1, box_x2, box_y2, red)
var box2_x1, box2_y1, box2_x2, box2_y2 : int
box2_x1 := 300
box2_x2 := 320
box2_y1 := 225
box2_y2 := 400
drawfillbox (box2_x1, box2_y1, box2_x2, box2_y2, red)
loop
mouth := mouth mod 45 + 1 % change size of the mouth
drawfillarc (x, y, 15, 15, mouth + dir, -mouth + dir, yellow)
delay (30)
drawfillarc (x, y, 15, 15, mouth + dir, -mouth + dir, green)
var key : string (1)
if hasch then
getch (key)
if ord (key) = 208 then
dir := 270
dx := 0
dy := -1
elsif ord (key) = 200 then
dir := 90
dx := 0
dy := 1
elsif ord (key) = 203 then
dir := 180
dx := -1
dy := 0
elsif ord (key) = 205 then
dir := 0
dx := 1
dy := 0
end if
end if
x_temp := x + dx
y_temp := y + dy
if (x_temp <= 620 and x_temp >= 20 and y_temp >= 20 and y_temp <= 380 and
(x_temp < (box_x1 - 20) or x_temp > (box_x2 + 20) or y_temp > (box_y2 + 20) or y_temp < (box_y1 - 20)) and
(x_temp < (box2_x1 - 20) or x_temp > (box2_x2 + 20) or y_temp > (box2_y2 + 20) or y_temp < (box2_y1 - 20))
) then
x := x + dx
y := y + dy
end if
end loop
|