Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: GArc & move help.

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    29
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default GArc & move help.

    This program shows a pacman like figure moving right across the screen using GArcs. I run my program and it doesnt even show the first PacMan garc that I have added. Any Help?

    Heres my code:
    /*
     * Name: Connor Moore
     * File: PacMan.java
     * Date: 3/24/13
     * Purpose: The program displays a PacMan like figure moving 
     * rightward across the canvas starting on the very left side.
     */
     
    package mat2670;
     
    import acm.graphics.*;
    import acm.program.*;
    import java.awt.Color;
     
    public class PacMan extends GraphicsProgram {
     
        public static void main(String[] args) {
            (new PacMan()).start();
        }
     
        public void run() {
     
            //Gets the window's width
            double windowWidth = getWidth();
     
            //Initializes all the components to the GArc
            double r = 50;
            double x = 0;
            double y = getHeight() / 2;
            double width = 2 * r;
            double height = 2 * r;
            double start = 60;
            double sweep = 240;
     
            //displacement of x
            double dx = 120;
     
            //Creates and adds the first PacMan shape.
            GArc PacMan = new GArc(x, y, 2 * r, 2 * r, start, sweep);
            PacMan.setFilled(true);
            PacMan.setFillColor(Color.YELLOW);
            add(PacMan);
     
            int count = 0;
            while ((x + r) < windowWidth) {
     
                //takes 3 times for PacMans mouth to shut.
                //Starts open, shuts at 3, switch to opening again, etc
                if (count < 3 || count > 6) {
                    start -= 20;
                    sweep += 40;
                    x += dx;
                } else if (count > 3 || count > 9) {
                    start += 20;
                    sweep -= 40;
                    x += dx;
                }
                PacMan.move(x, y);
                pause(PAUSE_TIME);
            }
        }
        private static final int PAUSE_TIME = 5;
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: GArc & move help.

    The problem for others trying to test the code is that it uses 3rd party packages. Is there a forum for users of those packages?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    29
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: GArc & move help.

    I dont believe so, its just the acmlibrary