Kwiftee
07-25-2008, 02:17 AM
Hi.
I'm working on my first flash game, and I've done pretty well so far. I've got all the physics and stuff down, and they all work fine, it's just I want to see if I can do some stuff to make it easier for me.
You see, every time I add a new enemy, I have to add code to THREE different objects: the main character (cursor_mc), the bullets it can shoot (shota), and the enemy itself. (enemya, or enemyb, or whatever)
Here's the code I put on the main character for every enemy - inside the 'onClipEvent (EnterFrame) {' :
if (_root.enemya.hitTest(this) and (_alpha >= 100)) {
_root.hpcount -= 1;
_alpha = 10
}
(and the alpha increases every frame by about 5, giving you time to get away from the enemy before you take damage again)
The code for 'shota':
if (_root.enemya.hitTest(this) and _alpha == 100 and _alpha.enemya == 100) {
_root.score += 1;
_alpha = 0
_root.enemyahp -=1
}
So, this makes the bullet disappear after it hits something, makes your score increase by 1, and makes enemies hp decrease by 1
And, the code for the enemy itself:
onClipEvent (load) {
_root.enemyahp = 1
}
onClipEvent (enterFrame) {
if (_root.enemyahp == 0) {
_alpha = 0
}
}
This ensures that, if the hp of the enemy is 0, it disappears.
This all works fine, but it's kinda a pain, since, as I said, every time I add a new enemy, I have to paste this code in three seperate locations.
Is there anyway I can merge all this code, so I can put it on only one object? (the enemy)?
I tried just pasting it all in the one mc, changing a few things so it wasn't performing a hittest with itself and stuff, but it didn't work.
So, yeah, help?
EDIT: Almost forgot, I'm using AS2.0, Flash MX.
I'm working on my first flash game, and I've done pretty well so far. I've got all the physics and stuff down, and they all work fine, it's just I want to see if I can do some stuff to make it easier for me.
You see, every time I add a new enemy, I have to add code to THREE different objects: the main character (cursor_mc), the bullets it can shoot (shota), and the enemy itself. (enemya, or enemyb, or whatever)
Here's the code I put on the main character for every enemy - inside the 'onClipEvent (EnterFrame) {' :
if (_root.enemya.hitTest(this) and (_alpha >= 100)) {
_root.hpcount -= 1;
_alpha = 10
}
(and the alpha increases every frame by about 5, giving you time to get away from the enemy before you take damage again)
The code for 'shota':
if (_root.enemya.hitTest(this) and _alpha == 100 and _alpha.enemya == 100) {
_root.score += 1;
_alpha = 0
_root.enemyahp -=1
}
So, this makes the bullet disappear after it hits something, makes your score increase by 1, and makes enemies hp decrease by 1
And, the code for the enemy itself:
onClipEvent (load) {
_root.enemyahp = 1
}
onClipEvent (enterFrame) {
if (_root.enemyahp == 0) {
_alpha = 0
}
}
This ensures that, if the hp of the enemy is 0, it disappears.
This all works fine, but it's kinda a pain, since, as I said, every time I add a new enemy, I have to paste this code in three seperate locations.
Is there anyway I can merge all this code, so I can put it on only one object? (the enemy)?
I tried just pasting it all in the one mc, changing a few things so it wasn't performing a hittest with itself and stuff, but it didn't work.
So, yeah, help?
EDIT: Almost forgot, I'm using AS2.0, Flash MX.