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

Username:   Password: 
 RegisterRegister   
 Confused help please
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
kirstenpratt




PostPosted: Tue Feb 27, 2007 7:27 pm   Post subject: Confused help please

Sorry to make a help topic, im in grade 10, my teacher teaches bad and i learned most of my things of this site, i just registered today so i can make this post, so im making pacman and i am trying to use a picture for the map, because useing draw.line and draw.arc to make the whole map would kill me, my problem is my pacman doesnt really fit on the map, and he eats the map .. wierdd but yea soo i havnt put ghost or anything and ive been stuck on how to make my packman fit on the map, and not eat it... so if you can help i thank you here is my code; (sorry i dont know how to put it here so ill just copy paste)

%Kirsten Pratt
% PacMan game omg this is gun take so long

%%DECLARATION OF VARIABLES
var x, y : int := 50 % pacmans center location
var dx, dy : int %direction pacman moves
var eyeright, eyeup : int
var chars : array char of boolean
var mouth : int := 0 %size of mouth
var dir : int := 0
var exit1 : boolean := false
var picId : array 1 .. 10 of int

picId (1) := Pic.FileNew ("pacman map.bmp")
picId (2) := Pic.FileNew ("pacman fruit.bmp")
picId (3) := Pic.FileNew ("pacman get ready.bmp")
picId (4) := Pic.FileNew ("pacman ghost.bmp")
picId (5) := Pic.FileNew ("pacman life symbol.bmp")
picId (6) := Pic.FileNew ("pacman score.bmp")

eyeright := 5
eyeup := 13
dx := 1
dy := 0
%%% BORDER AND SCREEN SETUP
setscreen ("graphics:1000;650")
setscreen ("nocursour;noecho")
colorback (black)
cls
Pic.Draw (picId (1),0,0,0)
Draw.ThickLine (0, 0, maxx, 0, 10, brightblue)
Draw.ThickLine (0, 0, 0, maxy, 10, brightblue)
Draw.ThickLine (0, maxy, maxx, maxy, 10, brightblue)
Draw.ThickLine (maxx, 0, maxx, maxy, 10, brightblue)


%%% PACMAN MOUTH loop

loop
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
dir := 360
dx := +1
dy := 0
eyeright := 5
eyeup := 13
elsif chars (KEY_LEFT_ARROW) then
dir := 180
dx := -1
dy := 0
eyeright := -5
eyeup := 13
elsif chars (KEY_UP_ARROW) then
dir := 90
dy := +1
dx := 0
eyeright := -10
eyeup := 5
elsif chars (KEY_DOWN_ARROW) then
dir := 270
dy := -1
dx := 0
eyeright := -10
eyeup := -5
elsif chars (KEY_ESC) then
exit1 := true
exit when exit1 = true
end if
if Math.DistancePointLine (x, y, 0, 0, maxx, 0) < 27 then
dy := 0
dx := 0
y := y + 1
elsif Math.DistancePointLine (x, y, 0, 0, 0, maxy) < 27 then
dy := 0
dx := 0
x := x + 1
elsif Math.DistancePointLine (x, y, 0, maxy, maxx, maxy) < 27 then
dy := 0
dx := 0
y := y - 1
elsif Math.DistancePointLine (x, y, maxx, 0, maxx, maxy) < 27 then
dy := 0
dx := 0
x := x - 1
end if
y := y + dy
x := x + dx
mouth := mouth mod 35 + 1
Draw.FillArc (x, y, 20, 20, mouth + dir, -mouth + dir, yellow)
Draw.FillOval (x + eyeright, y + eyeup, 2, 2, black)
delay (5) %%%CHANGE PACMANS SPEED
Draw.FillArc (x, y, 20, 20, mouth + dir, -mouth + dir, black)
exit when exit1 = true
end loop
Window.Hide (-1)

thats my program so thanks if u can help
Sponsor
Sponsor
Sponsor
sponsor
chrisbrown




PostPosted: Tue Feb 27, 2007 8:45 pm   Post subject: Re: Confused help please

It might be hard to do if you are working from school, but if you can, please attach your pictures in a zipped file. We cannot give you much help without them.

