Skip to content

Commit

Permalink
Replace particle sprite with a solid color
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Jul 8, 2024
1 parent 19e7090 commit 9635d78
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 48 deletions.
Binary file removed assets/images/custom/particle.png
Binary file not shown.
41 changes: 21 additions & 20 deletions game.js

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

45 changes: 23 additions & 22 deletions game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@
//
// Only simple functions that operate on objects that don't store any functions can be easily
// hot-reloaded. Examples are State and Player which we defined as interfaces.

export class RGBA {
r: number;
g: number;
b: number;
a: number;
constructor(r: number, g: number, b: number, a: number) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
toStyle(): string {
return `rgba(`
+`${Math.floor(this.r*255)}, `
+`${Math.floor(this.g*255)}, `
+`${Math.floor(this.b*255)}, `
+`${this.a})`;
}
}

const EPS = 1e-6;
const NEAR_CLIPPING_PLANE = 0.1;
const FAR_CLIPPING_PLANE = 10.0;
Expand All @@ -32,6 +53,7 @@ const PARTICLE_LIFETIME = 1.0;
const PARTICLE_DAMP = 0.8;
const PARTICLE_SCALE = 0.05;
const PARTICLE_MAX_SPEED = 8;
const PARTICLE_COLOR = new RGBA(1, 0.5, 0.15, 1);

const MINIMAP = false;
const MINIMAP_SPRITES = false;
Expand All @@ -55,26 +77,6 @@ function resetSpritePool(spritePool: SpritePool) {
spritePool.length = 0;
}

export class RGBA {
r: number;
g: number;
b: number;
a: number;
constructor(r: number, g: number, b: number, a: number) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
toStyle(): string {
return `rgba(`
+`${Math.floor(this.r*255)}, `
+`${Math.floor(this.g*255)}, `
+`${Math.floor(this.b*255)}, `
+`${this.a})`;
}
}

export class Vector2 {
x: number;
y: number;
Expand Down Expand Up @@ -898,7 +900,7 @@ function updateParticles(deltaTime: number, scene: Scene, particles: Array<Parti

if (particle.lifetime <= 0) {
} else {
pushSprite(assets.particleImageData, new Vector2().set(particle.position.x, particle.position.y), particle.position.z, PARTICLE_SCALE)
pushSprite(PARTICLE_COLOR, new Vector2().set(particle.position.x, particle.position.y), particle.position.z, PARTICLE_SCALE)
}
}
}
Expand Down Expand Up @@ -980,7 +982,6 @@ function updateBombs(player: Player, bombs: Array<Bomb>, particles: Array<Partic
export interface Assets {
keyImageData: ImageData,
bombImageData: ImageData,
particleImageData: ImageData,
bombRicochetSound: HTMLAudioElement,
itemPickupSound: HTMLAudioElement,
bombBlastSound: HTMLAudioElement
Expand Down
4 changes: 1 addition & 3 deletions index.js

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

4 changes: 1 addition & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ async function loadImageData(url: string): Promise<ImageData> {
if (ctx === null) throw new Error("2D context is not supported");
ctx.imageSmoothingEnabled = false;

const [wall, keyImageData, bombImageData, particleImageData] = await Promise.all([
const [wall, keyImageData, bombImageData] = await Promise.all([
loadImageData("assets/images/custom/wall.png"),
loadImageData("assets/images/custom/key.png"),
loadImageData("assets/images/custom/bomb.png"),
loadImageData("assets/images/custom/particle.png"),
]);
const itemPickupSound = new Audio("assets/sounds/bomb-pickup.ogg");
const bombRicochetSound = new Audio("assets/sounds/ricochet.wav");
const bombBlastSound = new Audio("assets/sounds/blast.ogg");
const assets = {
keyImageData,
bombImageData,
particleImageData,
bombRicochetSound,
itemPickupSound,
bombBlastSound,
Expand Down

0 comments on commit 9635d78

Please sign in to comment.