
-----------------------------------
Insectoid
Mon May 05, 2008 6:48 pm

Pacman's mouth
-----------------------------------
I used the search engine and got nothing.

I am making a pacman program which I am going to use for my final project (My paint program is for comp. engineering)
Today I finished making packman move around and not bump into things, as well as pointing him in a different direction. 
I would like to know how to make pacman's mouth open and close. How can I make his mouth move without interupting the rest of my program? I could use and fork a process, but that is not the smartest idea...

p.s.- All my images were drawn in turing! (except the map)
p.p.s.- The map sucks because I did it quickly to get the main algorithm to work.

-----------------------------------
cavetroll
Mon May 05, 2008 7:41 pm

Re: Pacman's mouth
-----------------------------------
Here is an example of a very ineloquent way of solving this problem. I'm not as familiar with the Sprite module as I could be.



var x : int := 339 % pacman's X coordinate
var y : int := 396 % pacman's Y coordinate
var chars : array char of boolean %Input.KeyDown variable

var pacman : int %sprite name

%MY ADDITION---------------------------------------
const PAC_TIME := 25
var mouth_open : boolean := false
var mouth_count : int := 0
%-------------------------------------------------------


var map : int %the map. looks crappy.
var pacmanpic1 : int % pacman mouth open right
var pacmanpic2 : int % pacman mouth open up
var pacmanpic3 : int % pacman mouth open left
var pacmanpic4 : int %pacman mouth open down
var mouthclosed : int % pacman mouth closed
setscreen ("offscreenonly")

setscreen ("graphics: 679, 729")
map := Pic.FileNew ("Map1.bmp")
pacmanpic1 := Pic.FileNew ("pacman1.bmp") %various sprite things
Pic.SetTransparentColor (pacmanpic1, white)
pacmanpic2 := Pic.FileNew ("pacman2.bmp")
Pic.SetTransparentColor (pacmanpic2, white)
pacmanpic3 := Pic.FileNew ("pacman3.bmp")
Pic.SetTransparentColor (pacmanpic3, white)
pacmanpic4 := Pic.FileNew ("pacman4.bmp")
Pic.SetTransparentColor (pacmanpic4, white)
pacman := Sprite.New (pacmanpic1)
mouthclosed := Pic.FileNew ("pacmanmouthclosed.bmp")

Sprite.SetPosition (pacman, x, y, true) %more various sprite things
Sprite.SetHeight (pacman, 2)
Sprite.Show (pacman)

Pic.Draw (map, 1, 1, picCopy) %Draw the map

%move pacman
loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and whatdotcolor (x, y + 10) = white then
    mouth_count += 1
        y := y + 1
        if mouth_open = true then
        Sprite.Animate (pacman, pacmanpic2, x, y, true)
        if mouth_count > PAC_TIME then
        mouth_count := 0
        mouth_open := false
        end if
        else
        Sprite.Animate (pacman, mouthclosed, x, y, true)
        if mouth_count > PAC_TIME then
        mouth_count := 0
        mouth_open := true
        end if
        end if
    end if

    if chars (KEY_DOWN_ARROW) and whatdotcolor (x, y - 10) = white then
        y := y - 1
        mouth_count += 1
        if mouth_open = true then
        Sprite.Animate (pacman, pacmanpic4, x, y, true)
        if mouth_count > PAC_TIME then
        mouth_count := 0
        mouth_open := false
        end if
        else
        if mouth_count > PAC_TIME then
        mouth_count := 0
        mouth_open := true
        end if
        Sprite.Animate (pacman, mouthclosed, x, y, true)
        end if
    end if

    if chars (KEY_RIGHT_ARROW) and whatdotcolor (x + 10, y) = white then
        x := x + 1
        mouth_count += 1
        if mouth_open = true then
        Sprite.Animate (pacman, pacmanpic1, x, y, true)
        if mouth_count > PAC_TIME then
        mouth_count := 0
        mouth_open := false
        end if
        else
        if mouth_count > PAC_TIME then
        mouth_count := 0
        mouth_open := true
        end if
        Sprite.Animate (pacman, mouthclosed, x, y, true)
        end if
    end if

    if chars (KEY_LEFT_ARROW) and whatdotcolor (x - 10, y) = white then
    mouth_count += 1
        x := x - 1
        if mouth_open = true then
        Sprite.Animate (pacman, pacmanpic3, x, y, true)
        if mouth_count > PAC_TIME then
        mouth_count := 0
        mouth_open := false
        end if
        else
        if mouth_count > PAC_TIME then
        mouth_count := 0
        mouth_open := true
        end if
        Sprite.Animate (pacman, mouthclosed, x, y, true)
        end if
    end if

    View.Update %get rid of flash
    delay (6)


end loop


Anything using the variables surrounded by the comments "MY ADDITION---------------------------------------" is my addition :lol:

Basically it counts the number of frames that each picture has moved for and flips it accordingly. You can modify the speed of animation by changing the constant PAC_TIME. 

Please note: This is not an ideal solution nor a recommended one. It is simply an example of how it can be done, not how it should be done. As for how it should be done, I'm not really sure.

-----------------------------------
Insectoid
Mon May 05, 2008 8:01 pm

RE:Pacman\'s mouth
-----------------------------------
I guess variable += 1  is the same as  variable := variable + 1 ?
I get how you are doing it, and will find this very useful un my later programs.

Thanks.

-----------------------------------
cavetroll
Mon May 05, 2008 8:15 pm

Re: RE:Pacman\'s mouth
-----------------------------------
I guess variable += 1  is the same as  variable := variable + 1 ?

Ya they are the same. You can also use the following (If not more): 


var a : real := 2
put a, " : NO CHANGE"
a*=2 %Times 2
put a, " : *= 2"
a += 2 %Plus 2
put a, " : += 2"
a -= 2 %Minus 2
put a, " : -= 2"
a /= 2 %Divided by 2
put a, " : /= 2"
a**= 2 %Exponent 2
put a, " : **= 2" 


-----------------------------------
isaiahk9
Fri May 09, 2008 3:24 pm

RE:Pacman\'s mouth
-----------------------------------
http://compsci.ca/v3/viewtopic.php?t=17932&highlight=pacman
