|
主题: 关于超类与子类的小问题。
|
 aaee1122
职务:普通成员
等级:1
金币:0.0
发贴:66
注册:2003/4/1 21:45:45
|
#12003/11/24 21:45:23
我正在做一个飞机的小游戏, 在最顶的超类是关于所有的飞机,包括敌机和我方的机,共同的属性是 health, body(就是飞机的外观), side(决定它是我方的机还是敌机) deep, level(就是把创建出来的飞机控制在一个范围的层次里面) 所以这一段代码是这样的: function Planes(health,body,side,deep,level){ //创建飞机 function new_plane(body,side,deep,level) { _root.attachMovie(body,string(side)+deep,deep++)//这里那个命名 的格式我觉得有点问题~  deep=deep%level+level return _root[string(side)+deep] } this.MainBody=new_plane(body,side,deep,level) this.MainBody.health=health //把生命属性放在影片里面,不知道有没有问题?  } //接下我是这方飞机的子类; function defender(body,side,deep,level){ this.planes=planes; this.planes(body,side,deep,level) this.side="defender" } defender.prototype=new planes() function enemy(body,side,deep,level){ this.planes=planes; this.planes(body,side,deep,level) this.side="enemy" } enemy.prototype= new planes(); //创建的时候  planes=new defender("plane","defender",_root.deep) enemy1= new enemy("ene1","enemy",_root.ene_depth,40) 现在的问题是很奇怪啊,这样子创建实例的时候都要加入side 属性,我不想每次都要创建实例都要输入一次,想在子类中获取的side属性,然后怎么办?
|
 aaee1122
职务:普通成员
等级:1
金币:0.0
发贴:66
注册:2003/4/1 21:45:45
|
#22003/11/25 12:16:35
怎么过了一个晚上也没人来回,还是自己顶一下好了。
|
 UndeadCraft
职务:版主
等级:4
金币:10.0
发贴:1993
注册:2001/5/28 17:37:43
|
#32003/11/26 10:40:57
类的继承在as1.0里可以这样: function car() {
this.a = "blue";
}
function bus() {
this.people = 20;
}
bus.prototype = new car();
mycar=new bus();
trace(mycar.a);
|
 aaee1122
职务:普通成员
等级:1
金币:0.0
发贴:66
注册:2003/4/1 21:45:45
|
#42003/11/26 14:38:44
谢谢版主,不过我的问题还是没有得到解决,我的问题并不是这个。
|
 UndeadCraft
职务:版主
等级:4
金币:10.0
发贴:1993
注册:2001/5/28 17:37:43
|
#52003/11/26 16:44:15
你这个太乱了。_root.attachMovie(body,string(side)+deep,deep++)这里应该也有问题。
Ps.继承的好像不能用变量.你先自己试试吧。我最近没空搞这些东东。可能要过两天才会来,到时再说吧
|
 aaee1122
职务:普通成员
等级:1
金币:0.0
发贴:66
注册:2003/4/1 21:45:45
|
#62003/11/27 10:07:43
期待中~
|
 UndeadCraft
职务:版主
等级:4
金币:10.0
发贴:1993
注册:2001/5/28 17:37:43
|
#72003/11/28 12:34:57
期待? 是叫你自己做啊,还等我给你做?
|
 aaee1122
职务:普通成员
等级:1
金币:0.0
发贴:66
注册:2003/4/1 21:45:45
|
#82003/11/30 11:43:32
我在做啊。  昨晚弄到3点。 呵呵  不过只是期待你会怎么做嘛。 象到更年期那样,唉~
|
 UndeadCraft
职务:版主
等级:4
金币:10.0
发贴:1993
注册:2001/5/28 17:37:43
|
#92003/12/1 9:08:55
没时间啊。 给你一个我原来做的东东,也许有用。是个纯AS的小游戏 你自己研究一下吧,祝你做出好东东 
var n = 5;
MovieClip.prototype.Killer = function() {
for (a in this) {
this[a].removeMovieClip();
}
delete a;
};
MovieClip.prototype.circle = function(x, y, radii) {
var theta = (45/180)*Math.PI;
var ctrlRadius = radii/Math.cos(theta/2);
this.lineStyle(1, 0xFF0000, 100);
this.beginFill(random(0xffffff), 100);
this.moveTo(x+radii, y);
var angle = 0;
for (var i = 0; i<8; i++) {
angle += theta;
angleMid = angle-(theta/2);
cx = x+Math.cos(angleMid)*(ctrlRadius);
cy = y+Math.sin(angleMid)*(ctrlRadius);
px = x+Math.cos(angle)*radii;
py = y+Math.sin(angle)*radii;
this.curveTo(cx, cy, px, py);
}
};
spider = function (name, x, y, body, legnum, attackaround, attacktimed, speed) {
this.id = name;
this.name = createEmptyMovieClip("sp_"+name, random(200)+10);
this.name._x = x;
this.name._y = y;
this.name.speed = speed;
this.name.id = this.id;
this.name.astate = false;
this.name.bt = this.name.ct=this.nt=0;
this.name.createEmptyMovieClip("around", random(100)+50);
this.name.around.circle(0, 0, attackaround);
this.name.around._alpha = 0;
this.name.createTextField("say", 20, 0, 0, 260, 20);
this.name.say.textColor = 0xFFFFFF;
for (i=0; i<legnum; i++) {
this["j"+i] = this.name.createEmptyMovieClip("leg"+i, i+3);
this["j"+i].x = this["j"+i].y=this["j"+i].x2=this["j"+i].y2=0;
}
this.run = true;
this.name.circle(0, 0, body);
this.name.attacktime = attacktimed;
if (this.id == "master") {
this.name.onEnterFrame = master;
} else {
this.name.onEnterFrame = enemy;
}
};
function enemy() {
var w = this._x-_root.sp_master._x;
var h = this._y-_root.sp_master._y;
if ((w*w+h*h)*2<(this._height*this._height) and this.astate == false) {
this.astate = true;
this.bt = getTimer();
}
if (!((w*w+h*h)*2<(this._height*this._height))) {
this.astate = false;
this.say.text = "";
this.around._alpha = 0;
}
if (this.astate) {
if (_root.sp_master.astate) {
removeMovieClip(this);
num = 0;
for (o=0; o<n; o++) {
if (_root["sp_"+o] == undefined) {
num++;
}
}
if (num == n) {
win();
} else {
_root.sp_master.say.text = "kill "+num;
}
}
this.ct = getTimer();
this.nt = this.ct-this.bt;
this.say.text = this.attacktime-int(this.nt/1000);
this.around._alpha = 10;
if (this.nt>this.attacktime*1000) {
gameover();
}
}
var targetX = this._parent.sp_master._x;
var targetY = this._parent.sp_master._y;
// var speed = Math.random()*setspeed;
var tempX = this._x-targetX;
var tempY = this._y-targetY;
tempAngle = Math.atan2(tempX, tempY);
var vx = -Math.sin(tempAngle);
var vy = -Math.cos(tempAngle);
for (b=0; b<n; b++) {
if (b == this.id) {
b++;
}
if (this.around.hitTest(this._parent["sp_"+b].around, true)) {
}
}
speed = random(this.speed);
this._x += vx*speed;
this._y += vy*speed;
for (i=0; i<4; i++) {
this.tL = this["leg"+i];
if (Math.random()>.95) {
this.tL.x2 = (Math.random()>.5) ? (Math.random()*40)-20 : this.tL.x2=(Math.random()>.5) ? 20 : -20;
this.tL.y2 = (this.tL.x2 == 20) ? (Math.random()*40)-20 : this.tL.y2=(Math.random()>.5) ? 20 : -20;
}
this.tL.x += (this.tL.x2-this.tL.x)/3;
this.tL.y += (this.tL.y2-this.tL.y)/3;
this.tL.clear();
this.tL.lineStyle(1, 0x00FF00, 100);
this.tL.MoveTo(10, 10);
this.tL.curveTo(this.tL.destX/2, this.tL.destY/2, this.tL.x, this.tL.y);
}
}
function master() {
for (i=0; i<4; i++) {
this.tL = this["leg"+i];
if (Math.random()>.95) {
this.tL.x2 = (Math.random()>.5) ? (Math.random()*40)-20 : this.tL.x2=(Math.random()>.5) ? 20 : -20;
this.tL.y2 = (this.tL.x2 == 20) ? (Math.random()*40)-20 : this.tL.y2=(Math.random()>.5) ? 20 : -20;
}
this.tL.x += (this.tL.x2-this.tL.x)/3;
this.tL.y += (this.tL.y2-this.tL.y)/3;
this.tL.clear();
this.tL.lineStyle(1, 0x00FF00, 100);
this.tL.MoveTo(10, 10);
this.tL.curveTo(this.tL.destX/2, this.tL.destY/2, this.tL.x, this.tL.y);
}
var speed = random(this.speed);
if (Key.isDown(Key.LEFT) and this._x>0) {
this._x -= speed;
}
if (Key.isDown(Key.RIGHT) and this._x<Stage.width) {
this._x += speed;
}
if (Key.isDown(Key.UP) and this._y>0) {
this._y -= speed;
}
if (Key.isDown(Key.DOWN) and this._y<Stage.height) {
this._y += speed;
}
}
my = new Object();
my.onKeyDown = function() {
if (Key.getCode() == Key.SPACE) {
attacktime = _root.sp_master.attacktime*1000;
if (t1 == undefined) {
t1 = getTimer();
}
t2 = getTimer();
t3 = t2-t1;
if (t3>attacktime and t3<attacktime+500) {
_root.sp_master.astate = true;
_root.sp_master.around._alpha = 100;
} else if (t3>attacktime+500) {
t1 = undefined;
_root.sp_master.astate = false;
} else {
_root.sp_master.around._alpha = int(t3/100);
}
}
};
my.onKeyUp = function() {
if (Key.getCode() == Key.SPACE) {
_root.sp_master.around._alpha = 0;
t1 = undefined;
_root.sp_master.astate = false;
}
};
function gameover() {
win = false;
for (i=0; i<n; i++) {
delete _root["sp_"+i].onEnterFrame;
}
Key.removeListener(my);
delete _root.sp_master.onEnterFrame;
_root.sp_master.say.text = "left mouse again";
onmousedown = function () {
restart();
};
}
function win() {
delete _root.sp_master.onEnterFrame;
win = true;
Key.removeListener(my);
_root.sp_master.say.text = "left mouse next";
_root.sp_master.around._alpha = 0;
onmousedown = function () {
restart(true);
};
}
function restart(win) {
_root.killer();
if (win) {
n = n+5;
} else {
n = 5;
}
init();
}
function init() {
onMouseDown = "num";
Key.addListener(my);
for (a=0; a<n; a++) {
spider(a, random(Stage.width), random(Stage.height), 4, 4, 60, 4, 5);
}
spider("master", (Stage.width)/2, (Stage.height)/2, 10, 5, 50, 5, 8);
}
init();
stop();
|
 aaee1122
职务:普通成员
等级:1
金币:0.0
发贴:66
注册:2003/4/1 21:45:45
|
#102003/12/1 10:19:00
谢谢啦,我在做~ 要参加学校的比赛的,第一名是128M的MP3啊。
|
 byboy
职务:普通成员
等级:1
金币:0.0
发贴:28
注册:2003/11/5 10:04:49
|
#112003/12/10 10:12:24
急急!加入文字后,文件变得非常大,怎样解决呢?谢谢
|