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

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




PostPosted: Sun Oct 17, 2004 6:23 pm   Post subject: whatdotcolor help please

I am creating a version of pac-man for school and i am trying to get my pac-man character to stop when it hits a specific color wall. any hints?
Sponsor
Sponsor
Sponsor
sponsor
Hikaru79




PostPosted: Sun Oct 17, 2004 6:52 pm   Post subject: (No subject)

Do you want actual code or just an idea? The idea would be to constantly do a whatdotcolor check at the pac-man's location + 5 or so in the direction that he's heading. If whatdotcolor = some color that the wall is, then set his acceleration to 0. Let me know if you need the actual code for this. It'll be more work Sad Try and figure it out for yourself, and I'll give you some bits Smile
skier




PostPosted: Mon Oct 18, 2004 6:38 am   Post subject: (No subject)

ya the code for it would be great.
McKenzie




PostPosted: Mon Oct 18, 2004 7:27 am   Post subject: (No subject)

Whatdotcolour for pac-man collision detection will probably cause a mess. Most of the time you get a pac-man that eats part of the walls or gets stuck in some spots. If you want to go ahead anyways the important thing to look at in your program is how many pixels your guy moves during each increment. For actual code use the Search option above and type "collision Detection"
DanShadow




PostPosted: Mon Oct 18, 2004 10:38 am   Post subject: (No subject)

First of all, I ask that nobody post the code for PacMan, as it breaks one of our main purposes which is to help people learn, not to give away the answers. And as for whatdotcolor collision detection, I used that when I was new at Turing to make my own Pacman game. It worked, but there are some problems (like eating through and into walls, depending on how many co-ordinates your looking using the whatdotcolor command. More problems indefinitely with the AI of the ghosts too using whatdotcolor.) But if you really want to do it, Ill try to explain. (Sorry, I dont have paint on this computer to show you.) Picture your Pacman, now picture him inside a box. This box, of course, has four sides, so we will record these following co-ordinates: The four edges of the box, and four co-ordinates, each being between two of the edges.
code:

. _._ .
.|    |.
.|_._|.

(Each of the dots is supposed to represent a co-ordinate.)

Now, make a procedure that checks each of these co-ordinates....
For example, the middle of the box is at (x,y) and the radius of pacman (assuming he is a perfect circle) is 10 by 10.
code:

var x,y:int:=200    %x and y of pacman%
var px,py:array 1..8 of int     %px= point x, py= point y%
px(1):=x-10
py(1):=y+10
px(2):=x
py(2):=y+10
px(3):=x+10
py(3):=y+10

This records the top three 'dots' (co-ordinates)'s (x,y) values. So do something like this now:
code:

var wallColor:int:=1
for i:1..3   %would be 8 for all co-ordinates
if whatdotcolor(px(i),py(i))=wallColor then
%Dont Move!
else
%Move Away!
end if
end for

Anyways, thats the basics of whatdotcolor collision detection in a Pacman game. If you need any further help, post. Smile
skier




PostPosted: Tue Oct 19, 2004 3:27 pm   Post subject: (No subject)

Ihave figured out the whatdotcolor command. but i am now trying to get it to check a whole line of pixels infront of the pacman. any help on what im doing wrong? Wink

procedure check
for linecheck : -10 .. 10
clr1 := whatdotcolor (x +linecheck, y )
if clr1 = blue then
x := x - 1
kp := "x"
end if

end for
end check
Cervantes




PostPosted: Tue Oct 19, 2004 4:07 pm   Post subject: (No subject)

I'm going to assume that your walls are blue, and your pacman is a different colour, likely yellow. I'm also assuming you are using offscreenonly
If you have a problem, it's not located in the code that you posted. However, the location of that code within your loop is critical.

code:

loop

    cls

    if whatdotcolour(x,y) = some_colour then
        do_code
    end if

    drawfilloval (100, 100, 50, 50, blue)


    View.Update

end loop

The above code won't work, so if you have your whatdotcolour if statement between the cls and the drawing & View.Update, move it elsewhere.

