View Full Version : Bullet shooting constant
killingdyl
11-01-2007, 12:00 AM
i want to be able to shoot a constant chain of bullets
i know it has something to do with duplicating the bullet
but i dont know how to make it shoot
killingdyl
11-03-2007, 08:02 PM
let me reword that
i want it to look something like the pig game
but my actionscript is in the char
i want to know how to duplicate then shoot
ash_man_06
11-04-2007, 09:02 AM
Here's the best I can think of off the top of my head.
Make an MC called bullet. On that, put this code:
onClipEvent(load){
this._x = _root.man._x;
this._y = _root.man._y;
//assuming the guy who's shooting's called man
}
onClipEvent(enterFrame){
this._x++;
//or whichever direction you want it to go
}
Then on the 'man' put this code
onClipEvent(load){
i = 1;
}
onClipEvent(enterFrame){
if (Key.isDown(Key.SPACE)){
duplicateMovieClip(_root.bullet,i,i);
i ++;
}
}
\
Give that a wack mate.
It should recreate bullets at the speed of one a frame.
Probably some errors in it as I typed it in here and not in Flash, but just ask and I'll help ya.
killingdyl
11-04-2007, 10:16 PM
heres my actionscript in my bullet and ship
BULLET
onClipEvent (enterFrame) {
if (hitTest(_level0.pad.protect) == true) {
gotoAndStop(1);
}
if (hitTest(_level0.enemy) == true) {
tellTarget (_level0.enemy) {
_root.score.text -= -100;
_root.enemy.isAlive = 0;
gotoAndPlay(2);
}
tellTarget (_root.pad) {
play();
}
gotoAndStop(1);
}
if (hitTest(_level0.enemy2) == true) {
tellTarget (_level0.enemy2) {
_root.score.text -= -100;
_root.enemy2.isAlive = 0;
gotoAndPlay(2);
}
tellTarget (_root.pad) {
play();
}
gotoAndStop(1);
}
if (hitTest(_level0.enemy3) == true) {
tellTarget (_level0.enemy3) {
_root.score.text -= -100;
_root.enemy3.isAlive = 0;
gotoAndPlay(2);
}
tellTarget (_root.pad) {
play();
}
gotoAndStop(1);
}
}
SHIP
onClipEvent (load) {
var speed:Number = 0;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
speed += 1.5;
_root.speed.text -= -1.5;
}
speed = speed*0.90;
if (_root.speed.text>1) {
_root.speed.text = _root.speed.text*0.90;
} else if (_root.speed.text<1) {
_root.speed.text = 0;
}
if (Key.isDown(Key.DOWN)) {
if (speed>0) {
speed -= 0.8;
_root.speed.text -= 0.8;
}
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 5;
}
if (Key.isDown(Key.LEFT)) {
_rotation -= 5;
}
if (Key.isDown(Key.SPACE)) {
tellTarget (_root.bullet) {
play();
}
}
_x += Math.sin(_rotation*Math.PI/180)*speed;
_y += Math.cos(_rotation*Math.PI/180)*-speed;
}
onClipEvent (enterFrame) {
if (_x<10) {
_x += speed;
}
if (_x>790) {
_x -= speed;
}
if (_y<10) {
_y += speed;
}
if (_y>590) {
_y -= speed;
}
}
onClipEvent (enterFrame) {
if (hitTest(_level0.pad.land) == true) {
speed = 0;
_root.speed.text = 0;
tellTarget (_level0.ship.flame1) {
gotoAndStop(4);
}
tellTarget (_level0.ship.flame2) {
gotoAndStop(4);
}
tellTarget (_level0.ship.flame3) {
gotoAndStop(4);
}
} else {
tellTarget (_level0.ship.flame1) {
gotoAndStop(1);
}
tellTarget (_level0.ship.flame2) {
gotoAndStop(1);
}
tellTarget (_level0.ship.flame3) {
gotoAndStop(1);
}
}
if (hitTest(_root.enemy) == true) {
_root.enemy.isAlive = 0;
if (_root.arm.text<1) {
_root.arm.text = 0
_root.health.text -= random(6)+6;
if (_root.health.text<1) {
tellTarget (_root) {
gotoAndStop(3);
}
}
}else{
_root.arm.text -= random(10)+10
}
tellTarget (_root.enemy) {
play();
}
tellTarget(_root.pad){
play();
}
}
if (hitTest(_root.enemy2) == true) {
_root.enemy2.isAlive = 0;
if (_root.arm.text<1) {
_root.arm.text = 0
_root.health.text -= random(6)+6;
if (_root.health.text<1) {
tellTarget (_root) {
gotoAndStop(3);
}
}
}else{
_root.arm.text -= random(10)+10
}
tellTarget (_root.enemy2) {
play();
}
tellTarget(_root.pad){
play();
}
}
if (hitTest(_root.enemy3) == true) {
_root.enemy3.isAlive = 0;
if (_root.arm.text<1) {
_root.arm.text = 0
_root.health.text -= random(6)+6;
if (_root.health.text<1) {
tellTarget (_root) {
gotoAndStop(3);
}
}
}else{
_root.arm.text -= random(10)+10
}
tellTarget (_root.enemy3) {
play();
}
tellTarget(_root.pad){
play();
}
}
}
can you help me work it in
Seeing the way you treat enemy2, enemy3 and enemy by repasting the same code with the name changed, makes me suspect you don't know how to use for loops. Like this:
for (var count=1;count<=3;count++) {
if (hitTest(_root["enemy"+count])==true)
{
.....
}
}
Not completely off-topic, since if you add a stream of bullets, your code is going to be a mess if it's all
if (bullet1)
....
if (bullet2)
....
if (bullet3)
....
While you're googling "for loop actionscript" for tutorials, you could also look up how to define a function, and how to use attachMovie() They will also prove useful for bullet streams.
majicassassin
11-07-2007, 06:06 PM
Use an arrays to store all bullets and all enemies... the best way I know of to keep track of things created dynamically.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.