mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
some changes
This commit is contained in:
parent
764220675b
commit
86dcdf92df
5 changed files with 250 additions and 4 deletions
52
app/Game/Client/Physics/Doll.js
Normal file
52
app/Game/Client/Physics/Doll.js
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
define([
|
||||||
|
"Game/Core/Physics/Doll",
|
||||||
|
"Game/Config/Settings",
|
||||||
|
"Game/Core/NotificationCenter"
|
||||||
|
],
|
||||||
|
|
||||||
|
function (Parent, Settings, NotificationCenter) {
|
||||||
|
|
||||||
|
function Doll(physicsEngine, playerId) {
|
||||||
|
Parent.call(this, physicsEngine, playerId);
|
||||||
|
this.height = 36;
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype = Object.create(Parent.prototype);
|
||||||
|
|
||||||
|
Doll.prototype.createMesh = function() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var imgPath = Settings.GRAPHICS_PATH
|
||||||
|
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
|
||||||
|
+ 'Chuck' + '/'
|
||||||
|
+ 'chuck.png';
|
||||||
|
|
||||||
|
var callback = function(mesh) {
|
||||||
|
self.mesh = mesh;
|
||||||
|
NotificationCenter.trigger("view/addMesh", mesh);
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationCenter.trigger("view/createMesh",
|
||||||
|
10,
|
||||||
|
36,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
imgPath,
|
||||||
|
callback
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Doll.prototype.render = function() {
|
||||||
|
|
||||||
|
NotificationCenter.trigger("view/updateMesh",
|
||||||
|
this.mesh,
|
||||||
|
{
|
||||||
|
x: this.body.GetPosition().x * Settings.RATIO + 4,
|
||||||
|
y: (this.body.GetPosition().y * Settings.RATIO) - 29
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Doll;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -2,11 +2,11 @@ define([
|
||||||
"Game/Config/Settings",
|
"Game/Config/Settings",
|
||||||
"Lib/Utilities/Exception",
|
"Lib/Utilities/Exception",
|
||||||
"Game/Client/View/Views/AbstractView",
|
"Game/Client/View/Views/AbstractView",
|
||||||
"Game/Client/View/Views/ThreeView",
|
//"Game/Client/View/Views/ThreeView",
|
||||||
"Game/Client/View/Views/PixiView",
|
"Game/Client/View/Views/PixiView",
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Settings, Exception, AbstractView, ThreeView, PixiView) {
|
function (Settings, Exception, AbstractView, PixiView) {
|
||||||
|
|
||||||
var ViewManager = {};
|
var ViewManager = {};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ define({
|
||||||
IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined',
|
IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined',
|
||||||
USE_WEGBL: true,
|
USE_WEGBL: true,
|
||||||
|
|
||||||
DEBUG_MODE: 1,
|
DEBUG_MODE: 0,
|
||||||
|
|
||||||
// NETWORKING
|
// NETWORKING
|
||||||
WORLD_UPDATE_BROADCAST_INTERVAL: 70,
|
WORLD_UPDATE_BROADCAST_INTERVAL: 70,
|
||||||
|
|
|
||||||
193
app/Game/Core/Physics/Doll.js
Executable file
193
app/Game/Core/Physics/Doll.js
Executable file
|
|
@ -0,0 +1,193 @@
|
||||||
|
define([
|
||||||
|
"Game/" + GLOBALS.context + "/GameObjects/GameObject",
|
||||||
|
"Lib/Vendor/Box2D",
|
||||||
|
"Game/Config/Settings",
|
||||||
|
"Game/" + GLOBALS.context + "/Collision/Detector"
|
||||||
|
],
|
||||||
|
|
||||||
|
function (Parent, Box2D, Settings, CollisionDetector) {
|
||||||
|
|
||||||
|
function Doll (physicsEngine, playerId) {
|
||||||
|
|
||||||
|
Parent.call(this, physicsEngine);
|
||||||
|
|
||||||
|
this.playerId = playerId;
|
||||||
|
|
||||||
|
this.standing = false;
|
||||||
|
this.moveDirection = 0;
|
||||||
|
this.lookDirection = 0;
|
||||||
|
this.legs;
|
||||||
|
|
||||||
|
this.createFixtures();
|
||||||
|
this.body.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype = Object.create(Parent.prototype);
|
||||||
|
|
||||||
|
Doll.prototype.getBodyDef = function() {
|
||||||
|
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||||
|
bodyDef.position.x = 220 / Settings.RATIO;
|
||||||
|
bodyDef.position.y = 0 / Settings.RATIO;
|
||||||
|
bodyDef.fixedRotation = true;
|
||||||
|
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
||||||
|
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||||
|
bodyDef.userData = CollisionDetector.IDENTIFIER.PLAYER + '-' + this.playerId;
|
||||||
|
|
||||||
|
return bodyDef;
|
||||||
|
};
|
||||||
|
|
||||||
|
Doll.prototype.createFixtures = function () {
|
||||||
|
|
||||||
|
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||||
|
fixtureDef.density = Settings.PLAYER_DENSITY;
|
||||||
|
fixtureDef.friction = 0;
|
||||||
|
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
|
||||||
|
|
||||||
|
var headShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||||
|
headShape.SetRadius(5 / Settings.RATIO);
|
||||||
|
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -37 / Settings.RATIO));
|
||||||
|
fixtureDef.shape = headShape;
|
||||||
|
fixtureDef.isSensor = false;
|
||||||
|
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;
|
||||||
|
this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
|
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||||
|
legsShape.SetRadius(5 / Settings.RATIO);
|
||||||
|
legsShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -5 / Settings.RATIO));
|
||||||
|
fixtureDef.shape = legsShape;
|
||||||
|
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
||||||
|
fixtureDef.isSensor = false;
|
||||||
|
|
||||||
|
this.legs = this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
|
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||||
|
feetShape.SetRadius(4 / Settings.RATIO);
|
||||||
|
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 0 / Settings.RATIO));
|
||||||
|
fixtureDef.shape = feetShape;
|
||||||
|
fixtureDef.isSensor = true;
|
||||||
|
|
||||||
|
fixtureDef.userData = {
|
||||||
|
onCollisionChange: this.onFootSensorDetection.bind(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.body.CreateFixture(fixtureDef);
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype.spawn = function (x, y) {
|
||||||
|
this.body.SetPosition(new Box2D.Common.Math.b2Vec2(x / Settings.RATIO, y / Settings.RATIO));
|
||||||
|
this.body.SetActive(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype.getPosition = function() {
|
||||||
|
return this.body.GetPosition();
|
||||||
|
};
|
||||||
|
|
||||||
|
Doll.prototype.setFriction = function (friction) {
|
||||||
|
if(!friction) friction = -1;
|
||||||
|
|
||||||
|
if (this.legs.GetFriction() != friction) {
|
||||||
|
this.legs.SetFriction(friction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype.move = function (direction) {
|
||||||
|
|
||||||
|
this.moveDirection = direction;
|
||||||
|
var speed;
|
||||||
|
|
||||||
|
switch(true) {
|
||||||
|
case direction == this.lookDirection && this.isStanding():
|
||||||
|
speed = Settings.RUN_SPEED;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case !this.isStanding():
|
||||||
|
speed = Settings.FLY_SPEED;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
speed = Settings.WALK_SPEED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setFriction(Settings.PLAYER_MOTION_FRICTION);
|
||||||
|
this.body.SetAwake(true);
|
||||||
|
var vector = new Box2D.Common.Math.b2Vec2(speed * direction, this.body.GetLinearVelocity().y);
|
||||||
|
this.body.SetLinearVelocity(vector);
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype.stop = function () {
|
||||||
|
this.moveDirection = 0;
|
||||||
|
this.setFriction(Settings.PLAYER_FRICTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype.jump = function () {
|
||||||
|
if (this.isStanding()) {
|
||||||
|
|
||||||
|
this.body.SetAwake(true);
|
||||||
|
var vector = new Box2D.Common.Math.b2Vec2(0, -Settings.JUMP_SPEED);
|
||||||
|
this.body.ApplyImpulse(vector, this.body.GetPosition());
|
||||||
|
|
||||||
|
this.setStanding(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype.destroy = function () {
|
||||||
|
this.body.GetWorld().DestroyBody(this.body);
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype.setStanding = function (isStanding) {
|
||||||
|
this.standing = isStanding;
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype.isStanding = function () {
|
||||||
|
return this.standing;
|
||||||
|
}
|
||||||
|
|
||||||
|
Doll.prototype.lookAt = function(x, y) {
|
||||||
|
var lastLookDirection = this.lookDirection;
|
||||||
|
/*
|
||||||
|
var degree = Math.atan2(Settings.STAGE_WIDTH / 2 - x, Settings.STAGE_HEIGHT / 2 - 25 - y) / (Math.PI / 180);
|
||||||
|
if (x < Settings.STAGE_WIDTH / 2) {
|
||||||
|
this.mc.scaleX = -1;
|
||||||
|
this.lookDirection = -1;
|
||||||
|
degree = (-45 + degree / 2);
|
||||||
|
this.mc.head.rotation = degree;
|
||||||
|
} else if (x >= Settings.STAGE_WIDTH / 2) {
|
||||||
|
this.mc.scaleX = 1;
|
||||||
|
this.lookDirection = 1;
|
||||||
|
degree = (45 + -degree / 2) - 90;
|
||||||
|
this.mc.head.rotation = degree;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(x < 0) {
|
||||||
|
this.lookDirection = -1;
|
||||||
|
} else {
|
||||||
|
this.lookDirection = 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Doll.prototype.onFootSensorDetection = function(isColliding) {
|
||||||
|
if(isColliding && !(this.body.GetLinearVelocity().y < -Settings.JUMP_SPEED && !this.isStanding())) {
|
||||||
|
this.setStanding(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Doll.prototype.update = function() {
|
||||||
|
|
||||||
|
if (this.body.GetLinearVelocity().x == 0) {
|
||||||
|
this.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.body.IsAwake() && !this.isStanding()) {
|
||||||
|
this.setStanding(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return Doll;
|
||||||
|
});
|
||||||
|
|
@ -2,7 +2,8 @@ GLOBALS = { context: "Client" };
|
||||||
|
|
||||||
requirejs.config({
|
requirejs.config({
|
||||||
baseUrl: 'app',
|
baseUrl: 'app',
|
||||||
deps: ['Lib/Utilities/Extensions']
|
deps: ['Lib/Utilities/Extensions'],
|
||||||
|
waitSeconds: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
var inspector = {};
|
var inspector = {};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue