mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Merge branch 'master' of github.com:logsol/chuck.js
This commit is contained in:
commit
1d16f29bf0
13 changed files with 84 additions and 71 deletions
10
README.md
10
README.md
|
|
@ -7,13 +7,11 @@ Follow the development at http://chuck-game.tumblr.com/
|
|||
|
||||
How to run:
|
||||
|
||||
* git clone https://github.com/logsol/chuck.js.git
|
||||
* cd chuck.js
|
||||
* npm install
|
||||
* node server.js
|
||||
* ```git clone https://github.com/logsol/chuck.js.git```
|
||||
* ```cd chuck.js```
|
||||
* ```npm install```
|
||||
* ```node server.js [port] [log level]```
|
||||
|
||||
Open in browser http://localhost:1234
|
||||
|
||||
|
||||
|
||||
This game is licensed under the GPLv3 licence http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
define(["Vendor/Box2D"], function(Box2D) {
|
||||
define(["Vendor/Box2D", "Chuck/Constants"], function(Box2D, Constants) {
|
||||
|
||||
function Detector(me) {
|
||||
this.me = me;
|
||||
|
|
@ -15,7 +15,9 @@ define(["Vendor/Box2D"], function(Box2D) {
|
|||
}
|
||||
|
||||
Detector.prototype.handleStand = function(point, isColliding) {
|
||||
if (point.GetFixtureA().GetUserData() == 'myFeet' || point.GetFixtureB().GetUserData() == 'myFeet') {
|
||||
if (point.GetFixtureA().GetUserData() == Constants.COLLISION_IDENTIFIER_FOOTSENSOR
|
||||
|| point.GetFixtureB().GetUserData() == Constants.COLLISION_IDENTIFIER_FOOTSENSOR) {
|
||||
|
||||
this.me.onFootSensorDetection(isColliding);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,15 @@
|
|||
Constants.js
|
||||
define(function() {
|
||||
|
||||
var Constants = {
|
||||
COLLISION_IDENTIFIER_PLAYER: 'player',
|
||||
COLLISION_IDENTIFIER_PLAYER_HEAD: 'head',
|
||||
COLLISION_IDENTIFIER_PLAYER_CHEST: 'chest',
|
||||
COLLISION_IDENTIFIER_PLAYER_LEGS: 'legs',
|
||||
COLLISION_IDENTIFIER_PLAYER_FOOT_SENSOR: 'footsensor',
|
||||
|
||||
COLLISION_IDENTIFIER_TILE: 'tile'
|
||||
}
|
||||
|
||||
return Constants;
|
||||
|
||||
});
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
define(["Chuck/Settings", "Chuck/Processors/ServerProcessor", "Chuck/Processors/ClientProcessor"], function(Settings, ServerProcessor, ClientProcessor){
|
||||
|
||||
function Game(networker){
|
||||
this.networker = networker;
|
||||
this.processor = this.createProcessor();
|
||||
|
||||
this.processor.loadLevel("default.json");
|
||||
}
|
||||
|
||||
Game.prototype.createProcessor = function(){
|
||||
var processor;
|
||||
|
||||
if(Settings.IS_BROWSER_ENVIRONMENT){
|
||||
processor = new ClientProcessor();
|
||||
} else {
|
||||
processor = new ServerProcessor();
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
|
||||
Game.prototype.processGameCommand = function(command, options){
|
||||
console.log('(not implemented) processGameCommand:', command, options);
|
||||
}
|
||||
|
||||
Game.prototype.destruct = function(){
|
||||
this.processor.destruct();
|
||||
}
|
||||
|
||||
return Game;
|
||||
});
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
define(["Chuck/Settings", "Vendor/Box2D"], function(Settings, Box2D) {
|
||||
define(["Chuck/Settings", "Chuck/Constants", "Vendor/Box2D"], function(Settings, Constants, Box2D) {
|
||||
|
||||
// Public
|
||||
function Level(path, engine) {
|
||||
|
|
@ -50,7 +50,7 @@ define(["Chuck/Settings", "Vendor/Box2D"], function(Settings, Box2D) {
|
|||
fixtureDef.friction = Settings.TILE_FRICTION;
|
||||
fixtureDef.restitution = Settings.TILE_RESTITUTION;
|
||||
fixtureDef.isSensor = false;
|
||||
fixtureDef.userData = 'tile';
|
||||
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_TILE;
|
||||
|
||||
this.engine.createBody(bodyDef).CreateFixture(fixtureDef);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
|
||||
define(["Vendor/Box2D", "Chuck/Constants", "Chuck/Settings"], function(Box2D, Constants, Settings){
|
||||
|
||||
function Doll (physicsEngine, id){
|
||||
this.id = id;
|
||||
|
|
@ -18,7 +18,7 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
|
|||
bodyDef.fixedRotation = true;
|
||||
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
bodyDef.userData = 'player-' + this.id;
|
||||
bodyDef.userData = Constants.COLLISION_IDENTIFIER_PLAYER + '-' + this.id;
|
||||
|
||||
this.body = world.CreateBody(bodyDef);
|
||||
|
||||
|
|
@ -32,14 +32,14 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
|
|||
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -37 / Settings.RATIO));
|
||||
fixtureDef.shape = headShape;
|
||||
fixtureDef.isSensor = false;
|
||||
fixtureDef.userData = 'myHead-' + this.id;
|
||||
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_PLAYER_HEAD;
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
bodyShape.SetAsOrientedBox(5 / Settings.RATIO, 16 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -21 / Settings.RATIO));
|
||||
fixtureDef.shape = bodyShape;
|
||||
fixtureDef.isSensor = false;
|
||||
fixtureDef.userData = 'myBody-' + this.id;
|
||||
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_PLAYER_CHEST;
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
|
|
@ -48,7 +48,8 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
|
|||
fixtureDef.shape = legsShape;
|
||||
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
||||
fixtureDef.isSensor = false;
|
||||
fixtureDef.userData = 'myLegs-' + this.id;
|
||||
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_PLAYER_LEGS;
|
||||
|
||||
this.legs = this.body.CreateFixture(fixtureDef);
|
||||
|
||||
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
|
|
@ -56,7 +57,7 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
|
|||
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 0 / Settings.RATIO));
|
||||
fixtureDef.shape = feetShape;
|
||||
fixtureDef.isSensor = true;
|
||||
fixtureDef.userData = 'myFeet-' + this.id;
|
||||
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_FOOTSENSOR;
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
this.body.SetActive(false);
|
||||
|
|
@ -74,8 +75,7 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
|
|||
Doll.prototype.setFriction = function (friction) {
|
||||
if(!friction) friction = -1;
|
||||
|
||||
if (this.legs.GetFriction() != friction)
|
||||
{
|
||||
if (this.legs.GetFriction() != friction) {
|
||||
this.legs.SetFriction(friction);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ define(requires, function(PhysicsEngine, Player, Box2D, Level, InputController,
|
|||
ServerProcessor.prototype.userIdLeft = function(id) {
|
||||
var player = this.players[id].player;
|
||||
player.destroy();
|
||||
delete this.players[id];
|
||||
}
|
||||
|
||||
ServerProcessor.prototype.updateWorld = function() {
|
||||
|
|
|
|||
|
|
@ -67,9 +67,7 @@ define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientG
|
|||
}
|
||||
|
||||
Networker.prototype.sendGameCommand = function(command, options) {
|
||||
var message = {};
|
||||
message[command] = options || true;
|
||||
this.sendCommand('gameCommand', message);
|
||||
this.sendCommand('gameCommand', ProtocolHelper.assemble(command, options));
|
||||
}
|
||||
|
||||
Networker.prototype.onUserLeft = function(userId) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ define(["Protocol/Parser"], function(Parser) {
|
|||
|
||||
Helper.assemble = function(command, options){
|
||||
var commands = {};
|
||||
commands[command] = options;
|
||||
commands[command] = options || null;
|
||||
return commands;
|
||||
}
|
||||
|
||||
|
|
|
|||
24
lib/Server/Factory.js
Normal file
24
lib/Server/Factory.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
define(['Server/NotificationCenter'], function(NotificationCenter) {
|
||||
|
||||
function Factory() {
|
||||
this.notificationCenter = new NotificationCenter();
|
||||
}
|
||||
|
||||
Factory.prototype.new = function () {
|
||||
|
||||
if (arguments.length < 1)
|
||||
throw 'Too fiew arguments';
|
||||
if (typeof arguments[0] != 'function')
|
||||
throw arguments[0] + ' is not a function';
|
||||
|
||||
var type = arguments[0];
|
||||
var object = new (type.bind.apply(type,arguments))();
|
||||
object.notificationCenter = this.notificationCenter;
|
||||
object.factory = this;
|
||||
return object;
|
||||
|
||||
}
|
||||
|
||||
return Factory;
|
||||
|
||||
});
|
||||
7
lib/Server/NotificationCenter.js
Normal file
7
lib/Server/NotificationCenter.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
define(function() {
|
||||
|
||||
function NotificationCenter() {
|
||||
}
|
||||
|
||||
return NotificationCenter;
|
||||
});
|
||||
|
|
@ -1,18 +1,21 @@
|
|||
define(['socket.io'], function(io) {
|
||||
|
||||
function Socket(server, coordinator) {
|
||||
function Socket(server, options, coordinator) {
|
||||
options.logLevel = typeof options.logLevel != 'undefined'
|
||||
? options.logLevel
|
||||
: 0;
|
||||
|
||||
this.coordinator = coordinator;
|
||||
this.socket = io.listen(server);
|
||||
|
||||
this.init(server);
|
||||
this.init(options);
|
||||
}
|
||||
|
||||
Socket.prototype.init = function(){
|
||||
Socket.prototype.init = function(options){
|
||||
|
||||
var self = this;
|
||||
|
||||
this.socket.configure('development', function(){
|
||||
this.set('log level', 0);
|
||||
this.set('log level', options.logLevel);
|
||||
});
|
||||
|
||||
this.socket.on('connection', function(user){
|
||||
|
|
@ -26,4 +29,4 @@ define(['socket.io'], function(io) {
|
|||
|
||||
return Socket;
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
20
server.js
20
server.js
|
|
@ -13,28 +13,24 @@ var requirements = [
|
|||
"Server/Coordinator"
|
||||
];
|
||||
|
||||
var port = process.argv[2]
|
||||
|| process.env.PORT
|
||||
|| process.env.npm_package_config_port;
|
||||
|
||||
requirejs(requirements, function(HttpServer, Socket, Coordinator) {
|
||||
|
||||
var options = {
|
||||
port: process.env.npm_package_config_port,
|
||||
port: port,
|
||||
rootDirectory: './',
|
||||
caching: false
|
||||
caching: false,
|
||||
logLevel: process.argv[3]
|
||||
};
|
||||
|
||||
var coordinator = new Coordinator();
|
||||
var httpServer = new HttpServer(options);
|
||||
var socket = new Socket(httpServer.getServer(), coordinator);
|
||||
var socket = new Socket(httpServer.getServer(), options, coordinator);
|
||||
|
||||
inspector.coordinator = coordinator;
|
||||
});
|
||||
|
||||
exports = module.exports = inspector;
|
||||
|
||||
/*
|
||||
belongs to channel.js
|
||||
var chuck;
|
||||
requirejs(["Chuck/Chuck"], function(Chuck) {
|
||||
Chuck.init();
|
||||
chuck = Chuck;
|
||||
});
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue