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

Username:   Password: 
 RegisterRegister   
 pacman eating coins
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Insectoid




PostPosted: Tue May 06, 2008 5:44 pm   Post subject: pacman eating coins

Yes, another pacman question.

I cannot create a decent way of getting pacman to eat coins. What I currently have is, when his center hits a red pixel (coins are red so I can se them better) he draws a white (backgorund color) thick line overtop. The line is supposed to point up/down/left/right depending on which way he is moving. This does not work.

Also, I am currently using
code:
whatdotcolor (x, y+10) ~= black
for collision detection (4 of those, changing x/y). This works if he's already in a tunnel, but if he turns a corner, half of him can go through it. I suppose this requires pythagorean theorum to work properly? Could this be explained to me, so that I can undertand it, and adapt it to other things?

Here is my current 'coin collection' code:

code:

 if whatdotcolor (x, y) = red then
        score := score + 10
        if whatdotcolor (x, y + 2) ~= yellow then
            Draw.ThickLine (x, y, x, y + 10, 12, white)
       
        elsif whatdotcolor (x, y - 2) ~= yellow then
            Draw.ThickLine (x, y, x, y - 10, 12, white)
       
        elsif whatdotcolor (x + 2, y) ~= yellow then
            Draw.ThickLine (x, y, x + 10, y, 12, white)
       
        elsif whatdotcolor (x - 2, y) ~= white then
            Draw.ThickLine (x, y, x - 10, y, 12, white)
end if


And here is my movement code:
code:

 loop

        locate (1, 16)
        put score
        Input.KeyDown (chars)
        if chars (KEY_UP_ARROW) and whatdotcolor (x, y + 10) ~= black then
            y := y + 1
            Sprite.Animate (pacman, pacmanpic2, x, y, true)
        end if

        if chars (KEY_DOWN_ARROW) and whatdotcolor (x, y - 10) ~= black then
            y := y - 1
            Sprite.Animate (pacman, pacmanpic4, x, y, true)
        end if

        if chars (KEY_RIGHT_ARROW) and whatdotcolor (x + 10, y) ~= black then
            x := x + 1
            Sprite.Animate (pacman, pacmanpic1, x, y, true)
        end if

        if chars (KEY_LEFT_ARROW) and whatdotcolor (x - 10, y) ~= black then
            x := x - 1
            Sprite.Animate (pacman, pacmanpic3, x, y, true)
        end if
        coincapture
        View.Update             %get rid of flash
        delay (6)
end loop


And here is my nifty 'automated coin drawing' code, just for fun.
code:

loop
        coinx := coinx + 10
        if coinx >= maxx then
            coinx := 0
            coiny := coiny + 10
        end if
        if coiny >= maxy then
            coiny := 0
        end if
        if whatdotcolor (coinx, coiny) = white and whatdotcolor (coinx + 7, coiny) = white and whatdotcolor (coinx - 7, coiny) = white and whatdotcolor (coinx, coiny + 7) = white and
                whatdotcolor (coinx, coiny - 7) = white then
            Draw.FillOval (coinx, coiny, 6, 6, red)
        end if
        exit when coiny >= maxy - 60
end loop
[/b]
Sponsor
Sponsor
Sponsor
sponsor
isaiahk9




PostPosted: Wed May 07, 2008 5:32 pm   Post subject: Re: pacman eating coins

A way to do this is to assign an x and y coordinate to every dot, and if the pacman coordinate is the same as one of the coin coordinates, then you draw a circle the size of the coin in white, so the coin will dissapear.
The only bad thing is that this would mean spending hours of code-writing on just making the x and y coordinates for the coins. But I thought of a faster way.
Instead of writing out all your code, make Turing write your code!
Set your screen to text :
setscreen ("text")
and then make some put statements in a for loop. Every time the for loop runs, whatever is in the put statements will be put out, with variables changing depending on the run-number of the for loop (your variables will have to relate to i).
So it would go a something like this :

setscreen ("text")
var coinx, coiny : int := 0
%say you wanted 200 coins
for i : 1..200
coinx := coinx + 10
put "Draw.FillOval (", coinx, ", ", coiny, ", 6, 6, red)"
if coinx = 600 then
coinx := 0
coiny := coiny + 10
end if
end for

Then, just copy the code out of the run window and into your game.
So, make Turing write its own code and then use those coin coordinates to correspond with pacman's coordinates.
Or, if the coins are evenly placed, you could just go :
If Pacman's x is a multiple of twenty (say that the coins were placed every 20 pixels), and Pacman's y is a multiple of 20 (coins placed every 20 pixels) then draw a white circle the size of a coin on pacman's position.
Hope that helps.
Insectoid




PostPosted: Wed May 07, 2008 6:38 pm   Post subject: RE:pacman eating coins

The problem with that is that if you look at my code for placing coins, there are as many coins as can fit (with proper spacing)

Anyway, I fixed it (my teacher finally got around to teaching us Draw.Fill, which I would't have even considered before because I did not know what it did.

So now I have

[syntax="turing"]
procedure coingrab
if whatdotcolor (pacmanx, pacmany)= red then Draw.Fill (x, y, white, white)
score += 1
end if
end coingrab
isaiahk9




PostPosted: Wed May 07, 2008 7:01 pm   Post subject: RE:pacman eating coins

So you're good now? Sorry i couldn't help.
Insectoid




PostPosted: Wed May 07, 2008 7:42 pm   Post subject: RE:pacman eating coins

No problem. That would've helped...If I hadn't thought of another (far easier) way.

I must be honest and say, your way would've been a pain in the ass. I have just worked out the last bug, and am ready to continue my program! Next semi-project: a better map. Then ghosts, mouth open/close, pacman dying, game end, high scores..oh dear, this is going to take a while...
isaiahk9




PostPosted: Wed May 07, 2008 8:17 pm   Post subject: Re: pacman eating coins

a better map - draw it in paint or Macromedia Fireworks and then upload it. make the boundaries with View.WhatDotColor
Then ghosts - if ghost x < pac x then ghost x = ghost x + 5, if ghost x > pac x then ghost x = ghost x - 5. If ghost x = pac x, do the same with y. Although this is a ridiculously simple AI system, with many ghosts it will be insanely hard. Or look here http://compsci.ca/v3/viewtopic.php?t=17602&highlight=pacman
mouth open/close - there is a submission/help file on pacman's animation of mouth opening and closing
pacman dying - if ghost x,y = pac x,y then cls, score = 0
game end - cls, Pic.Draw ending screen, end all loops and procedures, end program
high scores - if pac x,y = ball x,y then score += 5. If pac x,y = cherry x,y then score += 10. If pac has eaten cherry and pac x,y = ghost x,y then score += 20.
. . . I am just being annoying?
Insectoid




PostPosted: Thu May 08, 2008 8:37 am   Post subject: RE:pacman eating coins

I really don't need this thread anymore. If you want to comment go over to http://compsci.ca/v3/viewtopic.php?t=18054.

Quote:
. . . I am just being annoying?


When someone else continually proves they know more than you, do you get anoyed? Jk, no you are not. You actually just helped my with my AI!
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  [ 7 Posts ]
Jump to:   


Style:  
Search: