2023-05-21 22:06:04 -04:00

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;
};