restructured repository

This commit is contained in:
logsol 2012-06-13 17:27:42 +02:00
parent cc6279eac9
commit 080a2e410c
38 changed files with 87 additions and 26 deletions

View file

@ -1,33 +0,0 @@
Chuck.Collision.Detector = function(me) { //extends b2ContactListener {
this._me = me;
this._listener = new Chuck.b2ContactListener();
this._listener._chuckDetector = this;
this._listener.BeginContact = this.BeginContact;
this._listener.PostSolve = this.PostSolve;
this._listener.EndContact = this.EndContact;
}
Chuck.Collision.Detector.prototype.getListener = function() {
return this._listener;
}
Chuck.Collision.Detector.prototype.handleStand = function(point, isColliding) {
if (point.GetFixtureA().GetUserData() == 'myFeet' || point.GetFixtureB().GetUserData() == 'myFeet') {
this._me.onFootSensorDetection(isColliding);
}
}
/** Extension **/
Chuck.Collision.Detector.prototype.BeginContact = function(point) {
this._chuckDetector.handleStand(point, true);
}
Chuck.Collision.Detector.prototype.PostSolve = function(point, impulse) {
this._chuckDetector.handleStand(point, true);
}
Chuck.Collision.Detector.prototype.EndContact = function(point) {
this._chuckDetector.handleStand(point, false);
}

View file

@ -1,62 +0,0 @@
var Chuck = {
Physics: {},
Loader: {},
Control: {},
Collision: {},
b2Vec2 : Box2D.Common.Math.b2Vec2,
b2AABB : Box2D.Collision.b2AABB,
b2BodyDef : Box2D.Dynamics.b2BodyDef,
b2Body : Box2D.Dynamics.b2Body,
b2FixtureDef : Box2D.Dynamics.b2FixtureDef,
b2Fixture : Box2D.Dynamics.b2Fixture,
b2World : Box2D.Dynamics.b2World,
b2MassData : Box2D.Collision.Shapes.b2MassData,
b2PolygonShape : Box2D.Collision.Shapes.b2PolygonShape,
b2CircleShape : Box2D.Collision.Shapes.b2CircleShape,
b2DebugDraw : Box2D.Dynamics.b2DebugDraw,
b2MouseJointDef : Box2D.Dynamics.Joints.b2MouseJointDef,
b2ContactListener : Box2D.Dynamics.b2ContactListener
};
Chuck.Settings = {
STAGE_WIDTH : 600,
STAGE_HEIGHT : 400,
// BOX2D INITIALATORS
RATIO : 35,
BOX2D_WORLD_AABB_SIZE : 3000,
BOX2D_ALLOW_SLEEP : true,
BOX2D_GRAVITY : 16,
BOX2D_VELOCITY_ITERATIONS : 5,
BOX2D_POSITION_ITERATIONS : 5,
BOX2D_TIME_STEP : 1 / 30,
// GRAPHIC PATHS
GRAPHICS_PATH : 'img',
GRAPHICS_SUBPATH_ITEMS : 'Items',
GRAPHICS_SUBPATH_CHARACTERS : 'Characters',
TILE_SIZE : 15,
// GAME PLAY
WALK_SPEED : 2.5,
RUN_SPEED : 4.0,
FLY_SPEED : 3.2,
JUMP_SPEED : 3.0,
// restitution : bouncyness, friction : rubbing, density : mass
TILE_FRICTION : 0.99,
TILE_RESTITUTION : 0.1,
PLAYER_DENSITY : 0.96,
PLAYER_FRICTION : 5,
PLAYER_MOTION_FRICTION : 0.1,
PLAYER_RESTITUTION : 0.0,
PLAYER_LINEAR_DAMPING : .5,
ITEM_DENSITY : 0.9,
ITEM_FRICTION : 0.99,
ITEM_RESTITUTION : 0.02
}

View file

