Package model_pkg.gameobject_pkg

Source Code of model_pkg.gameobject_pkg.Cookie

package model_pkg.gameobject_pkg;

import model_pkg.GfxState;
import java.util.Random;
import def_classes.*;
import display_pkg.*;
import def_classes.Box;

/**
* A cookie type. The player might pick up a cookie.
* @author Johansson M., Kullman K.
*/
public class Cookie extends GameObject {
 
  private double gravityForce = 4;
  private double groundFriction = 0.5;
  private double maxVertSpeed = 18;
  private double maxHoriSpeed = 10;
 
  /**
   *
   * @param x
   * @param y
   * @param bbox
   * @param sprSheet
   */
  public Cookie(int x, int y, Box bbox, SpriteSheet sprSheet) {   
    super(x, y, bbox);
    currentAnim = new GfxState(sprSheet, 0);
    setMovable(true);
    setCollectable(true);
  }
 
  public Vector2D collisionOccured(GameObject obj, Vector2D offsetDisplacement){
    if (obj.isSolidSurfaceP()) {
      align(obj,offsetDisplacement);
    }
    return getMovement();   
  }
 
  public void updateObject() { 
    updateSpeed();   
    reboundVelocity();           
    myWorld.checkForCollisions(this);       
    updatePosition();
    updateSpriteBase();
  }
 
  private void updateSpeed() {
    setVelocity(getVelocity().scalarMultX(groundFriction));      
    addVelocityY(gravityForce);
    reboundVelocity();
    setMovement(this.getVelocity());
  }
 
  private void reboundVelocity() {
    if (getVelocity().getY() > maxVertSpeed) {
      getVelocity().setY(maxVertSpeed);
    }
  }
 
  private void updatePosition() {
    setMovement(myWorld.clipMovement(getBoundingBox(), getWorldPosition(), getMovement()));
    addToWorldPosition(getMovement());
  }
 
  public void destroyObject() {
    myWorld.pickUpCookie();
    myWorld.removeInstance(getObjectID());
  }
 
TOP

Related Classes of model_pkg.gameobject_pkg.Cookie

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.