Package model_pkg.gameobject_pkg

Source Code of model_pkg.gameobject_pkg.CloudCircular

package model_pkg.gameobject_pkg;

import model_pkg.GfxState;
import def_classes.Box;
import def_classes.Point;
import def_classes.Vector2D;
import display_pkg.SpriteSheet;

/**
* A cicularly moving cloud
* @author Alving J., Kullman K.
*/
public class CloudCircular extends Cloud {

  // Horizontal and vertical radius of the circular motion
  private int xRadius;
  private int yRadius;
 
  /**
   * Creates a cicular cloud
   * @param x the left position of the box the cloud will be moving in
   * @param y the top position of the box
   * @param x2 the right position of the box
   * @param y2 the bottom position of the box
   * @param velocity the angular velocity of the motion
   * @param bbox the bounding box of the cloud
   * @param sprSheet the sprite sheet of the cloud
   * @param cloudSize the size of the cloud (determines which animation index to use)
   */
  public CloudCircular(
      int x, int y, int x2, int y2,
      int velocity, Box bbox, SpriteSheet sprSheet, int cloudSize){
    xRadius = (x2-x)/2;
    yRadius = (y2-y)/2;
    setWorldPosition(new Point(x2 - (bbox.getLeft() + bbox.getWidth()/2),
        y2-yRadius - (bbox.getTop() + bbox.getHeight()/2)));   
    setBoundingBox(bbox);
    cycleDegree = 0;
    cycleStep = velocity/10.0;
    setSolidSurface(true);
    currentAnim = new GfxState(sprSheet, cloudSize);
  }

  public void updateMovement() {
    double speedX = -xRadius*(Math.sin(cycleDegree*Math.PI/180))*cycleStep*Math.PI/180;
    double speedY = yRadius*(Math.cos(cycleDegree*Math.PI/180))*cycleStep*Math.PI/180;
    Vector2D newVelocity = new Vector2D(speedX,speedY);
    //velocity.setX(speedX);
    //velocity.setY(speedY);
    setVelocity(newVelocity);
    cycleDegree += cycleStep;
    setMovement(getVelocity());
  }
}

TOP

Related Classes of model_pkg.gameobject_pkg.CloudCircular

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.