mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
Fixed tile and scale sizes, Fixed Animation using RequestAnimationFrame
This commit is contained in:
parent
01043a2ea3
commit
ff6456fd47
6 changed files with 137 additions and 116 deletions
|
|
@ -36,8 +36,8 @@ define(["Chuck/Settings", "Box2D/Box2D"], function(Settings, Box2D) {
|
||||||
|
|
||||||
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody;
|
bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody;
|
||||||
bodyDef.position.x = tile.x / Settings.RATIO * Settings.RATIO / 2;
|
bodyDef.position.x = tile.x * Settings.TILE_SIZE / Settings.RATIO;
|
||||||
bodyDef.position.y = tile.y / Settings.RATIO * Settings.RATIO / 2;
|
bodyDef.position.y = tile.y * Settings.TILE_SIZE / Settings.RATIO;
|
||||||
bodyDef.angle = tile.r * 90 * Math.PI / 180;
|
bodyDef.angle = tile.r * 90 * Math.PI / 180;
|
||||||
|
|
||||||
var tileShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
var tileShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||||
|
|
@ -196,7 +196,7 @@ define(["Chuck/Settings", "Box2D/Box2D"], function(Settings, Box2D) {
|
||||||
{s:2, x:22, y:25},
|
{s:2, x:22, y:25},
|
||||||
{s:1, x:40, y:25},
|
{s:1, x:40, y:25},
|
||||||
{s:1, x:38, y:26},
|
{s:1, x:38, y:26},
|
||||||
{s:1, x: 8, y: 8},
|
{s:1, x:8, y:18},
|
||||||
{s:1, x:38, y:25},
|
{s:1, x:38, y:25},
|
||||||
{s:1, x:28, y:28},
|
{s:1, x:28, y:28},
|
||||||
{s:1, x:36, y:27},
|
{s:1, x:36, y:27},
|
||||||
|
|
@ -253,7 +253,8 @@ define(["Chuck/Settings", "Box2D/Box2D"], function(Settings, Box2D) {
|
||||||
{s:1, x:22, y:26},
|
{s:1, x:22, y:26},
|
||||||
{s:1, x:1, y:17},
|
{s:1, x:1, y:17},
|
||||||
{s:1, x:35, y:29},
|
{s:1, x:35, y:29},
|
||||||
{s:1, x:12, y:1}
|
{s:1, x:12, y:19}
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ define(["Box2D/Box2D", "Chuck/Settings"], function(Box2D, Settings){
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.jumping = function () {
|
Doll.prototype.jumping = function () {
|
||||||
var vector = new Box2D.Common.Math.b2Vec2(0, -0.1);
|
var vector = new Box2D.Common.Math.b2Vec2(0, -0.05);
|
||||||
this._body.ApplyImpulse(vector, this._body.GetPosition());
|
this._body.ApplyImpulse(vector, this._body.GetPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ define(["Chuck/Settings", "Box2D/Box2D"], function(Settings, Box2D){
|
||||||
|
|
||||||
debugDraw.SetSprite(debugSprite);
|
debugDraw.SetSprite(debugSprite);
|
||||||
debugDraw.SetDrawScale(Settings.RATIO);
|
debugDraw.SetDrawScale(Settings.RATIO);
|
||||||
debugDraw.SetDrawScale(30.0);
|
|
||||||
debugDraw.SetFillAlpha(0.5);
|
debugDraw.SetFillAlpha(0.5);
|
||||||
debugDraw.SetLineThickness(1.0);
|
debugDraw.SetLineThickness(1.0);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,11 @@ var requires = [
|
||||||
"Chuck/Control/InputControlUnit",
|
"Chuck/Control/InputControlUnit",
|
||||||
"Chuck/Settings",
|
"Chuck/Settings",
|
||||||
"Box2D/Box2D",
|
"Box2D/Box2D",
|
||||||
"Chuck/Loader/Level"
|
"Chuck/Loader/Level",
|
||||||
|
"RequestAnimationFrame"
|
||||||
];
|
];
|
||||||
|
|
||||||
define(requires, function(PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level){
|
define(requires, function(PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level, requestAnimFrame){
|
||||||
|
|
||||||
function Processor () {
|
function Processor () {
|
||||||
this._me;
|
this._me;
|
||||||
|
|
@ -41,10 +42,11 @@ define(requires, function(PhysicsEngine, Player, InputControlUnit, Settings, Box
|
||||||
//this._physicsEngine.setCollisionDetector(this._me);
|
//this._physicsEngine.setCollisionDetector(this._me);
|
||||||
}
|
}
|
||||||
|
|
||||||
//new Chuck.Loader.Level(this._physicsEngine);
|
//new Chuck.Loader.Level(this._physicsEngine);u
|
||||||
//new Items();
|
//new Items();
|
||||||
|
|
||||||
setInterval(this._update, 1000/60, this);
|
//setInterval(this._update, 1000/60, this);
|
||||||
|
this._update();
|
||||||
}
|
}
|
||||||
|
|
||||||
Processor.prototype.loadLevel = function(path) {
|
Processor.prototype.loadLevel = function(path) {
|
||||||
|
|
@ -101,15 +103,18 @@ define(requires, function(PhysicsEngine, Player, InputControlUnit, Settings, Box
|
||||||
return this._me;
|
return this._me;
|
||||||
}
|
}
|
||||||
|
|
||||||
Processor.prototype._update = function(self) {
|
Processor.prototype._update = function() {
|
||||||
|
|
||||||
|
|
||||||
|
requestAnimFrame(this._update.bind(this));
|
||||||
|
|
||||||
//console.log(self._physicsEngine.getWorld().GetBodyList().GetPosition());
|
//console.log(self._physicsEngine.getWorld().GetBodyList().GetPosition());
|
||||||
|
|
||||||
self._physicsEngine.update();
|
this._physicsEngine.update();
|
||||||
|
|
||||||
if(Settings.IS_BROWSER_ENVIRONMENT) {
|
if(Settings.IS_BROWSER_ENVIRONMENT) {
|
||||||
self._inputControlUnit.update();
|
this._inputControlUnit.update();
|
||||||
self._me.update();
|
this._me.update();
|
||||||
//self._camera.update();
|
//self._camera.update();
|
||||||
//self._repository.update();
|
//self._repository.update();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ define(function() {
|
||||||
STAGE_HEIGHT: 400,
|
STAGE_HEIGHT: 400,
|
||||||
|
|
||||||
// BOX2D INITIALATORS
|
// BOX2D INITIALATORS
|
||||||
RATIO : 30,
|
RATIO: 35,
|
||||||
BOX2D_WORLD_AABB_SIZE: 3000,
|
BOX2D_WORLD_AABB_SIZE: 3000,
|
||||||
BOX2D_ALLOW_SLEEP: true,
|
BOX2D_ALLOW_SLEEP: true,
|
||||||
BOX2D_GRAVITY: 16,
|
BOX2D_GRAVITY: 16,
|
||||||
BOX2D_VELOCITY_ITERATIONS: 5,
|
BOX2D_VELOCITY_ITERATIONS: 5,
|
||||||
BOX2D_POSITION_ITERATIONS: 5,
|
BOX2D_POSITION_ITERATIONS: 5,
|
||||||
BOX2D_TIME_STEP : 1 / 30,
|
BOX2D_TIME_STEP: 1 / 60,
|
||||||
|
|
||||||
// GRAPHIC PATHS
|
// GRAPHIC PATHS
|
||||||
GRAPHICS_PATH: 'img',
|
GRAPHICS_PATH: 'img',
|
||||||
|
|
@ -25,6 +25,7 @@ define(function() {
|
||||||
RUN_SPEED: 4.0,
|
RUN_SPEED: 4.0,
|
||||||
FLY_SPEED: 3.2,
|
FLY_SPEED: 3.2,
|
||||||
JUMP_SPEED: 3.0,
|
JUMP_SPEED: 3.0,
|
||||||
|
JUMP_UPLIFT: 0.05,
|
||||||
|
|
||||||
// restitution: bouncyness, friction: rubbing, density: mass
|
// restitution: bouncyness, friction: rubbing, density: mass
|
||||||
TILE_FRICTION: 0.99,
|
TILE_FRICTION: 0.99,
|
||||||
|
|
|
||||||
15
lib/RequestAnimationFrame.js
Normal file
15
lib/RequestAnimationFrame.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
define(['Chuck/Settings'], function(Settings) {
|
||||||
|
|
||||||
|
var requestAnimFrame = (function(){
|
||||||
|
return window.requestAnimationFrame ||
|
||||||
|
window.webkitRequestAnimationFrame ||
|
||||||
|
window.mozRequestAnimationFrame ||
|
||||||
|
window.oRequestAnimationFrame ||
|
||||||
|
window.msRequestAnimationFrame ||
|
||||||
|
function( callback ){
|
||||||
|
setTimeout(callback, Settings.BOX2D_TIME_STEP * 1000);
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
return requestAnimFrame;
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue