-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Handle Game Over and Restart (#5)
* restart game after death && show particles * build gh-pages && adjust factory amount
- Loading branch information
1 parent
f7df420
commit 301bf7f
Showing
10 changed files
with
669 additions
and
514 deletions.
There are no files selected for viewing
1,008 changes: 504 additions & 504 deletions
1,008
docs/assets/index-BqF0neoc.js → docs/assets/index-v7LhaIZJ.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Vector3 } from "@babylonjs/core"; | ||
import { Particle } from "."; | ||
import { Entity } from ".."; | ||
import { Game } from "../../app"; | ||
import { HomeScene } from "../../scene"; | ||
|
||
type DeathParticlesGroupOptions = { | ||
start: Vector3; | ||
} | ||
|
||
export class DeathParticlesGroup extends Entity{ | ||
public static TTL = 1000; | ||
public scene: HomeScene; | ||
|
||
private particles: Entity[] = []; | ||
private life = 0; | ||
|
||
constructor(scene: HomeScene, options: DeathParticlesGroupOptions){ | ||
super(scene); | ||
|
||
const NUMBER_OF_PARTICLES = 20; | ||
for (let i = 0; i < NUMBER_OF_PARTICLES; i++){ | ||
const particle = new Particle(scene, { | ||
start: options.start, | ||
TTL: DeathParticlesGroup.TTL, | ||
}); | ||
|
||
this.particles.push(particle); | ||
scene.addEntity(particle); | ||
} | ||
|
||
this.scene = scene; | ||
} | ||
|
||
public update(_game: Game, _delta: number): void { | ||
if (this.life > DeathParticlesGroup.TTL) { | ||
this.kill(); | ||
this.scene.restart(); | ||
return; | ||
} | ||
|
||
this.life += _delta; | ||
} | ||
|
||
kill(): void { | ||
super.kill(); | ||
this.particles.forEach(particle => particle.kill()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './death-particles.group'; | ||
export * from './particle'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Color3, MeshBuilder, StandardMaterial, Vector3 } from "@babylonjs/core"; | ||
import { Entity } from ".."; | ||
|
||
import { Game } from "../../app"; | ||
import { HomeScene } from "../../scene"; | ||
import { BASE_SIZE } from "../../config"; | ||
|
||
type ParticleOptions = { | ||
start: Vector3; | ||
TTL: number; | ||
} | ||
|
||
export class Particle extends Entity{ | ||
private pointingTo: Vector3; | ||
|
||
private ttl: number; | ||
private life: number = 0; | ||
|
||
constructor(scene: HomeScene, options: ParticleOptions){ | ||
super(scene); | ||
this._mesh = MeshBuilder.CreateBox('PARTICLE-MESH', { | ||
size: BASE_SIZE/16, | ||
}, scene); | ||
this.mesh.material = new StandardMaterial('PLAYER-MESH-MATERIAL', scene); | ||
if (this.mesh.material instanceof StandardMaterial) this.mesh.material.diffuseColor = Math.random() < 0.5 ? Color3.White() : Color3.Red(); | ||
|
||
this.mesh.position = options.start; | ||
this.ttl = options.TTL; | ||
|
||
const getNormalizedComponent = () => (-1 + Math.floor(3 * Math.random())); | ||
|
||
this.pointingTo = new Vector3( | ||
getNormalizedComponent(), | ||
getNormalizedComponent(), | ||
getNormalizedComponent(), | ||
); | ||
} | ||
|
||
public update(_game: Game, _delta: number): void { | ||
this.life += _delta; | ||
this.mesh.position = this.mesh.position.add(this.pointingTo.scale(0.01*_delta)); | ||
|
||
if (this.mesh.material) this.mesh.material.alpha = 1 - (this.life / this.ttl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters