Computer Science Canada

Pacman Character

Author:  Boiq [ Wed Sep 10, 2008 7:13 am ]
Post subject:  Pacman Character

Hey guys,

I was wondering if any one could lend me in the right dirrection or show me a basic code that simply has the animated pacman character that can move in every dirrection, and it's animated open and closing mouth would follow with the dirrection. I've been trying for quite sometime now and a little bit of assistance or a preview of how to do it would really help me here. I would not like the whole Pacman game, just the animated character itself, and it being able to move up, down, left, and right while the animation portion of that character follows.

This is what i got so far:

loop
%Up
drawfilloval (120, 120, 20, 20, yellow)
delay (120)
drawfillarc (120, 120, 20, 20, 70, 120, 30)
delay (175)
%Left
drawfilloval (120, 120, 20, 20, yellow)
delay (120)
drawfillarc (120, 120, 20, 20, 130, 210, 30)
delay (175)
%Down
drawfilloval (120, 120, 20, 20, yellow)
delay (120)
drawfillarc (120, 120, 20, 20, 230, 310, 30)
delay (175)
%Right
drawfilloval (120, 120, 20, 20, yellow)
delay (120)
drawfillarc (120, 120, 20, 20, 310, 40, 30)
delay (175)
end loop

And i'm basically stuck there. I can make the animation move in all dirrection, but when I try to make him move they like stop working and stuff. Haha, anyways if anyone could lend me in the right direction, and possibly the finished code to refer to would be great as well.

Thanks!

Author:  Warchamp7 [ Wed Sep 10, 2008 7:49 am ]
Post subject:  Re: Pacman Character

Boiq @ Wed Sep 10, 2008 7:13 am wrote:
Hey guys,

I was wondering if any one could lend me in the right dirrection or show me a basic code that simply has the animated pacman character that can move in every dirrection, and it's animated open and closing mouth would follow with the dirrection. I've been trying for quite sometime now and a little bit of assistance or a preview of how to do it would really help me here. I would not like the whole Pacman game, just the animated character itself, and it being able to move up, down, left, and right while the animation portion of that character follows.

This is what i got so far:

loop
%Up
drawfilloval (120, 120, 20, 20, yellow)
delay (120)
drawfillarc (120, 120, 20, 20, 70, 120, 30)
delay (175)
%Left
drawfilloval (120, 120, 20, 20, yellow)
delay (120)
drawfillarc (120, 120, 20, 20, 130, 210, 30)
delay (175)
%Down
drawfilloval (120, 120, 20, 20, yellow)
delay (120)
drawfillarc (120, 120, 20, 20, 230, 310, 30)
delay (175)
%Right
drawfilloval (120, 120, 20, 20, yellow)
delay (120)
drawfillarc (120, 120, 20, 20, 310, 40, 30)
delay (175)
end loop

And i'm basically stuck there. I can make the animation move in all dirrection, but when I try to make him move they like stop working and stuff. Haha, anyways if anyone could lend me in the right direction, and possibly the finished code to refer to would be great as well.

Thanks!


How much have you done? Like, is this all the code you've done for this or do you have more.

Do you actually have pacman moving around or just these animations.

Author:  Boiq [ Wed Sep 10, 2008 9:22 am ]
Post subject:  RE:Pacman Character

That is basically just the animation. All I need is for it to be able to move now in each direction along with the animated mouth.

I've made it move but then the animation stops, so i'm a bit stuck.

Anyways, it would be nice if If anyone could get the code of just the character on a blank screen being able to move i every dirrection, etc. I don't need the full game, I don't want that much of a hint.

Thanks

Author:  S_Grimm [ Wed Sep 10, 2008 9:42 am ]
Post subject:  RE:Pacman Character

use Input.Keydown and and a counter for states (ie. state 1 = mouth open, state 2 closed) the use if statements.
ie (pseodocode)
if Input + Keyright arrow and state = 1 then
pacman moves to the right
draw pacman closed
end if
if Input + Keyright arrow and state = 2 then
pacman moves to the right
draw pacman mouth open
end if
edit: put wrong number. Sorry

Author:  Warchamp7 [ Wed Sep 10, 2008 11:17 am ]
Post subject:  Re: RE:Pacman Character

A\V @ Wed Sep 10, 2008 9:42 am wrote:
use Input.Keydown and and a counter for states (ie. state 1 = mouth open, state 2 closed) the use if statements.
ie (pseodocode)
if Input + Keyright arrow and state = 1 then
pacman moves to the right
draw pacman closed
end if
if Input + Keyright arrow and state = 2 then
pacman moves to the right
draw pacman mouth open
end if
edit: put wrong number. Sorry


PSEUDOCODE IS FOR NOOBZ lol

First off, I notticed you're drawing pacman in a very wrong way. You're drawing a yellow circle and then "drawing" a chunk out of it. You should just draw an arc that's not a complete circle.

Posted Image, might have been reduced in size. Click Image to view fullscreen.

CODEZ cause I was bored

Turing:
View.Set ("offscreenonly")

var chars : array char of boolean
var x, y : int %Pac Man's coordinates
var pacstate : boolean %True - Mouth Closed    %False - Mouth Open

x := 120
y := 120
pacstate := true

