mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
missing commits from last commit 7eb3d0b8b0
This commit is contained in:
parent
7eb3d0b8b0
commit
039213cf50
11 changed files with 257 additions and 430 deletions
|
|
@ -53,14 +53,16 @@ function (Parent, Item, Box2D, Nc) {
|
|||
|
||||
if(absItemVelocity.x > max || absItemVelocity.y > max) {
|
||||
if(item.lastMoved && item.lastMoved.player != this.player) {
|
||||
var damage = b2Math.SubtractVV(itemVelocity, ownVelocity);
|
||||
damage.Abs();
|
||||
damage.Multiply(itemMass);
|
||||
var damageVector = b2Math.SubtractVV(itemVelocity, ownVelocity);
|
||||
damageVector.Abs();
|
||||
damageVector.Multiply(itemMass);
|
||||
var damage = damageVector.Length() * 2;
|
||||
damage *= item.options.danger ? item.options.danger : 1;
|
||||
|
||||
var player = item.lastMoved.player;
|
||||
|
||||
var callback = function() {
|
||||
self.player.addDamage(damage.Length() * 2, player);
|
||||
self.player.addDamage(damage, player);
|
||||
}
|
||||
|
||||
Nc.trigger(Nc.ns.channel.engine.worldQueue.add, callback)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ function (Parent, Settings) {
|
|||
var objects = this.getLayer(levelData, "items").objects;
|
||||
for (var i = 0; i < objects.length; i++) {
|
||||
var object = objects[i];
|
||||
var options = object.properties;
|
||||
|
||||
var options = this.gatherOptions(object);
|
||||
|
||||
var texturePath = Settings.GRAPHICS_PATH
|
||||
+ Settings.GRAPHICS_SUBPATH_ITEMS
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ define(function() {
|
|||
GRAPHICS_SUBPATH_CHARACTERS: 'Characters/',
|
||||
GRAPHICS_SUBPATH_TILES: 'Tiles/',
|
||||
MAPS_PATH: 'static/maps/tiled/',
|
||||
DEFAULT_LEVELS: ['debug', 'stones2', 'debug'],
|
||||
DEFAULT_LEVELS: ['stones2', 'debug', 'stones2', 'debug'],
|
||||
|
||||
RATIO: 21, //35
|
||||
// original tile size is 25 but we want it to resize to 20
|
||||
|
|
|
|||
|
|
@ -2,14 +2,17 @@ define([
|
|||
"Game/" + GLOBALS.context + "/GameObjects/GameObject",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Lib/Utilities/Options",
|
||||
"Game/Config/Settings"
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/Exception"
|
||||
],
|
||||
|
||||
function (Parent, Box2D, Options, Settings) {
|
||||
function (Parent, Box2D, Options, Settings, Exception) {
|
||||
|
||||
function Item(physicsEngine, uid, options) {
|
||||
|
||||
var floatOptions = {
|
||||
grabAngle: parseFloat(options.grabAngle),
|
||||
danger: parseFloat(options.danger),
|
||||
weight: parseFloat(options.weight),
|
||||
width: parseFloat(options.width),
|
||||
height: parseFloat(options.height),
|
||||
|
|
@ -21,6 +24,11 @@ function (Parent, Box2D, Options, Settings) {
|
|||
|
||||
this.options = Options.merge(floatOptions, options);
|
||||
|
||||
if(!this.options.category) {
|
||||
// FIXME add more validation
|
||||
console.warn('item category empty (' + this.options.name + ')' );
|
||||
}
|
||||
|
||||
Parent.call(this, physicsEngine, uid);
|
||||
this.createFixture();
|
||||
this.body.ResetMassData();
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@ define([
|
|||
"Game/Config/Settings",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Utilities/Exception",
|
||||
"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"
|
||||
|
||||
], function (Settings, Box2D, Nc, Exception, CollisionDetector, Tile, Item, Skateboard, RagDoll) {
|
||||
], function (Settings, Box2D, Nc, CollisionDetector, Tile, Item, Skateboard, RagDoll) {
|
||||
|
||||
function Level (uid, engine, gameObjects) {
|
||||
this.uid = uid;
|
||||
|
|
|
|||
|
|
@ -1,16 +1,20 @@
|
|||
define([
|
||||
"Game/" + GLOBALS.context + "/Loader/Level",
|
||||
"Game/Config/Settings",
|
||||
"Game/Config/ItemSettings",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Lib/Utilities/Options",
|
||||
"Lib/Utilities/Exception",
|
||||
"Game/" + GLOBALS.context + "/Collision/Detector",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Tile",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard",
|
||||
|
||||
], function (Parent, Settings, Box2D, CollisionDetector, Tile, Item, Skateboard) {
|
||||
], function (Parent, Settings, ItemSettings, Box2D, Options, Exception, CollisionDetector, Tile, Item, Skateboard) {
|
||||
|
||||
// Public
|
||||
function TiledLevel (path, engine, gameObjects) {
|
||||
|
||||
this.levelData = null;
|
||||
Parent.call(this, path, engine, gameObjects);
|
||||
}
|
||||
|
|
@ -57,19 +61,58 @@ define([
|
|||
|
||||
TiledLevel.prototype.createItems = function() {
|
||||
var objects = this.getLayer(this.levelData, "items").objects;
|
||||
|
||||
for (var i = 0; i < objects.length; i++) {
|
||||
var object = objects[i];
|
||||
var options = object.properties;
|
||||
options.x = object.x / Settings.TILE_RATIO;
|
||||
options.y = object.y / Settings.TILE_RATIO;
|
||||
|
||||
var options = this.gatherOptions(object);
|
||||
|
||||
var uid = "item-" + i;
|
||||
var item = this.createItem(uid, options);
|
||||
this.gameObjects.animated.push(item);
|
||||
};
|
||||
};
|
||||
|
||||
TiledLevel.prototype.gatherOptions = function(tiledObject) {
|
||||
var options = {};
|
||||
|
||||
options.name = tiledObject.name;
|
||||
options.rotation = tiledObject.rotation;
|
||||
options.width = tiledObject.width / Settings.TILE_RATIO;
|
||||
options.height = tiledObject.height / Settings.TILE_RATIO;
|
||||
options.x = (tiledObject.x + tiledObject.width / 2) / Settings.TILE_RATIO;
|
||||
options.y = (tiledObject.y + options.height / 2) / Settings.TILE_RATIO;
|
||||
|
||||
if (!options.width) options.width = undefined;
|
||||
if (!options.height) options.height = undefined;
|
||||
|
||||
var defaultOptions = this.getDefaultItemSettingsByName(options.name);
|
||||
|
||||
options = Options.merge(options, defaultOptions);
|
||||
//options = Options.merge(tiledObject.properties, options);
|
||||
|
||||
return options;
|
||||
};
|
||||
|
||||
|
||||
TiledLevel.prototype.getDefaultItemSettingsByName = function(name) {
|
||||
|
||||
if(!name) {
|
||||
throw new Exception('Item name cannot be be empty');
|
||||
}
|
||||
|
||||
if(ItemSettings[name] === undefined) {
|
||||
throw new Exception('Item name (' + name + ') cannot be found in item list');
|
||||
}
|
||||
|
||||
var options = ItemSettings.Default;
|
||||
|
||||
options = Options.merge(ItemSettings[name], options);
|
||||
|
||||
return options;
|
||||
};
|
||||
|
||||
TiledLevel.prototype.getTileImagePath = function(gid) {
|
||||
//console.log(this.levelData.tilesets)
|
||||
for (var i = 0; i < this.levelData.tilesets.length; i++) {
|
||||
var tileset = this.levelData.tilesets[i];
|
||||
var offset = tileset.firstgid;
|
||||
|
|
|
|||
|
|
@ -26,10 +26,18 @@ function (Exception) {
|
|||
return preset;
|
||||
}
|
||||
|
||||
// FIXME there is a bad bug here, the preset is being manipulated by reference, so no config can be used!
|
||||
|
||||
// hotfix for the bug
|
||||
preset = JSON.parse(JSON.stringify(preset));
|
||||
|
||||
for (var key in options) {
|
||||
if(!preset.hasOwnProperty(key)) {
|
||||
preset[key] = options[key];
|
||||
} else {
|
||||
if(options[key] === undefined) {
|
||||
continue;
|
||||
}
|
||||
if(options[key].constructor !== Object) {
|
||||
preset[key] = options[key];
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue