setscreen ("graphics:490;540")
View.Set ("offscreenonly")
const BACKGROUND : int := black
const PACMAN_RADIUS : int := 11
const DOT_RADIUS : int := 2
const WALL : int := 30
const ROOM : int := 4
var direction : int := 360
var x : int := 245
var y : int := 230
var x_temp, y_temp : int := 0
var xInc, yInc : int := 0
var yDot, xDot : int
var MouthAngle : int := 0
var move : string (1) := KEY_RIGHT_ARROW
%Ghost
const GHOST_RADIUS : int := 12
var ghostX : int := 220
var ghostX_temp, ghostY_temp : int := 0
var ghostY : int := 270
var ghostCol : array 1 .. 4 of int := init (40, 43, 53, 13)
colourback (BACKGROUND)
cls
%Draw Walls
var box1x : array 1 .. 49 of int := init (0, 0, 0, 490, 0, 480, 50, 140, 190, 240, 290, 340, 0, 440, 50, 90, 140, 290, 390, 390, 0, 90, 0, 140, 190, 240, 340, 390, 390, 400, 0, 90, 0, 390, 390, 390,
140, 340, 140, 290, 50, 390, 190, 240, 50, 140, 290, 390, 240)
var box1y : array 1 .. 49 of int := init (0, 0, 530, 260, 300, 300, 50, 50, 100, 100, 50, 60, 100, 100, 150, 160, 160, 160, 160, 160, 210, 260, 260, 260, 210, 210, 260, 260, 260, 200, 300, 360, 350,
350, 300, 300, 300, 300, 350, 350, 400, 400, 400, 410, 450, 450, 450, 450, 450)
var box2x : array 1 .. 49 of int := init (10, 490, 490, 480, 10, 490, 200, 150, 300, 250, 440, 350, 50, 490, 100, 100, 200, 350, 400, 440, 100, 100, 90, 150, 300, 250, 350, 480, 400, 480, 100, 100,
100, 480, 480, 400, 150, 350, 200, 350, 100, 440, 300, 250, 100, 200, 350, 440, 250)
var box2y : array 1 .. 49 of int := init (260, 10, 540, 0, 540, 540, 60, 110, 110, 50, 60, 110, 110, 110, 160, 100, 150, 150, 100, 150, 200, 200, 250, 200, 200, 150, 200, 250, 200, 210, 310, 310,
360, 360, 310, 360, 410, 410, 360, 360, 410, 410, 410, 350, 490, 490, 490, 490, 540)
for i : 1 .. 49
drawfillbox (box1x (i), box1y (i), box2x (i), box2y (i), grey)
end for
for i : 45 .. 48
drawfillbox (box1x (i) + 10, box1y (i) + 10, box2x (i) - 10, box2y (i) - 10, black)
end for
%Mouth Opening and closing....
%Draw mouth close
procedure drawMouthClose (x : int, y : int)
MouthAngle := MouthAngle mod 45 + 1
drawfillarc (x, y, PACMAN_RADIUS, PACMAN_RADIUS, MouthAngle + direction, -MouthAngle + direction, 14)
end drawMouthClose
%Erase Pacman
procedure erasePacman (x : int, y : int)
%The "+1" allows the prgram to remove any extra pixels
drawfillarc (x, y, PACMAN_RADIUS, PACMAN_RADIUS, MouthAngle + direction, -MouthAngle + direction, BACKGROUND)
end erasePacman
%Change Direction
procedure directionChange
if hasch then
getch (move)
if ord (move) = ORD_DOWN_ARROW then
direction := 270
xInc := 0
yInc := -1
elsif ord (move) = ORD_UP_ARROW then
direction := 90
xInc := 0
yInc := 1
elsif ord (move) = ORD_LEFT_ARROW then
direction := 180
xInc := -1
yInc := 0
elsif ord (move) = ORD_RIGHT_ARROW then
direction := 0
xInc := 1
yInc := 0
end if
end if
end directionChange
%Ghost
procedure ghost
drawfillarc (ghostX, ghostY, GHOST_RADIUS, GHOST_RADIUS, 0, 180, ghostCol (1))
Draw.FillBox (ghostX - 12, ghostY, ghostX + 12, ghostY - 10, ghostCol (1))
Draw.FillOval (ghostX - 10, ghostY - 10, 2, 2, ghostCol (1))
Draw.FillOval (ghostX - 3, ghostY - 10, 2, 2, ghostCol (1))
Draw.FillOval (ghostX + 3, ghostY - 10, 2, 2, ghostCol (1))
Draw.FillOval (ghostX + 10, ghostY - 10, 2, 2, ghostCol (1))
Draw.FillOval (ghostX - 5, ghostY, 3, 3, white)
Draw.FillOval (ghostX + 5, ghostY, 3, 3, white)
Draw.FillOval (ghostX - 5, ghostY, 1, 1, black)
Draw.FillOval (ghostX + 5, ghostY, 1, 1, black)
end ghost
%Ghost Erase
procedure ghostErase
drawfillarc (ghostX, ghostY, GHOST_RADIUS, GHOST_RADIUS, 0, 180, black)
Draw.FillBox (ghostX - 12, ghostY, ghostX + 12, ghostY - 10, black)
Draw.FillOval (ghostX - 10, ghostY - 10, 2, 2, black)
Draw.FillOval (ghostX - 3, ghostY - 10, 2, 2, black)
Draw.FillOval (ghostX + 3, ghostY - 10, 2, 2, black)
Draw.FillOval (ghostX + 10, ghostY - 10, 2, 2, black)
end ghostErase
%Dots
procedure dots
for xDot : 26 .. 480 by 23
drawfilloval (xDot, 27, DOT_RADIUS, DOT_RADIUS, 31)
end for
end dots
%Movement
const DEL : int := 15
dots
loop
for i : x .. maxx
drawMouthClose (x, y)
View.Update
delay (DEL)
erasePacman (x, y)
ghost
View.Update
delay (DEL)
ghostErase
if ghostX_temp = 15 then
ghostX := 475
elsif ghostX_temp = 475 then
ghostX := 15
end if
x_temp := x + xInc
y_temp := y + yInc
directionChange
if x_temp = 15 then
x := 475
elsif x_temp = 475 then
x := 15
end if
ghostX := ghostX + xInc
ghostY := ghostY + yInc
if whatdotcolor (x_temp + PACMAN_RADIUS, y_temp) ~= grey
and whatdotcolor (x_temp + PACMAN_RADIUS + ROOM, y_temp) ~= grey
and whatdotcolor (x_temp - PACMAN_RADIUS - ROOM, y_temp) ~= grey
and whatdotcolor (x_temp, y_temp + PACMAN_RADIUS + ROOM) ~= grey
and whatdotcolor (x_temp, y_temp - PACMAN_RADIUS - ROOM) ~= grey
and whatdotcolor (x_temp + PACMAN_RADIUS + ROOM, y_temp + PACMAN_RADIUS + ROOM) ~= grey
and whatdotcolor (x_temp - PACMAN_RADIUS - ROOM, y_temp - PACMAN_RADIUS - ROOM) ~= grey
and whatdotcolor (x_temp - PACMAN_RADIUS - ROOM, y_temp + PACMAN_RADIUS + ROOM) ~= grey
and whatdotcolor (x_temp + PACMAN_RADIUS + ROOM, y_temp - PACMAN_RADIUS - ROOM) ~= grey
and whatdotcolor (x_temp + PACMAN_RADIUS, y_temp + PACMAN_RADIUS + ROOM) ~= grey
and whatdotcolor (x_temp - PACMAN_RADIUS, y_temp - PACMAN_RADIUS - ROOM) ~= grey
and whatdotcolor (x_temp - PACMAN_RADIUS, y_temp + PACMAN_RADIUS + ROOM) ~= grey
and whatdotcolor (x_temp + PACMAN_RADIUS, y_temp - PACMAN_RADIUS - ROOM) ~= grey
and whatdotcolor (x_temp + PACMAN_RADIUS + ROOM, y_temp + PACMAN_RADIUS) ~= grey
and whatdotcolor (x_temp - PACMAN_RADIUS - ROOM, y_temp - PACMAN_RADIUS) ~= grey
and whatdotcolor (x_temp - PACMAN_RADIUS - ROOM, y_temp + PACMAN_RADIUS) ~= grey
and whatdotcolor (x_temp + PACMAN_RADIUS + ROOM, y_temp - PACMAN_RADIUS) ~= grey
then
x := x + xInc
y := y + yInc
end if
end for
end loop
|