From what I can determine, though, your problem is collision detection. You need to write some code to detect if pacman is hitting a wall, and if he is, the set your speed to zero. The problem arising out of that is since you are using an external graphic for your map, you cannot easily tell whether pacman is touching a wall since you don't know the coordinates of each wall. It would be possible using whatdotcolour, though it is frowned upon by almost everyone (except Andy, of course Smile )

The line
code:

Pic.Draw(picId (1),0,0,0)
...
loop
draws your map only once, as it is outside the main loop. This means whenever pacman goes over (eats) the walls, they are not redrawn.

Here is a slightly modified version with the map drawn every loop cycle, as well as smooth animation. Though I don't have your graphics, it should still work.

code:

%Kirsten Pratt
% PacMan game omg this is gun take so long
% MODIFIED BY METHODOXX

%%DECLARATION OF VARIABLES
var x, y : int := 50 % pacmans center location
var dx, dy : int %direction pacman moves
var eyeright, eyeup : int
var chars : array char of boolean
var mouth : int := 0 %size of mouth
var dir : int := 0
var exit1 : boolean := false
var picId : array 1 .. 10 of int

picId (1) := Pic.FileNew ("pacman map.bmp")
picId (2) := Pic.FileNew ("pacman fruit.bmp")
picId (3) := Pic.FileNew ("pacman get ready.bmp")
picId (4) := Pic.FileNew ("pacman ghost.bmp")
picId (5) := Pic.FileNew ("pacman life symbol.bmp")
picId (6) := Pic.FileNew ("pacman score.bmp")

eyeright := 5
eyeup := 13
dx := 1
dy := 0
%%% BORDER AND SCREEN SETUP
View.Set ("graphics:1000;650;offscreenonly")
colorback (black)

Draw.ThickLine (0, 0, maxx, 0, 10, brightblue)
Draw.ThickLine (0, 0, 0, maxy, 10, brightblue)
Draw.ThickLine (0, maxy, maxx, maxy, 10, brightblue)
Draw.ThickLine (maxx, 0, maxx, maxy, 10, brightblue)


%%% PACMAN MOUTH loop

loop
    Pic.Draw (picId (1), 0, 0, 0)
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        dir := 360
        dx := +1
        dy := 0
        eyeright := 5
        eyeup := 13
    elsif chars (KEY_LEFT_ARROW) then
        dir := 180
        dx := -1
        dy := 0
        eyeright := -5
        eyeup := 13
    elsif chars (KEY_UP_ARROW) then
        dir := 90
        dy := +1
        dx := 0
        eyeright := -10
        eyeup := 5
    elsif chars (KEY_DOWN_ARROW) then
        dir := 270
        dy := -1
        dx := 0
        eyeright := -10
        eyeup := -5
    elsif chars (KEY_ESC) then
        exit1 := true
        exit when exit1 = true
    end if
    if Math.DistancePointLine (x, y, 0, 0, maxx, 0) < 27 then
        dy := 0
        dx := 0
        y := y + 1
    elsif Math.DistancePointLine (x, y, 0, 0, 0, maxy) < 27 then
        dy := 0
        dx := 0
        x := x + 1
    elsif Math.DistancePointLine (x, y, 0, maxy, maxx, maxy) < 27 then
        dy := 0
        dx := 0
        y := y - 1
    elsif Math.DistancePointLine (x, y, maxx, 0, maxx, maxy) < 27 then
        dy := 0
        dx := 0
        x := x - 1
    end if
    y := y + dy
    x := x + dx
    mouth := mouth mod 35 + 1
    Draw.FillArc (x, y, 20, 20, mouth + dir, -mouth + dir, yellow)
    Draw.FillOval (x + eyeright, y + eyeup, 2, 2, black)
    View.Update
    delay (1) %%%CHANGE PACMANS SPEED
    Draw.FillArc (x, y, 20, 20, mouth + dir, -mouth + dir, black)

    exit when exit1 = true
end loop
Window.Hide (-1)


...if only functions and procedures were taught first ... Confused
kirstenpratt




