chuck.js/app/Game/Channel/Control/PlayerController.js
Karl Pannek dc779def9c Complete Box2D to Planck.js migration
- 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
2025-07-16 15:01:59 +02:00

80 lines
No EOL
2.4 KiB
JavaScript
Executable file

define([
"Game/Core/Control/PlayerController",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Protocol/Parser",
"Game/Config/Settings"
],
function(Parent, nc, Parser, Settings) {
"use strict";
function PlayerController(player) {
Parent.call(this, player);
}
PlayerController.prototype = Object.create(Parent.prototype);
/*
* retrieves move (and other) commands from client and executes them at the server
*/
PlayerController.prototype.applyCommand = function(options) {
// FIXME: remove this function and use ProtocolHelper.applyCommand() instead
// Don't forget to change the function names to on...
var message;
if (typeof options == "string") {
message = Parser.decode(options);
} else {
message = options;
}
for (var command in message) {
this[command].call(this, message[command]);
}
};
PlayerController.prototype.handActionRequest = function(options) {
options.x = parseFloat(options.x) || 0.0;
options.y = parseFloat(options.y) || 0.0;
options.av = parseFloat(options.av) || 0.0;
if (options) this.player.handActionRequest(options);
};
PlayerController.prototype.suicide = function() {
this.player.suicide();
};
PlayerController.prototype.mePositionStateOverride = function(update) {
if(!this.player.isSpawned()) {
// if someone still falls but is dead on the server already
return;
}
var difference = {
x: Math.abs(update.p.x - this.player.doll.body.getPosition().x),
y: Math.abs(update.p.y - this.player.doll.body.getPosition().y)
};
if(difference.x < Settings.PUNKBUSTER_DIFFERENCE_METERS &&
difference.y < Settings.PUNKBUSTER_DIFFERENCE_METERS) {
this.player.doll.updatePositionState(update);
} else {
// HARD UPDATE FOR SELF
console.log(this.player.user.options.nickname + " is cheating.");
var body = this.player.doll.body;
var options = {
p: body.getPosition(),
lv: body.getLinearVelocity()
};
nc.trigger(nc.ns.channel.to.client.user.gameCommand.send + this.player.id, "positionStateReset", options);
}
};
return PlayerController;
});