Package net.sf.arianne.marboard.client.entity.shape

Source Code of net.sf.arianne.marboard.client.entity.shape.StraightLine

package net.sf.arianne.marboard.client.entity.shape;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;

import marauroa.common.game.RPObject;

/**
* A straight line.
*/
public class StraightLine extends Shape {

  /**
   * creates a new straight line
   *
   * @param rpobject RPObject provided by marauroa
   */
  public StraightLine(RPObject rpobject) {
    super(rpobject);
  }

  /**
   * draws the line on the graphics object
   *
   * @param graphics Graphics2D to draw on
   */
  @Override
  public void draw(Graphics2D graphics) {
    graphics.setColor(new Color(rpobject.getInt("color"), true));
    graphics.setStroke(new BasicStroke(rpobject.getInt("thickness")));
    int x1 = rpobject.getInt("x");
    int y1 = rpobject.getInt("y");
    int x2 = rpobject.getInt("x2");
    int y2 = rpobject.getInt("y2");
    graphics.drawLine(x1, y1, x2, y2);
  }

  /**
   * is this object located at the specified coordinates?
   *
   * @param x x-coordinate
   * @param y y-coordinate
   * @return true, if the point is within this shape; false otherwise
   */
  @Override
  public boolean isAt(int x, int y) {
    int x1 = rpobject.getInt("x");
    int y1 = rpobject.getInt("y");
    int x2 = rpobject.getInt("x2");
    int y2 = rpobject.getInt("y2");
    int thickness = rpobject.getInt("thickness");
    Line2D line = new Line2D.Float(x1, y1, x2, y2);
    return line.intersects(x, y, thickness, thickness);
  }
 
}
TOP

Related Classes of net.sf.arianne.marboard.client.entity.shape.StraightLine

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.