Enemy Fire Repost

For questions about using Classic.

Post » Mon Nov 16, 2009 2:39 am

This is a repost. I apologize but the last one got bogged down in other conversation and I have made addendum's.


I want my enemies to randomly fire at my player, with a maximum of 2 times per each enemy.

You see, they are moving in and out of the screen, I want them to fire twice each time they are on screen, then travel off screen. I dont want them to fire twice in a row though, it should be random.

The also need to shoot straight up.

I used a "ever *** milliseconds-spawn bullet" but it shoots sideways, so I put a "rotate 90 degrees clockwise" to shoot up. It worked but after every first shot it will begin shooting sideways again.

http://www.megafileupload.com/en/file/1 ... t-cap.html

This is the .cap

Can anyone help? Thanks in advance.
B
2
G
3
Posts: 24
Reputation: 898

Post » Mon Nov 16, 2009 11:39 am

I haven't looked at the cap, but I've got a few tips...

If you want enemies to fire only when on-screen, just add a condition "Is On Screen", I believe sprites have that.

Then add another event that checks when the sprite is out of visible area (Negated On Screen), trigger once, set the 'ammo' to 2. So, whenever it flies onto screen, it would fire two bullets, then as soon as it flies out, it would refresh ammunition.

For random firing, try for every 1000+random(2000) ms. That will randomize it a bit between one and three seconds. Fire a bullet, substract by one, stop firing when it hits 0 ammo.

As for pacing, you want it to face directly north? Then just set angle to 270 (360-90). If you want it to face the player, then use Set Angle Toward (player sprite) - or use angle(enemy.x,enemy.y,player.x,player.y) expression. However, if you don't want the enemy to change angle and wander off its path, you can just change the bullet spawn angle instead. The sprite won't rotate, but the fire will fire into given angle.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Tue Nov 17, 2009 9:58 pm

Thanks. I will try these soon. Haven't had the time as of yet. If anyone else has a suggestion, I would be glad to look at that too.
B
2
G
3
Posts: 24
Reputation: 898

Post » Wed Nov 18, 2009 7:08 pm

[quote="Mipey":ukl0queg]I haven't looked at the cap, but I've got a few tips...

If you want enemies to fire only when on-screen, just add a condition "Is On Screen", I believe sprites have that.

Then add another event that checks when the sprite is out of visible area (Negated On Screen), trigger once, set the 'ammo' to 2. So, whenever it flies onto screen, it would fire two bullets, then as soon as it flies out, it would refresh ammunition.

For random firing, try for every 1000+random(2000) ms. That will randomize it a bit between one and three seconds. Fire a bullet, substract by one, stop firing when it hits 0 ammo.
[/quote:ukl0queg]

When you say add condition "is on screen" do you mean to the enemy or the bullet?

And when you say Negated on screen, is that in system or on the enemy sprite?

Also I cant get your random formula to work. Do I put it in as written?
B
2
G
3
Posts: 24
Reputation: 898

Post » Thu Nov 19, 2009 8:48 am

1.) Enemies. You want them to fire when they are visible (on screen). Bullets don't matter, destroy them once they're not on screen anymore, though, to keep things tidy.

2.) Right click a condition in event sheet, there will be "Invert condition" command. This is basically negation.

3.) Yes. Add the "every x miliseconds" condition (from System), then instead of typing 1000 you type 1000+random(3000). This is an expression. random(3000) returns a random number between 0 and 2999.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Nov 19, 2009 5:32 pm

I do not understand #2. And the random code is not doing what you say it does. It makes the enemies fire once all at the same time, then they travel offscreen.

Will you look at my cap?

http://www.easy-share.com/1908476354/Subhunt.cap

Oh, and if you do, dont look at your highscore, it crashes the game.
B
2
G
3
Posts: 24
Reputation: 898

Post » Thu Nov 19, 2009 5:55 pm

[quote="Squeedom":39nvtn6q]I do not understand #2.[/quote:39nvtn6q]

It's inverting the condition, making it the opposite of what it normally is.

For instance, if you want something to happen when your sprite is overlapping an enemy you would do this:

[code:39nvtn6q]-> Sprite is overlapping Enemy
- Do stuff[/code:39nvtn6q]

Then every time your sprite overlaps the enemy, stuff will happen.

If you invert the condition (Right click -> Invert condition) then it makes it do the opposite. So instead of doing "stuff" when your sprite is overlapping enemy, you will do stuff when your sprite is NOT overlapping enemy.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Thu Nov 19, 2009 6:12 pm

[quote="deadeye":20plgpfn][quote="Squeedom":20plgpfn]I do not understand #2.[/quote:20plgpfn]

It's inverting the condition, making it the opposite of what it normally is.

[/quote:20plgpfn]

Let me rephrase, I understood the direction. But what purpose does it serve in this situation?

I think I have the ammo set up well enough, is the random not working because I did not do step 2?
B
2
G
3
Posts: 24
Reputation: 898

Post » Thu Nov 19, 2009 6:15 pm

<snip> A slight misunderstanding.

As for the random timer, remove the space between random and (2000). These two should be together, like this: random(2000).

Edit: As for Invert condition, what purpose does it serve? Well, let's take "Is On Screen" condition. You use it to determine if an object is present on the screen (viewable).

What do you do if you want to determine if it is outside the screen? Easy, Invert the "Is On Screen". A simple toggle between two truths :)
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Thu Nov 19, 2009 11:07 pm

I just cant get the random to work, the enemy will shoot once then roll right along until it is out of screen. And it shoots after 1000ms thats it.

I am just going to set it on a timing pattern so it shoots ever ****ms instead. Random would have been nice but it just aint working.
B
2
G
3
Posts: 24
Reputation: 898

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests