Skip to content

Commit

Permalink
adjust particles and rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
gtanczyk committed Oct 15, 2024
1 parent 13d9c79 commit 3e35f54
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 41 deletions.
6 changes: 3 additions & 3 deletions games/masterplan/src/screens/battle/game/game-render-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const layerOrder: { [key: string]: number } = {
};

export class RenderQueue {
constructor(private worldRender: GameWorldRender) {}
constructor(public worldRender: GameWorldRender) {}

private commands: RenderCommand[] = [];

Expand Down Expand Up @@ -86,10 +86,10 @@ export class RenderQueue {
const path = new Path2D();
for (const command of batch) {
const firstPoint = command.points[0];
path.moveTo(command.x + firstPoint[0], command.y + firstPoint[1]);
path.moveTo(command.x + firstPoint[0], command.y + firstPoint[1] - command.z);
for (let i = 1; i < command.points.length; i++) {
const point = command.points[i];
path.lineTo(command.x + point[0], command.y + point[1]);
path.lineTo(command.x + point[0], command.y + point[1] - command.z);
}
}
path.closePath();
Expand Down
15 changes: 4 additions & 11 deletions games/masterplan/src/screens/battle/game/objects/game-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,10 @@ export abstract class GameObject {
abstract update(deltaTime: number): void;

render(queue: RenderQueue) {
queue.addObjectCommand(
this.getX(),
this.getY() - this.world.terrain.getHeightAt(this.vec),
this.getZ(),
true,
'red',
[
[-this.getWidth() / 2 + this.getX(), -this.getHeight() / 2 + this.getY() - this.getZ()],
[this.getWidth(), this.getHeight()],
],
);
queue.addObjectCommand(this.getX(), this.getY(), this.getZ(), true, 'red', [
[-this.getWidth() / 2 + this.getX(), -this.getHeight() / 2 + this.getY() - this.getZ()],
[this.getWidth(), this.getHeight()],
]);
}

getX() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,7 @@ export class ArrowObject extends GameObject {
return [x, y];
});

queue.addObjectCommand(
this.getX(),
this.getY() - this.world.terrain.getHeightAt(this.vec),
this.getZ(),
true,
'red',
rotatedPoints,
);
queue.addObjectCommand(this.getX(), this.getY(), this.getZ(), true, 'red', rotatedPoints);
}

getY() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ export class ExplosionObject extends GameObject {
points.push([Math.cos(angle) * radius, Math.sin(angle) * radius]);
}

queue.addObjectCommand(
this.getX(),
this.getY() - this.world.terrain.getHeightAt(this.vec),
this.getZ(),
true,
'black',
points,
);
queue.addObjectCommand(this.getX(), this.getY(), this.getZ(), true, 'black', points);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class SoldierRender {
private renderShadow(renderQueue: RenderQueue) {
renderQueue.addShadowCommand(
this.soldier.getX(),
this.soldier.getY() + this.soldier.getHeight() / 2 - this.soldier.world.terrain.getHeightAt(this.soldier.vec),
this.soldier.getY() + this.soldier.getHeight() / 2,
this.soldier.getZ(),
'rgba(0, 0, 0, 0.3)',
SHADOW_POINTS,
Expand Down Expand Up @@ -71,9 +71,7 @@ export class SoldierRender {

renderQueue.addObjectCommand(
this.soldier.getX(),
this.soldier.getY() +
(isAlive ? 0 : this.soldier.getHeight() / 2) -
this.soldier.world.terrain.getHeightAt(this.soldier.vec),
this.soldier.getY() + (isAlive ? 0 : this.soldier.getHeight() / 2),
this.soldier.getZ(),
isAlive,
finalColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function createSmokeEffect([x, y]: Vec, [sourceX, sourceY]: Vec, particle
const velocityX = (Math.random() - Math.random()) * 2 + dirX;
const velocityY = (Math.random() - Math.random()) * 2 + dirY;
const velocityZ = Math.random() * 10 + 5; // Upward velocity
const life = 5;
const life = 50;

const particle = new Particle(
x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,34 @@ export class ParticleSystem {
particle.x,
particle.y,
particle.z,
[[0, 0], [1, 0], [1, 1], [0, 1]], // Simple square shape for the particle
'rgba(255, 0, 0, 0.5)'
[
[0, 0],
[1, 0],
[1, 1],
[0, 1],
], // Simple square shape for the particle
'rgba(255, 0, 0, 0.5)',
);
});
}

if (smokeParticles.length > 0) {
smokeParticles.forEach((particle) => {
const size = Math.min(particle.life, 2);
const size = Math.min(particle.life, 2) * 3;
renderQueue.renderShape(
'particles',
particle.x - size / 2,
particle.y - size / 2,
particle.z,
[[0, 0], [size, 0], [size, size], [0, size]], // Square shape with size based on particle life
'rgba(128, 128, 128, 0.5)'
[
[0, 0],
[size, 0],
[size, size],
[0, size],
], // Square shape with size based on particle life
'rgba(28, 28, 28, 0.5)',
);
});
}
}
}
}

0 comments on commit 3e35f54

Please sign in to comment.