%***********************************************************************%
% %
% PROGRAM HEADER %
%***********************************************************************%
%***********************************************************************%
% %
% PROGRAMMER'S NAME: Shahbaz Dhillon %
% %
% DATE: Friday, October 17, 2008 %
% %
% PROGRAM NAME: Pacman Game %
% %
% CLASS: ICS3M1 %
% %
% ASSIGNMENT: Assignment 2 %
% %
% TEACHER: Mrs. Barsan %
% %
% DUE DATE: Friday, October 17, 2008 %
% %
%***********************************************************************%
% %
% WHAT THE PROGRAM DOES %
% %
% This program is a game that plays Pacman. The pacman moves whit the %
% use of arrows. The pacman moves through the map or program travelling %
% around walls. The point is to eat the pills, food or coins in a %
% short time. If you hit a wall you must turn another way to move as %
% you cannot go through the walls. %
% %
%***********************************************************************%
% %
% EXTENSIONS AND IMPROVEMENTS %
% This program could be improved in a variety of ways: %
% 1. Having an AI %
% 2. Having lots of levels %
% 3. Having the high scores kept %
%***********************************************************************%
% background colour
colourback (black)
cls
%Declaring all variables
% y of Pacman's centre
var y : int := 200
% x of Pacman's centre
var x : int := 100
% direction Pacman moves
var dx, dy : int
%Read More % size of mouth
var mouth : int := 0
% mouth direction, 0=right, 90=up, etc.
var dir : int := 0
% string for storing one character
var key : string (1)
% Pill Start Variables
var pill_x : int := 600
var pill_y : int := 350
% Pill colour
var c : int := purple
% the time it takes to consume the pills
var timeRunning : int
%Start of Pacman Game
loop
%border
drawfillbox (0, 0, 20, 420, blue)
drawfillbox (20, 420, 620, 380, blue)
drawfillbox (640, 400, 620, 20, blue)
drawfillbox (640, 0, 20, 20, blue)
%Draws pacman
drawfillarc (x, y, 15, 15, mouth + dir, -mouth + dir, yellow)
delay (10)
%Draws pacmans mouth
drawfillarc (x, y, 15, 15, mouth + dir, -mouth + dir, black)
% If user presses a key
if hasch then
% Reads the key pressed
getch (key)
if ord (key) = 205 then
if x < 10000 then
% Pacman will go right
dir := 0
dx := 8
dy := 0
else
dx := 0
end if
end if
if ord (key) = 200 then
if y < 365 then
% Pacman will go up
dir := 90
dx := 0
dy := 8
else
dy := 0
end if
end if
if ord (key) = 203 then
if x > 38 then
% Pacman will go left
dir := 180
dx := -8
dy := 0
else
dx := 0
end if
end if
if ord (key) = 208 then
if y > 38 then
% Pacman will go down
dir := 270
dx := 0
dy := -8
else
dy := 0
end if
end if
% move Pacman's centre depending on
x := x + dx
% the value of dx and dy
y := y + dy
end if
% change size of the mouth
mouth := mouth mod 45 + 1
% Draws the walls
Draw.FillBox (330, 1, 300, 150, blue)
Draw.FillBox (330, 255, 300, 490, blue)
Draw.FillBox (490, 300, 955, 330, blue)
% Draws the pill
Draw.FillOval (pill_x, pill_y, 4, 4, purple)
%Eating the pill
if Math.Distance (x, y, pill_x, pill_y) < 20 then
pill_x := 0
pill_y := 0
end if
end loop
% End of Pacman Game |