PDA

View Full Version : Re: Object orientated Game help


craigguthrie
11-24-2002, 01:28 PM
hi , Im trying to get a ship class to get a "shot" class to fire a shot movie clip, but I have two seperate ships but want to use the shot class for them both, I have tried this:onClipEvent (load) {
if (String(_name) != "shot") {
cannonLength = 1;
turretpoint = _root["ship1"&&"ship2"]._rotation+_root["ship1"&&"ship2"]._rotation;
angle = (turretpoint/360)*2*Math.PI;
xcomponent = cannonLength*Math.sin(angle);
ycomponent = -cannonLength*Math.cos(angle);
_x = xcomponent+_root["ship1"&&"ship2"]._x;
_y = ycomponent+_root["ship1"&&"ship2"]._y;
xmove = (xcomponent/cannonLength)*10;
ymove = (ycomponent/cannonLength)*10;
}
}
but it doesnt work, could anyone also maybe tell me why my shot isnt unloading when it hits the ship? I currently have this code:
onClipEvent (enterFrame) {
if (String(_name) != "shot") {
_x += xmove;
_y += ymove;

if (_root["ship1||ship2"].hitTest(_x, _y, true)) {
_root.d++;
_root.attachMovie ("ground","d"+_root.d,(_root.d%100)+500);
_root["d"+_root.d]._x = _x;
_root["d"+_root.d]._y = _y;
_root["d"+_root.d]._xscale = 150;
_root["d"+_root.d]._yscale = 150;
unloadMovie (_root["ship1"||"ship2"]);
unloadMovie (this);
}
}

}
Much a ppreciated craig

jimburton
11-24-2002, 09:10 PM
what's this about:

_root["ship1"&&"ship2"]._rotation

?

this isn't meaningful, as far as I know

xxlm
11-25-2002, 10:34 AM
Hey man, did you look the tut I made...
http://www.actionscript.org/tutorials/advanced/class_and_object_in_games/index.shtml

You can find here how to make a class ship and get multiple instance of it (then you can use the method ie "fire");

Read it carefuly, it should help you...
;)