Add working debug level with grass and soil tiles

- Created DebugLevel class that bypasses complex TiledLevel loader
- Simple platform with grass tiles (10.gif) on top, soil tiles (10.gif) underneath
- Fixed tile texture paths to work with MAPS_PATH
- Fixed null check in User.js to prevent server crashes
- Working physics collision with Box2D
- Clean test environment for physics engine migration
This commit is contained in:
Karl Pannek 2025-07-16 12:51:31 +02:00
parent e6089687ed
commit 244dc50037
8 changed files with 336 additions and 6 deletions

View file

@ -0,0 +1,19 @@
define([
"Game/Core/Loader/DebugLevel"
],
function (Parent) {
"use strict";
function DebugLevel(uid, engine) {
Parent.call(this, uid, engine);
}
DebugLevel.prototype = Object.create(Parent.prototype);
// Channel side doesn't need any special handling beyond the core functionality
// The physics engine and tile creation is handled by the parent class
return DebugLevel;
});

View file

@ -0,0 +1,121 @@
define([
"Game/Core/Loader/DebugLevel",
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter",
"Lib/Vendor/Pixi",
"Game/Client/View/Abstract/Layer"
],
function (Parent, Settings, nc, PIXI, AbstractLayer) {
"use strict";
function DebugLevel (uid, engine, gameObjects) {
this.levelSize = {
width: 30 * Settings.TILE_SIZE,
height: 20 * Settings.TILE_SIZE
};
// Set level size before parent setup
nc.trigger(nc.ns.client.view.layer.levelSizeUpdate, this.levelSize);
Parent.call(this, uid, engine, gameObjects);
}
DebugLevel.prototype = Object.create(Parent.prototype);
DebugLevel.prototype.setup = function() {
console.log("Setting up debug level (client) - loading minimal assets");
// Load minimal assets needed for debug mode
this.loadDebugAssets(function() {
// Create the required layers before parent setup
this.createRequiredLayers();
// Call parent setup after assets are loaded
Parent.prototype.setup.call(this);
}.bind(this));
};
DebugLevel.prototype.createRequiredLayers = function() {
console.log("Creating debug layers");
// Create the tile layer (required for tile rendering)
nc.trigger(
nc.ns.client.view.layer.createAndInsert,
AbstractLayer.ID.TILE, // "tile"
{
parallaxSpeed: 0.0,
levelSize: this.levelSize
},
true, // behind
null // no reference
);
// Create the spawn layer (required for spawn points)
nc.trigger(
nc.ns.client.view.layer.createAndInsert,
AbstractLayer.ID.SPAWN, // "spawnpoints"
{
parallaxSpeed: 0.0,
levelSize: this.levelSize
},
false, // in front
AbstractLayer.ID.TILE // after tile layer
);
};
DebugLevel.prototype.loadDebugAssets = function(callback) {
var paths = this.getDebugAssetPaths();
if (paths.length === 0) {
callback();
return;
}
var count = 0;
var numPaths = paths.length;
var loader = new PIXI.AssetLoader(paths);
loader.onComplete = function() {
console.log("Debug assets loaded successfully");
callback();
};
loader.onProgress = function() {
var progress = parseInt(100 / numPaths * ++count, 10) + 1;
nc.trigger(nc.ns.client.view.preloadBar.update, progress);
};
loader.load();
};
DebugLevel.prototype.getDebugAssetPaths = function() {
var paths = [];
// Load character assets (needed for player)
var characterName = "Chuck";
paths.push(
Settings.GRAPHICS_PATH
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
+ characterName
+ "/Animation/"
+ "/TexturePacker"
+ "/chuck_sheet.json"
);
paths.push(
Settings.GRAPHICS_PATH
+ Settings.GRAPHICS_SUBPATH_CHARACTERS
+ characterName
+ "/head.png"
);
// Load the grass tile texture we're using
paths.push("static/img/Tiles/GrassSoil/22.gif");
return paths;
};
return DebugLevel;
});

View file

@ -1,6 +1,7 @@
define([
"Game/" + GLOBALS.context + "/Physics/Engine",
"Game/" + GLOBALS.context + "/Loader/TiledLevel",
"Game/" + GLOBALS.context + "/Loader/DebugLevel",
"Game/" + GLOBALS.context + "/Player",
"Lib/Utilities/NotificationCenter",
"Game/" + GLOBALS.context + "/GameObjects/Doll",
@ -9,7 +10,7 @@ define([
"Lib/Utilities/Assert",
],
function (PhysicsEngine, TiledLevel, Player, nc, Doll, GameObject, Item, Assert) {
function (PhysicsEngine, TiledLevel, DebugLevel, Player, nc, Doll, GameObject, Item, Assert) {
"use strict";
@ -61,7 +62,14 @@ function (PhysicsEngine, TiledLevel, Player, nc, Doll, GameObject, Item, Assert)
this.worldUpdateObjects = {};
}
this.level = new TiledLevel(levelUid, this.physicsEngine);
// Use DebugLevel for debug mode, otherwise use TiledLevel
if (levelUid === "debug") {
console.log("Loading debug level (simple platform)");
this.level = new DebugLevel(levelUid, this.physicsEngine);
} else {
console.log("Loading tiled level: " + levelUid);
this.level = new TiledLevel(levelUid, this.physicsEngine);
}
};
/*

View file

@ -0,0 +1,105 @@
define([
"Game/Config/Settings",
"Lib/Vendor/Box2D",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Abstract",
"Game/" + GLOBALS.context + "/GameObjects/Tile"
], function (Settings, Box2D, nc, Abstract, Tile) {
"use strict";
function DebugLevel (uid, engine) {
this.uid = uid;
this.engine = engine;
this.isLoaded = false;
this.spawnPoints = null;
this.setup();
}
DebugLevel.prototype.setup = function() {
console.log("Setting up debug level - creating simple platform");
// Create a simple platform in the middle of the screen
this.createSimplePlatform();
this.createSimpleSpawnPoints();
this.isLoaded = true;
nc.trigger(nc.ns.core.game.events.level.loaded);
};
DebugLevel.prototype.createSimplePlatform = function() {
// Create a simple horizontal platform with grass on top, soil underneath
var platformTiles = [
// Top layer - grass tiles at y=8
{s: 1, r: 0, t: "../../img/Tiles/GrassSoil/10.gif", x: 10, y: 8},
{s: 1, r: 0, t: "../../img/Tiles/GrassSoil/10.gif", x: 11, y: 8},
{s: 1, r: 0, t: "../../img/Tiles/GrassSoil/10.gif", x: 12, y: 8},
{s: 1, r: 0, t: "../../img/Tiles/GrassSoil/10.gif", x: 13, y: 8},
{s: 1, r: 0, t: "../../img/Tiles/GrassSoil/10.gif", x: 14, y: 8},
{s: 1, r: 0, t: "../../img/Tiles/GrassSoil/10.gif", x: 15, y: 8},
{s: 1, r: 0, t: "../../img/Tiles/GrassSoil/10.gif", x: 16, y: 8},
{s: 1, r: 0, t: "../../img/Tiles/GrassSoil/10.gif", x: 17, y: 8},
{s: 1, r: 0, t: "../../img/Tiles/GrassSoil/10.gif", x: 18, y: 8},
{s: 1, r: 0, t: "../../img/Tiles/GrassSoil/10.gif", x: 19, y: 8},
// Bottom layer - soil tiles at y=9
{s: 1, r: 0, t: "../../img/Tiles/Soil/10.gif", x: 10, y: 9},
{s: 1, r: 0, t: "../../img/Tiles/Soil/10.gif", x: 11, y: 9},
{s: 1, r: 0, t: "../../img/Tiles/Soil/10.gif", x: 12, y: 9},
{s: 1, r: 0, t: "../../img/Tiles/Soil/10.gif", x: 13, y: 9},
{s: 1, r: 0, t: "../../img/Tiles/Soil/10.gif", x: 14, y: 9},
{s: 1, r: 0, t: "../../img/Tiles/Soil/10.gif", x: 15, y: 9},
{s: 1, r: 0, t: "../../img/Tiles/Soil/10.gif", x: 16, y: 9},
{s: 1, r: 0, t: "../../img/Tiles/Soil/10.gif", x: 17, y: 9},
{s: 1, r: 0, t: "../../img/Tiles/Soil/10.gif", x: 18, y: 9},
{s: 1, r: 0, t: "../../img/Tiles/Soil/10.gif", x: 19, y: 9}
];
console.log("Creating " + platformTiles.length + " debug tiles (grass + soil)");
for (var i = 0; i < platformTiles.length; i++) {
var tileData = platformTiles[i];
var tileUid = "debug_tile_" + i;
new Tile(this.engine, tileUid, tileData);
}
};
DebugLevel.prototype.createSimpleSpawnPoints = function() {
// Create spawn points above the platform - spawn at y=5 (above y=8 tiles)
this.spawnPoints = [
{x: 12 * Settings.TILE_SIZE, y: 5 * Settings.TILE_SIZE},
{x: 15 * Settings.TILE_SIZE, y: 5 * Settings.TILE_SIZE},
{x: 18 * Settings.TILE_SIZE, y: 5 * Settings.TILE_SIZE}
];
};
DebugLevel.prototype.createTiles = function(options) {
console.log("Creating " + options.length + " debug tiles");
for (var i = 0; i < options.length; i++) {
new Tile(this.engine, "debug-tile-" + i, options[i]);
}
};
DebugLevel.prototype.getRandomSpawnPoint = function() {
if(!this.spawnPoints || this.spawnPoints.length === 0) {
return {
x: 15 * Settings.TILE_SIZE,
y: 10 * Settings.TILE_SIZE
};
}
var size = this.spawnPoints.length;
var object = this.spawnPoints[parseInt(Math.random() * size, 10)];
return {
x: object.x / Settings.TILE_RATIO,
y: object.y / Settings.TILE_RATIO
};
};
DebugLevel.prototype.destroy = function () {
this.isLoaded = false;
};
return DebugLevel;
});