implemented spawn points and a brand new map

This commit is contained in:
logsol 2014-02-03 16:18:22 +01:00
parent 4ea86a97aa
commit cc8aedd3ba
10 changed files with 1283 additions and 10645 deletions

View file

@ -16,6 +16,7 @@ define({
GRAPHICS_SUBPATH_CHARACTERS: 'Characters/',
GRAPHICS_SUBPATH_TILES: 'Tiles/',
MAPS_PATH: 'static/maps/tiled/',
DEFAULT_LEVELS: ['stones'],
RATIO: 21, //35
TILE_SIZE: 25, //15, 25 is original picture

View file

@ -8,6 +8,7 @@ function (PhysicsEngine, TiledLevel, Player) {
function GameController () {
this.players = {};
this.level = null;
this.gameObjects = {
animated: [],
fixed: []

View file

@ -75,5 +75,12 @@ define([
};
};
Level.prototype.getRandomSpawnPoint = function() {
return {
x: 150 + Math.random() * 300,
y: 0
};
};
return Level;
})

View file

@ -62,8 +62,6 @@ define([
} else {
console.warn("Level: No collision Layer given");
}
this.levelData = null; // free up memory
}
TiledLevel.prototype.getTileImagePath = function(gid) {
@ -77,5 +75,26 @@ define([
}
}
TiledLevel.prototype.getRandomSpawnPoint = function() {
if(!this.levelData) {
return Parent.prototype.getRandomSpawnPoint.call(this);
}
for (var i = 0; i < this.levelData.layers.length; i++) {
if(this.levelData.layers[i].name === "spawnpoints") {
var spawnLayer = this.levelData.layers[i];
var size = spawnLayer.objects.length;
var object = spawnLayer.objects[parseInt(Math.random() * (size -1), 10)];
return {
x: object.x,
y: object.y
}
}
}
};
return TiledLevel;
})

View file

@ -3,17 +3,18 @@
"Lib/Utilities/NotificationCenter",
"Game/Server/User",
"Lib/Utilities/Protocol/Helper",
"Lib/Utilities/Options"
"Lib/Utilities/Options",
"Game/Config/Settings"
],
function (GameController, NotificationCenter, User, ProtocolHelper, Options) {
function (GameController, NotificationCenter, User, ProtocolHelper, Options, Settings) {
function Channel (pipeToLobby, name, options) {
var self = this;
this.options = options = Options.merge(options, {
levelUids: ["circles", "dungeon"]
levelUids: Settings.DEFAULT_LEVELS
});
this.name = name;

View file

@ -54,16 +54,17 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
}
GameController.prototype.spawnPlayer = function(player) {
var x = 150 + Math.random() * 300,
y = 0;
player.spawn(x, y);
var spawnPoint = this.level.getRandomSpawnPoint();
player.spawn(spawnPoint.x, spawnPoint.y);
this.gameObjects.animated.push(player.getDoll());
var message = {
spawnPlayer: {
id: player.id,
x: x,
y: y
x: spawnPoint.x,
y: spawnPoint.y
}
};
NotificationCenter.trigger("sendControlCommandToAllUsers", "gameCommand", message);