Skip to content

Commit

Permalink
Merged difficulty update by fenwulf (Maescool#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Borsty authored and zorro300 committed Feb 22, 2012
1 parent 5266315 commit 3bfa547
Show file tree
Hide file tree
Showing 20 changed files with 129 additions and 76 deletions.
20 changes: 12 additions & 8 deletions src/com/mojang/mojam/entity/Bullet.java
Expand Up @@ -10,8 +10,9 @@ public class Bullet extends Entity {
boolean hit = false;
public int life;
private int facing;
private float damage;

public Bullet(Mob e, double xa, double ya) {
public Bullet(Mob e, double xa, double ya, float damage) {
this.owner = e;
pos.set(e.pos.x + xa * 4, e.pos.y + ya * 4);
this.xa = xa * 6;
Expand All @@ -21,8 +22,10 @@ public Bullet(Mob e, double xa, double ya) {
life = 40;
double angle = (Math.atan2(ya, xa) + Math.PI * 1.625);
facing = (8 + (int) (angle / Math.PI * 4)) & 7;
this.damage = damage;
}

@Override
public void tick() {
if (--life <= 0) {
remove();
Expand All @@ -36,33 +39,34 @@ public void tick() {
}
}

@Override
protected boolean shouldBlock(Entity e) {
if (e instanceof Bullet)
return false;
if ((e instanceof Mob) && !(e instanceof RailDroid)
&& !((Mob) e).isNotFriendOf(owner))
if ((e instanceof Mob) && !(e instanceof RailDroid) && !((Mob) e).isNotFriendOf(owner))
return false;
return e != owner;
}

@Override
public void render(Screen screen) {
screen.blit(Art.bullet[facing][0], pos.x - 8, pos.y - 10);
}

@Override
public void collide(Entity entity, double xa, double ya) {
if (entity instanceof Mob) {
if (((Mob) entity).isNotFriendOf(owner)
|| (entity instanceof RailDroid)) {
entity.hurt(this);
Mob mobEnt = (Mob) entity;
if (mobEnt.isNotFriendOf(owner) || (entity instanceof RailDroid)) {
mobEnt.hurt(this,damage);
hit = true;
}
} else {
entity.hurt(this);
hit = true;
}
if (hit) {
MojamComponent.soundPlayer.playSound("/sound/Shot 2.wav",
(float) pos.x, (float) pos.y);
MojamComponent.soundPlayer.playSound("/sound/Shot 2.wav", (float) pos.x, (float) pos.y);
}
}
}
10 changes: 4 additions & 6 deletions src/com/mojang/mojam/entity/Entity.java
Expand Up @@ -51,13 +51,11 @@ public boolean intersects(double xx0, double yy0, double xx1, double yy1) {
}

public BB getBB() {
return new BB(this, pos.x - radius.x, pos.y - radius.y, pos.x
+ radius.x, pos.y + radius.y);
return new BB(this, pos.x - radius.x, pos.y - radius.y, pos.x + radius.x, pos.y + radius.y);
}

public void render(Screen screen) {
screen.blit(Art.floorTiles[3][0], pos.x - Tile.WIDTH / 2, pos.y
- Tile.HEIGHT / 2 - 8);
screen.blit(Art.floorTiles[3][0], pos.x - Tile.WIDTH / 2, pos.y - Tile.HEIGHT / 2 - 8);
}

protected boolean move(double xa, double ya) {
Expand Down Expand Up @@ -147,8 +145,7 @@ private boolean partMove(List<BB> bbs, double xa, double ya) {
}

public final boolean blocks(Entity e) {
return isBlocking && e.isBlocking && shouldBlock(e)
&& e.shouldBlock(this);
return isBlocking && e.isBlocking && shouldBlock(e) && e.shouldBlock(this);
}

protected boolean shouldBlock(Entity e) {
Expand All @@ -159,6 +156,7 @@ public void remove() {
removed = true;
}

@Override
public void handleCollision(Entity entity, double xa, double ya) {
if (this.blocks(entity)) {
this.collide(entity, xa, ya);
Expand Down
19 changes: 16 additions & 3 deletions src/com/mojang/mojam/entity/Player.java
Expand Up @@ -111,6 +111,7 @@ private void levelUp() {
MojamComponent.soundPlayer.playSound("/sound/levelUp.wav", (float) pos.x, (float) pos.y, true);
}

@Override
public void tick() {
calculLevel();

Expand Down Expand Up @@ -144,8 +145,10 @@ public void tick() {
}
if (keys.up.isDown || keys.down.isDown || keys.left.isDown || keys.right.isDown) {
int stepCount = 25;
if (carrying == null) stepCount = 15;
if (isSprint) stepCount *= 0.6;
if (carrying == null)
stepCount = 15;
if (isSprint)
stepCount *= 0.6;
if (steps % stepCount == 0) {
MojamComponent.soundPlayer.playSound("/sound/Step " + (TurnSynchronizer.synchedRandom.nextInt(2) + 1) + ".wav", (float) pos.x, (float) pos.y, true);
}
Expand Down Expand Up @@ -384,6 +387,7 @@ public void dropAllMoney() {
score = 0;
}

@Override
public void render(Screen screen) {
Bitmap[][] sheet = Art.lordLard;
if (team == Team.Team2) {
Expand Down Expand Up @@ -417,34 +421,41 @@ public void render(Screen screen) {
renderCarrying(screen, (frame == 0 || frame == 3) ? -1 : 0);
}

@Override
public void collide(Entity entity, double xa, double ya) {
xd += xa * 0.4;
yd += ya * 0.4;
}

@Override
public void take(Loot loot) {
loot.remove();
level.addEntity(new Sparkle(pos.x, pos.y, -1, 0));
level.addEntity(new Sparkle(pos.x, pos.y, +1, 0));
score += loot.getScoreValue();
}

@Override
public double getSuckPower() {
return suckRadius / 60.0;
}

@Override
public boolean canTake() {
return takeDelay > 0;
}

@Override
public void flash() {
flashTime = 20;
}

@Override
public int getScore() {
return score;
}

@Override
public Bitmap getSprite() {
return null;
}
Expand Down Expand Up @@ -485,11 +496,12 @@ public void setCanSee(boolean b) {
this.isSeeing = b;
}

@Override
public void notifySucking() {
}

@Override
public void hurt(Entity source, int damage) {
public void hurt(Entity source, float damage) {
if (isImmortal) {
return;
}
Expand Down Expand Up @@ -522,6 +534,7 @@ public void hurt(Bullet bullet) {
hurt(bullet, 1);
}

@Override
public String getDeatchSound() {
return "/sound/Death.wav";
}
Expand Down
5 changes: 1 addition & 4 deletions src/com/mojang/mojam/entity/building/Bomb.java
Expand Up @@ -62,10 +62,7 @@ public Bitmap getSprite() {
}

@Override
public void hurt(Entity source, int damage) {
public void hurt(Entity source, float damage) {
super.hurt(source, damage);
// if (health <= 0) {
// freezeTime = 30;
// }
}
}
2 changes: 1 addition & 1 deletion src/com/mojang/mojam/entity/building/Building.java
Expand Up @@ -74,7 +74,7 @@ public void hurt(Bullet bullet) {
}

@Override
public void hurt(Entity source, int damage) {
public void hurt(Entity source, float damage) {
super.hurt(source, damage);
healingTime = HEALING_INTERVAL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/mojang/mojam/entity/building/Harvester.java
Expand Up @@ -121,7 +121,7 @@ public void render(Screen screen) {
if (health < 0) {
health = 0;
}
int col = 180 - health * 180 / maxHealth;
int col = (int) (180 - health * 180 / maxHealth);
if (hurtTime < 10) {
col = col * hurtTime / 10;
}
Expand Down
11 changes: 7 additions & 4 deletions src/com/mojang/mojam/entity/building/ShopItem.java
Expand Up @@ -5,6 +5,7 @@
import com.mojang.mojam.entity.mob.Team;
import com.mojang.mojam.gui.Font;
import com.mojang.mojam.gui.Notifications;
import com.mojang.mojam.level.DifficultyInformation;
import com.mojang.mojam.screen.*;

public class ShopItem extends Building {
Expand All @@ -18,6 +19,7 @@ public class ShopItem extends Building {
public static final int[] COST = { 150, 300, 500 };

private final int type;
private int effectiveCost;

public ShopItem(double x, double y, int type, int team) {
super(x, y, team);
Expand All @@ -32,10 +34,11 @@ public ShopItem(double x, double y, int type, int team) {
public void render(Screen screen) {
super.render(screen);
// Bitmap image = getSprite();
Font.drawCentered(screen, MojamComponent.texts.cost(COST[type]), (int) (pos.x), (int) (pos.y + 10));
Font.drawCentered(screen, MojamComponent.texts.cost(effectiveCost), (int) (pos.x), (int) (pos.y + 10));
}

public void init() {
effectiveCost = DifficultyInformation.calculateCosts(COST[type]);
}

public void tick() {
Expand All @@ -58,8 +61,8 @@ public Bitmap getSprite() {
public void use(Entity user) {
if (user instanceof Player && ((Player) user).getTeam() == team) {
Player player = (Player) user;
if (player.carrying == null && player.getScore() >= COST[type]) {
player.payCost(COST[type]);
if (player.carrying == null && player.getScore() >= effectiveCost) {
player.payCost(effectiveCost);
Building item = null;
switch (type) {
case SHOP_TURRET:
Expand All @@ -74,7 +77,7 @@ public void use(Entity user) {
}
level.addEntity(item);
player.pickup(item);
} else if ( player.getScore() < COST[type] ){
} else if ( player.getScore() < effectiveCost ){
Notifications.getInstance().add("You dont have enough money");
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/com/mojang/mojam/entity/building/SpawnerEntity.java
Expand Up @@ -2,6 +2,7 @@

import com.mojang.mojam.entity.mob.*;
import com.mojang.mojam.network.TurnSynchronizer;
import com.mojang.mojam.level.DifficultyInformation;
import com.mojang.mojam.level.tile.Tile;
import com.mojang.mojam.screen.*;

Expand Down Expand Up @@ -31,7 +32,7 @@ public void tick() {

if (--spawnTime <= 0) {
spawn();
spawnTime = SPAWN_INTERVAL;
spawnTime = DifficultyInformation.calculateSpawntime(SPAWN_INTERVAL);
}
}

Expand Down Expand Up @@ -62,7 +63,7 @@ public void die() {
private int lastIndex = 0;

public Bitmap getSprite() {
int newIndex = 3 - (3 * health) / maxHealth;
int newIndex = (int)(3 - (3 * health) / maxHealth);
if (newIndex != lastIndex) {
// if (newIndex > lastIndex) // means more hurt
// level.addEntity(new SmokeAnimation(pos.x - 12, pos.y - 20,
Expand Down
16 changes: 10 additions & 6 deletions src/com/mojang/mojam/entity/building/Turret.java
Expand Up @@ -4,11 +4,14 @@

import com.mojang.mojam.entity.*;
import com.mojang.mojam.entity.mob.*;
import com.mojang.mojam.level.DifficultyInformation;
import com.mojang.mojam.level.tile.Tile;
import com.mojang.mojam.screen.*;

public class Turret extends Building {


private static final float BULLET_DAMAGE = .75f;

private int delayTicks = 0;
private int delay;
private double radius;
Expand All @@ -23,11 +26,12 @@ public Turret(double x, double y, int team) {
super(x, y, team);
setStartHealth(10);
freezeTime = 10;

makeUpgradeableWithCosts(new int[] { 500, 1000, 5000 });
}

public void init() {
makeUpgradeableWithCosts(new int[] { DifficultyInformation.calculateCosts(500),
DifficultyInformation.calculateCosts(1000),
DifficultyInformation.calculateCosts(5000)});
}

public void tick() {
Expand Down Expand Up @@ -60,12 +64,12 @@ public void tick() {
double xd = closest.pos.x - pos.x;
double angle = (Math.atan2(yd, xd) + Math.PI * 1.625);
facing = (8 + (int) (angle / Math.PI * 4)) & 7;
Bullet bullet = new Bullet(this, xd * invDist, yd * invDist);
Bullet bullet = new Bullet(this, xd * invDist, yd * invDist, BULLET_DAMAGE * ((upgradeLevel + 1) / 2.f));
bullet.pos.y -= 10;
level.addEntity(bullet);

if (upgradeLevel > 0) {
Bullet second_bullet = new Bullet(this, xd * invDist, yd * invDist);
Bullet second_bullet = new Bullet(this, xd * invDist, yd * invDist, BULLET_DAMAGE * ((upgradeLevel + 1) / 2.f));
level.addEntity(second_bullet);
if (facing == 0 || facing == 4) {
bullet.pos.x -= 5;
Expand All @@ -82,7 +86,7 @@ private boolean isTargetBehindWall(double dx2, double dy2) {
int x2 = (int) dx2 / Tile.WIDTH;
int y2 = (int) dy2 / Tile.HEIGHT;

Bullet bullet = new Bullet(this, pos.x, pos.y);
Bullet bullet = new Bullet(this, pos.x, pos.y, 0);

int dx, dy, inx, iny, e;
Tile temp;
Expand Down
7 changes: 4 additions & 3 deletions src/com/mojang/mojam/entity/mob/Bat.java
Expand Up @@ -2,16 +2,17 @@

import com.mojang.mojam.entity.Entity;
import com.mojang.mojam.gui.TitleMenu;
import com.mojang.mojam.level.DifficultyInformation;
import com.mojang.mojam.network.TurnSynchronizer;
import com.mojang.mojam.screen.*;

public class Bat extends Mob {
public class Bat extends HostileMob {
private int tick = 0;

public Bat(double x, double y) {
super(x, y, Team.Neutral);
setPos(x, y);
setStartHealth(1 + TitleMenu.Difficulty);
setStartHealth(1);
dir = TurnSynchronizer.synchedRandom.nextDouble() * Math.PI * 2;
minimapColor = 0xffff0000;
yOffs = 5;
Expand Down Expand Up @@ -67,7 +68,7 @@ public void collide(Entity entity, double xa, double ya) {
if (entity instanceof Mob) {
Mob mob = (Mob) entity;
if (isNotFriendOf(mob)) {
mob.hurt(this, 1);
mob.hurt(this, DifficultyInformation.calculateStrength(1));
}
}
}
Expand Down

0 comments on commit 3bfa547

Please sign in to comment.