loop

Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        if pacstate = true then %Mouth Closed
            drawfilloval (x, y, 20, 20, yellow)
            x := x + 5
            pacstate := false %Changes it so the next time around it's open
        else %Mouth Open
            drawfilloval (x, y, 20, 20, yellow)
            drawfillarc (x, y, 20, 20, 310, 40, white)
            x := x + 5
            pacstate := true %Changes it so the next time the mouth is closed
        end if
       
    elsif chars (KEY_LEFT_ARROW) then
        if pacstate = true then
            drawfilloval (x, y, 20, 20, yellow)
            x := x - 5
            pacstate := false
        else
            drawfilloval (x, y, 20, 20, yellow)
            drawfillarc (x, y, 20, 20, 130, 210, white)
            x := x - 5
            pacstate := true
        end if
       
    elsif chars (KEY_DOWN_ARROW) then
        if pacstate = true then
            drawfilloval (x, y, 20, 20, yellow)
            y := y - 5
            pacstate := false
        else
            drawfilloval (x, y, 20, 20, yellow)
            drawfillarc (x, y, 20, 20, 230, 310, white)
            y := y - 5
            pacstate := true
        end if
       
    elsif chars (KEY_UP_ARROW) then
        if pacstate = true then
            drawfilloval (x, y, 20, 20, yellow) 
            y := y + 5
            pacstate := false
        else
            drawfilloval (x, y, 20, 20, yellow) 
            drawfillarc (x, y, 20, 20, 70, 120, white)
            y := y + 5
            pacstate := true
        end if     
else
drawfilloval (x, y, 20, 20, yellow) %If no key is pressed, draws Pacman

end if

View.UpdateArea (x - 45, y - 45, x + 45, y + 45) %Updates just the area that pac man takes up to reduce lag
drawfilloval (x, y, 45, 45, white) %Erases the old pacman
delay (120)
end loop

Author:  Insectoid [ Wed Sep 10, 2008 3:01 pm ]
Post subject:  Re: Pacman Character

Here's my way:

Use a variable for the angle of Pacman's mouth (will be using Draw.FillArc).

If the right arrow is pressed, the angle is equivelent to x (not sure the exact number...). Then Draw.FillArc (x, y, 20, 20, angle, angle+90, yellow). The trick here is to find the actual numbers for the angles (very simple math) to implement into your code.

Author:  Boiq [ Thu Sep 11, 2008 7:11 am ]
Post subject:  RE:Pacman Character

Warchamp your code is pretty good in my opinion. It does the trick, except I'm trying to figure it out with procedures instead of they way you programmed it.

Hmm..

Author:  Warchamp7 [ Thu Sep 11, 2008 7:40 am ]
Post subject:  Re: RE:Pacman Character

Boiq @ Thu Sep 11, 2008 7:11 am wrote:
Warchamp your code is pretty good in my opinion. It does the trick, except I'm trying to figure it out with procedures instead of they way you programmed it.

Hmm..


Just put this part in one and call the procedure in your main loop (Which should have your delay)

Turing:
Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        if pacstate = true then %Mouth Closed
            drawfilloval (x, y, 20, 20, yellow)
            x := x + 5
            pacstate := false %Changes it so the next time around it's open
        else %Mouth Open
            drawfilloval (x, y, 20, 20, yellow)
            drawfillarc (x, y, 20, 20, 310, 40, white)
            x := x + 5
            pacstate := true %Changes it so the next time the mouth is closed
        end if
       
    elsif chars (KEY_LEFT_ARROW) then
        if pacstate = true then
            drawfilloval (x, y, 20, 20, yellow)
            x := x - 5
            pacstate := false
        else
            drawfilloval (x, y, 20, 20, yellow)
            drawfillarc (x, y, 20, 20, 130, 210, white)
            x := x - 5
            pacstate := true
        end if
       
    elsif chars (KEY_DOWN_ARROW) then
        if pacstate = true then
            drawfilloval (x, y, 20, 20, yellow)
            y := y - 5
            pacstate := false
        else
            drawfilloval (x, y, 20, 20, yellow)
            drawfillarc (x, y, 20, 20, 230, 310, white)
            y := y - 5
            pacstate := true
        end if
       
    elsif chars (KEY_UP_ARROW) then
        if pacstate = true then
            drawfilloval (x, y, 20, 20, yellow) 
            y := y + 5
            pacstate := false
        else
            drawfilloval (x, y, 20, 20, yellow) 
            drawfillarc (x, y, 20, 20, 70, 120, white)
            y := y + 5
            pacstate := true
        end if     
else
drawfilloval (x, y, 20, 20, yellow) %If no key is pressed, draws Pacman

end if

View.UpdateArea (x - 45, y - 45, x + 45, y + 45) %Updates just the area that pac man takes up to reduce lag
drawfilloval (x, y, 45, 45, white) %Erases the old pacman

Author:  Boiq [ Thu Sep 11, 2008 9:27 am ]
Post subject:  RE:Pacman Character

Alright thanks for the help.

That should get me on the right track.

Author:  isaiahk9 [ Thu Sep 11, 2008 11:55 am ]
Post subject:  RE:Pacman Character

By the way, in the classic Pacman, his mouth moved whether he was moving or not.

Author:  Warchamp7 [ Thu Sep 11, 2008 9:01 pm ]
Post subject:  Re: RE:Pacman Character

isaiahk9 @ Thu Sep 11, 2008 11:55 am wrote:
By the way, in the classic Pacman, his mouth moved whether he was moving or not.


It's a simple change

Author:  isaiahk9 [ Fri Sep 12, 2008 4:54 am ]
Post subject:  RE:Pacman Character

I know, just putting it out there.


: