mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
update of client data by server
This commit is contained in:
parent
2cb401bbd3
commit
c8d0a48489
11 changed files with 239 additions and 120 deletions
|
|
@ -1,120 +1,120 @@
|
|||
define(["Chuck/Physics/Doll", "Chuck/Settings"], function(Doll, Settings){
|
||||
|
||||
function Player (physicsEngine, id, repository) {
|
||||
this._physicsEngine = physicsEngine;
|
||||
this.physicsEngine = physicsEngine;
|
||||
this.id = id;
|
||||
this._repository = repository;
|
||||
this._standing = false;
|
||||
this._doll;
|
||||
this._mc;
|
||||
this._currentAnimationState = 'stand';
|
||||
this._lookDirection = 1;
|
||||
this._moveDirection = 0;
|
||||
this.repository = repository;
|
||||
this.standing = false;
|
||||
this.doll;
|
||||
this.mc;
|
||||
this.currentAnimationState = 'stand';
|
||||
this.lookDirection = 1;
|
||||
this.moveDirection = 0;
|
||||
|
||||
this.init(id);
|
||||
}
|
||||
|
||||
Player.prototype.init = function(id) {
|
||||
this._doll = new Doll(this._physicsEngine, id);
|
||||
//this._mc = EmbedHandler.load(EmbedHandler.CHUCK);
|
||||
//this._mc.stop();
|
||||
this.doll = new Doll(this.physicsEngine, id);
|
||||
//this.mc = EmbedHandler.load(EmbedHandler.CHUCK);
|
||||
//this.mc.stop();
|
||||
//var mclp = new MovieClipLabelParser();
|
||||
//mclp.parse(this._mc);
|
||||
//mclp.parse(this.mc);
|
||||
}
|
||||
|
||||
Player.prototype.spawn = function(x, y) {
|
||||
//this._repository.createModel(this._mc, this._doll.getBody());
|
||||
this._doll.spawn(x, y);
|
||||
//this.repository.createModel(this.mc, this.doll.getBody());
|
||||
this.doll.spawn(x, y);
|
||||
}
|
||||
|
||||
Player.prototype.getDoll = function() {
|
||||
return this._doll;
|
||||
return this.doll;
|
||||
}
|
||||
|
||||
Player.prototype.getBody = function() {
|
||||
return this._doll.getBody();
|
||||
return this.doll.getBody();
|
||||
}
|
||||
|
||||
Player.prototype.setStanding = function(isStanding) {
|
||||
var resetStates = ['jump', 'jumploop'];
|
||||
if (resetStates.indexOf(this._currentAnimationState)>=0 && !this._standing && isStanding) {
|
||||
this._animate('stand');
|
||||
if (resetStates.indexOf(this.currentAnimationState)>=0 && !this.standing && isStanding) {
|
||||
this.animate('stand');
|
||||
}
|
||||
this._standing = isStanding;
|
||||
this.standing = isStanding;
|
||||
}
|
||||
|
||||
Player.prototype.isStanding = function() {
|
||||
return this._standing;
|
||||
return this.standing;
|
||||
}
|
||||
|
||||
Player.prototype.move = function(direction) {
|
||||
this._moveDirection = direction;
|
||||
this.moveDirection = direction;
|
||||
|
||||
switch(true) {
|
||||
case direction == this._lookDirection && this.isStanding():
|
||||
this._doll.move(direction, Settings.RUN_SPEED);
|
||||
case direction == this.lookDirection && this.isStanding():
|
||||
this.doll.move(direction, Settings.RUN_SPEED);
|
||||
break;
|
||||
|
||||
case !this.isStanding():
|
||||
this._doll.move(direction, Settings.FLY_SPEED);
|
||||
this.doll.move(direction, Settings.FLY_SPEED);
|
||||
break;
|
||||
|
||||
default:
|
||||
this._doll.move(direction, Settings.WALK_SPEED);
|
||||
this.doll.move(direction, Settings.WALK_SPEED);
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.isStanding()) {
|
||||
this._animate(this._calculateWalkAnimation());
|
||||
this.animate(this.calculateWalkAnimation());
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.stop = function() {
|
||||
this._moveDirection = 0;
|
||||
this._doll.stop();
|
||||
if (this._isWalking() || this._standing) {
|
||||
this._animate('stand');
|
||||
this.moveDirection = 0;
|
||||
this.doll.stop();
|
||||
if (this.isWalking() || this.standing) {
|
||||
this.animate('stand');
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.jump = function() {
|
||||
if (this.isStanding()) {
|
||||
this._doll.jump();
|
||||
this._animate('jump');
|
||||
this.doll.jump();
|
||||
this.animate('jump');
|
||||
this.setStanding(false);
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.jumping = function() {
|
||||
if (!this.isStanding()) {
|
||||
this._doll.jumping();
|
||||
this.doll.jumping();
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.duck = function() {
|
||||
if (this._standing && !this._isWalking()) {
|
||||
this._animate('duck');
|
||||
if (this.standing && !this.isWalking()) {
|
||||
this.animate('duck');
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.standUp = function() {
|
||||
if (this._standing) {
|
||||
this._animate('standup');
|
||||
if (this.standing) {
|
||||
this.animate('standup');
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype._animate = function(type) {
|
||||
if (type == this._currentAnimationState) {
|
||||
Player.prototype.animate = function(type) {
|
||||
if (type == this.currentAnimationState) {
|
||||
return;
|
||||
}
|
||||
|
||||
//this._mc.gotoAndPlay(type);
|
||||
//this.mc.gotoAndPlay(type);
|
||||
|
||||
this._currentAnimationState = type;
|
||||
this.currentAnimationState = type;
|
||||
}
|
||||
|
||||
Player.prototype._calculateWalkAnimation = function() {
|
||||
if (this._moveDirection == this._lookDirection) {
|
||||
Player.prototype.calculateWalkAnimation = function() {
|
||||
if (this.moveDirection == this.lookDirection) {
|
||||
return 'run';
|
||||
}
|
||||
return 'walkback';
|
||||
|
|
@ -123,29 +123,29 @@ define(["Chuck/Physics/Doll", "Chuck/Settings"], function(Doll, Settings){
|
|||
Player.prototype.look = function(x, y) {
|
||||
/*
|
||||
var degree = Math.atan2(Settings.STAGE_WIDTH / 2 - x, Settings.STAGE_HEIGHT / 2 - 25 - y) / (Math.PI / 180);
|
||||
var lastLookDirection = this._lookDirection;
|
||||
var lastLookDirection = this.lookDirection;
|
||||
|
||||
if (x < Settings.STAGE_WIDTH / 2) {
|
||||
this._mc.scaleX = -1;
|
||||
this._lookDirection = -1;
|
||||
this.mc.scaleX = -1;
|
||||
this.lookDirection = -1;
|
||||
degree = (-45 + degree / 2);
|
||||
this._mc.head.rotation = degree;
|
||||
this.mc.head.rotation = degree;
|
||||
} else if (x >= Settings.STAGE_WIDTH / 2) {
|
||||
this._mc.scaleX = 1;
|
||||
this._lookDirection = 1;
|
||||
this.mc.scaleX = 1;
|
||||
this.lookDirection = 1;
|
||||
degree = (45 + -degree / 2) - 90;
|
||||
this._mc.head.rotation = degree;
|
||||
this.mc.head.rotation = degree;
|
||||
}
|
||||
|
||||
if (this._lookDirection != lastLookDirection && this._isWalking()) {
|
||||
this._animate(this._calculateWalkAnimation());
|
||||
if (this.lookDirection != lastLookDirection && this.isWalking()) {
|
||||
this.animate(this.calculateWalkAnimation());
|
||||
}*/
|
||||
}
|
||||
|
||||
Player.prototype._isWalking = function() {
|
||||
Player.prototype.isWalking = function() {
|
||||
var states = ['walk', 'walkback', 'run'];
|
||||
|
||||
if (states.indexOf(this._currentAnimationState) >= 0) {
|
||||
if (states.indexOf(this.currentAnimationState) >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -154,7 +154,7 @@ define(["Chuck/Physics/Doll", "Chuck/Settings"], function(Doll, Settings){
|
|||
// called by CollisionDetection
|
||||
Player.prototype.onFootSensorDetection = function(isColliding) {
|
||||
if(isColliding) {
|
||||
if(this._doll.getBody().GetLinearVelocity().y < -Settings.JUMP_SPEED && !this.isStanding()) {
|
||||
if(this.doll.getBody().GetLinearVelocity().y < -Settings.JUMP_SPEED && !this.isStanding()) {
|
||||
return;
|
||||
}
|
||||
this.setStanding(true);
|
||||
|
|
@ -164,18 +164,18 @@ define(["Chuck/Physics/Doll", "Chuck/Settings"], function(Doll, Settings){
|
|||
// to group all tiles together
|
||||
|
||||
//this.setStanding(false);
|
||||
//this._animate('jumploop');
|
||||
//this.animate('jumploop');
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.update = function() {
|
||||
//this._mc.head.y = this._mc.head_posmask.y;
|
||||
//this.mc.head.y = this.mc.head_posmask.y;
|
||||
|
||||
if (this._doll.getBody().GetLinearVelocity().x == 0 && this._isWalking()) {
|
||||
if (this.doll.getBody().GetLinearVelocity().x == 0 && this.isWalking()) {
|
||||
this.stop();
|
||||
}
|
||||
|
||||
if (!this._doll.getBody().IsAwake()) {
|
||||
if (!this.doll.getBody().IsAwake()) {
|
||||
this.setStanding(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue