// Implementation of the Vehicle class // CSE143 Spring '01 // Homework 6 #include "vehicle.h" // Construct a vehicle with uninitialized position and heading Vehicle::Vehicle() { } // Construct a vehicle with same position and heading as õ Vehicle::Vehicle(const Vehicle& other) { pos = other.pos; heading = other.heading; } // Set position and heading of this vehicle to 's Vehicle& Vehicle::operator =(const Vehicle& other) { pos = other.pos; heading = other.heading; return *this; } // Destructor (empty - no dynamic memory in this class) Vehicle::~Vehicle() {} // Draw the vehicle on the screen void Vehicle::draw(GP142Display& gp) { gp.drawRectangle(pos.getX() - 5, pos.getY() - 5, pos.getX() + 5, pos.getY() + 5, Yellow, 0); Position frontRight, frontLeft, frontCtr; frontLeft = Position(pos.getX() - 5, pos.getY() + 5); frontRight = Position(pos.getX() + 5, pos.getY() + 5); frontCtr = Position(pos.getX(), pos.getY() + 10); frontLeft.rotate(pos, heading); frontRight.rotate(pos, heading); frontCtr.rotate(pos, heading); gp.drawTriangle(frontLeft.getX(), frontLeft.getY(), frontRight.getX(), frontRight.getY(), frontCtr.getX(), frontCtr.getY(), Red, 0); } // Update vehicle appearance (empty for this class) void Vehicle::tick() {} // Advance the specified distance in pixels, in the current direction. void Vehicle::advance(int distance) { pos.move(heading, distance); } // Turn the vehicle to face the new direction. void Vehicle::turn(Direction newHeading) { heading = newHeading; } // Move the vehicle to the specified position void Vehicle::setPosition(Position pos) { this->pos = pos; } // Returns the current position. Position Vehicle::getPosition() const { return pos; } // Returns the current heading. Direction Vehicle::getHeading() const { return heading; }