@ -1,68 +0,0 @@
Chuck.Control.InputControlUnit = function(ki, me) {
this._ki = ki;
this._me = me;
this._shift;
this._isJumping;
this.KEY_LEFT = 65;
this.KEY_RIGHT = 68;
this.KEY_UP = 87;
this.KEY_DOWN = 83;
this.init();
}
Chuck.Control.InputControlUnit.prototype.init = function() {
this._ki.setInputControlUnit(this);
this._ki.registerKey(this.KEY_LEFT, 'moveLeft', 'stop', 'moveLeft');
this._ki.registerKey(this.KEY_RIGHT, 'moveRight', 'stop', 'moveRight');
this._ki.registerKey(this.KEY_UP, 'jump', 'jumped', 'jumping');
this._ki.registerKey(this.KEY_DOWN, 'duck', 'standUp', 'duck');
this._ki.registerKey(this.KEY_DOWN, 'activateShift', 'activateShift', 'deactivateShift');
}
Chuck.Control.InputControlUnit.prototype.moveLeft = function() {
this._me.move(-1);
}
Chuck.Control.InputControlUnit.prototype.moveRight = function() {
this._me.move(1);
}
Chuck.Control.InputControlUnit.prototype.stop = function() {
this._me.stop();
}
Chuck.Control.InputControlUnit.prototype.jump = function() {
this._isJumping = true;
this._me.jump();
}
Chuck.Control.InputControlUnit.prototype.jumped = function() {
this._isJumping = false;
}
Chuck.Control.InputControlUnit.prototype.jumping = function() {
if (this._isJumping) {
this._me.jumping();
}
}
Chuck.Control.InputControlUnit.prototype.duck = function() {
this._me.duck();
}
Chuck.Control.InputControlUnit.prototype.standUp = function() {
this._me.standUp();
}
Chuck.Control.InputControlUnit.prototype.activateShift = function() {
this._shift = true;
}
Chuck.Control.InputControlUnit.prototype.deactivateShift = function() {
this._shift = false;
}

View file

@ -1,56 +0,0 @@
Chuck.Control.Key = function() {
this._active = false;
this._activityUpdateStatus = false;
this._activityUpdateNeeded = false;
this._keyDown = null;
this._keyUp = null;
this._keyFrame = null;
}
Chuck.Control.Key.prototype.setActivityUpdateStatus = function(active) {
this._activityUpdateStatus = active;
}
Chuck.Control.Key.prototype.getActivityUpdateStatus = function() {
return this._activityUpdateStatus;
}
Chuck.Control.Key.prototype.setActivityUpdateNeeded = function(need) {
this._activityUpdateNeeded = need;
}
Chuck.Control.Key.prototype.getActivityUpdateNeeded = function() {
return this._activityUpdateNeeded;
}
Chuck.Control.Key.prototype.setActive = function(active) {
this._active = active;
}
Chuck.Control.Key.prototype.getActive = function() {
return this._active;
}
Chuck.Control.Key.prototype.setKeyDownFunction = function(f) {
this._keyDown = f;
}
Chuck.Control.Key.prototype.getKeyDownFunction = function() {
return this._keyDown;
}
Chuck.Control.Key.prototype.setKeyUpFunction = function(f) {
this._keyUp = f;
}
Chuck.Control.Key.prototype.getKeyUpFunction = function() {
return this._keyUp;
}
Chuck.Control.Key.prototype.setKeyFrameFunction = function(f) {
this._keyFrame = f;
}
Chuck.Control.Key.prototype.getKeyFrameFunction = function() {
return this._keyFrame;
}

View file

