Ejemplo n.º 1
0
 /* Damage do to the cactus by the player */
 public void hurt(Level level, int x, int y, Mob source, int dmg, int attackDir) {
   int damage =
       level.getData(x, y)
           + dmg; // Damage done to the cactus (it's "health" in some sense). dmg is the amount the
                  // player did to the cactus.
   level.add(new SmashParticle(x * 16 + 8, y * 16 + 8)); // creates a smash particle
   level.add(
       new TextParticle(
           "" + dmg,
           x * 16 + 8,
           y * 16 + 8,
           Color.get(
               -1, 500, 500,
               500))); // creates a text particle about how much damage has been done.
   if (damage >= 10) { // If the damage is equal to, or larger than 10 then...
     int count = random.nextInt(2) + 1; // count is random from 0 to 1 and adds one. (1-2 count)
     for (int i = 0; i < count; i++) { // cycles through the count
       level.add(
           new ItemEntity(
               new ResourceItem(Resource.cactusFlower),
               x * 16 + random.nextInt(10) + 3,
               y * 16 + random.nextInt(10) + 3)); // adds a cactus flower
     }
     level.setTile(x, y, Tile.sand, 0); // sets the tile to cactus
   } else {
     level.setData(x, y, damage); // else it will set the data to damage
   }
 }
Ejemplo n.º 2
0
 public void hurt(Level level, int x, int y, int dmg) {
   int damage = level.getData(x, y) + dmg;
   level.add(new SmashParticle(x * 16 + 8, y * 16 + 8));
   level.add(new TextParticle("" + dmg, x * 16 + 8, y * 16 + 8, Color.get(-1, 500, 500, 500)));
   if (damage >= 200) {
     int count = random.nextInt(4) + 1;
     for (int i = 0; i < count; i++) {
       level.add(
           new ItemEntity(
               new ResourceItem(Resource.stone),
               x * 16 + random.nextInt(10) + 3,
               y * 16 + random.nextInt(10) + 3));
     }
     count = random.nextInt(2);
     for (int i = 0; i < count; i++) {
       level.add(
           new ItemEntity(
               new ResourceItem(Resource.coal),
               x * 16 + random.nextInt(10) + 3,
               y * 16 + random.nextInt(10) + 3));
     }
     level.setTile(x, y, Tile.dirt, 0);
   } else {
     level.setData(x, y, damage);
   }
 }
Ejemplo n.º 3
0
 public void hurt(Level level, int x, int y, Mob source, int dmg, int attackDir) {
   int count = random.nextInt(2) + 1;
   for (int i = 0; i < count; i++) {
     level.add(
         new ItemEntity(
             new ResourceItem(Resource.flower),
             x * 16 + random.nextInt(10) + 3,
             y * 16 + random.nextInt(10) + 3));
   }
   level.setTile(x, y, Tile.grass, 0);
 }
Ejemplo n.º 4
0
 public boolean interact(Level level, int x, int y, Player player, Item item, int attackDir) {
   if (item instanceof ToolItem) {
     ToolItem tool = (ToolItem) item;
     if (tool.type == ToolType.shovel) {
       if (player.payStamina(4 - tool.level)) {
         level.add(
             new ItemEntity(
                 new ResourceItem(Resource.flower),
                 x * 16 + random.nextInt(10) + 3,
                 y * 16 + random.nextInt(10) + 3));
         level.add(
             new ItemEntity(
                 new ResourceItem(Resource.flower),
                 x * 16 + random.nextInt(10) + 3,
                 y * 16 + random.nextInt(10) + 3));
         level.setTile(x, y, Tile.grass, 0);
         return true;
       }
     }
   }
   return false;
 }