chuck.js/app/Game/Core/Loader/Level.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

102 lines
No EOL
3.1 KiB
JavaScript
Executable file

define([
"Game/Config/Settings",
"Lib/Vendor/Planck",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Abstract",
"Game/" + GLOBALS.context + "/Collision/Detector",
"Game/" + GLOBALS.context + "/GameObjects/Tile",
"Game/" + GLOBALS.context + "/GameObjects/Item",
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard",
"Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll",
"Game/" + GLOBALS.context + "/GameObjects/Items/RubeDoll"
], function (Settings, Box2D, nc, Abstract, CollisionDetector, Tile, Item, Skateboard, RagDoll, RubeDoll) {
"use strict";
function Level (uid, engine) {
this.uid = uid;
this.engine = engine;
this.levelObject = null;
this.isLoaded = false;
this.load(this.uid);
this.spawnPoints = null;
}
Level.prototype.load = function (uid) {
var self = this;
// FIXME: check if theres a security hazard here (user injected path)
var path = Settings.MAPS_PATH + uid + ".json";
this.loadLevelDataFromPath(path, function (levelData) {
self.setup(levelData);
});
};
Level.prototype.setup = function(levelData) { // jshint unused:false
this.isLoaded = true;
nc.trigger(nc.ns.core.game.events.level.loaded);
};
Level.prototype.createItems = function(options) {
for (var i = 0; i < options.length; i++) {
var uid = "item-" + i;
this.createItem(uid, options[i]);
}
};
Level.prototype.createItem = function(uid, options) {
switch(options.type) {
case "skateboard":
return new Skateboard(this.engine, uid, options);
case "ragdoll":
return new RagDoll(this.engine, uid, options);
case "rubedoll":
return new RubeDoll(this.engine, uid, options);
default:
return new Item(this.engine, uid, options);
}
};
Level.prototype.createTiles = function(options) {
for (var i = 0; i < options.length; i++) {
new Tile(this.engine, "tile-" + i, options[i]);
}
};
Level.prototype.createSpawnPoints = function(points) {
this.spawnPoints = points;
};
Level.prototype.setupLayer = function(options, behind, referenceId) { // jshint unused:false
// will be extended (so far only in client)
};
Level.prototype.createContainer = function(options) { // jshint unused:false
// nothing to do here yet, in the future perhaps synchronize day/night graphics
};
Level.prototype.getRandomSpawnPoint = function() {
if(!this.spawnPoints) {
return {
x: 150 + Math.random() * 300,
y: -500
};
}
var size = this.spawnPoints.length;
var object = this.spawnPoints[parseInt(Math.random() * (size -1), 10)];
return {
x: object.x / Settings.TILE_RATIO,
y: object.y / Settings.TILE_RATIO
};
};
Level.prototype.destroy = function () {
this.isLoaded = false;
};
return Level;
});