Enemy Fire Repost

This forum is currently in read-only mode.
From the Asset Store
Pixel Enemies for SHMUP consists of 45 enemy ship sprites to be used in your game.
  • 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.

  • 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.

  • 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.

  • 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.

    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?

  • 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.

  • 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.

  • I do not understand #2.

    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:

    -> 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.
  • > I do not understand #2.

    >

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

    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?

  • <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

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It is working for me. :s maybe it is not really noticable? If you set larger time frame, such as 10000ms? Since subs seem to take longer. Actually, make that 5000+random(10000) ms, so at minimum they'd fire every 5 seconds, at longest 15. Does it become noticeable then?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)