ForumsProgramming ForumNeed some help with flash

10 3245
markrjg
offline
markrjg
11 posts
Nomad

I need some help for makng a game like endless war game i have the code for rotation i just need help with the bullets and hit test

  • 10 Replies
PixelSmash
offline
PixelSmash
566 posts
Nomad

In what way do you need help? Do you have something but you're not sure how to implement it? Because rotation and hittest are essential for these kind of games, which I'm sure you've realised

In any case... what you'll probably need to do is keep a list of every enemy, and run some hittests on them...

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Something like this?

if (Bullet.hitTest(Enemy) )
{
Bullet..removeMovieClip();
EnemyDead = true;
}
Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Sorry, only one dot, Bullet.removeMovieClip();

markrjg
offline
markrjg
11 posts
Nomad

Sorry, only one dot, Bullet.removeMovieClip();

I know that

And also i need help by making the collition if the bullet hits the enemy the ememy dies
markrjg
offline
markrjg
11 posts
Nomad

Oops i forgot and when you click the bullet shoots out there all i need help on

jpx111
offline
jpx111
264 posts
Nomad

for the first question, just add the following inside the if statement:
Enemy.removeMovieClip();

For the second question, where do you want the bullet to shoot out to?

for moving the bullet, you need to change the bullet movie clip's x and y

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

This is not easy

First you'll have to code the angle in degrees your character is shoting, which we'll obtain from atan2, tan from tangent

http://img79.imageshack.us/img79/5020/atan2he4.jpg

So code something like this

rotationinradians = Math.atan2(_ymouse - Your Arm/Gun._y , _xmouse - Your Arma/Gun._x);


The problem is, this will give you the value in radians, and we want degrees, so a litle more math to convert it

rotationindegrees = rotationinradians * 180 / Math.PI;


This is on Flash Help

So ok, Attach your bullet like usual, and now let's take care of how it will move

Usually we just think of a value like 10 and add it to the current X to make a straight shot, but when we have an angle, it's different. Let's create two variable that will calculate how much we have to add to the X and Y to create a 10 speed in a line that's not in front of you. Let's call it progression.

And since it's easier, let's code this inside your bullet

ProgressionX = (Math.cos(_parent.rotationindegrees * Math.PI / 180) * Your Speed);
ProgressionY = (Math.sin(_parent.rotationindegrees * Math.PI / 180) * Your Speed);


Having this, outside the loop of the object, will grant these values the exact moment the bullet is created, so it will keep the perfect progression of that angle

And then code this right under it

this.onEnterFrame = function()
{
this._x = this._x + ProgressionX;
this._y = this._y + ProgressionY;
}


That should work
markrjg
offline
markrjg
11 posts
Nomad

well now all i need is the collition code becuse i cant make the enemy die!

Captain_J_Sheridan
offline
Captain_J_Sheridan
313 posts
Nomad

Have you tried this?

if (Bullet.hitTest(Enemy) )
{
Bullet..removeMovieClip();
EnemyDead = true;
}
IQAndreas
offline
IQAndreas
299 posts
Peasant

Also, you might want to add

Enemy..removeMovieClip()


If you make the enemy invisible when you kill it, but don't remove the movie clip, it will still be hogging up your computer's resources.
Showing 1-10 of 10