How do I... (Instances in a space-invader type of game)

0 favourites
From the Asset Store
five golem elements Sprites Sheet.Best for enemy or villain game characters.
  • Hey all,

    I'm creating a vertical space shooter game for a game design course, and I have a specific question:

    I've set up a system where a spotlight is pinned to a cannon that moves along the X axis. What I want to have happen is as the spotlight overlaps an enemy, I want the lowest instance to trigger a pulse effect, as well as play a musical note.

    How would I go about setting this up?

  • Hey Radioteque,

    Let me make sure I understand you here. You must have a setup somewhat similar to this:

    Pretend my black stars here are enemies. You want the lowest (i.e. closest to the bottom of the screen) enemy to trigger a pulse effect and play a note when it overlaps with the spotlight. Is this what you mean by 'lowest instance'?

  • with the lowest instance you mean the one with the highest y-position?

    I guess a system for each sprite ordered y ascending event setting a variable to the sprite.uid and picking sprite by uid = variable would work..

  • Hey Radioteque,

    Let me make sure I understand you here. You must have a setup somewhat similar to this:

    Pretend my black stars here are enemies. You want the lowest (i.e. closest to the bottom of the screen) enemy to trigger a pulse effect and play a note when it overlaps with the spotlight. Is this what you mean by 'lowest instance'?

    Yeah, that's exactly it! The only difference being that the spotlight is a box, and not angled like that.

  • Another thing to consider that I totally didn't mention is on the enemy spawn, they are assigned a variable (1,2,3).

    So if enemy.music = 1, play a C note, if enemy.music = 2, play an E note, etc.

  • with the lowest instance you mean the one with the highest y-position?

    I guess a system for each sprite ordered y ascending event setting a variable to the sprite.uid and picking sprite by uid = variable would work..

    I tried this earlier, but I feel like I didn't nest a few of the commands properly ~

  • > with the lowest instance you mean the one with the highest y-position?

    >

    > I guess a system for each sprite ordered y ascending event setting a variable to the sprite.uid and picking sprite by uid = variable would work..

    >

    I tried this earlier, but I feel like I didn't nest a few of the commands properly ~

    Without seeing your events I wouldn't know, maybe true, maybe false..

  • Hang tight, I'll print screen. I really appreciate the help, by the way!

  • You might need to right click and 'view image' to read the comments correctly depending on your resolution.

    Try something like this on for size. This will pick the correct enemy for you to play your pulse and sound effects at. Those shouldn't be too difficult for you to implement. Hint: The 'Play by Name' audio combined with Enemy.Music should give you an easy way to play different sound effects for different enemies.

    Let us know if you get stuck.

  • Woah! So quickly too. I'll give it a shot and report back.

  • Sure thing. If you have some trouble, make sure you print your screen. It'll really help us work out what you're doing right/wrong.

  • So I've popped in the system with the enemy music variables, but if the spotlight moves left or right with the lowest instance selected, the next instance up begins to pulse and play a note

    (and I just realized I'm not even calling the highestY variable )

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not able to duplicate your problem on my end. If you don't mind, you should attach your capx.

    P.S. Don't worry about calling the highestY variable. It is only used in the loop. Think of the UID variable as the 'result' we want from the loop, with the highestY variable just a means of getting it.

  • https://www.dropbox.com/s/8smmqui3o80nh1r/musicalspaceinvaders.capx?dl=0

    Here's the capx. I'm hoping to finally sweep the issue under the bed

  • Yes, I think I've worked out what's going on here. Correct me if I'm wrong, but I believe that you are getting the 'double pulse' when you move the spotlight off the lowest enemy and onto another with no gap between them. So, if the two enemies had the same Y coordinate they would overlap (See below):

    This is caused by your 'Else' function which disables the Pulse effect. The Else function only triggers when the condition: "Enemy is overlapping Spotlight_Detect" is false, but because there is no gap in between the two, it never triggers. Therefore, the first is still pulsing because it was never told to stop, and the second is pulsing because it is correctly the lowest now. In fact, the first is no longer even in the loop because it's no longer in the spotlight. That means we have to deal with it in another block. This can be a little tricky so let me take some time to think about it.

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