PostPosted: Wed Feb 28, 2007 1:12 am   Post subject: Re: Confused help please

Thanks for the replay, but sadly i ask for help once more. i found something called Math.DistancePointLine and i desided to make a couple lines, (witch later one i could make invisible) to keep pacman from eating the boarder but i cant get that command to work (no one told me how to add code yet so sorry)this is my code;
%Kirsten Pratt
% PacMan game omg this is gun take so long

%%DECLARATION OF VARIABLES
var x, y : int % pacmans center location
var dx, dy : int %direction pacman moves
var eyeright, eyeup : int
var chars : array char of boolean
var mouth : int := 0 %size of mouth
var dir : int := 0
var exit1 : boolean := false
var picId : array 1 .. 10 of int

picId (1) := Pic.FileNew ("pacman map.bmp")
picId (2) := Pic.FileNew ("pacman fruit.bmp")
picId (3) := Pic.FileNew ("pacman get ready.bmp")
picId (4) := Pic.FileNew ("pacman ghost.bmp")
picId (5) := Pic.FileNew ("pacman life symbol.bmp")
picId (6) := Pic.FileNew ("pacman score.bmp")

x := 65
y := 40
eyeright := 3
eyeup := 9
dx := 1
dy := 0
%%% BORDER AND SCREEN SETUP
setscreen ("graphics:1000;650")
setscreen ("nocursour;noecho")
colorback (black)
cls
Pic.Draw (picId (1), 0, 0, 0)
Draw.ThickLine (0, 0, maxx, 0, 10, brightblue)
Draw.ThickLine (0, 0, 0, maxy, 10, brightblue)
Draw.ThickLine (0, maxy, maxx, maxy, 10, brightblue)
Draw.ThickLine (maxx, 0, maxx, maxy, 10, brightblue)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%MAP INTERGRATION%%%%%%%%%%%%%%%%%%%
Draw.ThickLine (37, 10, 37, 230, 8, brightred) %% left (x +1)
Draw.ThickLine (40, 127, 90, 127, 8, brightred) %% middle (y +/1 1)
Draw.ThickLine (125, 188, 210, 188, 8, brightred) %%middle (y +/- 1)
Draw.ThickLine (120, 70, 410, 70, 8, brightred) %%middle
Draw.ThickLine (40, 238, 210, 238, 5, brightred) %%middle
Draw.ThickLine (200, 130, 200, 180, 15, brightred) %left
Draw.ThickLine (205, 240, 205, 300, 8, brightred) %left
Draw.ThickLine (40, 310, 205, 310, 5, brightred) %middle
Draw.ThickLine (40, 360, 205, 360, 5, brightred) % ""
Draw.ThickLine (208, 360, 208, 420, 8, brightred) %left
Draw.ThickLine (208, 427, 40, 427, 5, brightred) %midle
Draw.ThickLine (40, 15, maxx - 15, 15, 5, brightred) %bottom
Draw.ThickLine (40, 427, 40, maxy - 37, 5, brightred) % left
Draw.ThickLine (40, maxy - 30, maxx - 10, maxy - 30, 5, brightred) %top
Draw.ThickLine (maxx - 10, maxy - 30, maxx - 10, 445, 5, brightred) %right
Draw.ThickLine (127, maxy - 95, 195, maxy - 95, 25, brightred) %middle
Draw.ThickLine (127, maxy - 165, 195, maxy - 165, 9, brightred) %middle
Draw.ThickLine (310, maxy - 95, 400, maxy - 95, 23, brightred) % middle
Draw.ThickLine (305, 80, 305, 125, 15, brightred) %mid
Draw.ThickLine (305, 250, 305, 300, 15, brightred) % mid
Draw.ThickLine (305, 380, 305, 470, 15, brightred) %mid
Draw.ThickLine (305, 425, 395, 425, 15, brightred)
Draw.ThickLine (405, 485, 610, 485, 15, brightred)
Draw.ThickLine (305, 190, 400, 190, 15, brightred)
Draw.ThickLine (405, 132, 630, 132, 10, brightred)
Draw.ThickLine (405, 246, 630, 246, 10, brightred)
Draw.ThickLine (405, 300, 630, 300, 5, brightred)
Draw.ThickLine (405, 375, 630, 375, 5, brightred)
Draw.ThickLine (515, 75, 515, 120, 15, brightred)
Draw.ThickLine (515, 200, 515, 240, 15, brightred)
Draw.ThickLine (515, 555, 515, 615, 15, brightred)
Draw.ThickLine (515, 425, 515, 480, 15, brightred)
Draw.ThickLine (400, 305, 400, 370, 10, brightred)
Draw.ThickLine (630, 305, 630, 370, 10, brightred)
Draw.ThickLine (maxx - 15, 15, maxx - 15, 225, 5, brightred)
Draw.ThickLine (maxx - 15, 240, maxx - 185, 240, 5, brightred)
Draw.ThickLine (maxx - 185, 240, maxx - 185, 300, 5, brightred)
Draw.ThickLine (maxx - 185, 310, maxx - 15, 310, 5, brightred)
Draw.ThickLine (maxx - 15, 363, maxx - 185, 363, 5, brightred)
Draw.ThickLine (maxx - 185, 363, maxx - 185, 423, 5, brightred)
Draw.ThickLine (maxx - 185, 430, maxx - 15, 430, 5, brightred)
Draw.ThickLine (615, 70, 900, 70, 15, brightred)
Draw.ThickLine (615, 190, 720, 190, 15, brightred)
Draw.ThickLine (720, 80, 720, 120, 20, brightred)
Draw.ThickLine (720, 260, 720, 300, 20, brightred)
Draw.ThickLine (720, 375, 720, 485, 20, brightred)
Draw.ThickLine (720, 430, 630, 430, 15, brightred)
Draw.ThickLine (maxx - 65, 130, maxx - 15, 130, 15, brightred)
Draw.ThickLine (maxx - 175, 137, maxx - 175, 180, 30, brightred)
Draw.ThickLine (maxx - 175, 190, maxx - 100, 190, 10, brightred)
Draw.ThickLine (maxx - 165, maxy - 95, maxx - 110, maxy - 95, 25, brightred)
Draw.ThickLine (620, maxy - 95, 710, maxy - 95, 25, brightred)
Draw.ThickLine (maxx - 175, maxy - 167, maxx - 100, maxy - 167, 15, brightred)

