/* 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 } }
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); } }
public void tick(Level level, int xt, int yt) { int damage = level.getData(xt, yt); // gets the amount of damage the cactus has if (damage > 0) level.setData( xt, yt, damage - 1); // If the number of damage is above 0, then it will minus itself by 1 (heal) // Commenter note: I had no idea that cactuses healed themselves. }
public void render(Screen screen, Level level, int x, int y) { super.render(screen, level, x, y); int data = level.getData(x, y); int shape = (data / 16) % 2; int flowerCol = Color.get(10, level.grassColor, 555, 440); if (shape == 0) screen.render(x * 16 + 0, y * 16 + 0, 1 + 1 * 32, flowerCol, 0); if (shape == 1) screen.render(x * 16 + 8, y * 16 + 0, 1 + 1 * 32, flowerCol, 0); if (shape == 1) screen.render(x * 16 + 0, y * 16 + 8, 1 + 1 * 32, flowerCol, 0); if (shape == 0) screen.render(x * 16 + 8, y * 16 + 8, 1 + 1 * 32, flowerCol, 0); }
public void tick(Level level, int xt, int yt) { int damage = level.getData(xt, yt); if (damage > 0) level.setData(xt, yt, damage - 1); }