Question: package hw 4 ; import java.awt.Rectangle; import api.AbstractElement; / * * * An attached element is one that is associated with another base element *
package hw;
import java.awt.Rectangle;
import api.AbstractElement;
An attached element is one that is associated with another "base" element
such as a PlatformElement or a LiftElement. Specifically, the attached
element's movement is determined by the movement of the base element, the
element always remains a fixed distance away.
@author YOUR NAME HERE
TODO: This class must directly or indirectly extend AbstractElement
public class AttachedElement extends PlatformElement
private int frameCount;
private int height;
private int width;
private double y;
private double x;
private AbstractElement baseElement;
private double newY;
private double offset;
private double hover;
private double newX;
Constructs a new AttachedElement. Before being added to an associated "base"
element such as a PlatformElement or LiftElement, the x and y coordinates are
initialized to zero. When the base object is set not in this constructor
the xcoordinate will be calculated as the base object's xcoordinate, plus
the given offset, and the ycoordinate will become the base object's
ycoordinate, minus this element's height, minus the hover amount.
@param width element's width
@param height element's height
@param offset when added to a base object, this amount will be added to the
other object's xcoordinate to calculate this element's
xcoordinate
@param hover when added to a base object, this element's ycoordinate is the
other object's ycoordinate, minus this element's height, minus
the hover amount
public AttachedElementint width, int height, int offset, int hover
superwidth height, offset, hover;
this.offset ;
this.hover ;
this.x ;
this.y ;
this.newX ;
this.newY ;
@Override
public boolean collidesAbstractElement other
return thisx other.getXInt other.getWidth &&
this.x this.width other.getXInt &&
this.y other.getYInt other.getHeight &&
this.y this.height other.getYInt;
@Override
public int getFrameCount
return frameCount;
@Override
public int getHeight
return height;
@Override
public int getWidth
return width;
@Override
public java.awt.Rectangle getRect
return new Rectangleint Math.roundxint Math.roundy width, height;
@Override
public int getXInt
return int Math.roundx;
@Override
public int getYInt
return int Math.roundy;
@Override
public double getXReal
return x;
@Override
public double getYReal
return y;
@Override
public boolean isMarked
return markedForDeletion;
@Override
public void markForDeletion
markedForDeletion true;
public void setBaseAbstractElement b
baseElement b;
@Override
public void setPositiondouble newX, double newY
this.newX newX;
this.newY newY;
Constructs a new AttachedElement. Before being added to an associated "base"
element such as a PlatformElement or LiftElement, the x and y coordinates are
initialized to zero. When the base object is set not in this constructor
the xcoordinate will be calculated as the base object's xcoordinate, plus
the given offset, and the ycoordinate will become the base object's
ycoordinate, minus this element's height, minus the hover amount.
@param width element's width
@param height element's height
@param offset when added to a base object, this amount will be added to the
other object's xcoordinate to calculate this element's
xcoordinate
@param hover when added to a base object, this element's ycoordinate is the
other object's ycoordinate, minus this element's height, minus
the hover amount
Updates this element's position to remain stationary
relative to the parent element provided that a parent has been set
@Override
public void update
frameCount;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
