First attack draft, working. Fixed bug in Player-Creation
This commit is contained in:
parent
d48da33db2
commit
a9c7f04230
2 changed files with 151 additions and 83 deletions
224
src/jsds.js
224
src/jsds.js
|
@ -1,87 +1,157 @@
|
||||||
{
|
{
|
||||||
function Creature(info,attributes,properties,drawinfo,battle){
|
// OOP-Setup
|
||||||
/* info: pname, cname,class, level, experience, race, size
|
var reflection = {};
|
||||||
* attributes: body, agility, spirit
|
|
||||||
* properties: strength, hardness, movement, skill, mind, aura
|
|
||||||
* drawinfo: x,y,w,h,col
|
|
||||||
*/
|
|
||||||
this.info = {"pname": info["pname"]+"", "experience": info["experience"]*1, "race":info["race"]+"",
|
|
||||||
"size":info["size"]*1};
|
|
||||||
this.attributes = {"body": attributes["body"]*1, "agility": attributes["agility"]*1,
|
|
||||||
"spirit": attributes["spirit"]*1};
|
|
||||||
this.properties = {"strength": properties["strength"]*1 , "hardness": info["hardness"]*1,
|
|
||||||
"movement": info["movement"]*1, "skill": properties["skill"]*1,
|
|
||||||
"mind": properties["mind"]*1, "aura": properties["aura"]*1};
|
|
||||||
this.graphelement = Crafty.e("Creature").creature(this.info["pname"],drawinfo["x"],drawinfo["y"],
|
|
||||||
drawinfo["w"],drawinfo["h"],drawinfo["col"]);
|
|
||||||
|
|
||||||
this.battle = {};
|
(function(){
|
||||||
if(battle) {
|
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
||||||
this.battle={"life": battle["life"], "defense": battle["defense"],"ini":battle["ini"],
|
|
||||||
"walk": battle["walk"], "melee": battle["melee"], "shoot": battle["shoot"],
|
// The base Class implementation (does nothing)
|
||||||
"chant": battle["chant"], "shoot_chant": battle["shoot_chant"]};
|
this.Class = function(){ };
|
||||||
}
|
|
||||||
else {
|
// Create a new Class that inherits from this class
|
||||||
this.battle["life"] = this.attributes.body + this.properties.strength + 10;
|
Class.extend = function(prop, ref_name) {
|
||||||
this.battle["defense"] = this.attributes.body + this.properties.hardness;
|
if(ref_name)
|
||||||
this.battle["ini"] = this.attributes.agility + this.properties.movement;
|
reflection[ref_name] = Class;
|
||||||
this.battle["walk"] = (this.attributes.agility / 2) +1;
|
|
||||||
this.battle["melee"] = this.attributes.body + this.properties.strength;
|
var _super = this.prototype;
|
||||||
this.battle["shoot"] = this.attributes.agility + this.properties.mind;
|
|
||||||
this.battle["chant"] = this.attributes.spirit + this.properties.aura;
|
// Instantiate a base class (but only create the instance,
|
||||||
this.battle["shoot_chant"] = this.attributes.spirit + this.properties.skill;
|
// don't run the init constructor)
|
||||||
|
initializing = true;
|
||||||
|
var prototype = new this();
|
||||||
|
initializing = false;
|
||||||
|
|
||||||
|
// Copy the properties over onto the new prototype
|
||||||
|
for (var name in prop) {
|
||||||
|
// Check if we're overwriting an existing function
|
||||||
|
prototype[name] = typeof prop[name] == "function" &&
|
||||||
|
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||||
|
(function(name, fn) {
|
||||||
|
return function() {
|
||||||
|
var tmp = this._super;
|
||||||
|
|
||||||
|
// Add a new ._super() method that is the same method
|
||||||
|
// but on the super-class
|
||||||
|
this._super = _super[name];
|
||||||
|
|
||||||
|
// The method only need to be bound temporarily, so we
|
||||||
|
// remove it when we're done executing
|
||||||
|
var ret = fn.apply(this, arguments);
|
||||||
|
this._super = tmp;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
})(name, prop[name]) :
|
||||||
|
prop[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
// The dummy class constructor
|
||||||
|
function Class() {
|
||||||
|
// All construction is actually done in the init method
|
||||||
|
if ( !initializing && this.init )
|
||||||
|
this.init.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate our constructed prototype object
|
||||||
|
Class.prototype = prototype;
|
||||||
|
|
||||||
|
// Enforce the constructor to be what we expect
|
||||||
|
Class.prototype.constructor = Class;
|
||||||
|
|
||||||
|
// And make this class extendable
|
||||||
|
Class.extend = arguments.callee;
|
||||||
|
|
||||||
|
return Class;
|
||||||
};
|
};
|
||||||
this.life = this.battle["life"]*1;
|
})();
|
||||||
};
|
|
||||||
|
|
||||||
Creature.prototype.attack = function(enem) {
|
var Creature = Class.extend({
|
||||||
console.log("attack");
|
init: function(info,attributes,properties,drawinfo,battle){
|
||||||
//console.log(this.cname+" greift "+enem.cname+" an!");
|
/* info: pname, cname,class, level, experience, race, size
|
||||||
//console.log("Ergebnis: " + this.melee + ( this.melee > enem.defense? " > " : " < ") + enem.defense);
|
* attributes: body, agility, spirit
|
||||||
};
|
* properties: strength, hardness, movement, skill, mind, aura
|
||||||
|
* drawinfo: x,y,w,h,col
|
||||||
|
*/
|
||||||
|
console.log("Creature called!");
|
||||||
|
this.info = {"pname": info["pname"]+"", "experience": info["experience"]*1, "race":info["race"]+"",
|
||||||
|
"size":info["size"]*1};
|
||||||
|
console.log("Creature Ready!");
|
||||||
|
this.attributes = {"body": attributes["body"]*1, "agility": attributes["agility"]*1,
|
||||||
|
"spirit": attributes["spirit"]*1};
|
||||||
|
console.log("Problem?");
|
||||||
|
this.properties = {"strength": properties["strength"]*1 , "hardness": properties["hardness"]*1,
|
||||||
|
"movement": properties["movement"]*1, "skill": properties["skill"]*1,
|
||||||
|
"mind": properties["mind"]*1, "aura": properties["aura"]*1};
|
||||||
|
this.graphelement = Crafty.e("Creature").creature(this.info["pname"],drawinfo["x"],drawinfo["y"],
|
||||||
|
drawinfo["w"],drawinfo["h"],drawinfo["col"]);
|
||||||
|
|
||||||
|
this.battle = {};
|
||||||
|
if(battle) {
|
||||||
|
this.battle={"life": battle["life"]*1, "defense": battle["defense"]*1,"ini":battle["ini"]*1,
|
||||||
|
"walk": battle["walk"]*1, "melee": battle["melee"]*1, "shoot": battle["shoot"]*1,
|
||||||
|
"chant": battle["chant"]*1, "shoot_chant": battle["shoot_chant"]*1};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.battle["life"] = this.attributes.body + this.properties.strength + 10;;
|
||||||
|
this.battle["defense"] = this.attributes.body + this.properties.hardness;
|
||||||
|
this.battle["ini"] = this.attributes.agility + this.properties.movement;
|
||||||
|
this.battle["walk"] = (this.attributes.agility / 2) +1;
|
||||||
|
this.battle["melee"] = this.attributes.body + this.properties.strength;
|
||||||
|
this.battle["shoot"] = this.attributes.agility + this.properties.mind;
|
||||||
|
this.battle["chant"] = this.attributes.spirit + this.properties.aura;
|
||||||
|
this.battle["shoot_chant"] = this.attributes.spirit + this.properties.skill;
|
||||||
|
};
|
||||||
|
this.life = this.battle["life"]*1;
|
||||||
|
},
|
||||||
|
attack: function(enem) {
|
||||||
|
//console.log("attack");
|
||||||
|
console.log(this.info.cname+" greift "+enem.info.cname+" an!");
|
||||||
|
console.log("Ergebnis: " + this.battle.melee + ( this.battle.melee > enem.battle.defense ? " > " : " < ") + enem.battle.defense);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function Player(info,attributes,properties,drawinfo,battle){ // x,y,w,h,col) {
|
var Player = Creature.extend({
|
||||||
/* info: pname, cname,class, level, experience, race, size
|
init: function(info,attributes,properties,drawinfo,battle){ // x,y,w,h,col) {
|
||||||
* attributes: body, agility, spirit
|
/* info: pname, cname,class, level, experience, race, size
|
||||||
* properties: strength, hardness, movement, skill, mind, aura
|
* attributes: body, agility, spirit
|
||||||
* drawinfo: x,y,w,h,col
|
* properties: strength, hardness, movement, skill, mind, aura
|
||||||
*/
|
* drawinfo: x,y,w,h,col
|
||||||
|
*/
|
||||||
|
this._super(info,attributes,properties,drawinfo,battle);
|
||||||
|
this.info["cname"]= info["cname"]+"";
|
||||||
|
this.info["class"]= info["class"]+"";
|
||||||
|
this.info["level"]= info["level"]*1;
|
||||||
|
|
||||||
Creature.apply(this, arguments);
|
// Set default battle-propoerties.
|
||||||
this.info["cname"]= info["cname"]+"";
|
this.extern = {"armor":0,"chant":0,"weapon":0};
|
||||||
this.info["class"]= info["class"]+"";
|
console.log(this.battle.defense);
|
||||||
this.info["level"]= info["level"]*1;
|
this.battle.defense += this.extern.armor;
|
||||||
|
this.battle.melee += this.extern.weapon;
|
||||||
|
this.battle.shoot += this.extern.weapon;
|
||||||
|
this.battle.chant = this.battle.chant + this.extern.chant - this.extern.armor;
|
||||||
|
this.battle.shoot_chant = this.battle.chant + this.extern.chant - this.extern.armor;
|
||||||
|
},
|
||||||
|
printoutput: function() {
|
||||||
|
$('#output').empty();
|
||||||
|
$('#output').html(this.info.cname+"<br>"+this.info.pname);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Set default battle-propoerties.
|
var Beast = Creature.extend({
|
||||||
this.extern = {"armor":0,"chant":0,"weapon":0};
|
init: function(info,attributes,properties,drawinfo,battle){ // x,y,w,h,col) {
|
||||||
this.battle["defense"] += this.extern.armor;
|
/* info: pname, experience, race, size
|
||||||
this.battle.melee += this.extern.weapon;
|
* attributes: body, agility, spirit
|
||||||
this.battle.shoot += this.extern.weapon;
|
* properties: strength, hardness, movement, skill, mind, aura
|
||||||
this.battle.chant = this.battle.chant + this.extern.chant - this.extern.armor;
|
* drawinfo: x,y,w,h,col
|
||||||
this.battle.shoot_chant = this.battle.chant + this.extern.chant - this.extern.armor;
|
* battle: life, defense,ini,walk,melee,shoot,chant,shoot_chant
|
||||||
};
|
*/
|
||||||
Player.prototype = new Creature();
|
|
||||||
|
|
||||||
Player.prototype.printoutput = function() {
|
this._super(info,attributes,properties,drawinfo,battle);
|
||||||
$('#output').empty();
|
this.info.cname=this.info.pname;
|
||||||
$('#output').html(this.info.cname+"<br>"+this.info.pname);
|
},
|
||||||
};
|
printoutput: function() {
|
||||||
|
$('#output').empty();
|
||||||
function Beast(info,attributes,properties,drawinfo,battle){ // x,y,w,h,col) {
|
$('#output').html(this.info.race+"<br>"+this.info.pname);
|
||||||
/* info: pname, experience, race, size
|
}
|
||||||
* attributes: body, agility, spirit
|
});
|
||||||
* properties: strength, hardness, movement, skill, mind, aura
|
|
||||||
* drawinfo: x,y,w,h,col
|
|
||||||
* battle: life, defense,ini,walk,melee,shoot,chant,shoot_chant
|
|
||||||
*/
|
|
||||||
|
|
||||||
Creature.apply(this,arguments);
|
|
||||||
this.info.cname=this.info.pname;
|
|
||||||
};
|
|
||||||
|
|
||||||
Beast.prototype.printoutput = function() {
|
|
||||||
$('#output').empty();
|
|
||||||
$('#output').html(this.info.race+"<br>"+this.info.pname);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,6 @@
|
||||||
this.enableControl();
|
this.enableControl();
|
||||||
};
|
};
|
||||||
if(e.mouseButton === Crafty.mouseButtons.RIGHT) {
|
if(e.mouseButton === Crafty.mouseButtons.RIGHT) {
|
||||||
console.log(player[this.id]);
|
|
||||||
console.log(cur_sel);
|
|
||||||
cur_sel.attack(player[this.id]);
|
cur_sel.attack(player[this.id]);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue