0

hey everyone i am pretty new to programming and i need a little help
with a code that i am writting it is a pacMan and i need it to open and close its mouth but i am not sure how to do that i started an array with the degrees needed to open and close that mouth but i dont know how to put it into a code that will make it work well this is what i hava so far if any one can help i would appreciate it a lot
thanks for your time

import acm.graphics.*;
import acm.program.*;

import java.awt.*;



public class pacMan extends GraphicsProgram
{

        int startpoints []={0,15,30,45,30,15};
        int sweeppoints []={0,330,300,270,300,330};


    public void run()
    {


        PacManMouth();
        setSize(800,600);

        GArc  pac = new GArc( 10,50,100,100,30,300);
        add(pac,0,400);
        pac.setFilled(true);
        pac.setFillColor(Color.yellow);
        while(true)
        {
            int postion=0;
            pac.move(1,0);
            pause(20);
        }

    }///end run

public void PacManMouth()
        {



        }

}///end class

Edited by Nick Evan: Fixed formatting

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by stultuske
0

hello goyofoyo

import java.awt.Color;
import acm.graphics.*;
import acm.program.*;

public class pacMan extends GraphicsProgram {

    int startpoints[] = {0, 15, 30, 45, 30, 15};
    int sweeppoints[] = {360, 330, 300, 270, 300, 330};
    int index = 0;

    public void run() {
        setSize(800, 600);
        GArc pac = new GArc(10, 50, 100, 100, 45, 360 - 2 * 45);
        add(pac, 0, 400);
        pac.setFilled(true);
        pac.setFillColor(Color.yellow);
        while (true) {
            pac.move(1, 0);
            PacManMouth(pac);
            pause(90);
        }
    }

    public void PacManMouth(GArc pac) {
        pac.setStartAngle(startpoints[index]);
        pac.setSweepAngle(sweeppoints[index]);
        index += 1;
        // if index exceed size of arrays then zero
        index = index % startpoints.length;

    }
    
    // delta control
    public void PacManMouth3(GArc pac) {
        double k = 0.3;
        pac.setStartAngle(pac.getStartAngle() - k);
        pac.setSweepAngle(pac.getSweepAngle() + 2 * k);
    }   
}

good luck
quuba

0

hello goyofoyo
...

you may also want to include some comments.
as he said, he is new to Java. He's propably more benefitted with code and explanation than just code to copy paste

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.