@ -1,72 +0,0 @@
Chuck.Control.KeyboardInput = function() {
this._registry = {};
this._inputControlUnit = null;
this.init();
}
Chuck.Control.KeyboardInput.prototype.init = function() {
$(window).keydown($.proxy(this._onKeyDown, this));
$(window).keyup($.proxy(this._onKeyUp, this));
}
Chuck.Control.KeyboardInput.prototype.setInputControlUnit = function(inputControlUnit) {
this._inputControlUnit = inputControlUnit;
}
Chuck.Control.KeyboardInput.prototype.registerKey = function(keyCode, onKeyDown, onKeyUp, onKeyFrame) {
var key = new Chuck.Control.Key();
key.setKeyDownFunction(onKeyDown);
key.setKeyUpFunction(onKeyUp);
key.setKeyFrameFunction(onKeyFrame);
this._registry[keyCode] = key;
}
Chuck.Control.KeyboardInput.prototype._getKeyByKeyCode = function(keyCode) {
return this._registry[keyCode];
}
Chuck.Control.KeyboardInput.prototype._onKeyDown = function(e) {
var key = this._getKeyByKeyCode(e.keyCode);
if (key && key.getActive() == false) {
key.setActivityUpdateStatus(true);
key.setActivityUpdateNeeded(true);
}
}
Chuck.Control.KeyboardInput.prototype._onKeyUp = function(e) {
var key = this._getKeyByKeyCode(e.keyCode);
if (key != null) {
key.setActivityUpdateStatus(false);
key.setActivityUpdateNeeded(true);
}
}
Chuck.Control.KeyboardInput.prototype.update = function() {
var callback = null;
var self = this;
$.each(this._registry, function(keyCode, key) {
if (key.getActivityUpdateNeeded()) {
if (key.getActivityUpdateStatus() == true) {
callback = key.getKeyDownFunction();
key.setActive(true);
} else {
callback = key.getKeyUpFunction();
key.setActive(false);
}
key.setActivityUpdateNeeded(false);
}
if (callback) {
self._inputControlUnit[callback]();
} else {
if (key.getActive()) {
callback = key.getKeyFrameFunction();
if (callback) {
self._inputControlUnit[callback]();
}
}
}
callback = null;
});
}

View file

