mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Set up new module structure
This commit is contained in:
parent
5f5178d2e8
commit
2e864f5293
534 changed files with 235854 additions and 1 deletions
13
lib/Chuck/Chuck.js
Normal file
13
lib/Chuck/Chuck.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
define(["Chuck/Processor"], function(Processor){
|
||||
var Chuck = {};
|
||||
|
||||
Chuck.init = function(){
|
||||
var processor = new Processor();
|
||||
}
|
||||
|
||||
Chuck.processRequest = function(package){
|
||||
console.log(package);
|
||||
}
|
||||
|
||||
return Chuck;
|
||||
});
|
||||
67
lib/Chuck/Physics/Engine.js
Normal file
67
lib/Chuck/Physics/Engine.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
define(["Chuck/Settings", "Box2D/Box2D"], function(Settings, Box2D){
|
||||
|
||||
function Engine () {
|
||||
this._world;
|
||||
this.init();
|
||||
}
|
||||
|
||||
Engine.prototype.init = function() {
|
||||
this._world = new Box2D.Dynamics.b2World(new Box2D.Common.Math.b2Vec2(0, Settings.Box2D_GRAVITY), Settings.Box2D_ALLOW_SLEEP);
|
||||
|
||||
if(Settings.IS_BROWSER_ENVIRONMENT) {
|
||||
this.setupDebugDraw();
|
||||
}
|
||||
}
|
||||
|
||||
Engine.prototype.getWorld = function() {
|
||||
return this._world;
|
||||
}
|
||||
|
||||
Engine.prototype.setCollisionDetector = function(me) {
|
||||
/*
|
||||
var cd = new Chuck.Collision.Detector(me);
|
||||
var listener = cd.getListener();
|
||||
this._world.SetContactListener(listener);*/
|
||||
}
|
||||
|
||||
Engine.prototype.setupDebugDraw = function() {
|
||||
var debugSprite = Settings.DEBUG_DRAW_CANVAS_SPRITE;
|
||||
console.log(debugSprite);
|
||||
|
||||
// set debug draw
|
||||
var dbgDraw = new Box2D.Dynamics.b2DebugDraw();
|
||||
|
||||
dbgDraw.SetSprite(debugSprite);
|
||||
dbgDraw.SetDrawScale(Settings.RATIO);
|
||||
dbgDraw.SetAlpha(0.5);
|
||||
dbgDraw.SetFillAlpha(0.1);
|
||||
dbgDraw.SetLineThickness(0);
|
||||
|
||||
dbgDraw.SetFlags(null
|
||||
| dbgDraw.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);
|
||||
console.log('Debug Draw was set up');
|
||||
}
|
||||
|
||||
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();
|
||||
this._world.DrawDebugData();
|
||||
}
|
||||
|
||||
return Engine;
|
||||
})
|
||||
118
lib/Chuck/Processor.js
Normal file
118
lib/Chuck/Processor.js
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
define(["Chuck/Physics/Engine", "Box2D/Box2D"], function(PhysicsEngine, Box2D){
|
||||
|
||||
function Processor () {
|
||||
this._me;
|
||||
this._physicsEngine;
|
||||
this._camera;
|
||||
this._repository;
|
||||
this._inputControlUnit;
|
||||
this._keyboardInput;
|
||||
|
||||
this.init();
|
||||
};
|
||||
|
||||
Processor.prototype.init = function() {
|
||||
|
||||
this._physicsEngine = new PhysicsEngine();
|
||||
|
||||
/*
|
||||
var fixDef = new Box2D.Dynamics.b2FixtureDef;
|
||||
fixDef.density = 1.0;
|
||||
fixDef.friction = 0.99;
|
||||
fixDef.restitution = .51;
|
||||
|
||||
var bodyDef = new Box2D.Dynamics.b2BodyDef;
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
fixDef.shape = new Box2D.Collision.Shapes.b2PolygonShape;
|
||||
fixDef.shape.SetAsBox(0.4, 0.4);
|
||||
|
||||
this._physicsEngine.createBody(bodyDef).CreateFixture(fixDef);
|
||||
bodyDef.position.x = 2;
|
||||
bodyDef.position.y = 3;
|
||||
|
||||
console.log('bodying');*/
|
||||
|
||||
|
||||
///------
|
||||
|
||||
var world = this._physicsEngine.getWorld();
|
||||
|
||||
var fixDef = new Box2D.Dynamics.b2FixtureDef;
|
||||
fixDef.density = 1.0;
|
||||
fixDef.friction = 0.99;
|
||||
fixDef.restitution = .51;
|
||||
|
||||
var bodyDef = new Box2D.Dynamics.b2BodyDef;
|
||||
|
||||
// create ground
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody;
|
||||
fixDef.shape = new Box2D.Collision.Shapes.b2PolygonShape;
|
||||
fixDef.shape.SetAsBox(20, 2);
|
||||
|
||||
bodyDef.position.Set(10, 400 / 30 + 1.8);
|
||||
|
||||
world.CreateBody(bodyDef).CreateFixture(fixDef);
|
||||
bodyDef.position.Set(10, -1.8);
|
||||
|
||||
world.CreateBody(bodyDef).CreateFixture(fixDef);
|
||||
fixDef.shape.SetAsBox(2, 14);
|
||||
|
||||
bodyDef.position.Set(-1.8, 13);
|
||||
world.CreateBody(bodyDef).CreateFixture(fixDef);
|
||||
|
||||
bodyDef.position.Set(21.8, 13);
|
||||
world.CreateBody(bodyDef).CreateFixture(fixDef);
|
||||
|
||||
// create some objects
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
|
||||
for(var i = 0; i < 5; i++) {
|
||||
fixDef.shape = new Box2D.Collision.Shapes.b2PolygonShape;
|
||||
fixDef.shape.SetAsBox(0.4, 0.4);
|
||||
|
||||
bodyDef.position.x = ((i + 1) * 2) % 8;
|
||||
bodyDef.position.y = 3;
|
||||
|
||||
bodyDef.userData = {
|
||||
'bodyId': i + ''
|
||||
};
|
||||
|
||||
world.CreateBody(bodyDef).CreateFixture(fixDef);
|
||||
}
|
||||
|
||||
/*
|
||||
this._me = new Chuck.Player(this._physicsEngine, this._repository);
|
||||
//this._camera = Camera.getInstance()
|
||||
//this._repository = Repository.getInstance();
|
||||
this._physicsEngine.setCollisionDetector(this._me);
|
||||
this._keyboardInput = new Chuck.Control.KeyboardInput();
|
||||
this._inputControlUnit = new Chuck.Control.InputControlUnit(this._keyboardInput, this._me);
|
||||
|
||||
new Chuck.Loader.Level(this._physicsEngine);
|
||||
//new Items();
|
||||
|
||||
this._me.spawn(100, 0);
|
||||
//this._camera.follow(this._me);
|
||||
*/
|
||||
setInterval(this._update, 1000/60, this);
|
||||
//View.getInstance().getSprite().addEventListener(Event.ENTER_FRAME, this._update)
|
||||
}
|
||||
|
||||
Processor.prototype.getPhysicsEngine = function() {
|
||||
return this._physicsEngine;
|
||||
}
|
||||
|
||||
Processor.prototype.getMe = function() {
|
||||
return this._me;
|
||||
}
|
||||
|
||||
Processor.prototype._update = function(self) {
|
||||
self._physicsEngine.update();
|
||||
//self._repository.update();
|
||||
//self._keyboardInput.update();
|
||||
//self._me.update();
|
||||
//self._camera.update();
|
||||
}
|
||||
|
||||
return Processor;
|
||||
});
|
||||
54
lib/Chuck/Settings.js
Normal file
54
lib/Chuck/Settings.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
define(function() {
|
||||
|
||||
var 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,
|
||||
|
||||
// debug draw
|
||||
DEBUG_DRAW_CANVAS_SPRITE: isBrowserEnvironment() ? document.getElementById("canvas").getContext("2d") : undefined,
|
||||
IS_BROWSER_ENVIRONMENT: isBrowserEnvironment()
|
||||
};
|
||||
|
||||
function isBrowserEnvironment(){
|
||||
return typeof window !== 'undefined';
|
||||
}
|
||||
|
||||
return Settings;
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue