Skip to content

Commit

Permalink
Merge pull request #106 from bandaloo/balance
Browse files Browse the repository at this point in the history
Minor balance tweaks
  • Loading branch information
jojonium authored Feb 27, 2020
2 parents b50dac5 + dae2de9 commit d5ea3b2
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 55 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "afterlight-caves",
"version": "0.10.1",
"version": "0.10.3",
"description": "a game where you shoot procedurally generated enemies in procedurally generated caves",
"main": "main.js",
"directories": {
Expand Down
80 changes: 49 additions & 31 deletions static/game/bomb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Vector } from "../modules/vector.js";
import { polygon, circle, splatter } from "./draw.js";
import { Particle, EffectEnum } from "./particle.js";
import { addParticle, cellToWorldPosition } from "../modules/gamemanager.js";
import { isColliding, calcCorners } from "../modules/collision.js";
import { isColliding, calcCorners, getCell } from "../modules/collision.js";
import { destroyBlock } from "./block.js";
import { playSound } from "../modules/sound.js";

Expand Down Expand Up @@ -41,13 +41,18 @@ export class Bomb extends Entity {

/**
* @param {Vector} [pos]
* @param {boolean} [good] true if this bomb was planted by the hero
* @param {import("./creature.js").Creature} [owner] the creature that planted this bomb
* @param {number} [hue] HSL hue for this bomb's color
* @param {number} [fuseTime] number of game steps to detonation
*/
constructor(pos = new Vector(0, 0), good = false, hue = 0, fuseTime = 180) {
constructor(
pos = new Vector(0, 0),
owner = undefined,
hue = 0,
fuseTime = 180
) {
super(pos);
this.good = good;
this.good = (owner !== undefined && owner.type === "Hero");
this.fuseTime = fuseTime;
this.maxFuseTime = fuseTime;
this.onDetonate = new Array();
Expand All @@ -60,14 +65,25 @@ export class Bomb extends Entity {
this.hue = hue;
this.speed = 0;
/** @type {import("./creature.js").Creature} */
this.owner = undefined; // the creature that created this bomb
this.owner = owner;
this.creaturesHit = {};
this.collisionType = "Circle";
}

/**
* @override
*/
action() {
// tick down cooldowns
this.fuseTime--;
for (const key in this.creaturesHit) {
if (this.creaturesHit[key]) {
if (this.creaturesHit[key].cooldown === 0)
this.creaturesHit[key] = undefined;
else
this.creaturesHit[key].cooldown--;
}
}
if (this.fuseTime === 0) {
this.detonate();
} else if (this.fuseTime < 0 && this.fuseTime >= -1 * this.timeToExplode) {
Expand All @@ -78,7 +94,7 @@ export class Bomb extends Entity {
this.width = radius * 2;
this.height = radius * 2;
// create some particles
const numParticles = 1;
const numParticles = 5;
for (let i = 0; i < numParticles; ++i) {
let particleHue = (this.hue - 30 + Math.random() * 30) % 360;
let color = `hsl(${particleHue}, 100%, 50%)`;
Expand All @@ -104,21 +120,25 @@ export class Bomb extends Entity {
p.width = 20;
p.height = 20;
addParticle(p);
}

// iterate through all overlapping blocks
const { topLeft: topLeft, bottomRight: bottomRight } = calcCorners(
this.getCollisionShape()
);
// iterate through all overlapping blocks and destroy them
// this is necessary because interior blocks aren't checked for collision
const { topLeft: topLeft, bottomRight: bottomRight } = calcCorners(
this.getCollisionShape()
);

for (let i = topLeft.x; i < bottomRight.x + 1; i++) {
for (let j = topLeft.y; j < bottomRight.y + 1; j++) {
const cellVec = new Vector(i, j);
if (
cellToWorldPosition(cellVec).dist2(this.pos) <
(this.width / 2) ** 2
) {
destroyBlock(cellVec, this.owner.type === "Hero");
}
for (let i = topLeft.x; i < bottomRight.x + 1; i++) {
for (let j = topLeft.y; j < bottomRight.y + 1; j++) {
const cellVec = new Vector(i, j);
if (
cellToWorldPosition(cellVec).dist2(this.pos) <
(this.width / 2) ** 2
) {
destroyBlock(
cellVec,
this.owner !== undefined && this.owner.type === "Hero"
);
}
}
}
Expand Down Expand Up @@ -174,18 +194,16 @@ export class Bomb extends Entity {
this.collideMap.set(
this.good ? "Enemy" : "Hero",
/** @param {import("./creature.js").Creature} creature */ creature => {
// deal damage only every 1/2 second or at the very end of the explosion
if (
isColliding(creature.getCollisionShape(), this.getCollisionShape())
) {
if (
this.fuseTime === -1 * this.timeToExplode ||
this.fuseTime % 30 === 0
) {
this.onBlastCreature.map(obj => {
obj.func(this, obj.data, creature);
});
}
// rate limit dealing damage to creatures
if (this.creaturesHit[creature.id] === undefined) {
this.creaturesHit[creature.id] = { c: creature, cooldown: 25 };
// impart momentum
creature.vel = creature.vel.add(
creature.pos.sub(this.pos).mult(10 / this.blastRadius)
);
this.onBlastCreature.map(obj => {
if (obj.func) obj.func(this, obj.data, creature);
});
}
}
);
Expand Down
23 changes: 13 additions & 10 deletions static/game/bullet.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,20 @@ export class Beam extends Bullet {
// deal basic damage
creature.takeDamage(this.damage, this.dir);
// impart momentum
const size = (creature.width * creature.height) / 300;
creature.vel = creature.vel.add(this.dir.mult(this.knockback / size));
const size = (creature.width * creature.height) / 1000;
creature.acc = creature.acc.add(this.dir.mult(this.knockback / size));
// call onHitEnemy functions
for (const ohe of this.onHitEnemy) {
if (ohe.func) ohe.func(this, ohe.data, creature);
}
} else {
// decrease cooldown if we've already hit the creature
if (this.creaturesHit[creature.id].cooldown === 0) {
this.creaturesHit[creature.id] = undefined;
} else {
this.creaturesHit[creature.id].cooldown--;
}
}
}

/** @override */
destroy() {
// execute all on-destroy functions
for (const od of this.onDestroy) {
if (od["func"]) od["func"](this, od["data"]);
if (od.func) od.func(this, od.data);
}
}

Expand Down Expand Up @@ -289,7 +282,17 @@ export class Beam extends Bullet {
this.collideWithBlock(intersect);
this.length = intersect.sub(this.pos).mag();

// tick down cooldowns
if (this.blockBreakCounter++ > this.maxBlockBreakCounter)
this.blockBreakCounter = 0;
for (const key in this.creaturesHit) {
if (this.creaturesHit[key]) {
if (this.creaturesHit[key].cooldown === 0)
this.creaturesHit[key] = undefined;
else
this.creaturesHit[key].cooldown--;
}
}

}
}
6 changes: 2 additions & 4 deletions static/game/creature.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,8 @@ export class Creature extends Entity {
* Places a bomb into the world
* @param {Vector} pos the position to place the bomb, by default the
* creature's position
* @param {boolean} [isGood] true if the bomb was planted by the player,
* false otherwise
*/
placeBomb(pos = this.pos, isGood = false) {
placeBomb(pos = this.pos) {
if (this.currentBombs > 0) {
const b = this.getBomb(pos);
addToWorld(b);
Expand All @@ -356,7 +354,7 @@ export class Creature extends Entity {
getBomb(pos) {
const b = new Bomb(
pos,
this.type === "Hero",
this,
this.bombHue,
this.bombFuseTime
);
Expand Down
4 changes: 2 additions & 2 deletions static/game/crosser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ chanceTable.addAll([
{ result: PowerUpTypes.Right, chance: 1 },
{ result: PowerUpTypes.Vitality, chance: 1 },
{ result: PowerUpTypes.Wall, chance: 1 },
{ result: PowerUpTypes.Xplode, chance: 2 },
{ result: PowerUpTypes.Xplode, chance: 0.5 },
{ result: PowerUpTypes.Yeet, chance: 1 },
{ result: PowerUpTypes.Zoom, chance: 1 }
]);
Expand All @@ -45,7 +45,7 @@ export class Crosser extends Enemy {
this.basePoints = 60;

// stuff for shooting
this.fireDelay = 90;
this.fireDelay = 120;
this.bulletSpeed = 3;
this.bulletLifetime = 300;
this.wiggleCount = 0;
Expand Down
1 change: 0 additions & 1 deletion static/game/enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { CHEAT_RADIUS, Hero } from "./hero.js";
import { EffectEnum, Particle } from "./particle.js";
import { Pickup, PickupEnum } from "./pickup.js";
import { splatter } from "./draw.js";
import { powerUpTypes } from "./powerups/poweruptypes.js";

export const MATRYOSHKA_SIZE = 50;
const DROP_CHANCE = 0.2;
Expand Down
4 changes: 2 additions & 2 deletions static/game/hero.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export class Hero extends Creature {
this.bulletSpeed = 8;
this.bulletLifetime = 60;
this.bulletDamage = 8;
this.bombFuseTime = 300;
this.bombFuseTime = 240;
this.bombHue = 126;
this.bulletColor = "white";
this.score = 0;
this.setBombDamage(18);
this.setBombDamage(22);

// Manually set the collision shape to allow for a smaller hitbox
const collisionShape = new CollisionCircle(
Expand Down
4 changes: 2 additions & 2 deletions static/game/powerups/zoom.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PowerUp } from "../powerup.js";
import { Vector } from "../../modules/vector.js";
import { Creature } from "../creature.js";
const MOVEMENT_FACTOR = 1 / 5;
const MAX_MOVEMENT_MULTIPLIER = 4;
const MOVEMENT_FACTOR = 1 / 10;
const MAX_MOVEMENT_MULTIPLIER = 2;

export class Zoom extends PowerUp {
/**
Expand Down
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div id="gamediv-holder">
<h1 class="title">Afterlight Caves</h1>
<span id="version"
>Beta version 0.10.1 (<a
>Beta version 0.10.3 (<a
href="https://github.com/bandaloo/afterlight-caves/releases"
>changelog</a
>)</span
Expand Down

0 comments on commit d5ea3b2

Please sign in to comment.