@ -1,139 +0,0 @@
Chuck.Loader.Level = function(engine) {
this._engine = engine;
this.init();
}
Chuck.Loader.Level.prototype.init = function() {
this.load();
}
Chuck.Loader.Level.prototype.load = function() {
$.get('xml/level.xml', $.proxy(this.process, this));
}
Chuck.Loader.Level.prototype.process = function(xml) {
var objects, tile;
objects = $(xml).find('tile');
for (var i = 0; i < objects.length; i++) {
var tile = {
shape: objects[i].attributes.shape
? parseInt(objects[i].attributes.shape.value)
: 1,
x: objects[i].attributes.x
? parseInt(objects[i].attributes.x.value) * Chuck.Settings.TILE_SIZE
: 0,
y: objects[i].attributes.y
? parseInt(objects[i].attributes.y.value) * Chuck.Settings.TILE_SIZE
: 0,
rotation: objects[i].attributes.rotation
? parseInt(objects[i].attributes.rotation.value)
: 0
}
this.createPhysicTile(tile);
}
}
Chuck.Loader.Level.prototype.generateAllTiles = function() {
// GENERATING ALL POSSIBLE TILE SHAPES
var xpos= 185;
var ypos = 150;
var space = 0;
for (var i = 0; i < 8; i++)
{
for (var r = 0; r < 4; r++)
{
this.createPhysicTile(i+1, xpos + r * (Chuck.Settings.TILE_SIZE + space), ypos + i * (Chuck.Settings.TILE_SIZE + space), r);
}
}
}
Chuck.Loader.Level.prototype.createPhysicTile = function(tile) {
if(tile.rotation == undefined){
tile.rotation = 0;
}
var tileSize = Chuck.Settings.TILE_SIZE;
var vertices = [];
switch(tile.shape) {
case 1:
vertices[0] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, -tileSize / 2 / Chuck.Settings.RATIO); // o o o
vertices[1] = new Chuck.b2Vec2( tileSize / 2 / Chuck.Settings.RATIO, -tileSize / 2 / Chuck.Settings.RATIO); // o o o
vertices[2] = new Chuck.b2Vec2( tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO); // o o o
vertices[3] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO);
break;
case 2:
vertices[0] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, -tileSize / 2 / Chuck.Settings.RATIO); // o
vertices[1] = new Chuck.b2Vec2( tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO); // o o
vertices[2] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO); // o o o
break;
case 3:
vertices[0] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, -tileSize / 2 / Chuck.Settings.RATIO); // o
vertices[1] = new Chuck.b2Vec2( 0, tileSize / 2 / Chuck.Settings.RATIO); // o
vertices[2] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO); // o o
break;
case 4:
vertices[0] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, -tileSize / 2 / Chuck.Settings.RATIO); // o
vertices[1] = new Chuck.b2Vec2( tileSize / 2 / Chuck.Settings.RATIO, 0 ); // o o o
vertices[2] = new Chuck.b2Vec2( tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO); // o o o
vertices[3] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO);
break;
case 5:
vertices[0] = new Chuck.b2Vec2( tileSize / 2 / Chuck.Settings.RATIO, -tileSize / 2 / Chuck.Settings.RATIO); // o
vertices[1] = new Chuck.b2Vec2( tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO); // o
vertices[2] = new Chuck.b2Vec2( 0 , tileSize / 2 / Chuck.Settings.RATIO); // o o
break;
case 6:
vertices[0] = new Chuck.b2Vec2( tileSize / 2 / Chuck.Settings.RATIO, -tileSize / 2 / Chuck.Settings.RATIO); // o
vertices[1] = new Chuck.b2Vec2( tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO); // o o o
vertices[2] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO); // o o o
vertices[3] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, 0 );
break;
case 7:
vertices[0] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, 0 ); //
vertices[1] = new Chuck.b2Vec2( 0 , tileSize / 2 / Chuck.Settings.RATIO); // o
vertices[2] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO); // o o
break;
case 8:
vertices[0] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, -tileSize / 2 / Chuck.Settings.RATIO);// o o
vertices[1] = new Chuck.b2Vec2( 0 , -tileSize / 2 / Chuck.Settings.RATIO);// o o o
vertices[2] = new Chuck.b2Vec2( tileSize / 2 / Chuck.Settings.RATIO, 0 ); // o o o
vertices[3] = new Chuck.b2Vec2( tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO);
vertices[4] = new Chuck.b2Vec2(-tileSize / 2 / Chuck.Settings.RATIO, tileSize / 2 / Chuck.Settings.RATIO);
break;
default:
break;
}
var bodyDef = new Chuck.b2BodyDef();
bodyDef.type = Chuck.b2Body.b2_staticBody;
bodyDef.position.x = tile.x / Chuck.Settings.RATIO;
bodyDef.position.y = tile.y / Chuck.Settings.RATIO;
bodyDef.angle = tile.rotation * 90 * Math.PI / 180;
var tileShape = new Chuck.b2PolygonShape;
tileShape.SetAsArray(vertices, vertices.length);
var fixtureDef = new Chuck.b2FixtureDef();
fixtureDef.shape = tileShape;
fixtureDef.density = 0;
fixtureDef.friction = Chuck.Settings.TILE_FRICTION;
fixtureDef.restitution = Chuck.Settings.TILE_RESTITUTION;
fixtureDef.isSensor = false;
fixtureDef.userData = 'tile';
var body = this._engine.createBody(bodyDef);
body.CreateFixture(fixtureDef);
}

View file

@ -1,5 +0,0 @@
Chuck.Main = function () {
// Settings were loaded automatically
var processor = new Chuck.Processor();
processor.init();
};

View file

@ -1,104 +0,0 @@
Chuck.Physics.Doll = function(engine){
this._engine = engine;
this._body;
this._legs;
this._contactPoint;
this.init(this._engine.getWorld());
}
Chuck.Physics.Doll.prototype.init = function (world) {
var bodyDef = new Chuck.b2BodyDef();
bodyDef.position.x = 220 / Chuck.Settings.RATIO;
bodyDef.position.y = 0 / Chuck.Settings.RATIO;
bodyDef.fixedRotation = true;
bodyDef.linearDamping = Chuck.Settings.PLAYER_LINEAR_DAMPING;
bodyDef.type = Chuck.b2Body.b2_dynamicBody;
this._body = world.CreateBody(bodyDef);
var fixtureDef = new Chuck.b2FixtureDef();
fixtureDef.density = Chuck.Settings.PLAYER_DENSITY;
fixtureDef.friction = 0;
fixtureDef.restitution = Chuck.Settings.PLAYER_RESTITUTION;
var headShape = new Chuck.b2CircleShape();
headShape.SetRadius(5 / Chuck.Settings.RATIO);
headShape.SetLocalPosition(new Chuck.b2Vec2(0 / Chuck.Settings.RATIO, -37 / Chuck.Settings.RATIO));
fixtureDef.shape = headShape;
fixtureDef.isSensor = false;
fixtureDef.userData = 'myHead';
this._body.CreateFixture(fixtureDef);
var bodyShape = new Chuck.b2PolygonShape();
bodyShape.SetAsOrientedBox(5 / Chuck.Settings.RATIO, 16 / Chuck.Settings.RATIO, new Chuck.b2Vec2(0 / Chuck.Settings.RATIO, -21 / Chuck.Settings.RATIO));
fixtureDef.shape = bodyShape;
fixtureDef.isSensor = false;
fixtureDef.userData = 'myBody';
this._body.CreateFixture(fixtureDef);
var legsShape = new Chuck.b2CircleShape();
legsShape.SetRadius(5 / Chuck.Settings.RATIO);
legsShape.SetLocalPosition(new Chuck.b2Vec2(0 / Chuck.Settings.RATIO, -5 / Chuck.Settings.RATIO));
fixtureDef.shape = legsShape;
fixtureDef.friction = Chuck.Settings.PLAYER_FRICTION;
fixtureDef.isSensor = false;
fixtureDef.userData = 'myLegs';
this._legs = this._body.CreateFixture(fixtureDef);
var feetShape = new Chuck.b2CircleShape();
feetShape.SetRadius(4 / Chuck.Settings.RATIO);
feetShape.SetLocalPosition(new Chuck.b2Vec2(0 / Chuck.Settings.RATIO, 0 / Chuck.Settings.RATIO));
fixtureDef.shape = feetShape;
fixtureDef.isSensor = true;
fixtureDef.userData = 'myFeet';
this._body.CreateFixture(fixtureDef);
this._body.SetActive(false);
}
Chuck.Physics.Doll.prototype.spawn = function (x, y) {
this._body.SetPosition(new Chuck.b2Vec2(x / Chuck.Settings.RATIO, y / Chuck.Settings.RATIO));
this._body.SetActive(true);
}
Chuck.Physics.Doll.prototype.getBody = function () {
return this._body;
}
Chuck.Physics.Doll.prototype._setFriction = function (friction) {
if(!friction) friction = -1;
if (this._legs.GetFriction() != friction)
{
this._legs.SetFriction(friction);
}
}
Chuck.Physics.Doll.prototype.move = function (direction, speed) {
this._setFriction(Chuck.Settings.PLAYER_MOTION_FRICTION);
this._body.SetAwake(true);
var vector = new Chuck.b2Vec2(speed * direction, this._body.GetLinearVelocity().y);
this._body.SetLinearVelocity(vector);
}
Chuck.Physics.Doll.prototype.stop = function () {
this._setFriction(Chuck.Settings.PLAYER_FRICTION);
}
Chuck.Physics.Doll.prototype.jump = function () {
this._body.SetAwake(true);
var vector = new Chuck.b2Vec2(0, -Chuck.Settings.JUMP_SPEED);
this._body.ApplyImpulse(vector, this._body.GetPosition());
// maybe change to a constant force instead of applying of force?
// to prevent higher jumping running uphill, etc.
}
Chuck.Physics.Doll.prototype.jumping = function () {
var vector = new Chuck.b2Vec2(0, -0.1);
this._body.ApplyImpulse(vector, this._body.GetPosition());
}

