Skip to content

Commit

Permalink
Merge pull request #26 from ENG1-Team-29/implement-difficulties
Browse files Browse the repository at this point in the history
Implement Difficulties
  • Loading branch information
HectorJVWoods authored Apr 22, 2022
2 parents f08d9b8 + d04741e commit 24fec6e
Show file tree
Hide file tree
Showing 25 changed files with 656 additions and 204 deletions.
27 changes: 18 additions & 9 deletions core/src/main/java/io/github/annabeths/Boats/AttackBoat.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ public AttackBoat(GameController controller, Vector2 initialPosition, String tex

@Override
public void Shoot() {
Projectile projLeft = createProjectile(projectileType, -90, 1, 1);
Projectile projRight = createProjectile(projectileType, 90, 1, 1);

float damageMul = 1;
if (this instanceof EnemyBoat) {
damageMul = controller.getGameDifficulty().getEnemyDmgMul();
}

Projectile projLeft = createProjectile(projectileType, -90, damageMul, 1);
Projectile projRight = createProjectile(projectileType, 90, damageMul, 1);

// Add the projectile to the GameController's physics objects list so it
// receives updates
Expand Down Expand Up @@ -68,26 +74,28 @@ public void updateAIState() {

@Override
public void Update(float delta) {
if (isDead()) Destroy();
if (isDead())
Destroy();
timeSinceLastShot += delta;

updateAIState();

switch (state) {
case APPROACH:
case APPROACH :
approach(delta);
break;
case ATTACK:
case ATTACK :
attack(delta);
break;
case IDLE:
case IDLE :
idle(delta);
break;
default:
default :
break;
}

if (destination != null) MoveToDestination(delta);
if (destination != null)
MoveToDestination(delta);
}

public void approach(float delta) {
Expand Down Expand Up @@ -115,7 +123,8 @@ public void attack(float delta) {
adjustedAng = MathHelper.normalizeAngle(adjustedAng);
adjustedAng -= adjustedAng > 270 ? 180 : 0;

// If the angle to the player is within acceptable angle range, shoot
// If the angle to the player is within acceptable angle range,
// shoot
if (adjustedAng > 80 && adjustedAng < 100) {
Shoot();
timeSinceLastShot = 0;
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/io/github/annabeths/Boats/EnemyBoat.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public EnemyBoat(GameController controller, Vector2 position) {
xpValue = 150;
plunderValue = 100;

this.HP = 100;
this.maxHP = 100;
this.maxHP = 100 * controller.getGameDifficulty().getEnemyHpMul();
this.HP = this.maxHP;
this.speed = 75;
this.turnSpeed = 150;
// uncomment for fun
Expand Down Expand Up @@ -77,7 +77,8 @@ public void OnCollision(PhysicsObject other) {
Destroy();
}

if (objWasPlayer) controller.addXp((dmgToInflict / maxHP) * xpValue);
if (objWasPlayer)
controller.addXp((dmgToInflict / maxHP) * xpValue);
damage(dmgToInflict);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class NeutralBoat extends AIBoat {
public NeutralBoat(GameController controller, Vector2 initialPosition) {
super(controller, initialPosition, "img/entity/boat_neutral.png");

xpValue = 20;
xpValue = 20 * controller.getGameDifficulty().getPlayerXpMul();
plunderValue = 25;

this.HP = 100;
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/io/github/annabeths/Boats/PlayerBoat.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public class PlayerBoat extends Boat {
public PlayerBoat(GameController controller, Vector2 initialPosition) {
super(controller, initialPosition, "img/entity/boat1.png");

this.HP = 100;

this.maxHP = 100;
this.HP = this.maxHP;
this.speed = 200;
this.turnSpeed = 150;

Expand Down Expand Up @@ -231,9 +232,9 @@ public void shootStock(float dmgMul) {
}

public float getDamageMul() {
float dmgMul = activePowerups.containsKey(PowerupType.DAMAGE) ? 3 : 1;
float dmgMul = activePowerups.containsKey(PowerupType.DAMAGE) ? 2 : 1;
// multiply by the overall damage multiplier
return dmgMul * projDmgMul;
return dmgMul * projDmgMul * controller.getGameDifficulty().getPlayerDmgMul();
}

@Override
Expand Down
26 changes: 16 additions & 10 deletions core/src/main/java/io/github/annabeths/Colleges/EnemyCollege.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class EnemyCollege extends College {

/**
* The inaccuracy when firing cannonballs. Measured in degrees and reflected
* about the center. i.e. the cannon could be fired anywhere between -x and x
* where x is the inaccuracy.
* about the center. i.e. the cannon could be fired anywhere between -x and
* x where x is the inaccuracy.
*/
public float shootingInaccuracy = 10f;
public float timeSinceLastShot = 0;
Expand All @@ -38,7 +38,7 @@ public EnemyCollege(Vector2 position, String aliveTexture, String islandTexture,
deadSprite = initSprite("img/world/castle/castle_dead.png", position,
new Vector2(100, 100));

this.maxHP = maxHP;
this.maxHP = maxHP * controller.getGameDifficulty().getEnemyHpMul();
HP = maxHP;
range = 500;
fireRate = 1.5f;
Expand Down Expand Up @@ -69,7 +69,8 @@ public void OnCollision(PhysicsObject other) {
p.kill();
if (!isInvulnerable()) {
damage(p.getDamage());
if (isDead()) gc.CollegeDestroyed(this);
if (isDead())
gc.CollegeDestroyed(this);
updateHpText();
} else {
hpText.setText(font, "RESISTED, destroy other colleges first!");
Expand Down Expand Up @@ -110,21 +111,26 @@ public void Draw(SpriteBatch batch) {

void ShootAt(Vector2 target) {
// If fire is disabled, skip calculation.
if (!DebugUtils.ENEMY_COLLEGE_FIRE) return;
if (!DebugUtils.ENEMY_COLLEGE_FIRE)
return;
/*
* calculate the shot angle by getting a vector from the center of the college
* to the target. Convert to degrees for the inaccuracy calculation.
* calculate the shot angle by getting a vector from the center of the
* college to the target. Convert to degrees for the inaccuracy
* calculation.
*/
Vector2 directionVec = target.cpy().sub(getCenter());
float shotAngle = directionVec.angleDeg();

shotAngle += MathUtils.random(-shootingInaccuracy, shootingInaccuracy);

float dmgMul = gc.getGameDifficulty().getEnemyDmgMul();

/*
* instantiate a new bullet and pass a reference to the gamecontroller so it can
* be updated and drawn
* instantiate a new bullet and pass a reference to the gamecontroller
* so it can be updated and drawn
*/
gc.NewPhysicsObject(new Projectile(getCenter(), shotAngle, projectileType, false));
gc.NewPhysicsObject(
new Projectile(getCenter(), shotAngle, projectileType, false, dmgMul, 1));

}

Expand Down
Loading

0 comments on commit 24fec6e

Please sign in to comment.