If that's not your problem, I can't help you. You'd have to post your code Wink
-Cervantes
skier




PostPosted: Tue Oct 19, 2004 4:39 pm   Post subject: (No subject)

that didn't work so heres the program:

setscreen ("graphics: 680,480,offscreenonly")

var x, y, mouth1, mouth2, way, openclose, clr1, clr2, clr3 : int
var chars : array char of boolean
var kp : string (1)
var picID : int := Pic.FileNew ("just map.jpg")


x := 300
y := 200
way := 0
openclose := 0
mouth1 := 10
mouth2 := 350
kp := "x"

Draw.FillBox (0, 0, 700, 500, 7)

procedure check
for linecheck : -10 .. 10
clr1 := whatdotcolor (x +linecheck, y )
if clr1 = blue then
x := x - 1
kp := "x"
end if

end for
end check


procedure draw

if (openclose = 100) then
openclose := 0
end if
if (way = 3) then
mouth1 := 100
mouth2 := 80
elsif (way = 1) then
mouth1 := 10
mouth2 := 350
elsif (way = 2) then
mouth1 := 190
mouth2 := 170
elsif (way = 4) then
mouth1 := 280
mouth2 := 260
end if

openclose := openclose + 2

if (openclose < 50) then
Draw.FillArc (x, y, 10, 10, mouth1, mouth2, 14)
else
Draw.FillArc (x, y, 10, 10, mouth1 + 30, mouth2 - 30, 14)
end if

end draw

procedure erase
Draw.FillOval (x, y, 11, 11, 7)
end erase

Pic.Draw (picID, 10, 10, picCopy)
loop

erase

if hasch then
getch (kp)
end if

if kp = KEY_RIGHT_ARROW then
check

clr1 := 0
clr2 := 0
way := 1
x := x + 1

end if

if kp = KEY_LEFT_ARROW then
clr1 := whatdotcolor (x - 10, y - 10)
clr2 := whatdotcolor (x - 10, y + 10)
clr3 := whatdotcolor (x - 10, y)
if clr1 = blue or clr2 = blue or clr3 = blue then
x := x + 1
kp := "x"
end if
way := 2
x := x - 1
end if

if kp = KEY_UP_ARROW then
clr1 := whatdotcolor (x - 10, y + 10)
clr2 := whatdotcolor (x + 10, y + 10)
clr3 := whatdotcolor (x, y + 10)
if clr1 = blue or clr2 = blue or clr3 = blue then
y := y - 1
kp := "x"
end if
way := 3
y := y + 1
end if

if kp = KEY_DOWN_ARROW then
clr1 := whatdotcolor (x + 10, y - 10)
clr2 := whatdotcolor (x - 10, y - 10)
clr3 := whatdotcolor (x, y - 10)
if clr1 = blue or clr2 = blue or clr3 = blue then
y := y + 1
kp := "x"
end if
way := 4
y := y - 1
end if

draw

Time.Delay (10)

View.Update

end loop
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Tue Oct 19, 2004 5:40 pm   Post subject: (No subject)

Without having run your program and without having looked carefully at your code, I still don't know what your problem is.
Could you either post "just map.jpg" or tell me what your problem is, or both.
-Cervantes
wtd




PostPosted: Tue Oct 19, 2004 5:55 pm   Post subject: (No subject)

This debate just further proves to me that the key to such a game is separation of logic and presentation.

Your game should be represented purely in terms of data structures. You make changes to those data sructures to change the state of the game. Drawing the game to the screen should be simple.

In simpler terms... the graphic should be dependent on the logic. The logic should not be dependent on the graphics.

If you want to keep track of something, keep track of it. It'll be far simpler and faster than drawing out a bonch of pixels, then going back and figuring out what you drew afterward.
skier




PostPosted: Fri Oct 22, 2004 5:20 pm   Post subject: (No subject)

I have figured it out and it works, now to figure out how to draw the ghost?
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  [ 11 Posts ]
Jump to:   


Style:  
Search: