【发布时间】:2014-01-08 22:29:46
【问题描述】:
所以我正在创建一个小游戏(以前从未这样做过),但它引起了我的注意并让我好奇,所以我在这里。
我正在尝试为游戏中的对象设计层次结构。
关于我目前拥有的一些物品。
/* this is the basic object - every object in game will have that */
var fnObject = function (node){
this.nNode = node || '';
this.id = '';
this.sType = 'pc'/*pc,npc,physics,obstacle*/;
this.oPosition = {
marginTop : 0,
marginLeft : 0
};
/*
* and more properties.
* */
}
/* not all objects will have those */
var fnPhysics = function(){
this.iFriction = '';
this.iAcceleration = '';
this.iGravity = '';
this.iWind = '';
this.iIncline = '';
this.iSpeed = 1;
this.iMoveDistant = 5;
/*
* and more properties.
* */
}
/* Only objects that can move will have those */
var fnControls = function (){
this.fnGetMvDist = function (){
//..
}
this.fnDoMove = function(){
//..
};
this.fnMoveRight = function(){
//..
}
}
/* not all objects will have those */
var fnStats = function(){
this.hp = 100;
this.manaLeft = 100;
this.livesLeft = 5;
/*
* and more properties.
* */
}
我怎样才能从中构建出良好的层次结构。我的意思是有些对象不会拥有所有这些,有些会。
谢谢
【问题讨论】:
标签: javascript jquery hierarchy