%%% PACMAN MOUTH loop

loop
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
dir := 360
dx := +1
dy := 0
eyeright := 3
eyeup := 9
elsif chars (KEY_LEFT_ARROW) then
dir := 180
dx := -1
dy := 0
eyeright := -3
eyeup := 9
elsif chars (KEY_UP_ARROW) then
dir := 90
dy := +1
dx := 0
eyeright := -10
eyeup := 3
elsif chars (KEY_DOWN_ARROW) then
dir := 270
dy := -1
dx := 0
eyeright := -10
eyeup := -3
elsif chars (KEY_ESC) then
exit1 := true
exit when exit1 = true
end if
if Math.DistancePointLine (x, y, 0, 0, maxx, 0) < 20 then
dy := 0
dx := 0
y := y + 1
elsif Math.DistancePointLine (x, y, 0, 0, 0, maxy) < 20 then
dy := 0
dx := 0
x := x + 1
elsif Math.DistancePointLine (x, y, 0, maxy, maxx, maxy) < 20 then
dy := 0
dx := 0
y := y - 1
elsif Math.DistancePointLine (x, y, maxx, 0, maxx, maxy) < 20 then
dy := 0
dx := 0
x := x - 1
elsif
Math.DistancePointLine (x, y, 37, 10, 37, 230) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 40, 127, 90, 127) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 40, 127, 90, 127) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 125, 188, 210, 188) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 120, 70, 410, 70) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 40, 238, 210, 238) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 200, 130, 200, 180) < 25 then
dy := 0
dx := 0



elsif
Math.DistancePointLine (x, y, 205, 240, 205, 300) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 40, 310, 205, 310) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 40, 360, 205, 360) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 208, 360, 208, 420) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 208, 427, 40, 427) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 40, 15, maxx - 15, 15) < 25 then
dy := 0
dx := 0






