mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
fixed skateboard and mesh positioning
This commit is contained in:
parent
7220e3b388
commit
bdab2a5760
9 changed files with 83 additions and 45 deletions
|
|
@ -138,7 +138,7 @@ function (Parent, Settings, NotificationCenter, Exception) {
|
||||||
this.headMesh,
|
this.headMesh,
|
||||||
{
|
{
|
||||||
x: this.body.GetPosition().x * Settings.RATIO,
|
x: this.body.GetPosition().x * Settings.RATIO,
|
||||||
y: this.body.GetPosition().y * Settings.RATIO - 31
|
y: this.body.GetPosition().y * Settings.RATIO - this.height + this.headHeight
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,7 @@ function (Parent, Settings, NotificationCenter) {
|
||||||
callback,
|
callback,
|
||||||
{
|
{
|
||||||
width: Settings.TILE_SIZE,
|
width: Settings.TILE_SIZE,
|
||||||
height: Settings.TILE_SIZE,
|
height: Settings.TILE_SIZE
|
||||||
pivot: "mb"
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
@ -47,8 +46,8 @@ function (Parent, Settings, NotificationCenter) {
|
||||||
NotificationCenter.trigger("view/updateMesh",
|
NotificationCenter.trigger("view/updateMesh",
|
||||||
this.mesh,
|
this.mesh,
|
||||||
{
|
{
|
||||||
x: this.options.x * Settings.TILE_SIZE,
|
x: this.body.GetPosition().x * Settings.RATIO - Settings.TILE_SIZE / 2,
|
||||||
y: this.options.y * Settings.TILE_SIZE,
|
y: this.body.GetPosition().y * Settings.RATIO - Settings.TILE_SIZE / 2
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,12 +89,18 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
||||||
if (options.height) mesh.height = options.height;
|
if (options.height) mesh.height = options.height;
|
||||||
if (options.visible === true || options.visible === false) mesh.visible = options.visible;
|
if (options.visible === true || options.visible === false) mesh.visible = options.visible;
|
||||||
if (options.pivot) {
|
if (options.pivot) {
|
||||||
switch(options.pivot.length) {
|
if(options.pivot.length) {
|
||||||
default:
|
switch(options.pivot) {
|
||||||
mesh.pivot.x = mesh.width / 2;
|
case "lb":
|
||||||
mesh.pivot.y = mesh.height;
|
mesh.pivot.x = mesh.width / 2;
|
||||||
break;
|
mesh.pivot.y = mesh.height / 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mesh.pivot.x = mesh.width / 2;
|
||||||
|
mesh.pivot.y = mesh.height;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -105,16 +111,11 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PixiView.prototype.calculateCameraPosition = function() {
|
PixiView.prototype.calculateCameraPosition = function() {
|
||||||
|
|
||||||
var reference = this.me.getPosition();
|
|
||||||
var pos = {};
|
|
||||||
|
|
||||||
pos.x = -reference.x;
|
|
||||||
pos.y = reference.y;
|
|
||||||
|
|
||||||
var zoom = this.container.scale.x;
|
var zoom = this.container.scale.x;
|
||||||
pos.x = pos.x * Settings.RATIO * zoom;
|
|
||||||
pos.y = -(pos.y * Settings.RATIO) * zoom;
|
var pos = this.me.getHeadPosition();
|
||||||
|
pos.x *= -Settings.RATIO * zoom;
|
||||||
|
pos.y *= -Settings.RATIO * zoom;
|
||||||
|
|
||||||
pos.x -= this.me.playerController.xyInput.x * Settings.STAGE_WIDTH / 4;
|
pos.x -= this.me.playerController.xyInput.x * Settings.STAGE_WIDTH / 4;
|
||||||
pos.y += this.me.playerController.xyInput.y * Settings.STAGE_HEIGHT / 4;
|
pos.y += this.me.playerController.xyInput.y * Settings.STAGE_HEIGHT / 4;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ define({
|
||||||
GRAPHICS_SUBPATH_TILES: 'Tiles/',
|
GRAPHICS_SUBPATH_TILES: 'Tiles/',
|
||||||
|
|
||||||
RATIO: 21, //35
|
RATIO: 21, //35
|
||||||
TILE_SIZE: 15, //15
|
TILE_SIZE: 65, //15, 25 is original picture
|
||||||
CAMERA_IS_ORTHOGRAPHIC: true,
|
CAMERA_IS_ORTHOGRAPHIC: true,
|
||||||
VIEW_CONTROLLER: 0 ? 'Three' : 'Pixi',
|
VIEW_CONTROLLER: 0 ? 'Three' : 'Pixi',
|
||||||
|
|
||||||
|
|
@ -45,9 +45,7 @@ define({
|
||||||
// BROWSER
|
// BROWSER
|
||||||
CANVAS_DOM_ID: 'canvasContainer',
|
CANVAS_DOM_ID: 'canvasContainer',
|
||||||
IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined',
|
IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined',
|
||||||
USE_WEGBL: true,
|
USE_WEGBL: true,
|
||||||
|
|
||||||
DEBUG_MODE: 1,
|
|
||||||
|
|
||||||
// NETWORKING
|
// NETWORKING
|
||||||
WORLD_UPDATE_BROADCAST_INTERVAL: 70,
|
WORLD_UPDATE_BROADCAST_INTERVAL: 70,
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,11 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||||
|
|
||||||
function Doll (physicsEngine, uid) {
|
function Doll (physicsEngine, uid) {
|
||||||
|
|
||||||
|
this.height = 43;
|
||||||
|
this.width = 9;
|
||||||
|
this.headHeight = 12;
|
||||||
|
this.reachDistance = 20;
|
||||||
|
|
||||||
Parent.call(this, physicsEngine, uid);
|
Parent.call(this, physicsEngine, uid);
|
||||||
|
|
||||||
this.standing = false;
|
this.standing = false;
|
||||||
|
|
@ -33,8 +38,8 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||||
|
|
||||||
Doll.prototype.getBodyDef = function() {
|
Doll.prototype.getBodyDef = function() {
|
||||||
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||||
bodyDef.position.x = 220 / Settings.RATIO;
|
bodyDef.position.x = 0;
|
||||||
bodyDef.position.y = 0 / Settings.RATIO;
|
bodyDef.position.y = 0;
|
||||||
bodyDef.fixedRotation = true;
|
bodyDef.fixedRotation = true;
|
||||||
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
||||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||||
|
|
@ -50,21 +55,25 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||||
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
|
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
|
||||||
|
|
||||||
var headShape = new Box2D.Collision.Shapes.b2CircleShape();
|
var headShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||||
headShape.SetRadius(5 / Settings.RATIO);
|
headShape.SetRadius(this.width / 2 / Settings.RATIO);
|
||||||
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -35 / Settings.RATIO));
|
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -(this.height - (this.width / 2)) / Settings.RATIO));
|
||||||
fixtureDef.shape = headShape;
|
fixtureDef.shape = headShape;
|
||||||
fixtureDef.isSensor = false;
|
fixtureDef.isSensor = false;
|
||||||
this.body.CreateFixture(fixtureDef);
|
this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||||
bodyShape.SetAsOrientedBox(5 / Settings.RATIO, 16 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -19 / Settings.RATIO));
|
bodyShape.SetAsOrientedBox(
|
||||||
|
this.width / 2 / Settings.RATIO,
|
||||||
|
(this.height - this.width) / 2 / Settings.RATIO,
|
||||||
|
new Box2D.Common.Math.b2Vec2(0, -this.height / 2 / Settings.RATIO)
|
||||||
|
);
|
||||||
fixtureDef.shape = bodyShape;
|
fixtureDef.shape = bodyShape;
|
||||||
fixtureDef.isSensor = false;
|
fixtureDef.isSensor = false;
|
||||||
this.body.CreateFixture(fixtureDef);
|
this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
|
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||||
legsShape.SetRadius(5 / Settings.RATIO);
|
legsShape.SetRadius(this.width / 2 / Settings.RATIO);
|
||||||
legsShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -3 / Settings.RATIO));
|
legsShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -this.width / 2 / Settings.RATIO));
|
||||||
fixtureDef.shape = legsShape;
|
fixtureDef.shape = legsShape;
|
||||||
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
||||||
fixtureDef.isSensor = false;
|
fixtureDef.isSensor = false;
|
||||||
|
|
@ -74,8 +83,8 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||||
fixtureDef.density = 0;
|
fixtureDef.density = 0;
|
||||||
|
|
||||||
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
|
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||||
feetShape.SetRadius(4 / Settings.RATIO);
|
feetShape.SetRadius((this.width - 1) / 2 / Settings.RATIO); // the -1 one prevents collisions with walls
|
||||||
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 2 / Settings.RATIO));
|
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, 2 / Settings.RATIO)); // 2 is offset into ground
|
||||||
fixtureDef.shape = feetShape;
|
fixtureDef.shape = feetShape;
|
||||||
fixtureDef.isSensor = true;
|
fixtureDef.isSensor = true;
|
||||||
|
|
||||||
|
|
@ -86,7 +95,14 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||||
this.body.CreateFixture(fixtureDef);
|
this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
var grabSensorLeftShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
var grabSensorLeftShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||||
grabSensorLeftShape.SetAsOrientedBox(10 / Settings.RATIO, 20 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(-10 / Settings.RATIO, -10 / Settings.RATIO));
|
grabSensorLeftShape.SetAsOrientedBox(
|
||||||
|
this.reachDistance / 2 / Settings.RATIO,
|
||||||
|
((this.height / 2) + this.reachDistance / 4) / Settings.RATIO,
|
||||||
|
new Box2D.Common.Math.b2Vec2(
|
||||||
|
-this.reachDistance / 2 / Settings.RATIO,
|
||||||
|
-this.height / 2 / Settings.RATIO
|
||||||
|
)
|
||||||
|
);
|
||||||
fixtureDef.shape = grabSensorLeftShape;
|
fixtureDef.shape = grabSensorLeftShape;
|
||||||
fixtureDef.isSensor = true;
|
fixtureDef.isSensor = true;
|
||||||
fixtureDef.userData = {
|
fixtureDef.userData = {
|
||||||
|
|
@ -97,7 +113,14 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||||
this.body.CreateFixture(fixtureDef);
|
this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
var grabSensorRightShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
var grabSensorRightShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||||
grabSensorRightShape.SetAsOrientedBox(10 / Settings.RATIO, 20 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(10 / Settings.RATIO, -10 / Settings.RATIO));
|
grabSensorRightShape.SetAsOrientedBox(
|
||||||
|
this.reachDistance / 2 / Settings.RATIO,
|
||||||
|
((this.height / 2) + this.reachDistance / 4) / Settings.RATIO,
|
||||||
|
new Box2D.Common.Math.b2Vec2(
|
||||||
|
this.reachDistance / 2 / Settings.RATIO,
|
||||||
|
-this.height / 2 / Settings.RATIO
|
||||||
|
)
|
||||||
|
);
|
||||||
fixtureDef.shape = grabSensorRightShape;
|
fixtureDef.shape = grabSensorRightShape;
|
||||||
fixtureDef.isSensor = true;
|
fixtureDef.isSensor = true;
|
||||||
|
|
||||||
|
|
@ -129,7 +152,19 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Doll.prototype.getPosition = function() {
|
Doll.prototype.getPosition = function() {
|
||||||
return this.body.GetPosition();
|
var pos = this.body.GetPosition();
|
||||||
|
return {
|
||||||
|
x: pos.x,
|
||||||
|
y: pos.y
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
Doll.prototype.getHeadPosition = function() {
|
||||||
|
var pos = this.body.GetPosition();
|
||||||
|
return {
|
||||||
|
x: pos.x,
|
||||||
|
y: pos.y - (this.height - this.headHeight / 2) / Settings.RATIO
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Doll.prototype.setFriction = function (friction) {
|
Doll.prototype.setFriction = function (friction) {
|
||||||
|
|
@ -249,11 +284,10 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
|
||||||
|
|
||||||
var p = this.body.GetPosition();
|
var p = this.body.GetPosition();
|
||||||
this.holdingItem.body.SetPosition(new Box2D.Common.Math.b2Vec2(
|
this.holdingItem.body.SetPosition(new Box2D.Common.Math.b2Vec2(
|
||||||
p.x + ((this.holdingItem.options.width / Settings.RATIO / 2 + 5 / Settings.RATIO) * this.lookDirection),
|
p.x + ((this.holdingItem.options.width / Settings.RATIO / 2 + this.width / 2 / Settings.RATIO) * this.lookDirection),
|
||||||
p.y - 1
|
p.y - 1 // 1m in the air
|
||||||
));
|
));
|
||||||
this.holdingItem.flip(this.lookDirection);
|
this.holdingItem.flip(this.lookDirection);
|
||||||
//this.holdingItem.body.SetAngle(Math.PI * 2 / 180 * 20 * -this.lookDirection);
|
|
||||||
this.holdingItem.body.SetAngle((this.holdingItem.options.grabAngle || 0) * this.lookDirection);
|
this.holdingItem.body.SetAngle((this.holdingItem.options.grabAngle || 0) * this.lookDirection);
|
||||||
|
|
||||||
var jointDef = new Box2D.Dynamics.Joints.b2WeldJointDef();
|
var jointDef = new Box2D.Dynamics.Joints.b2WeldJointDef();
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@ function (Parent, Box2D, Settings) {
|
||||||
this.wheels = [
|
this.wheels = [
|
||||||
this.addWheel(
|
this.addWheel(
|
||||||
options.x + 8,
|
options.x + 8,
|
||||||
options.y + 1.5
|
options.y - 1.5
|
||||||
),
|
),
|
||||||
this.addWheel(
|
this.addWheel(
|
||||||
options.x - 8,
|
options.x - 8,
|
||||||
options.y + 1.5
|
options.y - 1.5
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
@ -26,13 +26,13 @@ function (Parent, Box2D, Settings) {
|
||||||
|
|
||||||
Skateboard.prototype.createFixture = function () {
|
Skateboard.prototype.createFixture = function () {
|
||||||
|
|
||||||
var itemShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
var deckShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||||
var w = this.options.width / Settings.RATIO;
|
var w = this.options.width / Settings.RATIO;
|
||||||
var h = 1.5 / Settings.RATIO;
|
var h = 1.5 / Settings.RATIO;
|
||||||
itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(1.5 / Settings.RATIO)));
|
deckShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(4.5 / Settings.RATIO)));
|
||||||
|
|
||||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||||
fixtureDef.shape = itemShape;
|
fixtureDef.shape = deckShape;
|
||||||
|
|
||||||
var offset = 4,
|
var offset = 4,
|
||||||
factor = 80;
|
factor = 80;
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ define([
|
||||||
for (var i = 0; i < tiles.length; i++) {
|
for (var i = 0; i < tiles.length; i++) {
|
||||||
var options = tiles[i];
|
var options = tiles[i];
|
||||||
options.m = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil";
|
options.m = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil";
|
||||||
|
|
||||||
this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, options));
|
this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +117,7 @@ define([
|
||||||
// o o o
|
// o o o
|
||||||
// o o o
|
// o o o
|
||||||
|
|
||||||
this.levelObject = {
|
this.levelObject = this.levelObject || {
|
||||||
/*
|
/*
|
||||||
Material densities (g/cm^3):
|
Material densities (g/cm^3):
|
||||||
|
|
||||||
|
|
@ -277,6 +276,7 @@ microwave: 3.744
|
||||||
*/
|
*/
|
||||||
|
|
||||||
[
|
[
|
||||||
|
{s:1, x:0, y:0, r:0},
|
||||||
{s:1, x:1, y:1, r:0},
|
{s:1, x:1, y:1, r:0},
|
||||||
{s:1, x:3, y:18},
|
{s:1, x:3, y:18},
|
||||||
{s:1, x:37, y:27},
|
{s:1, x:37, y:27},
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,12 @@ function (Doll, Settings) {
|
||||||
return this.doll.getPosition();
|
return this.doll.getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player.prototype.getHeadPosition = function () {
|
||||||
|
if(!this.doll) return false;
|
||||||
|
return this.doll.getHeadPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Player.prototype.move = function (direction) {
|
Player.prototype.move = function (direction) {
|
||||||
this.doll.move(direction);
|
this.doll.move(direction);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
static/img/Animation/WithArms/ChuckAnimations0001.png
Executable file → Normal file
BIN
static/img/Animation/WithArms/ChuckAnimations0001.png
Executable file → Normal file
Binary file not shown.
|
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 749 B |
Loading…
Add table
Add a link
Reference in a new issue