View file

@ -1,63 +0,0 @@
Chuck.Physics.Engine = function () {
this._world;
this.init();
}
Chuck.Physics.Engine.prototype.init = function() {
this._world = this._initBox2d();
this.setupDebugDraw();
}
Chuck.Physics.Engine.prototype._initBox2d = function() {
return new Chuck.b2World(new Chuck.b2Vec2(0,Chuck.Settings.BOX2D_GRAVITY), Chuck.Settings.BOX2D_ALLOW_SLEEP);
}
Chuck.Physics.Engine.prototype.getWorld = function() {
return this._world;
}
Chuck.Physics.Engine.prototype.setCollisionDetector = function(me) {
var cd = new Chuck.Collision.Detector(me);
var listener = cd.getListener();
this._world.SetContactListener(listener);
}
Chuck.Physics.Engine.prototype.setupDebugDraw = function() {
//var debugSprite = new Sprite();
//View.getInstance().add(debugSprite);
var debugSprite = document.getElementById("canvas").getContext("2d");
// set debug draw
var dbgDraw = new Chuck.b2DebugDraw();
dbgDraw.SetSprite(debugSprite);
dbgDraw.SetDrawScale(Chuck.Settings.RATIO);
dbgDraw.SetAlpha(0.5);
dbgDraw.SetFillAlpha(0.1);
dbgDraw.SetLineThickness(0);
dbgDraw.SetFlags(null
| Chuck.b2DebugDraw.e_shapeBit
//| b2DebugDraw.e_jointBit
//| b2DebugDraw.e_coreShapeBit
//| b2DebugDraw.e_aabbBit
//| b2DebugDraw.e_centerOfMassBit
//| b2DebugDraw.e_obbBit
//| b2DebugDraw.e_pairBit
);
this._world.SetDebugDraw(dbgDraw);
this._world.SetWarmStarting(true);
}
Chuck.Physics.Engine.prototype.createBody = function(bodyDef) {
return this._world.CreateBody(bodyDef);
}
Chuck.Physics.Engine.prototype.update = function() {
this._world.Step(Chuck.Settings.BOX2D_TIME_STEP, Chuck.Settings.BOX2D_VELOCITY_ITERATIONS, Chuck.Settings.BOX2D_POSITION_ITERATIONS);
this._world.ClearForces();
this._world.DrawDebugData();
}

View file

@ -1,179 +0,0 @@
Chuck.Player = function(engine, repository) {
this._engine = engine;
this._repository = repository;
this._standing = false;
this._doll;
this._mc;
this._currentAnimationState = 'stand';
this._lookDirection = 1;
this._moveDirection = 0;
this.init();
}
Chuck.Player.prototype.init = function() {
this._doll = new Chuck.Physics.Doll(this._engine);
//this._mc = EmbedHandler.load(EmbedHandler.CHUCK);
//this._mc.stop();
//var mclp = new MovieClipLabelParser();
//mclp.parse(this._mc);
}
Chuck.Player.prototype.spawn = function(x, y) {
//this._repository.createModel(this._mc, this._doll.getBody());
this._doll.spawn(x, y);
}
Chuck.Player.prototype.getDoll = function() {
return this._doll;
}
Chuck.Player.prototype.getBody = function() {
return this._doll.getBody();
}
Chuck.Player.prototype.setStanding = function(isStanding) {
var resetStates = ['jump', 'jumploop'];
if (resetStates.indexOf(this._currentAnimationState)>=0 && !this._standing && isStanding)
{
this._animate('stand');
}
this._standing = isStanding;
}
Chuck.Player.prototype.isStanding = function() {
return this._standing;
}
Chuck.Player.prototype.move = function(direction) {
this._moveDirection = direction;
switch(true) {
case direction == this._lookDirection && this.isStanding():
this._doll.move(direction, Chuck.Settings.RUN_SPEED);
break;
case !this.isStanding():
this._doll.move(direction, Chuck.Settings.FLY_SPEED);
break;
default:
this._doll.move(direction, Chuck.Settings.WALK_SPEED);
break;
}
if (this.isStanding()) {
this._animate(this._calculateWalkAnimation());
}
}
Chuck.Player.prototype.stop = function() {
this._moveDirection = 0;
this._doll.stop();
if (this._isWalking() || this._standing) {
this._animate('stand');
}
}
Chuck.Player.prototype.jump = function() {
if (this.isStanding())
{
this._doll.jump();
this._animate('jump');
this.setStanding(false);
}
}
Chuck.Player.prototype.jumping = function() {
if (!this.isStanding()) {
this._doll.jumping();
}
}
Chuck.Player.prototype.duck = function() {
if (this._standing && !this._isWalking()) {
this._animate('duck');
}
}
Chuck.Player.prototype.standUp = function() {
if (this._standing) {
this._animate('standup');
}
}
Chuck.Player.prototype._animate = function(type) {
if (type == this._currentAnimationState) {
return;
}
//this._mc.gotoAndPlay(type);
this._currentAnimationState = type;
}
Chuck.Player.prototype._calculateWalkAnimation = function() {
if (this._moveDirection == this._lookDirection) {
return 'run';
}
return 'walkback';
}
Chuck.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 lastLookDirection = this._lookDirection;
if (x < Chuck.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) {
this._mc.scaleX = 1;
this._lookDirection = 1;
degree = (45 + -degree / 2) - 90;
this._mc.head.rotation = degree;
}
if (this._lookDirection != lastLookDirection && this._isWalking()) {
this._animate(this._calculateWalkAnimation());
}
}
Chuck.Player.prototype._isWalking = function() {
var states = ['walk', 'walkback', 'run'];
if (states.indexOf(this._currentAnimationState) >= 0) {
return true;
}
return false;
}
// called by CollisionDetection
Chuck.Player.prototype.onFootSensorDetection = function(isColliding) {
if(isColliding) {
if(this._doll.getBody().GetLinearVelocity().y < -Chuck.Settings.JUMP_SPEED && !this.isStanding()) {
return;
}
this.setStanding(true);
} else {
// TODO This needs some more thought to it.
// maybe take a look at collision groups for collision detection,
// to group all tiles together
//this.setStanding(false);
//this._animate('jumploop');
}
}
Chuck.Player.prototype.update = function() {
//this._mc.head.y = this._mc.head_posmask.y;
if (this._doll.getBody().GetLinearVelocity().x == 0 && this._isWalking()) {
this.stop();
}
if (!this._doll.getBody().IsAwake()) {
this.setStanding(true);
}
}

View file

@ -1,54 +0,0 @@
Chuck.Processor = function() {
var self = this;
this.count = 0;
this._me;
this._engine;
this._camera;
this._repository;
this._inputControlUnit;
this._keyboardInput;
}
Chuck.Processor.prototype.init = function() {
this._engine = new Chuck.Physics.Engine();
this._me = new Chuck.Player(this._engine, this._repository);
//this._camera = Camera.getInstance()
//this._repository = Repository.getInstance();
this._engine.setCollisionDetector(this._me);
this._keyboardInput = new Chuck.Control.KeyboardInput();
this._inputControlUnit = new Chuck.Control.InputControlUnit(this._keyboardInput, this._me);
new Chuck.Loader.Level(this._engine);
//new Items();
this._me.spawn(100, 0);
//this._camera.follow(this._me);
window.setInterval(this._update, 1000/60, this);
//View.getInstance().getSprite().addEventListener(Event.ENTER_FRAME, this._update)
}
Chuck.Processor.prototype.getMe = function() {
return this._me;
}
Chuck.Processor.prototype.getEngine = function() {
return this._engine;
}
Chuck.Processor.prototype._update = function(self) {
self.count++;
self._engine.update();
// Order is important
//self._repository.update();
self._keyboardInput.update();
self._me.update();
//self._camera.update();
}