elsif
Math.DistancePointLine (x, y, 40, 427, 40, maxy - 37) < 25 then
dy := 0
dx := 0



elsif
Math.DistancePointLine (x, y, 40, maxy - 30, maxx - 10, maxy - 30) < 25 then
dy := 0
dx := 0



elsif
Math.DistancePointLine (x, y, maxx - 10, maxy - 30, maxx - 10, 445) < 25 then
dy := 0
dx := 0



elsif
Math.DistancePointLine (x, y, 127, maxy - 95, 195, maxy - 95) < 25 then
dy := 0
dx := 0



elsif
Math.DistancePointLine (x, y, 127, maxy - 165, 195, maxy - 165) < 25 then
dy := 0
dx := 0





elsif
Math.DistancePointLine (x, y, 310, maxy - 95, 400, maxy - 95) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 305, 80, 305, 125) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 305, 250, 305, 300) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 305, 380, 305, 470) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 305, 425, 395, 425) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, 405, 485, 610, 485) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 305, 190, 400, 190) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 405, 246, 630, 246) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 405, 300, 630, 300) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 405, 132, 630, 132) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 405, 375, 630, 375) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 515, 75, 515, 120) < 25 then
dy := 0
dx := 0




elsif
Math.DistancePointLine (x, y, 515, 200, 515, 240) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 515, 555, 515, 615) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 515, 425, 515, 480) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 400, 305, 400, 370) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 630, 305, 630, 370) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, maxx - 15, 15, maxx - 15, 225) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, maxx - 15, 240, maxx - 185, 240) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, maxx - 185, 240, maxx - 185, 300) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, maxx - 185, 310, maxx - 15, 310) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, maxx - 15, 363, maxx - 185, 363) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, maxx - 185, 363, maxx - 185, 423) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, maxx - 185, 430, maxx - 15, 430) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 720, 80, 720, 120) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 720, 260, 720, 300) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 720, 375, 720, 485) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 720, 430, 630, 430) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, maxx - 65, 130, maxx - 15, 130) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, maxx - 175, 137, maxx - 175, 180) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, maxx - 175, 190, maxx - 100, 190) < 25 then
dy := 0
dx := 0


elsif
Math.DistancePointLine (x, y, maxx - 165, maxy - 95, maxx - 110, maxy - 95) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, 620, maxy - 95, 710, maxy - 95) < 25 then
dy := 0
dx := 0

elsif
Math.DistancePointLine (x, y, maxx - 175, maxy - 167, maxx - 100, maxy - 167) < 25 then
dy := 0
dx := 0

end if

y := y + dy
x := x + dx
mouth := mouth mod 25 + 1
Draw.FillArc (x, y, 15, 15, mouth + dir, -mouth + dir, yellow)
Draw.FillOval (x + eyeright, y + eyeup, 2, 2, black)
delay (5) %%%CHANGE PACMANS SPEED
Draw.FillArc (x, y, 15, 15, mouth + dir, -mouth + dir, black)
exit when exit1 = true
end loop
Window.Hide (-1)

umm my pictures are attached in an .rar file, thank you for your help preaviously and i hope someone replays soon =D



the pics.rar
 Description:
The pictures for my code =P

Download
 Filename:  the pics.rar
 Filesize:  13.83 KB
 Downloaded:  81 Time(s)

BenLi




PostPosted: Wed Feb 28, 2007 8:56 am   Post subject: RE:Confused help please

okay, I don't want to disencourage you in any way, but I would strongly encourage you to learn more if you are going to attempt pac man. You need to learn more tools to solve things more efficiently. I recommend two dimensional arrays. (<<<=== if you don't know what I'm talking about you can learn it in the tutorial
kirstenpratt




PostPosted: Wed Feb 28, 2007 9:31 am   Post subject: Re: Confused help please

ok so i looked at 2 dimentional arrays , and i dont quiet get it but i think i understand what you want me to do, make a grid right, but my question is how do i go about doing this? thank you again for replying
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  [ 5 Posts ]
Jump to:   


Style:  
Search: