mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
changed function( to function (
This commit is contained in:
parent
26f3d22db7
commit
7e5eeb0a27
36 changed files with 209 additions and 209 deletions
12
app/Game/Core/Collision/Detector.js
Normal file → Executable file
12
app/Game/Core/Collision/Detector.js
Normal file → Executable file
|
|
@ -3,7 +3,7 @@ define([
|
|||
"Game/Core/Collision/Detector"
|
||||
],
|
||||
|
||||
function(Box2D, Parent) {
|
||||
function (Box2D, Parent) {
|
||||
|
||||
function Detector() {
|
||||
this.listener = new Box2D.Dynamics.b2ContactListener();
|
||||
|
|
@ -22,25 +22,25 @@ function(Box2D, Parent) {
|
|||
PLAYER_FOOT_SENSOR: 'footsensor'
|
||||
}
|
||||
|
||||
Detector.prototype.getListener = function() {
|
||||
Detector.prototype.getListener = function () {
|
||||
return this.listener;
|
||||
}
|
||||
|
||||
Detector.prototype.handleStand = function(point, isColliding) {
|
||||
Detector.prototype.handleStand = function (point, isColliding) {
|
||||
throw "Overwrite this function";
|
||||
}
|
||||
|
||||
/** Extension **/
|
||||
|
||||
Detector.prototype.BeginContact = function(point) {
|
||||
Detector.prototype.BeginContact = function (point) {
|
||||
this.chuckDetector.handleStand(point, true);
|
||||
}
|
||||
|
||||
Detector.prototype.PostSolve = function(point, impulse) {
|
||||
Detector.prototype.PostSolve = function (point, impulse) {
|
||||
this.chuckDetector.handleStand(point, true);
|
||||
}
|
||||
|
||||
Detector.prototype.EndContact = function(point) {
|
||||
Detector.prototype.EndContact = function (point) {
|
||||
this.chuckDetector.handleStand(point, false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
define(function(){
|
||||
define(function (){
|
||||
|
||||
function InputController(player) {
|
||||
|
||||
|
|
@ -8,50 +8,50 @@ define(function(){
|
|||
this._isJumping;
|
||||
}
|
||||
|
||||
InputController.prototype.moveLeft = function() {
|
||||
InputController.prototype.moveLeft = function () {
|
||||
this.player.move(-1);
|
||||
}
|
||||
|
||||
InputController.prototype.moveRight = function() {
|
||||
InputController.prototype.moveRight = function () {
|
||||
this.player.move(1);
|
||||
}
|
||||
|
||||
InputController.prototype.stop = function() {
|
||||
InputController.prototype.stop = function () {
|
||||
this.player.stop();
|
||||
}
|
||||
|
||||
InputController.prototype.jump = function() {
|
||||
InputController.prototype.jump = function () {
|
||||
this._isJumping = true;
|
||||
this.player.jump();
|
||||
}
|
||||
|
||||
InputController.prototype.jumped = function() {
|
||||
InputController.prototype.jumped = function () {
|
||||
this._isJumping = false;
|
||||
}
|
||||
|
||||
InputController.prototype.jumping = function() {
|
||||
InputController.prototype.jumping = function () {
|
||||
if (this._isJumping) {
|
||||
this.player.jumping();
|
||||
}
|
||||
}
|
||||
|
||||
InputController.prototype.duck = function() {
|
||||
InputController.prototype.duck = function () {
|
||||
this.player.duck();
|
||||
}
|
||||
|
||||
InputController.prototype.standUp = function() {
|
||||
InputController.prototype.standUp = function () {
|
||||
this.player.standUp();
|
||||
}
|
||||
|
||||
InputController.prototype.activateShift = function() {
|
||||
InputController.prototype.activateShift = function () {
|
||||
this._shift = true;
|
||||
}
|
||||
|
||||
InputController.prototype.deactivateShift = function() {
|
||||
InputController.prototype.deactivateShift = function () {
|
||||
this._shift = false;
|
||||
}
|
||||
|
||||
InputController.prototype.update = function() {
|
||||
InputController.prototype.update = function () {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ define([
|
|||
"Game/Core/Player"
|
||||
],
|
||||
|
||||
function(Engine, Level, Player) {
|
||||
function (Engine, Level, Player) {
|
||||
|
||||
function GameController(physicsEngine) {
|
||||
this.players = {};
|
||||
|
|
@ -16,11 +16,11 @@ function(Engine, Level, Player) {
|
|||
this.physicsEngine = physicsEngine;
|
||||
}
|
||||
|
||||
GameController.prototype.getPhysicsEngine = function() {
|
||||
GameController.prototype.getPhysicsEngine = function () {
|
||||
return this.physicsEngine;
|
||||
}
|
||||
|
||||
GameController.prototype.loadLevel = function(path) {
|
||||
GameController.prototype.loadLevel = function (path) {
|
||||
if (this.level) {
|
||||
this.level.unload();
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ function(Engine, Level, Player) {
|
|||
|
||||
/*
|
||||
|
||||
GameController.prototype.destroy = function() {
|
||||
GameController.prototype.destroy = function () {
|
||||
for(var player in this.players) {
|
||||
this.players[player].destroy();
|
||||
}
|
||||
|
|
@ -39,13 +39,13 @@ function(Engine, Level, Player) {
|
|||
|
||||
|
||||
|
||||
GameController.prototype.userJoined = function(user) {
|
||||
GameController.prototype.userJoined = function (user) {
|
||||
var player = new Player(user.id, this.physicsEngine);
|
||||
this.players[user.id] = player;
|
||||
return player;
|
||||
}
|
||||
|
||||
GameController.prototype.userLeft = function(user) {
|
||||
GameController.prototype.userLeft = function (user) {
|
||||
var player = this.players[user.id];
|
||||
player.destroy();
|
||||
delete this.players[user.id];
|
||||
|
|
|
|||
16
app/Game/Core/Loader/Level.js
Normal file → Executable file
16
app/Game/Core/Loader/Level.js
Normal file → Executable file
|
|
@ -1,4 +1,4 @@
|
|||
define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detector"], function(Settings, Box2D, CollisionDetector) {
|
||||
define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detector"], function (Settings, Box2D, CollisionDetector) {
|
||||
|
||||
// Public
|
||||
function Level(path, engine) {
|
||||
|
|
@ -7,12 +7,12 @@ define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detecto
|
|||
this.levelObject = null;
|
||||
}
|
||||
|
||||
Level.prototype.loadLevelInToEngine = function() {
|
||||
Level.prototype.loadLevelInToEngine = function () {
|
||||
this.loadLevelObjectFromPath(this.path);
|
||||
this.createPhysicTiles();
|
||||
}
|
||||
|
||||
Level.prototype.unload = function() {
|
||||
Level.prototype.unload = function () {
|
||||
// TODO unload level from engine if necessary
|
||||
// Perhaps just remove all bodies?
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detecto
|
|||
}
|
||||
}
|
||||
|
||||
Level.prototype.createPhysicTile = function(tile) {
|
||||
Level.prototype.createPhysicTile = function (tile) {
|
||||
tile.r = tile.r || 0;
|
||||
var vertices = this.createVertices(tile);
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detecto
|
|||
this.engine.createBody(bodyDef).CreateFixture(fixtureDef);
|
||||
}
|
||||
|
||||
Level.prototype.createVertices = function(tile) {
|
||||
Level.prototype.createVertices = function (tile) {
|
||||
var vs = [];
|
||||
|
||||
switch(tile.s) {
|
||||
|
|
@ -119,15 +119,15 @@ define(["Game/Config/Settings", "Lib/Vendor/Box2D", "Game/Core/Collision/Detecto
|
|||
return vs;
|
||||
}
|
||||
|
||||
Level.prototype.mkArg = function(multiplier) {
|
||||
Level.prototype.mkArg = function (multiplier) {
|
||||
return Settings.TILE_SIZE / 2 / Settings.RATIO * multiplier;
|
||||
}
|
||||
|
||||
Level.prototype.addVec = function(vs, m1, m2) {
|
||||
Level.prototype.addVec = function (vs, m1, m2) {
|
||||
return vs.push(new Box2D.Common.Math.b2Vec2(this.mkArg(m1), this.mkArg(m2)));
|
||||
}
|
||||
|
||||
Level.prototype.loadLevelObjectFromPath = function(path) {
|
||||
Level.prototype.loadLevelObjectFromPath = function (path) {
|
||||
|
||||
// TODO: load JSON levelObject from path
|
||||
// s: shape
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
define([
|
||||
],
|
||||
|
||||
function() {
|
||||
function () {
|
||||
|
||||
function NotificationCenter() {
|
||||
this.topics = {};
|
||||
this.subUid = -1;
|
||||
}
|
||||
|
||||
NotificationCenter.prototype.trigger = function(topic) {
|
||||
NotificationCenter.prototype.trigger = function (topic) {
|
||||
|
||||
if (!this.topics[topic]) {
|
||||
throw "No such topic " + topic + ". Could not trigger.";
|
||||
|
|
@ -24,7 +24,7 @@ function() {
|
|||
}
|
||||
}
|
||||
|
||||
NotificationCenter.prototype.on = function(topic, func, context) {
|
||||
NotificationCenter.prototype.on = function (topic, func, context) {
|
||||
|
||||
if (!this.topics[topic]) {
|
||||
this.topics[topic] = [];
|
||||
|
|
@ -40,7 +40,7 @@ function() {
|
|||
return token;
|
||||
}
|
||||
|
||||
NotificationCenter.prototype.off = function(token) {
|
||||
NotificationCenter.prototype.off = function (token) {
|
||||
|
||||
for(var m in this.topics) {
|
||||
if (this.topics[m]) {
|
||||
|
|
|
|||
4
app/Game/Core/Physics/Doll.js
Normal file → Executable file
4
app/Game/Core/Physics/Doll.js
Normal file → Executable file
|
|
@ -1,4 +1,4 @@
|
|||
define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detector"], function(Box2D, Settings, CollisionDetector) {
|
||||
define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detector"], function (Box2D, Settings, CollisionDetector) {
|
||||
|
||||
function Doll (physicsEngine, id){
|
||||
this.id = id;
|
||||
|
|
@ -106,7 +106,7 @@ define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detecto
|
|||
this.body.ApplyImpulse(vector, this.body.GetPosition());
|
||||
}
|
||||
|
||||
Doll.prototype.destroy = function() {
|
||||
Doll.prototype.destroy = function () {
|
||||
this.body.GetWorld().DestroyBody(this.body);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ define([
|
|||
"Game/Core/Collision/Detector"
|
||||
],
|
||||
|
||||
function(Settings, Box2D, CollisionDetector) {
|
||||
function (Settings, Box2D, CollisionDetector) {
|
||||
|
||||
function Engine () {
|
||||
this.world = new Box2D.Dynamics.b2World(
|
||||
|
|
@ -13,21 +13,21 @@ function(Settings, Box2D, CollisionDetector) {
|
|||
);
|
||||
}
|
||||
|
||||
Engine.prototype.getWorld = function() {
|
||||
Engine.prototype.getWorld = function () {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
Engine.prototype.setCollisionDetector = function(me) {
|
||||
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) {
|
||||
Engine.prototype.createBody = function (bodyDef) {
|
||||
return this.world.CreateBody(bodyDef);
|
||||
}
|
||||
|
||||
Engine.prototype.update = function() {
|
||||
Engine.prototype.update = function () {
|
||||
this.world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS);
|
||||
this.world.ClearForces();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ define([
|
|||
"Game/Config/Settings"
|
||||
],
|
||||
|
||||
function(Doll, Settings) {
|
||||
function (Doll, Settings) {
|
||||
|
||||
function Player (id, physicsEngine, repository) {
|
||||
this.physicsEngine = physicsEngine;
|
||||
|
|
@ -19,7 +19,7 @@ function(Doll, Settings) {
|
|||
this.init(id);
|
||||
}
|
||||
|
||||
Player.prototype.init = function(id) {
|
||||
Player.prototype.init = function (id) {
|
||||
this.doll = new Doll(this.physicsEngine, id);
|
||||
//this.mc = EmbedHandler.load(EmbedHandler.CHUCK);
|
||||
//this.mc.stop();
|
||||
|
|
@ -27,20 +27,20 @@ function(Doll, Settings) {
|
|||
//mclp.parse(this.mc);
|
||||
}
|
||||
|
||||
Player.prototype.spawn = function(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() {
|
||||
Player.prototype.getDoll = function () {
|
||||
return this.doll;
|
||||
}
|
||||
|
||||
Player.prototype.getBody = function() {
|
||||
Player.prototype.getBody = function () {
|
||||
return this.doll.getBody();
|
||||
}
|
||||
|
||||
Player.prototype.setStanding = function(isStanding) {
|
||||
Player.prototype.setStanding = function (isStanding) {
|
||||
var resetStates = ['jump', 'jumploop'];
|
||||
if (resetStates.indexOf(this.currentAnimationState)>=0 && !this.standing && isStanding) {
|
||||
this.animate('stand');
|
||||
|
|
@ -48,11 +48,11 @@ function(Doll, Settings) {
|
|||
this.standing = isStanding;
|
||||
}
|
||||
|
||||
Player.prototype.isStanding = function() {
|
||||
Player.prototype.isStanding = function () {
|
||||
return this.standing;
|
||||
}
|
||||
|
||||
Player.prototype.move = function(direction) {
|
||||
Player.prototype.move = function (direction) {
|
||||
this.moveDirection = direction;
|
||||
|
||||
switch(true) {
|
||||
|
|
@ -74,7 +74,7 @@ function(Doll, Settings) {
|
|||
}
|
||||
}
|
||||
|
||||
Player.prototype.stop = function() {
|
||||
Player.prototype.stop = function () {
|
||||
this.moveDirection = 0;
|
||||
this.doll.stop();
|
||||
if (this.isWalking() || this.standing) {
|
||||
|
|
@ -82,7 +82,7 @@ function(Doll, Settings) {
|
|||
}
|
||||
}
|
||||
|
||||
Player.prototype.jump = function() {
|
||||
Player.prototype.jump = function () {
|
||||
if (this.isStanding()) {
|
||||
this.doll.jump();
|
||||
this.animate('jump');
|
||||
|
|
@ -90,25 +90,25 @@ function(Doll, Settings) {
|
|||
}
|
||||
}
|
||||
|
||||
Player.prototype.jumping = function() {
|
||||
Player.prototype.jumping = function () {
|
||||
if (!this.isStanding()) {
|
||||
this.doll.jumping();
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.duck = function() {
|
||||
Player.prototype.duck = function () {
|
||||
if (this.standing && !this.isWalking()) {
|
||||
this.animate('duck');
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.standUp = function() {
|
||||
Player.prototype.standUp = function () {
|
||||
if (this.standing) {
|
||||
this.animate('standup');
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.animate = function(type) {
|
||||
Player.prototype.animate = function (type) {
|
||||
if (type == this.currentAnimationState) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -118,14 +118,14 @@ function(Doll, Settings) {
|
|||
this.currentAnimationState = type;
|
||||
}
|
||||
|
||||
Player.prototype.calculateWalkAnimation = function() {
|
||||
Player.prototype.calculateWalkAnimation = function () {
|
||||
if (this.moveDirection == this.lookDirection) {
|
||||
return 'run';
|
||||
}
|
||||
return 'walkback';
|
||||
}
|
||||
|
||||
Player.prototype.look = function(x, y) {
|
||||
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;
|
||||
|
|
@ -147,7 +147,7 @@ function(Doll, Settings) {
|
|||
}*/
|
||||
}
|
||||
|
||||
Player.prototype.isWalking = function() {
|
||||
Player.prototype.isWalking = function () {
|
||||
var states = ['walk', 'walkback', 'run'];
|
||||
|
||||
if (states.indexOf(this.currentAnimationState) >= 0) {
|
||||
|
|
@ -157,7 +157,7 @@ function(Doll, Settings) {
|
|||
}
|
||||
|
||||
// called by CollisionDetection
|
||||
Player.prototype.onFootSensorDetection = function(isColliding) {
|
||||
Player.prototype.onFootSensorDetection = function (isColliding) {
|
||||
if(isColliding) {
|
||||
if(this.doll.getBody().GetLinearVelocity().y < -Settings.JUMP_SPEED && !this.isStanding()) {
|
||||
return;
|
||||
|
|
@ -173,7 +173,7 @@ function(Doll, Settings) {
|
|||
}
|
||||
}
|
||||
|
||||
Player.prototype.update = function() {
|
||||
Player.prototype.update = function () {
|
||||
//this.mc.head.y = this.mc.head_posmask.y;
|
||||
|
||||
if (this.doll.getBody().GetLinearVelocity().x == 0 && this.isWalking()) {
|
||||
|
|
@ -185,7 +185,7 @@ function(Doll, Settings) {
|
|||
}
|
||||
}
|
||||
|
||||
Player.prototype.destroy = function() {
|
||||
Player.prototype.destroy = function () {
|
||||
this.doll.destroy();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@ define([
|
|||
"Game/Core/Protocol/Parser"
|
||||
],
|
||||
|
||||
function(Parser) {
|
||||
function (Parser) {
|
||||
|
||||
var Helper = {}
|
||||
|
||||
Helper.encodeCommand = function(command, options){
|
||||
Helper.encodeCommand = function (command, options){
|
||||
return Parser.encode(Helper.assemble(command, options));
|
||||
}
|
||||
|
||||
Helper.assemble = function(command, options){
|
||||
Helper.assemble = function (command, options){
|
||||
var commands = {};
|
||||
commands[command] = options || null;
|
||||
return commands;
|
||||
}
|
||||
|
||||
Helper.runCommands = function(message, callback){
|
||||
Helper.runCommands = function (message, callback){
|
||||
var commands = Parser.decode(message);
|
||||
|
||||
for(var command in commands) {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
define([
|
||||
],
|
||||
|
||||
function() {
|
||||
function () {
|
||||
|
||||
var Parser = {};
|
||||
|
||||
Parser.encode = function(message){
|
||||
Parser.encode = function (message){
|
||||
return JSON.stringify(message);
|
||||
}
|
||||
|
||||
Parser.decode = function(message){
|
||||
Parser.decode = function (message){
|
||||
return JSON.parse(message);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
define(function() {
|
||||
define(function () {
|
||||
|
||||
function User(id) {
|
||||
this.id = id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue