mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
first attempt to implement tiled style maps
This commit is contained in:
parent
3c8d3d3d8e
commit
b02036a019
5 changed files with 87 additions and 16 deletions
|
|
@ -10,11 +10,12 @@ define({
|
||||||
BOX2D_POSITION_ITERATIONS: 5,
|
BOX2D_POSITION_ITERATIONS: 5,
|
||||||
BOX2D_TIME_STEP: 1 / 60,
|
BOX2D_TIME_STEP: 1 / 60,
|
||||||
|
|
||||||
// GRAPHIC PATHS
|
// PATHS
|
||||||
GRAPHICS_PATH: 'static/img/',
|
GRAPHICS_PATH: 'static/img/',
|
||||||
GRAPHICS_SUBPATH_ITEMS: 'Items/',
|
GRAPHICS_SUBPATH_ITEMS: 'Items/',
|
||||||
GRAPHICS_SUBPATH_CHARACTERS: 'Characters/',
|
GRAPHICS_SUBPATH_CHARACTERS: 'Characters/',
|
||||||
GRAPHICS_SUBPATH_TILES: 'Tiles/',
|
GRAPHICS_SUBPATH_TILES: 'Tiles/',
|
||||||
|
MAPS_PATH: 'static/maps/'
|
||||||
|
|
||||||
RATIO: 21, //35
|
RATIO: 21, //35
|
||||||
TILE_SIZE: 15, //15, 25 is original picture
|
TILE_SIZE: 15, //15, 25 is original picture
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,12 @@ define([
|
||||||
this.gameObjects = gameObjects;
|
this.gameObjects = gameObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
Level.prototype.loadLevelInToEngine = function () {
|
Level.prototype.loadLevelInToEngine = function (callback) {
|
||||||
this.loadLevelObjectFromPath(this.path);
|
this.loadLevelObjectFromPath(this.path, function(levelData){
|
||||||
this.createTiles();
|
this.createTiles(levelData);
|
||||||
this.createItems();
|
this.createItems(levelData);
|
||||||
|
callback();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Level.prototype.destroy = function () {
|
Level.prototype.destroy = function () {
|
||||||
|
|
@ -33,22 +35,26 @@ define([
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
Level.prototype.createTiles = function () {
|
Level.prototype.createTiles = function (levelData) {
|
||||||
if (!this.levelObject || !this.levelObject.tiles || this.levelObject.tiles.length < 1) {
|
|
||||||
|
if (!levelData || !levelData.tiles || levelData.tiles.length < 1) {
|
||||||
throw "Level: Can't create physic tiles, no tiles found";
|
throw "Level: Can't create physic tiles, no tiles found";
|
||||||
}
|
}
|
||||||
|
|
||||||
var tiles = this.levelObject.tiles;
|
var tiles = levelData.tiles;
|
||||||
|
|
||||||
for (var i = 0; i < tiles.length; i++) {
|
for (var i = 0; i < tiles.length; i++) {
|
||||||
var options = tiles[i];
|
var options = tiles[i];
|
||||||
options.m = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil";
|
//options.m = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil";
|
||||||
this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, options));
|
this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Level.prototype.createItems = function() {
|
Level.prototype.createItems = function() {
|
||||||
var items = this.levelObject.items;
|
if (!levelData || !levelData.tiles) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var items = levelData.items;
|
||||||
|
|
||||||
for (var i = 0; i < items.length; i++) {
|
for (var i = 0; i < items.length; i++) {
|
||||||
var options = items[i];
|
var options = items[i];
|
||||||
|
|
@ -358,6 +364,7 @@ microwave: 3.744
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove hack
|
// TODO remove hack
|
||||||
|
/*
|
||||||
Level.prototype.tileAtPositionExists = function(x, y) {
|
Level.prototype.tileAtPositionExists = function(x, y) {
|
||||||
|
|
||||||
for (var i = 0; i < this.levelObject.tiles.length; i++) {
|
for (var i = 0; i < this.levelObject.tiles.length; i++) {
|
||||||
|
|
@ -366,6 +373,7 @@ microwave: 3.744
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
return Level;
|
return Level;
|
||||||
})
|
})
|
||||||
46
app/Game/Core/Loader/TiledLevel.js
Executable file
46
app/Game/Core/Loader/TiledLevel.js
Executable file
|
|
@ -0,0 +1,46 @@
|
||||||
|
define([
|
||||||
|
"Game/Config/Settings",
|
||||||
|
"Lib/Vendor/Box2D",
|
||||||
|
"Game/" + GLOBALS.context + "/Collision/Detector",
|
||||||
|
"Game/" + GLOBALS.context + "/GameObjects/Tile",
|
||||||
|
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||||
|
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard",
|
||||||
|
|
||||||
|
], function (Settings, Box2D, CollisionDetector, Tile, Item, Skateboard) {
|
||||||
|
|
||||||
|
// Public
|
||||||
|
function Level (path, engine, gameObjects) {
|
||||||
|
this.path = path;
|
||||||
|
this.engine = engine;
|
||||||
|
this.levelObject = null;
|
||||||
|
this.gameObjects = gameObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
Level.prototype.loadLevelInToEngine = function () {
|
||||||
|
this.loadLevelObjectFromPath(this.path);
|
||||||
|
this.createTiles();
|
||||||
|
//this.createItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private
|
||||||
|
|
||||||
|
Level.prototype.createTiles = function () {
|
||||||
|
if (!this.levelObject || !this.levelObject.tiles || this.levelObject.tiles.length < 1) {
|
||||||
|
throw "Level: Can't create physic tiles, no tiles found";
|
||||||
|
}
|
||||||
|
|
||||||
|
var tiles = this.levelObject.tiles;
|
||||||
|
|
||||||
|
for (var i = 0; i < tiles.length; i++) {
|
||||||
|
var options = tiles[i];
|
||||||
|
options.m = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil";
|
||||||
|
this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, options));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Level.prototype.loadLevelObjectFromPath = function (path) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return Level;
|
||||||
|
})
|
||||||
|
|
@ -1,9 +1,25 @@
|
||||||
define([
|
define([
|
||||||
"Game/Core/Loader/Level"
|
"Game/Core/Loader/Level",
|
||||||
|
"Game/Config/Settings"
|
||||||
|
"fs"
|
||||||
],
|
],
|
||||||
|
|
||||||
function(Parent) {
|
function (Parent, Fs) {
|
||||||
|
|
||||||
return Parent;
|
function Level () {
|
||||||
|
Parent.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Level.prototype = Object.create(Parent.prototype);
|
||||||
|
|
||||||
|
Level.prototype.loadLevelObjectFromPath = function (path, callback) {
|
||||||
|
// overwriting parent
|
||||||
|
|
||||||
|
fs.readFile( + path, function (err, data) {
|
||||||
|
if (err) throw err;
|
||||||
|
callback(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Level;
|
||||||
});
|
});
|
||||||
BIN
static/img/Characters/Chuck/chuck-hats.psd
Normal file
BIN
static/img/Characters/Chuck/chuck-hats.psd
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue