mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
- Replace Box2D.js with Planck.js physics engine - Update all require paths from 'Lib/Vendor/Box2D' to 'Lib/Vendor/Planck' - Convert Box2D contact listeners to Planck.js event system - Fix all method name capitalization (Get* -> get*, Set* -> set*) - Update collision detection system for Planck.js compatibility - Server now starts successfully and basic physics working - Character can land on platforms - core physics functional Major milestone: Game now running on modern, maintained physics engine
127 lines
No EOL
3.2 KiB
JavaScript
127 lines
No EOL
3.2 KiB
JavaScript
define([
|
|
"Game/Client/Player",
|
|
"Game/Config/Settings",
|
|
"Lib/Utilities/NotificationCenter",
|
|
"Lib/Utilities/Assert",
|
|
"Game/Client/Control/PlayerController",
|
|
],
|
|
|
|
function (Parent, Settings, nc, Assert, PlayerController) {
|
|
|
|
"use strict";
|
|
|
|
function Me(id, physicsEngine, user) {
|
|
Parent.call(this, id, physicsEngine, user);
|
|
|
|
// View uses this to calculate center position
|
|
this.lookAtXY = {
|
|
x: Settings.VIEWPORT_LOOK_AHEAD,
|
|
y: 0
|
|
};
|
|
|
|
this.lastServerPositionState = {
|
|
p: {
|
|
x: 0,
|
|
y: 0
|
|
}
|
|
};
|
|
|
|
this.arrowMesh = null;
|
|
this.createAndAddArrow();
|
|
this.playerController = new PlayerController(this);
|
|
}
|
|
|
|
Me.prototype = Object.create(Parent.prototype);
|
|
|
|
Me.prototype.lookAt = function(x, y) {
|
|
this.lookAtXY = {
|
|
x: x,
|
|
y: y
|
|
};
|
|
|
|
Parent.prototype.lookAt.call(this, x, y);
|
|
};
|
|
|
|
Me.prototype.getLookAt = function() {
|
|
return {
|
|
x: this.lookAtXY.x,
|
|
y: this.lookAtXY.y
|
|
};
|
|
};
|
|
|
|
Me.prototype.setLastServerPositionState = function(update) {
|
|
this.lastServerPositionState = update;
|
|
};
|
|
|
|
// Checks if client should send out its position to server
|
|
Me.prototype.isPositionStateOverrideNeeded = function() {
|
|
|
|
if(!this.doll) {
|
|
return false;
|
|
}
|
|
|
|
if(this.doll.isAnotherPlayerNearby()) {
|
|
return false;
|
|
}
|
|
|
|
var difference = {
|
|
x: Math.abs(this.lastServerPositionState.p.x - this.doll.body.getPosition().x),
|
|
y: Math.abs(this.lastServerPositionState.p.y - this.doll.body.getPosition().y)
|
|
};
|
|
|
|
if(difference.x > Settings.ME_STATE_MAX_DIFFERENCE_METERS ||
|
|
difference.y > Settings.ME_STATE_MAX_DIFFERENCE_METERS) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
Me.prototype.getPositionStateOverride = function() {
|
|
return {
|
|
p: this.doll.body.getPosition().clone(),
|
|
lv: this.doll.body.getLinearVelocity().clone()
|
|
};
|
|
};
|
|
|
|
Me.prototype.acceptPositionStateUpdateFromServer = function() {
|
|
// gamecontroller should accept me's doll update only when another players doll is nearby.
|
|
return this.doll.isAnotherPlayerNearby();
|
|
};
|
|
|
|
Me.prototype.resetPositionState = function(options) {
|
|
Assert.number(options.p.x, options.p.y);
|
|
Assert.number(options.lv.x, options.lv.y);
|
|
this.doll.body.setPosition(options.p);
|
|
this.doll.body.setLinearVelocity(options.lv);
|
|
};
|
|
|
|
Me.prototype.createAndAddArrow = function() {
|
|
var self = this;
|
|
|
|
var position = this.getPosition();
|
|
|
|
var options = {
|
|
x: position.x * Settings.RATIO,
|
|
y: position.y * Settings.RATIO,
|
|
};
|
|
|
|
var callback = function(arrowMesh) {
|
|
self.arrowMesh = arrowMesh;
|
|
};
|
|
nc.trigger(nc.ns.client.view.playerArrow.createAndAdd, callback, options);
|
|
};
|
|
|
|
Me.prototype.render = function() {
|
|
|
|
Parent.prototype.render.call(this);
|
|
|
|
var position = this.getPosition();
|
|
var options = {
|
|
x: position.x * Settings.RATIO,
|
|
y: position.y * Settings.RATIO,
|
|
};
|
|
nc.trigger(nc.ns.client.view.playerArrow.update, this.arrowMesh, options);
|
|
};
|
|
|
|
return Me;
|
|
}); |