mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
parent
89c5e4a5d8
commit
ed23753c04
17 changed files with 286 additions and 224 deletions
|
|
@ -55,20 +55,23 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
}
|
||||
|
||||
GameController.prototype.spawnPlayer = function(player) {
|
||||
|
||||
var self = this;
|
||||
var spawnPoint = this.level.getRandomSpawnPoint();
|
||||
|
||||
player.spawn(spawnPoint.x, spawnPoint.y);
|
||||
this.gameObjects.animated.push(player.getDoll());
|
||||
setTimeout(function() {
|
||||
player.spawn(spawnPoint.x, spawnPoint.y);
|
||||
self.gameObjects.animated.push(player.getDoll());
|
||||
|
||||
var message = {
|
||||
spawnPlayer: {
|
||||
id: player.id,
|
||||
x: spawnPoint.x,
|
||||
y: spawnPoint.y
|
||||
}
|
||||
};
|
||||
NotificationCenter.trigger("broadcastControlCommand", "gameCommand", message);
|
||||
var message = {
|
||||
spawnPlayer: {
|
||||
id: player.id,
|
||||
x: spawnPoint.x,
|
||||
y: spawnPoint.y
|
||||
}
|
||||
};
|
||||
|
||||
NotificationCenter.trigger("broadcastControlCommand", "gameCommand", message);
|
||||
}, 5000);
|
||||
};
|
||||
|
||||
GameController.prototype.createPlayer = function(user) {
|
||||
|
|
|
|||
|
|
@ -57,8 +57,10 @@ function (Parent, Item, Box2D, NotificationCenter) {
|
|||
damage.Abs();
|
||||
damage.Multiply(itemMass);
|
||||
|
||||
var player = item.lastMoved.player;
|
||||
|
||||
var callback = function() {
|
||||
self.player.addDamage(damage.Length() * 2, item.lastMoved.player);
|
||||
self.player.addDamage(damage.Length() * 2, player);
|
||||
}
|
||||
|
||||
NotificationCenter.trigger("engine/addToWorldQueue", callback)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ function (Parent, NotificationCenter) {
|
|||
Player.prototype = Object.create(Parent.prototype);
|
||||
|
||||
Player.prototype.handActionRequest = function(x, y) {
|
||||
if(!this.doll) return false;
|
||||
|
||||
var item = null;
|
||||
var isHolding = !!this.holdingItem;
|
||||
|
|
@ -56,31 +57,27 @@ function (Parent, NotificationCenter) {
|
|||
};
|
||||
|
||||
Player.prototype.addDamage = function(damage, enemy) {
|
||||
this.updateHealth(this.stats.health - damage);
|
||||
this.stats.health -= damage;
|
||||
|
||||
if(this.stats.health <= 0) {
|
||||
enemy.score();
|
||||
this.kill();
|
||||
} else {
|
||||
this.broadcastStats();
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.spawn = function(x, y) {
|
||||
Parent.prototype.spawn.call(this, x, y);
|
||||
this.updateHealth(100);
|
||||
};
|
||||
|
||||
Player.prototype.updateHealth = function(health) {
|
||||
this.stats.health = health;
|
||||
NotificationCenter.trigger("user/" + this.id + "/gameCommand", "updateStats", {
|
||||
playerId: this.id,
|
||||
stats: this.stats
|
||||
});
|
||||
this.stats.health = 100;
|
||||
this.broadcastStats();
|
||||
};
|
||||
|
||||
Player.prototype.kill = function() {
|
||||
Parent.prototype.kill.call(this);
|
||||
this.stats.deaths++;
|
||||
this.broadcastStats();
|
||||
NotificationCenter.trigger("broadcastGameCommand", "playerKill", this.id);
|
||||
};
|
||||
|
||||
Player.prototype.score = function() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue