Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help me with pacman game ASAP please!!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shab257




PostPosted: Sat Oct 18, 2008 8:31 pm   Post subject: Help me with pacman game ASAP please!!!

I need it so the pacman doesn't go through any walls at all, also need help with getting another pill to come up when the first is eaten. please help.
heres my code.
please and thanks.

code:
%***********************************************************************%
%                                                                       %
%                          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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Oct 18, 2008 8:58 pm   Post subject: RE:Help me with pacman game ASAP please!!!

Well you've already figured out how to tell if pacman hits the pill -- use similar reasoning to figure out if there is a collision with a wall.

As for having a second pill -- perhaps instead of moving the "eaten" pill to be drawn off the map, perhaps you might want to place it somewhere more accessible to pacman.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Ledrif




PostPosted: Mon Nov 03, 2008 4:35 pm   Post subject: Re: Help me with pacman game ASAP please!!!

I have not done much coding myself, however I found that whatdotcolour works great in these situations.
Since blue is only used for walls.

Taken from the turing help referance...
Turing:

if whatdotcolor ( x, y ) not= 0 then
sound ( 400, 50 )
end if

You would need to add radius values, and set the colour, then code the effect.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: