mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
replaced all tabs with 4 spaces
This commit is contained in:
parent
5d11540c55
commit
26f3d22db7
30 changed files with 1017 additions and 1011 deletions
2
app/Game/Core/Control/InputController.js
Normal file → Executable file
2
app/Game/Core/Control/InputController.js
Normal file → Executable file
|
|
@ -31,7 +31,7 @@ define(function(){
|
|||
|
||||
InputController.prototype.jumping = function() {
|
||||
if (this._isJumping) {
|
||||
this.player.jumping();
|
||||
this.player.jumping();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,36 +1,36 @@
|
|||
define([
|
||||
"Game/Config/Settings",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Game/Core/Collision/Detector"
|
||||
"Game/Config/Settings",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Game/Core/Collision/Detector"
|
||||
],
|
||||
|
||||
function(Settings, Box2D, CollisionDetector) {
|
||||
|
||||
function Engine () {
|
||||
this.world = new Box2D.Dynamics.b2World(
|
||||
new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY),
|
||||
Settings.BOX2D_ALLOW_SLEEP
|
||||
);
|
||||
}
|
||||
function Engine () {
|
||||
this.world = new Box2D.Dynamics.b2World(
|
||||
new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY),
|
||||
Settings.BOX2D_ALLOW_SLEEP
|
||||
);
|
||||
}
|
||||
|
||||
Engine.prototype.getWorld = function() {
|
||||
return this.world;
|
||||
}
|
||||
Engine.prototype.getWorld = function() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
Engine.prototype.setCollisionDetector = function(me) {
|
||||
|
||||
var detector = new CollisionDetector(me); // FIXME: check if core collision detector works
|
||||
this.world.SetContactListener(detector.getListener());
|
||||
}
|
||||
Engine.prototype.setCollisionDetector = function(me) {
|
||||
|
||||
var detector = new CollisionDetector(me); // FIXME: check if core collision detector works
|
||||
this.world.SetContactListener(detector.getListener());
|
||||
}
|
||||
|
||||
Engine.prototype.createBody = function(bodyDef) {
|
||||
return this.world.CreateBody(bodyDef);
|
||||
}
|
||||
Engine.prototype.createBody = function(bodyDef) {
|
||||
return this.world.CreateBody(bodyDef);
|
||||
}
|
||||
|
||||
Engine.prototype.update = function() {
|
||||
this.world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS);
|
||||
this.world.ClearForces();
|
||||
}
|
||||
Engine.prototype.update = function() {
|
||||
this.world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS);
|
||||
this.world.ClearForces();
|
||||
}
|
||||
|
||||
return Engine;
|
||||
return Engine;
|
||||
});
|
||||
312
app/Game/Core/Player.js
Normal file → Executable file
312
app/Game/Core/Player.js
Normal file → Executable file
|
|
@ -1,193 +1,193 @@
|
|||
define([
|
||||
"Game/Core/Physics/Doll",
|
||||
"Game/Config/Settings"
|
||||
"Game/Core/Physics/Doll",
|
||||
"Game/Config/Settings"
|
||||
],
|
||||
|
||||
function(Doll, Settings) {
|
||||
|
||||
function Player (id, physicsEngine, repository) {
|
||||
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.init(id);
|
||||
}
|
||||
function Player (id, physicsEngine, repository) {
|
||||
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.init(id);
|
||||
}
|
||||
|
||||
Player.prototype.init = function(id) {
|
||||
this.doll = new Doll(this.physicsEngine, id);
|
||||
//this.mc = EmbedHandler.load(EmbedHandler.CHUCK);
|
||||
//this.mc.stop();
|
||||
//var mclp = new MovieClipLabelParser();
|
||||
//mclp.parse(this.mc);
|
||||
}
|
||||
Player.prototype.init = function(id) {
|
||||
this.doll = new Doll(this.physicsEngine, id);
|
||||
//this.mc = EmbedHandler.load(EmbedHandler.CHUCK);
|
||||
//this.mc.stop();
|
||||
//var mclp = new MovieClipLabelParser();
|
||||
//mclp.parse(this.mc);
|
||||
}
|
||||
|
||||
Player.prototype.spawn = function(x, y) {
|
||||
//this.repository.createModel(this.mc, this.doll.getBody());
|
||||
this.doll.spawn(x, y);
|
||||
}
|
||||
Player.prototype.spawn = function(x, y) {
|
||||
//this.repository.createModel(this.mc, this.doll.getBody());
|
||||
this.doll.spawn(x, y);
|
||||
}
|
||||
|
||||
Player.prototype.getDoll = function() {
|
||||
return this.doll;
|
||||
}
|
||||
Player.prototype.getDoll = function() {
|
||||
return this.doll;
|
||||
}
|
||||
|
||||
Player.prototype.getBody = function() {
|
||||
return this.doll.getBody();
|
||||
}
|
||||
Player.prototype.getBody = function() {
|
||||
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');
|
||||
}
|
||||
this.standing = isStanding;
|
||||
}
|
||||
Player.prototype.setStanding = function(isStanding) {
|
||||
var resetStates = ['jump', 'jumploop'];
|
||||
if (resetStates.indexOf(this.currentAnimationState)>=0 && !this.standing && isStanding) {
|
||||
this.animate('stand');
|
||||
}
|
||||
this.standing = isStanding;
|
||||
}
|
||||
|
||||
Player.prototype.isStanding = function() {
|
||||
return this.standing;
|
||||
}
|
||||
Player.prototype.isStanding = function() {
|
||||
return this.standing;
|
||||
}
|
||||
|
||||
Player.prototype.move = function(direction) {
|
||||
this.moveDirection = direction;
|
||||
|
||||
switch(true) {
|
||||
case direction == this.lookDirection && this.isStanding():
|
||||
this.doll.move(direction, Settings.RUN_SPEED);
|
||||
break;
|
||||
Player.prototype.move = function(direction) {
|
||||
this.moveDirection = direction;
|
||||
|
||||
switch(true) {
|
||||
case direction == this.lookDirection && this.isStanding():
|
||||
this.doll.move(direction, Settings.RUN_SPEED);
|
||||
break;
|
||||
|
||||
case !this.isStanding():
|
||||
this.doll.move(direction, Settings.FLY_SPEED);
|
||||
break;
|
||||
case !this.isStanding():
|
||||
this.doll.move(direction, Settings.FLY_SPEED);
|
||||
break;
|
||||
|
||||
default:
|
||||
this.doll.move(direction, Settings.WALK_SPEED);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
this.doll.move(direction, Settings.WALK_SPEED);
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.isStanding()) {
|
||||
this.animate(this.calculateWalkAnimation());
|
||||
}
|
||||
}
|
||||
if (this.isStanding()) {
|
||||
this.animate(this.calculateWalkAnimation());
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.stop = function() {
|
||||
this.moveDirection = 0;
|
||||
this.doll.stop();
|
||||
if (this.isWalking() || this.standing) {
|
||||
this.animate('stand');
|
||||
}
|
||||
}
|
||||
Player.prototype.stop = function() {
|
||||
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.setStanding(false);
|
||||
}
|
||||
}
|
||||
Player.prototype.jump = function() {
|
||||
if (this.isStanding()) {
|
||||
this.doll.jump();
|
||||
this.animate('jump');
|
||||
this.setStanding(false);
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.jumping = function() {
|
||||
if (!this.isStanding()) {
|
||||
this.doll.jumping();
|
||||
}
|
||||
}
|
||||
Player.prototype.jumping = function() {
|
||||
if (!this.isStanding()) {
|
||||
this.doll.jumping();
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.duck = function() {
|
||||
if (this.standing && !this.isWalking()) {
|
||||
this.animate('duck');
|
||||
}
|
||||
}
|
||||
Player.prototype.duck = function() {
|
||||
if (this.standing && !this.isWalking()) {
|
||||
this.animate('duck');
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.standUp = function() {
|
||||
if (this.standing) {
|
||||
this.animate('standup');
|
||||
}
|
||||
}
|
||||
Player.prototype.standUp = function() {
|
||||
if (this.standing) {
|
||||
this.animate('standup');
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.animate = function(type) {
|
||||
if (type == this.currentAnimationState) {
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
return 'run';
|
||||
}
|
||||
return 'walkback';
|
||||
}
|
||||
Player.prototype.calculateWalkAnimation = function() {
|
||||
if (this.moveDirection == this.lookDirection) {
|
||||
return 'run';
|
||||
}
|
||||
return 'walkback';
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
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 >= Settings.STAGE_WIDTH / 2) {
|
||||
this.mc.scaleX = 1;
|
||||
this.lookDirection = 1;
|
||||
degree = (45 + -degree / 2) - 90;
|
||||
this.mc.head.rotation = degree;
|
||||
}
|
||||
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 >= 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());
|
||||
}*/
|
||||
}
|
||||
if (this.lookDirection != lastLookDirection && this.isWalking()) {
|
||||
this.animate(this.calculateWalkAnimation());
|
||||
}*/
|
||||
}
|
||||
|
||||
Player.prototype.isWalking = function() {
|
||||
var states = ['walk', 'walkback', 'run'];
|
||||
Player.prototype.isWalking = function() {
|
||||
var states = ['walk', 'walkback', 'run'];
|
||||
|
||||
if (states.indexOf(this.currentAnimationState) >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (states.indexOf(this.currentAnimationState) >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// called by CollisionDetection
|
||||
Player.prototype.onFootSensorDetection = function(isColliding) {
|
||||
if(isColliding) {
|
||||
if(this.doll.getBody().GetLinearVelocity().y < -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
|
||||
// called by CollisionDetection
|
||||
Player.prototype.onFootSensorDetection = function(isColliding) {
|
||||
if(isColliding) {
|
||||
if(this.doll.getBody().GetLinearVelocity().y < -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');
|
||||
}
|
||||
}
|
||||
//this.setStanding(false);
|
||||
//this.animate('jumploop');
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.update = function() {
|
||||
//this.mc.head.y = this.mc.head_posmask.y;
|
||||
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().GetLinearVelocity().x == 0 && this.isWalking()) {
|
||||
this.stop();
|
||||
}
|
||||
|
||||
if (!this.doll.getBody().IsAwake()) {
|
||||
this.setStanding(true);
|
||||
}
|
||||
}
|
||||
if (!this.doll.getBody().IsAwake()) {
|
||||
this.setStanding(true);
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.destroy = function() {
|
||||
this.doll.destroy();
|
||||
}
|
||||
Player.prototype.destroy = function() {
|
||||
this.doll.destroy();
|
||||
}
|
||||
|
||||
return Player;
|
||||
return Player;
|
||||
});
|
||||
|
|
|
|||
38
app/Game/Core/Protocol/Helper.js
Normal file → Executable file
38
app/Game/Core/Protocol/Helper.js
Normal file → Executable file
|
|
@ -1,29 +1,29 @@
|
|||
define([
|
||||
"Game/Core/Protocol/Parser"
|
||||
"Game/Core/Protocol/Parser"
|
||||
],
|
||||
|
||||
function(Parser) {
|
||||
|
||||
var Helper = {}
|
||||
var Helper = {}
|
||||
|
||||
Helper.encodeCommand = function(command, options){
|
||||
return Parser.encode(Helper.assemble(command, options));
|
||||
}
|
||||
Helper.encodeCommand = function(command, options){
|
||||
return Parser.encode(Helper.assemble(command, options));
|
||||
}
|
||||
|
||||
Helper.assemble = function(command, options){
|
||||
var commands = {};
|
||||
commands[command] = options || null;
|
||||
return commands;
|
||||
}
|
||||
Helper.assemble = function(command, options){
|
||||
var commands = {};
|
||||
commands[command] = options || null;
|
||||
return commands;
|
||||
}
|
||||
|
||||
Helper.runCommands = function(message, callback){
|
||||
var commands = Parser.decode(message);
|
||||
|
||||
for(var command in commands) {
|
||||
callback(command, commands[command]);
|
||||
}
|
||||
}
|
||||
Helper.runCommands = function(message, callback){
|
||||
var commands = Parser.decode(message);
|
||||
|
||||
for(var command in commands) {
|
||||
callback(command, commands[command]);
|
||||
}
|
||||
}
|
||||
|
||||
return Helper;
|
||||
|
||||
return Helper;
|
||||
|
||||
});
|
||||
16
app/Game/Core/Protocol/Parser.js
Normal file → Executable file
16
app/Game/Core/Protocol/Parser.js
Normal file → Executable file
|
|
@ -3,15 +3,15 @@ define([
|
|||
|
||||
function() {
|
||||
|
||||
var Parser = {};
|
||||
var Parser = {};
|
||||
|
||||
Parser.encode = function(message){
|
||||
return JSON.stringify(message);
|
||||
}
|
||||
Parser.encode = function(message){
|
||||
return JSON.stringify(message);
|
||||
}
|
||||
|
||||
Parser.decode = function(message){
|
||||
return JSON.parse(message);
|
||||
}
|
||||
Parser.decode = function(message){
|
||||
return JSON.parse(message);
|
||||
}
|
||||
|
||||
return Parser;
|
||||
return Parser;
|
||||
});
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
define(function() {
|
||||
|
||||
function User(id) {
|
||||
this.id = id;
|
||||
}
|
||||
function User(id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
return User;
|
||||
return User;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue