Package games.mapacman.common

Source Code of games.mapacman.common.Fruit

package games.mapacman.common;

import marauroa.common.game.RPClass;
import marauroa.common.game.RPObject;
import marauroa.server.game.Statistics;
import games.mapacman.client.GameScreen;
import games.mapacman.server.MaPacmanZone;

public class Fruit extends Dot {

  private int fruitprob=1;
  private int fruit_score;
  private boolean isFruit;
 
  public Fruit(int x, int y, int dot_score, int fruit_score, int fruit_probability, MaPacmanZone zone) {
    super(x,y,dot_score,zone);
    myObject.put("type",consts.TYPE_FRUIT);
    myObject.put("fruitprob",fruit_probability);
    myObject.put("score",fruit_score);
    myObject.put("dottype",TYPE_FRUIT);
    fruitprob = fruit_probability;
    this.fruit_score = fruit_score;
  }
 
  public Fruit(RPObject object) {
    super(object);
    isFruit=(object.getInt("dottype")==TYPE_FRUIT);
     
  }

  public static void initRPClass()
  {
    RPClass fruit = new RPClass(consts.TYPE_FRUIT);
    fruit.isA(consts.TYPE_DOT);
    fruit.add("dottype",RPClass.INT);
    fruit.add("fruitprob",RPClass.INT)
  }
 
  public void setRespawnTime()
  {   
    if (zone.getRandom().nextInt(fruitprob)==0)
    {  // Fruit
      myObject.put("score",fruit_score);
      myObject.put("dottype",TYPE_FRUIT);
      setRespawnTime(zone.getFruitRespawnTime());     
    }
    else
    {
      myObject.put("dottype",TYPE_DOT);
      myObject.put("score",dot_score);
      setRespawnTime(zone.getDotRespawnTime());
    }   
  }
 
  public void addStats(Statistics stats) {
    if (myObject.getInt("dottype")==TYPE_FRUIT)
    {
      stats.add("Fruit eaten",1);
    }
    else super.addStats(stats);
  }
 
  public void draw(GameScreen screen) {
    if (isFruit)
      screen.draw(screen.getDotSprite(TYPE_FRUIT),x,y);
    else
      screen.draw(screen.getDotSprite(TYPE_DOT),x,y);
  }
 
}
TOP

Related Classes of games.mapacman.common.Fruit

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.