All right, I am sorry for my last zigzag as it was unclear. The project was to make the feet walk in a diamond or up and down the screen while moving forwards(i chose diamond). It does not matter if they go off the screen, just so long as it looks like they are actually walking and the distance between them stays the same. My problem is that at each turn except the first the feet move too far away from each other. I would appreciate any help. I will post 3 codes for reference. The .jar file only does what I want it to if it is with all the files from the project, so I will not be attatching it. I will post other files for reference at request. Any help is much appreciated.
( I dont know if it has an impact, but I use JCreator to run my Java programs.)
My first file, is ZigZag.
CODE
// Question 3-8
// A subclass of Walker that adds the turnAround method.
import java.awt.Image;
public class ZigZag extends Pacer
{
// Constructor
public ZigZag(int x, int y, Image leftPic, Image rightPic)
{
super(x, y, leftPic, rightPic);
}
public void firstTurn()
{
Foot lf = getLeftFoot();
Foot rf = getRightFoot();
lf.turn(45);
rf.turn(45);
lf.moveSideways(-PIXELS_PER_INCH * 8);
lf.moveForward(PIXELS_PER_INCH * 8);
}
Next is Pacer
CODE
// Question 3-8
// A subclass of Walker that adds the turnAround method.
import java.awt.Image;
public class Pacer extends Walker
{
// Constructor
public Pacer(int x, int y, Image leftPic, Image rightPic)
{
super(x, y, leftPic, rightPic);
}
// Turns this Pacer 180 degrees
// Precondition: the left and right feet are side by side
public void turnAround()
{
Foot lf = getLeftFoot();
Foot rf = getRightFoot();
lf.turn(180);
rf.turn(180);
lf.moveSideways(-PIXELS_PER_INCH * 8);
rf.moveSideways(PIXELS_PER_INCH * 8);
}
// Turns this Pacer left 90 degrees
// Precondition: the left and right feet are side by side
public void turnLeft()
{
Foot lf = getLeftFoot();
Foot rf = getRightFoot();
lf.turn(-90);
rf.turn(-90);
rf.moveSideways(PIXELS_PER_INCH * 8);
rf.moveForward(PIXELS_PER_INCH * 8);
}
// Turns this Pacer right 90 degrees
// Precondition: the left and right feet are side by side
public void turnRight()
{
Foot lf = getLeftFoot();
Foot rf = getRightFoot();
lf.turn(90);
rf.turn(90);
lf.moveSideways(-PIXELS_PER_INCH * 8);
lf.moveForward(PIXELS_PER_INCH * 8);
}
}
My last code is PacingGroup which organizes the methodss into what they do and when they should do it.
CODE
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PacingGroup implements StudentGroup
{
private ZigZag ben;
private Image leftWomansShoe, rightWomansShoe;
private Image leftMansShoe, rightMansShoe;
private DanceFloor danceFloor;
private enum State {READY, MOVING, STOPPED, PREPARED}
private State currentState;
private int stepsCount;
// Constructor
public PacingGroup(DanceFloor df)
{
danceFloor = df;
leftWomansShoe = (new ImageIcon("leftsandal.gif")).getImage();
rightWomansShoe = (new ImageIcon("rightsandal.gif")).getImage();
leftMansShoe = (new ImageIcon("leftshoe.gif")).getImage();
rightMansShoe = (new ImageIcon("rightshoe.gif")).getImage();
}
// Sets up this group of participants
public void setup(int floorDir, Dance steps1, Dance steps2)
{
int width = danceFloor.getWidth();
int height = danceFloor.getHeight();
int x = width / 10;
int y = height / 2;
if (floorDir == 0)
{
ben = new ZigZag(x, height / 2, leftMansShoe, rightMansShoe);
}
else
{
ben = new ZigZag(width, height / 2,
leftMansShoe, rightMansShoe);
}
currentState = State.READY;
danceFloor.update(this);
}
// Moves the group by one step
public void makeNextStep()
{
if (currentState == State.READY)
{
ben.firstTurn();
currentState = State.PREPARED;
stepsCount = 0;
}
else if (currentState == State.PREPARED)
{
ben.firstStep();
currentState = State.MOVING;
stepsCount = 0;
}
else if (currentState == State.MOVING)
{
if (ben.distanceTraveled() <= danceFloor.getHeight() * 1 / 4)
{
ben.nextStep();
stepsCount++;
}
else
{
ben.stop();
currentState = State.STOPPED;
}
}
else if (currentState == State.STOPPED)
{
ben.turnLeft();
currentState = State.PREPARED;
stepsCount = 0;
}
danceFloor.update(this);
}
// Draws this group
public void draw(Graphics g)
{
ben.draw(g);
}
}
This post has been edited by gormanator92: 10 Oct, 2008 - 08:40 AM