Moving objects assignment

this is the question


https://photos.google.com/photo/AF1QipM2ICRz3oqmgr-gBQ7dQp5yBVqK1_ag2hX2v0ap
https://photos.google.com/photo/AF1QipOUSXFSEl3n3UNftSNsEon3xtcczVtXGArcZV6G

Create a new program, with a size of 400x400 ,in processing and implement the features as described below using loops and if statements:

  1. Create a class called vehicle. The class should draw an arrow shaped vehicle and add the following pictures to the class:
    • A X and y coordinate of the centre of the vehicle
    • A fill colour.
    • A variable indicating the direction the vehicle is facing.
    • A constructor to give initial values to the X and Y coordinates.
    • A function to set the fill colour.
    • Functions to draw the vehicle facing the different directions (see fig 1 to 4).
    • A MoveLeft function to decrease the vehicles X coordinate by 1 pixel, moving it to the left.
    • A MoveRight function to increase the vehicles X coordinate by 1 pixel, moving it to the Right.
    • A MoveUp function to decrease the vehicles Y coordinate by 1 pixel, moving it Down.
    • A MoveDown function to increase the vehicles Y coordinate by 1 pixel, moving it Up .
    Using the mouse clicked function add the following features
    • Left mouse button is clicked the first vehicle must systematically move to the location where the mouse was clicked.
    • Right mouse button is clicked the second vehicle must systematically move to the location where the mouse was clicked.

this is my program

Vehicle myVehicle1;
Vehicle myVehicle2;
float xCoOrdinate = 50, yCoOrdinate = 50;
int move = 3;
void setup() {
  size(400, 400);
  // Initialize Car object
  myVehicle1 = new Vehicle(color(255, 0, 0), random(0, width), random(0, height), 1);
  myVehicle2 = new Vehicle(color(0, 0, 255), random(0, width), random(0, height), 1);
}
void draw() {
  background(255);
  // Operate Car object.
 // moving();
 // myVehicle1.move();
  myVehicle1.display();
 // myVehicle2.move();
  myVehicle2.display();
}
class Vehicle {
  color c;
  float xpos;
  float ypos;
  float xspeed;
  Vehicle(color tempC, float tempXpos, float tempYpos, float tempXspeed) {
    c = tempC;
    xpos = tempXpos;
    ypos = tempYpos;
    xspeed = tempXspeed;
    xpos = random(0, width);
    ypos = random(0, height);
  }
  void display() {//vehicle shape
    rectMode(CENTER);
    fill(c);
    quad(xpos, ypos-15, xpos+15, ypos+8, xpos, ypos, xpos-15, ypos+8);
  }
  //void move() {
    //xpos = xpos + xspeed;
    //if (xpos > width) {
      //xpos = 0;
    //}
  //}
  void facingLeft() {
  fill(c);
  quad(xpos-15, ypos, xpos+8, ypos-15, xpos, ypos, xpos+8, ypos+15);
}
void facingRight() {
  fill(c);
  quad(xpos, ypos, xpos-8, ypos-15, xpos+15, ypos, xpos-8, ypos+15);
}
void facingUp() {
  fill(c);
  quad(xpos, ypos-15, xpos+15, ypos+8, xpos, ypos, xpos-15, ypos+8);
}
void facingDown() {
  fill(c);
  quad(xpos-15, ypos-8, xpos, ypos, xpos+15, ypos-8, xpos, ypos+15);
}

  void moveLeft() {
    xCoOrdinate--;
  }
  void moveRight() {
    xCoOrdinate++;
  }
  void moveUp() {
    xCoOrdinate--;
  }
  void moveDown() {
    xCoOrdinate++;
  }
  void moving(){
for(int i = 0; i < 10; i++)
  {
      //rectMode(CORNER);
      fill(233,56,43);
      rect(xpos, ypos, 25, 25);
    // TestLocations(k);
     if(xpos < mouseX)
      {
        
       xpos = xpos + move; 
       facingLeft();
       moveLeft();
  }
       if(xpos > mouseX)
      {
       xpos = xpos - move; 
       facingRight();
       moveRight();
      }
      
      if(ypos > mouseY)
      {
       ypos = ypos - move; 
       facingUp();
       moveUp();
      }
      
       if(ypos < mouseY)
      {
       ypos = ypos + move; 
       facingDown();
       moveDown();
      } 
      //if((xpos == mouseX) && (ypos == mouseY))
     // {
       // xpos = tempXpos;
       // ypos = tempYpos;
      }
}
}
  void mouseClicked() {
    if (mouseButton == LEFT) {
      //myVehicle1.move();
    } else {
     // myVehicle2.move();
    }
  }
//}

What exactly do you need help with within your program?

1 Like

Im new to processing,so i dont know what its short of for it to function…so i need someone to troubleshoot for me and help me where doesn’t function well.The vehicles should be controlled by mouse clicking,right click one vehicle and right click the other one.

Alright, but it’s impossible for us to troubleshoot that code right now because it is a mess. You should at least edit your post and format your code properly - select the code, and hit the format button, which looks like this: </>

You’ve figured out how to make the vehicles go to the mouse, but it seems by the look of your assignment they only want it to move one direction at a time. (Right now the vehicle can go 2 directions at the same time)

It also seems you’ve mixed up left and right when drawing the vehicle.

thank you, I think its better now…please help ASAP

wasn’t aware of that,will get onto it…they actually dont move to the mouse,thats whats confusing me too.