mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Added Player
This commit is contained in:
parent
2ce46e1f43
commit
7560fd634a
3 changed files with 93 additions and 98 deletions
|
|
@ -1,4 +1,4 @@
|
|||
define(['Doll'], function(){
|
||||
define(["Chuck/Physics/Doll", "Chuck/Settings"], function(Doll, Settings){
|
||||
|
||||
function Player (physicsEngine, repository) {
|
||||
this._physicsEngine = physicsEngine;
|
||||
|
|
@ -36,8 +36,7 @@ define(['Doll'], function(){
|
|||
|
||||
Player.prototype.setStanding = function(isStanding) {
|
||||
var resetStates = ['jump', 'jumploop'];
|
||||
if (resetStates.indexOf(this._currentAnimationState)>=0 && !this._standing && isStanding)
|
||||
{
|
||||
if (resetStates.indexOf(this._currentAnimationState)>=0 && !this._standing && isStanding) {
|
||||
this._animate('stand');
|
||||
}
|
||||
this._standing = isStanding;
|
||||
|
|
@ -52,15 +51,15 @@ define(['Doll'], function(){
|
|||
|
||||
switch(true) {
|
||||
case direction == this._lookDirection && this.isStanding():
|
||||
this._doll.move(direction, Chuck.Settings.RUN_SPEED);
|
||||
this._doll.move(direction, Settings.RUN_SPEED);
|
||||
break;
|
||||
|
||||
case !this.isStanding():
|
||||
this._doll.move(direction, Chuck.Settings.FLY_SPEED);
|
||||
this._doll.move(direction, Settings.FLY_SPEED);
|
||||
break;
|
||||
|
||||
default:
|
||||
this._doll.move(direction, Chuck.Settings.WALK_SPEED);
|
||||
this._doll.move(direction, Settings.WALK_SPEED);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -78,8 +77,7 @@ define(['Doll'], function(){
|
|||
}
|
||||
|
||||
Player.prototype.jump = function() {
|
||||
if (this.isStanding())
|
||||
{
|
||||
if (this.isStanding()) {
|
||||
this._doll.jump();
|
||||
this._animate('jump');
|
||||
this.setStanding(false);
|
||||
|
|
@ -123,15 +121,15 @@ define(['Doll'], function(){
|
|||
|
||||
Player.prototype.look = function(x, y) {
|
||||
/*
|
||||
var degree = Math.atan2(Chuck.Settings.STAGE_WIDTH / 2 - x, Chuck.Settings.STAGE_HEIGHT / 2 - 25 - y) / (Math.PI / 180);
|
||||
var degree = Math.atan2(Settings.STAGE_WIDTH / 2 - x, Settings.STAGE_HEIGHT / 2 - 25 - y) / (Math.PI / 180);
|
||||
var lastLookDirection = this._lookDirection;
|
||||
|
||||
if (x < Chuck.Settings.STAGE_WIDTH / 2) {
|
||||
if (x < Settings.STAGE_WIDTH / 2) {
|
||||
this._mc.scaleX = -1;
|
||||
this._lookDirection = -1;
|
||||
degree = (-45 + degree / 2);
|
||||
this._mc.head.rotation = degree;
|
||||
} else if (x >= Chuck.Settings.STAGE_WIDTH / 2) {
|
||||
} else if (x >= Settings.STAGE_WIDTH / 2) {
|
||||
this._mc.scaleX = 1;
|
||||
this._lookDirection = 1;
|
||||
degree = (45 + -degree / 2) - 90;
|
||||
|
|
@ -155,7 +153,7 @@ define(['Doll'], function(){
|
|||
// called by CollisionDetection
|
||||
Player.prototype.onFootSensorDetection = function(isColliding) {
|
||||
if(isColliding) {
|
||||
if(this._doll.getBody().GetLinearVelocity().y < -Chuck.Settings.JUMP_SPEED && !this.isStanding()) {
|
||||
if(this._doll.getBody().GetLinearVelocity().y < -Settings.JUMP_SPEED && !this.isStanding()) {
|
||||
return;
|
||||
}
|
||||
this.setStanding(true);
|
||||
|
|
@ -180,4 +178,6 @@ define(['Doll'], function(){
|
|||
this.setStanding(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Player;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue