Skip to content

Instantly share code, notes, and snippets.

@TiagoSilvaPereira
Last active January 12, 2019 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiagoSilvaPereira/8f3c1a49c87a70446191dafda916674b to your computer and use it in GitHub Desktop.
Save TiagoSilvaPereira/8f3c1a49c87a70446191dafda916674b to your computer and use it in GitHub Desktop.
Cube Endless Runner - 3D WebGL Game code examples (BabylonJS)
class Monster {
// ...
moveAwayFromPlayer() {
this.statuses.CLOSE_TO_PLAYER = false;
this.level.interpolate(this, 'distanceBeetweenPlayer', 1.5, 1500);
}
// ... more methods here
attackPlayer() {
this.attackSound.play();
this.level.interpolate(this, 'distanceBeetweenPlayer', 0.1, 300);
// Player dies after 300ms
setTimeout(() => this.player.die(), 300);
}
}
class Player {
// ...
calculateTravelledDistance(animationRatio) {
if(this.travelledDistance >= 100) {
this.travelledDistance = 0;
}
this.travelledDistance += this.speed * animationRatio;
this.totalTravelledDistance += this.speed * animationRatio;
this.metersTextControl.text = 'Meters: ' + Math.floor(this.totalTravelledDistance);
}
// ... more methods here
checkPlayerAltitude() {
if(this.mesh.position.y < this.lastAltitude) {
this.statuses.FALLING_DOWN = true;
} else {
this.statuses.FALLING_DOWN = false;
}
this.lastAltitude = this.mesh.position.y;
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment