mirror of
https://gitlab.com/skysthelimit.dev/selenite.git
synced 2025-06-16 10:32:08 -05:00
23 lines
580 B
JavaScript
23 lines
580 B
JavaScript
var AddToScore = pc.createScript('addToScore');
|
|
|
|
AddToScore.attributes.add('bird', { type: 'entity' });
|
|
|
|
// initialize code called once per entity
|
|
AddToScore.prototype.initialize = function() {
|
|
this.lastX = this.entity.getPosition().x;
|
|
};
|
|
|
|
// update code called every frame
|
|
AddToScore.prototype.update = function(dt) {
|
|
var app = this.app;
|
|
|
|
var birdX = this.bird.getPosition().x;
|
|
var pipeX = this.entity.getPosition().x;
|
|
|
|
if ((pipeX <= birdX) && (this.lastX > birdX)) {
|
|
app.fire('game:addscore');
|
|
}
|
|
|
|
this.lastX = pipeX;
|
|
};
|