Last active
January 12, 2019 19:11
-
-
Save TiagoSilvaPereira/8f3c1a49c87a70446191dafda916674b to your computer and use it in GitHub Desktop.
Cube Endless Runner - 3D WebGL Game code examples (BabylonJS)
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
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); | |
} | |
} |
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
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