import code
This commit is contained in:
158
src/com/mojang/ld22/entity/AirWizard.java
Normal file
158
src/com/mojang/ld22/entity/AirWizard.java
Normal file
@@ -0,0 +1,158 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.gfx.Screen;
|
||||
import com.mojang.ld22.item.ResourceItem;
|
||||
import com.mojang.ld22.item.resource.Resource;
|
||||
import com.mojang.ld22.sound.Sound;
|
||||
|
||||
public class AirWizard extends Mob {
|
||||
private int xa, ya;
|
||||
private int randomWalkTime = 0;
|
||||
private int attackDelay = 0;
|
||||
private int attackTime = 0;
|
||||
private int attackType = 0;
|
||||
|
||||
public AirWizard() {
|
||||
x = random.nextInt(64 * 16);
|
||||
y = random.nextInt(64 * 16);
|
||||
health = maxHealth = 2000;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (attackDelay > 0) {
|
||||
dir = (attackDelay - 45) / 4 % 4;
|
||||
dir = (dir * 2 % 4) + (dir / 2);
|
||||
if (attackDelay < 45) {
|
||||
dir = 0;
|
||||
}
|
||||
attackDelay--;
|
||||
if (attackDelay == 0) {
|
||||
attackType = 0;
|
||||
if (health < 1000) attackType = 1;
|
||||
if (health < 200) attackType = 2;
|
||||
attackTime = 60 * 2;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (attackTime > 0) {
|
||||
attackTime--;
|
||||
double dir = attackTime * 0.25 * (attackTime % 2 * 2 - 1);
|
||||
double speed = (0.7) + attackType * 0.2;
|
||||
level.add(new Spark(this, Math.cos(dir) * speed, Math.sin(dir) * speed));
|
||||
return;
|
||||
}
|
||||
|
||||
if (level.player != null && randomWalkTime == 0) {
|
||||
int xd = level.player.x - x;
|
||||
int yd = level.player.y - y;
|
||||
if (xd * xd + yd * yd < 32 * 32) {
|
||||
xa = 0;
|
||||
ya = 0;
|
||||
if (xd < 0) xa = +1;
|
||||
if (xd > 0) xa = -1;
|
||||
if (yd < 0) ya = +1;
|
||||
if (yd > 0) ya = -1;
|
||||
} else if (xd * xd + yd * yd > 80 * 80) {
|
||||
xa = 0;
|
||||
ya = 0;
|
||||
if (xd < 0) xa = -1;
|
||||
if (xd > 0) xa = +1;
|
||||
if (yd < 0) ya = -1;
|
||||
if (yd > 0) ya = +1;
|
||||
}
|
||||
}
|
||||
|
||||
int speed = (tickTime % 4) == 0 ? 0 : 1;
|
||||
if (!move(xa * speed, ya * speed) || random.nextInt(100) == 0) {
|
||||
randomWalkTime = 30;
|
||||
xa = (random.nextInt(3) - 1);
|
||||
ya = (random.nextInt(3) - 1);
|
||||
}
|
||||
if (randomWalkTime > 0) {
|
||||
randomWalkTime--;
|
||||
if (level.player != null && randomWalkTime == 0) {
|
||||
int xd = level.player.x - x;
|
||||
int yd = level.player.y - y;
|
||||
if (random.nextInt(4) == 0 && xd * xd + yd * yd < 50 * 50) {
|
||||
if (attackDelay == 0 && attackTime == 0) {
|
||||
attackDelay = 60 * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void doHurt(int damage, int attackDir) {
|
||||
super.doHurt(damage, attackDir);
|
||||
if (attackDelay == 0 && attackTime == 0) {
|
||||
attackDelay = 60 * 2;
|
||||
}
|
||||
}
|
||||
|
||||
public void render(Screen screen) {
|
||||
int xt = 8;
|
||||
int yt = 14;
|
||||
|
||||
int flip1 = (walkDist >> 3) & 1;
|
||||
int flip2 = (walkDist >> 3) & 1;
|
||||
|
||||
if (dir == 1) {
|
||||
xt += 2;
|
||||
}
|
||||
if (dir > 1) {
|
||||
|
||||
flip1 = 0;
|
||||
flip2 = ((walkDist >> 4) & 1);
|
||||
if (dir == 2) {
|
||||
flip1 = 1;
|
||||
}
|
||||
xt += 4 + ((walkDist >> 3) & 1) * 2;
|
||||
}
|
||||
|
||||
int xo = x - 8;
|
||||
int yo = y - 11;
|
||||
|
||||
int col1 = Color.get(-1, 100, 500, 555);
|
||||
int col2 = Color.get(-1, 100, 500, 532);
|
||||
if (health < 200) {
|
||||
if (tickTime / 3 % 2 == 0) {
|
||||
col1 = Color.get(-1, 500, 100, 555);
|
||||
col2 = Color.get(-1, 500, 100, 532);
|
||||
}
|
||||
} else if (health < 1000) {
|
||||
if (tickTime / 5 % 4 == 0) {
|
||||
col1 = Color.get(-1, 500, 100, 555);
|
||||
col2 = Color.get(-1, 500, 100, 532);
|
||||
}
|
||||
}
|
||||
if (hurtTime > 0) {
|
||||
col1 = Color.get(-1, 555, 555, 555);
|
||||
col2 = Color.get(-1, 555, 555, 555);
|
||||
}
|
||||
|
||||
screen.render(xo + 8 * flip1, yo + 0, xt + yt * 32, col1, flip1);
|
||||
screen.render(xo + 8 - 8 * flip1, yo + 0, xt + 1 + yt * 32, col1, flip1);
|
||||
screen.render(xo + 8 * flip2, yo + 8, xt + (yt + 1) * 32, col2, flip2);
|
||||
screen.render(xo + 8 - 8 * flip2, yo + 8, xt + 1 + (yt + 1) * 32, col2, flip2);
|
||||
}
|
||||
|
||||
protected void touchedBy(Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
entity.hurt(this, 3, dir);
|
||||
}
|
||||
}
|
||||
|
||||
protected void die() {
|
||||
super.die();
|
||||
if (level.player != null) {
|
||||
level.player.score += 1000;
|
||||
level.player.gameWon();
|
||||
}
|
||||
Sound.bossdeath.play();
|
||||
}
|
||||
|
||||
}
|
||||
20
src/com/mojang/ld22/entity/Anvil.java
Normal file
20
src/com/mojang/ld22/entity/Anvil.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.crafting.Crafting;
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.screen.CraftingMenu;
|
||||
|
||||
public class Anvil extends Furniture {
|
||||
public Anvil() {
|
||||
super("Anvil");
|
||||
col = Color.get(-1, 000, 111, 222);
|
||||
sprite = 0;
|
||||
xr = 3;
|
||||
yr = 2;
|
||||
}
|
||||
|
||||
public boolean use(Player player, int attackDir) {
|
||||
player.game.setMenu(new CraftingMenu(Crafting.anvilRecipes, player));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
19
src/com/mojang/ld22/entity/Chest.java
Normal file
19
src/com/mojang/ld22/entity/Chest.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.screen.ContainerMenu;
|
||||
|
||||
public class Chest extends Furniture {
|
||||
public Inventory inventory = new Inventory();
|
||||
|
||||
public Chest() {
|
||||
super("Chest");
|
||||
col = Color.get(-1, 110, 331, 552);
|
||||
sprite = 1;
|
||||
}
|
||||
|
||||
public boolean use(Player player, int attackDir) {
|
||||
player.game.setMenu(new ContainerMenu(player, "Chest", inventory));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
134
src/com/mojang/ld22/entity/Entity.java
Normal file
134
src/com/mojang/ld22/entity/Entity.java
Normal file
@@ -0,0 +1,134 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.mojang.ld22.gfx.Screen;
|
||||
import com.mojang.ld22.item.Item;
|
||||
import com.mojang.ld22.level.Level;
|
||||
import com.mojang.ld22.level.tile.Tile;
|
||||
|
||||
public class Entity {
|
||||
protected final Random random = new Random();
|
||||
public int x, y;
|
||||
public int xr = 6;
|
||||
public int yr = 6;
|
||||
public boolean removed;
|
||||
public Level level;
|
||||
|
||||
public void render(Screen screen) {
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
removed = true;
|
||||
}
|
||||
|
||||
public final void init(Level level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public boolean intersects(int x0, int y0, int x1, int y1) {
|
||||
return !(x + xr < x0 || y + yr < y0 || x - xr > x1 || y - yr > y1);
|
||||
}
|
||||
|
||||
public boolean blocks(Entity e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void hurt(Mob mob, int dmg, int attackDir) {
|
||||
}
|
||||
|
||||
public void hurt(Tile tile, int x, int y, int dmg) {
|
||||
}
|
||||
|
||||
public boolean move(int xa, int ya) {
|
||||
if (xa != 0 || ya != 0) {
|
||||
boolean stopped = true;
|
||||
if (xa != 0 && move2(xa, 0)) stopped = false;
|
||||
if (ya != 0 && move2(0, ya)) stopped = false;
|
||||
if (!stopped) {
|
||||
int xt = x >> 4;
|
||||
int yt = y >> 4;
|
||||
level.getTile(xt, yt).steppedOn(level, xt, yt, this);
|
||||
}
|
||||
return !stopped;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean move2(int xa, int ya) {
|
||||
if (xa != 0 && ya != 0) throw new IllegalArgumentException("Move2 can only move along one axis at a time!");
|
||||
|
||||
int xto0 = ((x) - xr) >> 4;
|
||||
int yto0 = ((y) - yr) >> 4;
|
||||
int xto1 = ((x) + xr) >> 4;
|
||||
int yto1 = ((y) + yr) >> 4;
|
||||
|
||||
int xt0 = ((x + xa) - xr) >> 4;
|
||||
int yt0 = ((y + ya) - yr) >> 4;
|
||||
int xt1 = ((x + xa) + xr) >> 4;
|
||||
int yt1 = ((y + ya) + yr) >> 4;
|
||||
boolean blocked = false;
|
||||
for (int yt = yt0; yt <= yt1; yt++)
|
||||
for (int xt = xt0; xt <= xt1; xt++) {
|
||||
if (xt >= xto0 && xt <= xto1 && yt >= yto0 && yt <= yto1) continue;
|
||||
level.getTile(xt, yt).bumpedInto(level, xt, yt, this);
|
||||
if (!level.getTile(xt, yt).mayPass(level, xt, yt, this)) {
|
||||
blocked = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (blocked) return false;
|
||||
|
||||
List<Entity> wasInside = level.getEntities(x - xr, y - yr, x + xr, y + yr);
|
||||
List<Entity> isInside = level.getEntities(x + xa - xr, y + ya - yr, x + xa + xr, y + ya + yr);
|
||||
for (int i = 0; i < isInside.size(); i++) {
|
||||
Entity e = isInside.get(i);
|
||||
if (e == this) continue;
|
||||
|
||||
e.touchedBy(this);
|
||||
}
|
||||
isInside.removeAll(wasInside);
|
||||
for (int i = 0; i < isInside.size(); i++) {
|
||||
Entity e = isInside.get(i);
|
||||
if (e == this) continue;
|
||||
|
||||
if (e.blocks(this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
x += xa;
|
||||
y += ya;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void touchedBy(Entity entity) {
|
||||
}
|
||||
|
||||
public boolean isBlockableBy(Mob mob) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void touchItem(ItemEntity itemEntity) {
|
||||
}
|
||||
|
||||
public boolean canSwim() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean interact(Player player, Item item, int attackDir) {
|
||||
return item.interact(player, this, attackDir);
|
||||
}
|
||||
|
||||
public boolean use(Player player, int attackDir) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getLightRadius() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
20
src/com/mojang/ld22/entity/Furnace.java
Normal file
20
src/com/mojang/ld22/entity/Furnace.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.crafting.Crafting;
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.screen.CraftingMenu;
|
||||
|
||||
public class Furnace extends Furniture {
|
||||
public Furnace() {
|
||||
super("Furnace");
|
||||
col = Color.get(-1, 000, 222, 333);
|
||||
sprite = 3;
|
||||
xr = 3;
|
||||
yr = 2;
|
||||
}
|
||||
|
||||
public boolean use(Player player, int attackDir) {
|
||||
player.game.setMenu(new CraftingMenu(Crafting.furnaceRecipes, player));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
58
src/com/mojang/ld22/entity/Furniture.java
Normal file
58
src/com/mojang/ld22/entity/Furniture.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.gfx.Screen;
|
||||
import com.mojang.ld22.item.FurnitureItem;
|
||||
import com.mojang.ld22.item.PowerGloveItem;
|
||||
|
||||
public class Furniture extends Entity {
|
||||
private int pushTime = 0;
|
||||
private int pushDir = -1;
|
||||
public int col, sprite;
|
||||
public String name;
|
||||
private Player shouldTake;
|
||||
|
||||
public Furniture(String name) {
|
||||
this.name = name;
|
||||
xr = 3;
|
||||
yr = 3;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
if (shouldTake != null) {
|
||||
if (shouldTake.activeItem instanceof PowerGloveItem) {
|
||||
remove();
|
||||
shouldTake.inventory.add(0, shouldTake.activeItem);
|
||||
shouldTake.activeItem = new FurnitureItem(this);
|
||||
}
|
||||
shouldTake = null;
|
||||
}
|
||||
if (pushDir == 0) move(0, +1);
|
||||
if (pushDir == 1) move(0, -1);
|
||||
if (pushDir == 2) move(-1, 0);
|
||||
if (pushDir == 3) move(+1, 0);
|
||||
pushDir = -1;
|
||||
if (pushTime > 0) pushTime--;
|
||||
}
|
||||
|
||||
public void render(Screen screen) {
|
||||
screen.render(x - 8, y - 8 - 4, sprite * 2 + 8 * 32, col, 0);
|
||||
screen.render(x - 0, y - 8 - 4, sprite * 2 + 8 * 32 + 1, col, 0);
|
||||
screen.render(x - 8, y - 0 - 4, sprite * 2 + 8 * 32 + 32, col, 0);
|
||||
screen.render(x - 0, y - 0 - 4, sprite * 2 + 8 * 32 + 33, col, 0);
|
||||
}
|
||||
|
||||
public boolean blocks(Entity e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void touchedBy(Entity entity) {
|
||||
if (entity instanceof Player && pushTime == 0) {
|
||||
pushDir = ((Player) entity).dir;
|
||||
pushTime = 10;
|
||||
}
|
||||
}
|
||||
|
||||
public void take(Player player) {
|
||||
shouldTake = player;
|
||||
}
|
||||
}
|
||||
69
src/com/mojang/ld22/entity/Inventory.java
Normal file
69
src/com/mojang/ld22/entity/Inventory.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.ld22.item.Item;
|
||||
import com.mojang.ld22.item.ResourceItem;
|
||||
import com.mojang.ld22.item.resource.Resource;
|
||||
|
||||
public class Inventory {
|
||||
public List<Item> items = new ArrayList<Item>();
|
||||
|
||||
public void add(Item item) {
|
||||
add(items.size(), item);
|
||||
}
|
||||
|
||||
public void add(int slot, Item item) {
|
||||
if (item instanceof ResourceItem) {
|
||||
ResourceItem toTake = (ResourceItem) item;
|
||||
ResourceItem has = findResource(toTake.resource);
|
||||
if (has == null) {
|
||||
items.add(slot, toTake);
|
||||
} else {
|
||||
has.count += toTake.count;
|
||||
}
|
||||
} else {
|
||||
items.add(slot, item);
|
||||
}
|
||||
}
|
||||
|
||||
private ResourceItem findResource(Resource resource) {
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
if (items.get(i) instanceof ResourceItem) {
|
||||
ResourceItem has = (ResourceItem) items.get(i);
|
||||
if (has.resource == resource) return has;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasResources(Resource r, int count) {
|
||||
ResourceItem ri = findResource(r);
|
||||
if (ri == null) return false;
|
||||
return ri.count >= count;
|
||||
}
|
||||
|
||||
public boolean removeResource(Resource r, int count) {
|
||||
ResourceItem ri = findResource(r);
|
||||
if (ri == null) return false;
|
||||
if (ri.count < count) return false;
|
||||
ri.count -= count;
|
||||
if (ri.count <= 0) items.remove(ri);
|
||||
return true;
|
||||
}
|
||||
|
||||
public int count(Item item) {
|
||||
if (item instanceof ResourceItem) {
|
||||
ResourceItem ri = findResource(((ResourceItem)item).resource);
|
||||
if (ri!=null) return ri.count;
|
||||
} else {
|
||||
int count = 0;
|
||||
for (int i=0; i<items.size(); i++) {
|
||||
if (items.get(i).matches(item)) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
87
src/com/mojang/ld22/entity/ItemEntity.java
Normal file
87
src/com/mojang/ld22/entity/ItemEntity.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.gfx.Screen;
|
||||
import com.mojang.ld22.item.Item;
|
||||
import com.mojang.ld22.sound.Sound;
|
||||
|
||||
public class ItemEntity extends Entity {
|
||||
private int lifeTime;
|
||||
protected int walkDist = 0;
|
||||
protected int dir = 0;
|
||||
public int hurtTime = 0;
|
||||
protected int xKnockback, yKnockback;
|
||||
public double xa, ya, za;
|
||||
public double xx, yy, zz;
|
||||
public Item item;
|
||||
private int time = 0;
|
||||
|
||||
public ItemEntity(Item item, int x, int y) {
|
||||
this.item = item;
|
||||
xx = this.x = x;
|
||||
yy = this.y = y;
|
||||
xr = 3;
|
||||
yr = 3;
|
||||
|
||||
zz = 2;
|
||||
xa = random.nextGaussian() * 0.3;
|
||||
ya = random.nextGaussian() * 0.2;
|
||||
za = random.nextFloat() * 0.7 + 1;
|
||||
|
||||
lifeTime = 60 * 10 + random.nextInt(60);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
time++;
|
||||
if (time >= lifeTime) {
|
||||
remove();
|
||||
return;
|
||||
}
|
||||
xx += xa;
|
||||
yy += ya;
|
||||
zz += za;
|
||||
if (zz < 0) {
|
||||
zz = 0;
|
||||
za *= -0.5;
|
||||
xa *= 0.6;
|
||||
ya *= 0.6;
|
||||
}
|
||||
za -= 0.15;
|
||||
int ox = x;
|
||||
int oy = y;
|
||||
int nx = (int) xx;
|
||||
int ny = (int) yy;
|
||||
int expectedx = nx - x;
|
||||
int expectedy = ny - y;
|
||||
move(nx - x, ny - y);
|
||||
int gotx = x - ox;
|
||||
int goty = y - oy;
|
||||
xx += gotx - expectedx;
|
||||
yy += goty - expectedy;
|
||||
|
||||
if (hurtTime > 0) hurtTime--;
|
||||
}
|
||||
|
||||
public boolean isBlockableBy(Mob mob) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void render(Screen screen) {
|
||||
if (time >= lifeTime - 6 * 20) {
|
||||
if (time / 6 % 2 == 0) return;
|
||||
}
|
||||
screen.render(x - 4, y - 4, item.getSprite(), Color.get(-1, 0, 0, 0), 0);
|
||||
screen.render(x - 4, y - 4 - (int) (zz), item.getSprite(), item.getColor(), 0);
|
||||
}
|
||||
|
||||
protected void touchedBy(Entity entity) {
|
||||
if (time > 30) entity.touchItem(this);
|
||||
}
|
||||
|
||||
public void take(Player player) {
|
||||
Sound.pickup.play();
|
||||
player.score++;
|
||||
item.onTake(this);
|
||||
remove();
|
||||
}
|
||||
}
|
||||
17
src/com/mojang/ld22/entity/Lantern.java
Normal file
17
src/com/mojang/ld22/entity/Lantern.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
|
||||
public class Lantern extends Furniture {
|
||||
public Lantern() {
|
||||
super("Lantern");
|
||||
col = Color.get(-1, 000, 111, 555);
|
||||
sprite = 5;
|
||||
xr = 3;
|
||||
yr = 2;
|
||||
}
|
||||
|
||||
public int getLightRadius() {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
140
src/com/mojang/ld22/entity/Mob.java
Normal file
140
src/com/mojang/ld22/entity/Mob.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.entity.particle.TextParticle;
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.level.Level;
|
||||
import com.mojang.ld22.level.tile.Tile;
|
||||
import com.mojang.ld22.sound.Sound;
|
||||
|
||||
public class Mob extends Entity {
|
||||
protected int walkDist = 0;
|
||||
protected int dir = 0;
|
||||
public int hurtTime = 0;
|
||||
protected int xKnockback, yKnockback;
|
||||
public int maxHealth = 10;
|
||||
public int health = maxHealth;
|
||||
public int swimTimer = 0;
|
||||
public int tickTime = 0;
|
||||
|
||||
public Mob() {
|
||||
x = y = 8;
|
||||
xr = 4;
|
||||
yr = 3;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
tickTime++;
|
||||
if (level.getTile(x >> 4, y >> 4) == Tile.lava) {
|
||||
hurt(this, 4, dir ^ 1);
|
||||
}
|
||||
|
||||
if (health <= 0) {
|
||||
die();
|
||||
}
|
||||
if (hurtTime > 0) hurtTime--;
|
||||
}
|
||||
|
||||
protected void die() {
|
||||
remove();
|
||||
}
|
||||
|
||||
public boolean move(int xa, int ya) {
|
||||
if (isSwimming()) {
|
||||
if (swimTimer++ % 2 == 0) return true;
|
||||
}
|
||||
if (xKnockback < 0) {
|
||||
move2(-1, 0);
|
||||
xKnockback++;
|
||||
}
|
||||
if (xKnockback > 0) {
|
||||
move2(1, 0);
|
||||
xKnockback--;
|
||||
}
|
||||
if (yKnockback < 0) {
|
||||
move2(0, -1);
|
||||
yKnockback++;
|
||||
}
|
||||
if (yKnockback > 0) {
|
||||
move2(0, 1);
|
||||
yKnockback--;
|
||||
}
|
||||
if (hurtTime > 0) return true;
|
||||
if (xa != 0 || ya != 0) {
|
||||
walkDist++;
|
||||
if (xa < 0) dir = 2;
|
||||
if (xa > 0) dir = 3;
|
||||
if (ya < 0) dir = 1;
|
||||
if (ya > 0) dir = 0;
|
||||
}
|
||||
return super.move(xa, ya);
|
||||
}
|
||||
|
||||
protected boolean isSwimming() {
|
||||
Tile tile = level.getTile(x >> 4, y >> 4);
|
||||
return tile == Tile.water || tile == Tile.lava;
|
||||
}
|
||||
|
||||
public boolean blocks(Entity e) {
|
||||
return e.isBlockableBy(this);
|
||||
}
|
||||
|
||||
public void hurt(Tile tile, int x, int y, int damage) {
|
||||
int attackDir = dir ^ 1;
|
||||
doHurt(damage, attackDir);
|
||||
}
|
||||
|
||||
public void hurt(Mob mob, int damage, int attackDir) {
|
||||
doHurt(damage, attackDir);
|
||||
}
|
||||
|
||||
public void heal(int heal) {
|
||||
if (hurtTime > 0) return;
|
||||
|
||||
level.add(new TextParticle("" + heal, x, y, Color.get(-1, 50, 50, 50)));
|
||||
health += heal;
|
||||
if (health > maxHealth) health = maxHealth;
|
||||
}
|
||||
|
||||
protected void doHurt(int damage, int attackDir) {
|
||||
if (hurtTime > 0) return;
|
||||
|
||||
if (level.player != null) {
|
||||
int xd = level.player.x - x;
|
||||
int yd = level.player.y - y;
|
||||
if (xd * xd + yd * yd < 80 * 80) {
|
||||
Sound.monsterHurt.play();
|
||||
}
|
||||
}
|
||||
level.add(new TextParticle("" + damage, x, y, Color.get(-1, 500, 500, 500)));
|
||||
health -= damage;
|
||||
if (attackDir == 0) yKnockback = +6;
|
||||
if (attackDir == 1) yKnockback = -6;
|
||||
if (attackDir == 2) xKnockback = -6;
|
||||
if (attackDir == 3) xKnockback = +6;
|
||||
hurtTime = 10;
|
||||
}
|
||||
|
||||
public boolean findStartPos(Level level) {
|
||||
int x = random.nextInt(level.w);
|
||||
int y = random.nextInt(level.h);
|
||||
int xx = x * 16 + 8;
|
||||
int yy = y * 16 + 8;
|
||||
|
||||
if (level.player != null) {
|
||||
int xd = level.player.x - xx;
|
||||
int yd = level.player.y - yy;
|
||||
if (xd * xd + yd * yd < 80 * 80) return false;
|
||||
}
|
||||
|
||||
int r = level.monsterDensity * 16;
|
||||
if (level.getEntities(xx - r, yy - r, xx + r, yy + r).size() > 0) return false;
|
||||
|
||||
if (level.getTile(x, y).mayPass(level, x, y, this)) {
|
||||
this.x = xx;
|
||||
this.y = yy;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
20
src/com/mojang/ld22/entity/Oven.java
Normal file
20
src/com/mojang/ld22/entity/Oven.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.crafting.Crafting;
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.screen.CraftingMenu;
|
||||
|
||||
public class Oven extends Furniture {
|
||||
public Oven() {
|
||||
super("Oven");
|
||||
col = Color.get(-1, 000, 332, 442);
|
||||
sprite = 2;
|
||||
xr = 3;
|
||||
yr = 2;
|
||||
}
|
||||
|
||||
public boolean use(Player player, int attackDir) {
|
||||
player.game.setMenu(new CraftingMenu(Crafting.ovenRecipes, player));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
395
src/com/mojang/ld22/entity/Player.java
Normal file
395
src/com/mojang/ld22/entity/Player.java
Normal file
@@ -0,0 +1,395 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.ld22.Game;
|
||||
import com.mojang.ld22.InputHandler;
|
||||
import com.mojang.ld22.entity.particle.TextParticle;
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.gfx.Screen;
|
||||
import com.mojang.ld22.item.FurnitureItem;
|
||||
import com.mojang.ld22.item.Item;
|
||||
import com.mojang.ld22.item.PowerGloveItem;
|
||||
import com.mojang.ld22.item.ResourceItem;
|
||||
import com.mojang.ld22.item.ToolItem;
|
||||
import com.mojang.ld22.item.ToolType;
|
||||
import com.mojang.ld22.item.resource.Resource;
|
||||
import com.mojang.ld22.level.Level;
|
||||
import com.mojang.ld22.level.tile.Tile;
|
||||
import com.mojang.ld22.screen.InventoryMenu;
|
||||
import com.mojang.ld22.sound.Sound;
|
||||
|
||||
public class Player extends Mob {
|
||||
private InputHandler input;
|
||||
private int attackTime, attackDir;
|
||||
|
||||
public Game game;
|
||||
public Inventory inventory = new Inventory();
|
||||
public Item attackItem;
|
||||
public Item activeItem;
|
||||
public int stamina;
|
||||
public int staminaRecharge;
|
||||
public int staminaRechargeDelay;
|
||||
public int score;
|
||||
public int maxStamina = 10;
|
||||
private int onStairDelay;
|
||||
public int invulnerableTime = 0;
|
||||
|
||||
public Player(Game game, InputHandler input) {
|
||||
this.game = game;
|
||||
this.input = input;
|
||||
x = 24;
|
||||
y = 24;
|
||||
stamina = maxStamina;
|
||||
|
||||
inventory.add(new FurnitureItem(new Workbench()));
|
||||
inventory.add(new PowerGloveItem());
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (invulnerableTime > 0) invulnerableTime--;
|
||||
Tile onTile = level.getTile(x >> 4, y >> 4);
|
||||
if (onTile == Tile.stairsDown || onTile == Tile.stairsUp) {
|
||||
if (onStairDelay == 0) {
|
||||
changeLevel((onTile == Tile.stairsUp) ? 1 : -1);
|
||||
onStairDelay = 10;
|
||||
return;
|
||||
}
|
||||
onStairDelay = 10;
|
||||
} else {
|
||||
if (onStairDelay > 0) onStairDelay--;
|
||||
}
|
||||
|
||||
if (stamina <= 0 && staminaRechargeDelay == 0 && staminaRecharge == 0) {
|
||||
staminaRechargeDelay = 40;
|
||||
}
|
||||
|
||||
if (staminaRechargeDelay > 0) {
|
||||
staminaRechargeDelay--;
|
||||
}
|
||||
|
||||
if (staminaRechargeDelay == 0) {
|
||||
staminaRecharge++;
|
||||
if (isSwimming()) {
|
||||
staminaRecharge = 0;
|
||||
}
|
||||
while (staminaRecharge > 10) {
|
||||
staminaRecharge -= 10;
|
||||
if (stamina < maxStamina) stamina++;
|
||||
}
|
||||
}
|
||||
|
||||
int xa = 0;
|
||||
int ya = 0;
|
||||
if (input.up.down) ya--;
|
||||
if (input.down.down) ya++;
|
||||
if (input.left.down) xa--;
|
||||
if (input.right.down) xa++;
|
||||
if (isSwimming() && tickTime % 60 == 0) {
|
||||
if (stamina > 0) {
|
||||
stamina--;
|
||||
} else {
|
||||
hurt(this, 1, dir ^ 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (staminaRechargeDelay % 2 == 0) {
|
||||
move(xa, ya);
|
||||
}
|
||||
|
||||
if (input.attack.clicked) {
|
||||
if (stamina == 0) {
|
||||
|
||||
} else {
|
||||
stamina--;
|
||||
staminaRecharge = 0;
|
||||
attack();
|
||||
}
|
||||
}
|
||||
if (input.menu.clicked) {
|
||||
if (!use()) {
|
||||
game.setMenu(new InventoryMenu(this));
|
||||
}
|
||||
}
|
||||
if (attackTime > 0) attackTime--;
|
||||
|
||||
}
|
||||
|
||||
private boolean use() {
|
||||
int yo = -2;
|
||||
if (dir == 0 && use(x - 8, y + 4 + yo, x + 8, y + 12 + yo)) return true;
|
||||
if (dir == 1 && use(x - 8, y - 12 + yo, x + 8, y - 4 + yo)) return true;
|
||||
if (dir == 3 && use(x + 4, y - 8 + yo, x + 12, y + 8 + yo)) return true;
|
||||
if (dir == 2 && use(x - 12, y - 8 + yo, x - 4, y + 8 + yo)) return true;
|
||||
|
||||
int xt = x >> 4;
|
||||
int yt = (y + yo) >> 4;
|
||||
int r = 12;
|
||||
if (attackDir == 0) yt = (y + r + yo) >> 4;
|
||||
if (attackDir == 1) yt = (y - r + yo) >> 4;
|
||||
if (attackDir == 2) xt = (x - r) >> 4;
|
||||
if (attackDir == 3) xt = (x + r) >> 4;
|
||||
|
||||
if (xt >= 0 && yt >= 0 && xt < level.w && yt < level.h) {
|
||||
if (level.getTile(xt, yt).use(level, xt, yt, this, attackDir)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void attack() {
|
||||
walkDist += 8;
|
||||
attackDir = dir;
|
||||
attackItem = activeItem;
|
||||
boolean done = false;
|
||||
|
||||
if (activeItem != null) {
|
||||
attackTime = 10;
|
||||
int yo = -2;
|
||||
int range = 12;
|
||||
if (dir == 0 && interact(x - 8, y + 4 + yo, x + 8, y + range + yo)) done = true;
|
||||
if (dir == 1 && interact(x - 8, y - range + yo, x + 8, y - 4 + yo)) done = true;
|
||||
if (dir == 3 && interact(x + 4, y - 8 + yo, x + range, y + 8 + yo)) done = true;
|
||||
if (dir == 2 && interact(x - range, y - 8 + yo, x - 4, y + 8 + yo)) done = true;
|
||||
if (done) return;
|
||||
|
||||
int xt = x >> 4;
|
||||
int yt = (y + yo) >> 4;
|
||||
int r = 12;
|
||||
if (attackDir == 0) yt = (y + r + yo) >> 4;
|
||||
if (attackDir == 1) yt = (y - r + yo) >> 4;
|
||||
if (attackDir == 2) xt = (x - r) >> 4;
|
||||
if (attackDir == 3) xt = (x + r) >> 4;
|
||||
|
||||
if (xt >= 0 && yt >= 0 && xt < level.w && yt < level.h) {
|
||||
if (activeItem.interactOn(level.getTile(xt, yt), level, xt, yt, this, attackDir)) {
|
||||
done = true;
|
||||
} else {
|
||||
if (level.getTile(xt, yt).interact(level, xt, yt, this, activeItem, attackDir)) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
if (activeItem.isDepleted()) {
|
||||
activeItem = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (done) return;
|
||||
|
||||
if (activeItem == null || activeItem.canAttack()) {
|
||||
attackTime = 5;
|
||||
int yo = -2;
|
||||
int range = 20;
|
||||
if (dir == 0) hurt(x - 8, y + 4 + yo, x + 8, y + range + yo);
|
||||
if (dir == 1) hurt(x - 8, y - range + yo, x + 8, y - 4 + yo);
|
||||
if (dir == 3) hurt(x + 4, y - 8 + yo, x + range, y + 8 + yo);
|
||||
if (dir == 2) hurt(x - range, y - 8 + yo, x - 4, y + 8 + yo);
|
||||
|
||||
int xt = x >> 4;
|
||||
int yt = (y + yo) >> 4;
|
||||
int r = 12;
|
||||
if (attackDir == 0) yt = (y + r + yo) >> 4;
|
||||
if (attackDir == 1) yt = (y - r + yo) >> 4;
|
||||
if (attackDir == 2) xt = (x - r) >> 4;
|
||||
if (attackDir == 3) xt = (x + r) >> 4;
|
||||
|
||||
if (xt >= 0 && yt >= 0 && xt < level.w && yt < level.h) {
|
||||
level.getTile(xt, yt).hurt(level, xt, yt, this, random.nextInt(3) + 1, attackDir);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean use(int x0, int y0, int x1, int y1) {
|
||||
List<Entity> entities = level.getEntities(x0, y0, x1, y1);
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
Entity e = entities.get(i);
|
||||
if (e != this) if (e.use(this, attackDir)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean interact(int x0, int y0, int x1, int y1) {
|
||||
List<Entity> entities = level.getEntities(x0, y0, x1, y1);
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
Entity e = entities.get(i);
|
||||
if (e != this) if (e.interact(this, activeItem, attackDir)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void hurt(int x0, int y0, int x1, int y1) {
|
||||
List<Entity> entities = level.getEntities(x0, y0, x1, y1);
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
Entity e = entities.get(i);
|
||||
if (e != this) e.hurt(this, getAttackDamage(e), attackDir);
|
||||
}
|
||||
}
|
||||
|
||||
private int getAttackDamage(Entity e) {
|
||||
int dmg = random.nextInt(3) + 1;
|
||||
if (attackItem != null) {
|
||||
dmg += attackItem.getAttackDamageBonus(e);
|
||||
}
|
||||
return dmg;
|
||||
}
|
||||
|
||||
public void render(Screen screen) {
|
||||
int xt = 0;
|
||||
int yt = 14;
|
||||
|
||||
int flip1 = (walkDist >> 3) & 1;
|
||||
int flip2 = (walkDist >> 3) & 1;
|
||||
|
||||
if (dir == 1) {
|
||||
xt += 2;
|
||||
}
|
||||
if (dir > 1) {
|
||||
flip1 = 0;
|
||||
flip2 = ((walkDist >> 4) & 1);
|
||||
if (dir == 2) {
|
||||
flip1 = 1;
|
||||
}
|
||||
xt += 4 + ((walkDist >> 3) & 1) * 2;
|
||||
}
|
||||
|
||||
int xo = x - 8;
|
||||
int yo = y - 11;
|
||||
if (isSwimming()) {
|
||||
yo += 4;
|
||||
int waterColor = Color.get(-1, -1, 115, 335);
|
||||
if (tickTime / 8 % 2 == 0) {
|
||||
waterColor = Color.get(-1, 335, 5, 115);
|
||||
}
|
||||
screen.render(xo + 0, yo + 3, 5 + 13 * 32, waterColor, 0);
|
||||
screen.render(xo + 8, yo + 3, 5 + 13 * 32, waterColor, 1);
|
||||
}
|
||||
|
||||
if (attackTime > 0 && attackDir == 1) {
|
||||
screen.render(xo + 0, yo - 4, 6 + 13 * 32, Color.get(-1, 555, 555, 555), 0);
|
||||
screen.render(xo + 8, yo - 4, 6 + 13 * 32, Color.get(-1, 555, 555, 555), 1);
|
||||
if (attackItem != null) {
|
||||
attackItem.renderIcon(screen, xo + 4, yo - 4);
|
||||
}
|
||||
}
|
||||
int col = Color.get(-1, 100, 220, 532);
|
||||
if (hurtTime > 0) {
|
||||
col = Color.get(-1, 555, 555, 555);
|
||||
}
|
||||
|
||||
if (activeItem instanceof FurnitureItem) {
|
||||
yt += 2;
|
||||
}
|
||||
screen.render(xo + 8 * flip1, yo + 0, xt + yt * 32, col, flip1);
|
||||
screen.render(xo + 8 - 8 * flip1, yo + 0, xt + 1 + yt * 32, col, flip1);
|
||||
if (!isSwimming()) {
|
||||
screen.render(xo + 8 * flip2, yo + 8, xt + (yt + 1) * 32, col, flip2);
|
||||
screen.render(xo + 8 - 8 * flip2, yo + 8, xt + 1 + (yt + 1) * 32, col, flip2);
|
||||
}
|
||||
|
||||
if (attackTime > 0 && attackDir == 2) {
|
||||
screen.render(xo - 4, yo, 7 + 13 * 32, Color.get(-1, 555, 555, 555), 1);
|
||||
screen.render(xo - 4, yo + 8, 7 + 13 * 32, Color.get(-1, 555, 555, 555), 3);
|
||||
if (attackItem != null) {
|
||||
attackItem.renderIcon(screen, xo - 4, yo + 4);
|
||||
}
|
||||
}
|
||||
if (attackTime > 0 && attackDir == 3) {
|
||||
screen.render(xo + 8 + 4, yo, 7 + 13 * 32, Color.get(-1, 555, 555, 555), 0);
|
||||
screen.render(xo + 8 + 4, yo + 8, 7 + 13 * 32, Color.get(-1, 555, 555, 555), 2);
|
||||
if (attackItem != null) {
|
||||
attackItem.renderIcon(screen, xo + 8 + 4, yo + 4);
|
||||
}
|
||||
}
|
||||
if (attackTime > 0 && attackDir == 0) {
|
||||
screen.render(xo + 0, yo + 8 + 4, 6 + 13 * 32, Color.get(-1, 555, 555, 555), 2);
|
||||
screen.render(xo + 8, yo + 8 + 4, 6 + 13 * 32, Color.get(-1, 555, 555, 555), 3);
|
||||
if (attackItem != null) {
|
||||
attackItem.renderIcon(screen, xo + 4, yo + 8 + 4);
|
||||
}
|
||||
}
|
||||
|
||||
if (activeItem instanceof FurnitureItem) {
|
||||
Furniture furniture = ((FurnitureItem) activeItem).furniture;
|
||||
furniture.x = x;
|
||||
furniture.y = yo;
|
||||
furniture.render(screen);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void touchItem(ItemEntity itemEntity) {
|
||||
itemEntity.take(this);
|
||||
inventory.add(itemEntity.item);
|
||||
}
|
||||
|
||||
public boolean canSwim() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean findStartPos(Level level) {
|
||||
while (true) {
|
||||
int x = random.nextInt(level.w);
|
||||
int y = random.nextInt(level.h);
|
||||
if (level.getTile(x, y) == Tile.grass) {
|
||||
this.x = x * 16 + 8;
|
||||
this.y = y * 16 + 8;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean payStamina(int cost) {
|
||||
if (cost > stamina) return false;
|
||||
stamina -= cost;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void changeLevel(int dir) {
|
||||
game.scheduleLevelChange(dir);
|
||||
}
|
||||
|
||||
public int getLightRadius() {
|
||||
int r = 2;
|
||||
if (activeItem != null) {
|
||||
if (activeItem instanceof FurnitureItem) {
|
||||
int rr = ((FurnitureItem) activeItem).furniture.getLightRadius();
|
||||
if (rr > r) r = rr;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
protected void die() {
|
||||
super.die();
|
||||
Sound.playerDeath.play();
|
||||
}
|
||||
|
||||
protected void touchedBy(Entity entity) {
|
||||
if (!(entity instanceof Player)) {
|
||||
entity.touchedBy(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doHurt(int damage, int attackDir) {
|
||||
if (hurtTime > 0 || invulnerableTime > 0) return;
|
||||
|
||||
Sound.playerHurt.play();
|
||||
level.add(new TextParticle("" + damage, x, y, Color.get(-1, 504, 504, 504)));
|
||||
health -= damage;
|
||||
if (attackDir == 0) yKnockback = +6;
|
||||
if (attackDir == 1) yKnockback = -6;
|
||||
if (attackDir == 2) xKnockback = -6;
|
||||
if (attackDir == 3) xKnockback = +6;
|
||||
hurtTime = 10;
|
||||
invulnerableTime = 30;
|
||||
}
|
||||
|
||||
public void gameWon() {
|
||||
level.player.invulnerableTime = 60 * 5;
|
||||
game.won();
|
||||
}
|
||||
}
|
||||
97
src/com/mojang/ld22/entity/Slime.java
Normal file
97
src/com/mojang/ld22/entity/Slime.java
Normal file
@@ -0,0 +1,97 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.gfx.Screen;
|
||||
import com.mojang.ld22.item.ResourceItem;
|
||||
import com.mojang.ld22.item.resource.Resource;
|
||||
|
||||
public class Slime extends Mob {
|
||||
private int xa, ya;
|
||||
private int jumpTime = 0;
|
||||
private int lvl;
|
||||
|
||||
public Slime(int lvl) {
|
||||
this.lvl = lvl;
|
||||
x = random.nextInt(64 * 16);
|
||||
y = random.nextInt(64 * 16);
|
||||
health = maxHealth = lvl * lvl * 5;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
int speed = 1;
|
||||
if (!move(xa * speed, ya * speed) || random.nextInt(40) == 0) {
|
||||
if (jumpTime <= -10) {
|
||||
xa = (random.nextInt(3) - 1);
|
||||
ya = (random.nextInt(3) - 1);
|
||||
|
||||
if (level.player != null) {
|
||||
int xd = level.player.x - x;
|
||||
int yd = level.player.y - y;
|
||||
if (xd * xd + yd * yd < 50 * 50) {
|
||||
if (xd < 0) xa = -1;
|
||||
if (xd > 0) xa = +1;
|
||||
if (yd < 0) ya = -1;
|
||||
if (yd > 0) ya = +1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (xa != 0 || ya != 0) jumpTime = 10;
|
||||
}
|
||||
}
|
||||
|
||||
jumpTime--;
|
||||
if (jumpTime == 0) {
|
||||
xa = ya = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected void die() {
|
||||
super.die();
|
||||
|
||||
int count = random.nextInt(2) + 1;
|
||||
for (int i = 0; i < count; i++) {
|
||||
level.add(new ItemEntity(new ResourceItem(Resource.slime), x + random.nextInt(11) - 5, y + random.nextInt(11) - 5));
|
||||
}
|
||||
|
||||
if (level.player != null) {
|
||||
level.player.score += 25*lvl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void render(Screen screen) {
|
||||
int xt = 0;
|
||||
int yt = 18;
|
||||
|
||||
int xo = x - 8;
|
||||
int yo = y - 11;
|
||||
|
||||
if (jumpTime > 0) {
|
||||
xt += 2;
|
||||
yo -= 4;
|
||||
}
|
||||
|
||||
int col = Color.get(-1, 10, 252, 555);
|
||||
if (lvl == 2) col = Color.get(-1, 100, 522, 555);
|
||||
if (lvl == 3) col = Color.get(-1, 111, 444, 555);
|
||||
if (lvl == 4) col = Color.get(-1, 000, 111, 224);
|
||||
|
||||
if (hurtTime > 0) {
|
||||
col = Color.get(-1, 555, 555, 555);
|
||||
}
|
||||
|
||||
screen.render(xo + 0, yo + 0, xt + yt * 32, col, 0);
|
||||
screen.render(xo + 8, yo + 0, xt + 1 + yt * 32, col, 0);
|
||||
screen.render(xo + 0, yo + 8, xt + (yt + 1) * 32, col, 0);
|
||||
screen.render(xo + 8, yo + 8, xt + 1 + (yt + 1) * 32, col, 0);
|
||||
}
|
||||
|
||||
protected void touchedBy(Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
entity.hurt(this, lvl, dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
62
src/com/mojang/ld22/entity/Spark.java
Normal file
62
src/com/mojang/ld22/entity/Spark.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.gfx.Screen;
|
||||
|
||||
public class Spark extends Entity {
|
||||
private int lifeTime;
|
||||
public double xa, ya;
|
||||
public double xx, yy;
|
||||
private int time;
|
||||
private AirWizard owner;
|
||||
|
||||
public Spark(AirWizard owner, double xa, double ya) {
|
||||
this.owner = owner;
|
||||
xx = this.x = owner.x;
|
||||
yy = this.y = owner.y;
|
||||
xr = 0;
|
||||
yr = 0;
|
||||
|
||||
this.xa = xa;
|
||||
this.ya = ya;
|
||||
|
||||
lifeTime = 60 * 10 + random.nextInt(30);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
time++;
|
||||
if (time >= lifeTime) {
|
||||
remove();
|
||||
return;
|
||||
}
|
||||
xx += xa;
|
||||
yy += ya;
|
||||
x = (int) xx;
|
||||
y = (int) yy;
|
||||
List<Entity> toHit = level.getEntities(x, y, x, y);
|
||||
for (int i = 0; i < toHit.size(); i++) {
|
||||
Entity e = toHit.get(i);
|
||||
if (e instanceof Mob && !(e instanceof AirWizard)) {
|
||||
e.hurt(owner, 1, ((Mob) e).dir ^ 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBlockableBy(Mob mob) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void render(Screen screen) {
|
||||
if (time >= lifeTime - 6 * 20) {
|
||||
if (time / 6 % 2 == 0) return;
|
||||
}
|
||||
|
||||
int xt = 8;
|
||||
int yt = 13;
|
||||
|
||||
screen.render(x - 4, y - 4 - 2, xt + yt * 32, Color.get(-1, 555, 555, 555), random.nextInt(4));
|
||||
screen.render(x - 4, y - 4 + 2, xt + yt * 32, Color.get(-1, 000, 000, 000), random.nextInt(4));
|
||||
}
|
||||
}
|
||||
20
src/com/mojang/ld22/entity/Workbench.java
Normal file
20
src/com/mojang/ld22/entity/Workbench.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.crafting.Crafting;
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.screen.CraftingMenu;
|
||||
|
||||
public class Workbench extends Furniture {
|
||||
public Workbench() {
|
||||
super("Workbench");
|
||||
col = Color.get(-1, 100, 321, 431);
|
||||
sprite = 4;
|
||||
xr = 3;
|
||||
yr = 2;
|
||||
}
|
||||
|
||||
public boolean use(Player player, int attackDir) {
|
||||
player.game.setMenu(new CraftingMenu(Crafting.workbenchRecipes, player));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
103
src/com/mojang/ld22/entity/Zombie.java
Normal file
103
src/com/mojang/ld22/entity/Zombie.java
Normal file
@@ -0,0 +1,103 @@
|
||||
package com.mojang.ld22.entity;
|
||||
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.gfx.Screen;
|
||||
import com.mojang.ld22.item.ResourceItem;
|
||||
import com.mojang.ld22.item.resource.Resource;
|
||||
|
||||
public class Zombie extends Mob {
|
||||
private int xa, ya;
|
||||
private int lvl;
|
||||
private int randomWalkTime = 0;
|
||||
|
||||
public Zombie(int lvl) {
|
||||
this.lvl = lvl;
|
||||
x = random.nextInt(64 * 16);
|
||||
y = random.nextInt(64 * 16);
|
||||
health = maxHealth = lvl * lvl * 10;
|
||||
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if (level.player != null && randomWalkTime == 0) {
|
||||
int xd = level.player.x - x;
|
||||
int yd = level.player.y - y;
|
||||
if (xd * xd + yd * yd < 50 * 50) {
|
||||
xa = 0;
|
||||
ya = 0;
|
||||
if (xd < 0) xa = -1;
|
||||
if (xd > 0) xa = +1;
|
||||
if (yd < 0) ya = -1;
|
||||
if (yd > 0) ya = +1;
|
||||
}
|
||||
}
|
||||
|
||||
int speed = tickTime & 1;
|
||||
if (!move(xa * speed, ya * speed) || random.nextInt(200) == 0) {
|
||||
randomWalkTime = 60;
|
||||
xa = (random.nextInt(3) - 1) * random.nextInt(2);
|
||||
ya = (random.nextInt(3) - 1) * random.nextInt(2);
|
||||
}
|
||||
if (randomWalkTime > 0) randomWalkTime--;
|
||||
}
|
||||
|
||||
public void render(Screen screen) {
|
||||
int xt = 0;
|
||||
int yt = 14;
|
||||
|
||||
int flip1 = (walkDist >> 3) & 1;
|
||||
int flip2 = (walkDist >> 3) & 1;
|
||||
|
||||
if (dir == 1) {
|
||||
xt += 2;
|
||||
}
|
||||
if (dir > 1) {
|
||||
|
||||
flip1 = 0;
|
||||
flip2 = ((walkDist >> 4) & 1);
|
||||
if (dir == 2) {
|
||||
flip1 = 1;
|
||||
}
|
||||
xt += 4 + ((walkDist >> 3) & 1) * 2;
|
||||
}
|
||||
|
||||
int xo = x - 8;
|
||||
int yo = y - 11;
|
||||
|
||||
int col = Color.get(-1, 10, 252, 050);
|
||||
if (lvl == 2) col = Color.get(-1, 100, 522, 050);
|
||||
if (lvl == 3) col = Color.get(-1, 111, 444, 050);
|
||||
if (lvl == 4) col = Color.get(-1, 000, 111, 020);
|
||||
if (hurtTime > 0) {
|
||||
col = Color.get(-1, 555, 555, 555);
|
||||
}
|
||||
|
||||
screen.render(xo + 8 * flip1, yo + 0, xt + yt * 32, col, flip1);
|
||||
screen.render(xo + 8 - 8 * flip1, yo + 0, xt + 1 + yt * 32, col, flip1);
|
||||
screen.render(xo + 8 * flip2, yo + 8, xt + (yt + 1) * 32, col, flip2);
|
||||
screen.render(xo + 8 - 8 * flip2, yo + 8, xt + 1 + (yt + 1) * 32, col, flip2);
|
||||
}
|
||||
|
||||
protected void touchedBy(Entity entity) {
|
||||
if (entity instanceof Player) {
|
||||
entity.hurt(this, lvl + 1, dir);
|
||||
}
|
||||
}
|
||||
|
||||
protected void die() {
|
||||
super.die();
|
||||
|
||||
int count = random.nextInt(2) + 1;
|
||||
for (int i = 0; i < count; i++) {
|
||||
level.add(new ItemEntity(new ResourceItem(Resource.cloth), x + random.nextInt(11) - 5, y + random.nextInt(11) - 5));
|
||||
}
|
||||
|
||||
if (level.player != null) {
|
||||
level.player.score += 50 * lvl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
11
src/com/mojang/ld22/entity/particle/Particle.java
Normal file
11
src/com/mojang/ld22/entity/particle/Particle.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.mojang.ld22.entity.particle;
|
||||
|
||||
import com.mojang.ld22.entity.Entity;
|
||||
|
||||
public class Particle extends Entity {
|
||||
public Particle() {
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
}
|
||||
}
|
||||
31
src/com/mojang/ld22/entity/particle/SmashParticle.java
Normal file
31
src/com/mojang/ld22/entity/particle/SmashParticle.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.mojang.ld22.entity.particle;
|
||||
|
||||
import com.mojang.ld22.entity.Entity;
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.gfx.Screen;
|
||||
import com.mojang.ld22.sound.Sound;
|
||||
|
||||
public class SmashParticle extends Entity {
|
||||
private int time = 0;
|
||||
|
||||
public SmashParticle(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
Sound.monsterHurt.play();
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
time++;
|
||||
if (time > 10) {
|
||||
remove();
|
||||
}
|
||||
}
|
||||
|
||||
public void render(Screen screen) {
|
||||
int col = Color.get(-1, 555, 555, 555);
|
||||
screen.render(x - 8, y - 8, 5 + 12 * 32, col, 2);
|
||||
screen.render(x - 0, y - 8, 5 + 12 * 32, col, 3);
|
||||
screen.render(x - 8, y - 0, 5 + 12 * 32, col, 0);
|
||||
screen.render(x - 0, y - 0, 5 + 12 * 32, col, 1);
|
||||
}
|
||||
}
|
||||
53
src/com/mojang/ld22/entity/particle/TextParticle.java
Normal file
53
src/com/mojang/ld22/entity/particle/TextParticle.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.mojang.ld22.entity.particle;
|
||||
|
||||
import com.mojang.ld22.entity.Entity;
|
||||
import com.mojang.ld22.gfx.Color;
|
||||
import com.mojang.ld22.gfx.Font;
|
||||
import com.mojang.ld22.gfx.Screen;
|
||||
|
||||
public class TextParticle extends Entity {
|
||||
private String msg;
|
||||
private int col;
|
||||
private int time = 0;
|
||||
public double xa, ya, za;
|
||||
public double xx, yy, zz;
|
||||
|
||||
public TextParticle(String msg, int x, int y, int col) {
|
||||
this.msg = msg;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.col = col;
|
||||
xx = x;
|
||||
yy = y;
|
||||
zz = 2;
|
||||
xa = random.nextGaussian() * 0.3;
|
||||
ya = random.nextGaussian() * 0.2;
|
||||
za = random.nextFloat() * 0.7 + 2;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
time++;
|
||||
if (time > 60) {
|
||||
remove();
|
||||
}
|
||||
xx += xa;
|
||||
yy += ya;
|
||||
zz += za;
|
||||
if (zz < 0) {
|
||||
zz = 0;
|
||||
za *= -0.5;
|
||||
xa *= 0.6;
|
||||
ya *= 0.6;
|
||||
}
|
||||
za -= 0.15;
|
||||
x = (int) xx;
|
||||
y = (int) yy;
|
||||
}
|
||||
|
||||
public void render(Screen screen) {
|
||||
// Font.draw(msg, screen, x - msg.length() * 4, y, Color.get(-1, 0, 0, 0));
|
||||
Font.draw(msg, screen, x - msg.length() * 4 + 1, y - (int) (zz) + 1, Color.get(-1, 0, 0, 0));
|
||||
Font.draw(msg, screen, x - msg.length() * 4, y - (int) (zz), col);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user