{"size": 915, "ext": "js", "max_stars_repo_path": "static/js/games/pong/GoalSystem.js", "max_stars_repo_name": "nazhrenn/breakpong", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "static/js/games/pong/GoalSystem.js", "max_issues_repo_name": "nazhrenn/breakpong", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "static/js/games/pong/GoalSystem.js", "max_forks_repo_name": "nazhrenn/breakpong", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.5161290323, "max_line_length": 184, "alphanum_fraction": 0.6743169399}

var GoalSystem = System.extend({
    interval: 20,
    game: null,
    init: function (game) {
        this.game = game;
		this.componentClasses = ['Ball', 'Position', 'Rectangle', 'Velocity'];
		this.goalEntities = [];
		this.trackedEntities = 0;
		this._super(this.interval);
	},
	
	before: function (entities) {
	    var count = System.getEntityCount(entities);
		if (this.trackedEntities != count) {
		    this.goalEntities = System.getEntitiesWithComponents(entities, ["GoalZone"]);
			this.trackedEntities = count;
		}
	},
	
	action: function (entity) {
		for (var id in this.goalEntities) {
			var goal = this.goalEntities[id];
			if (this.game.overlap(entity.components.Position.x + entity.components.Velocity.x, entity.components.Position.y + entity.components.Velocity.y, entity.components.Rectangle, goal)) {
				entity.components.Velocity.x *= -1;
				goal.components.Score.value += 1;
			}
		}
	}
});
