# Space Invaders logic. Need help (NEW PROBLEM)

Get help using Construct 2

### » Mon Jun 25, 2012 10:38 pm

Hi. I'm making a Space Invaders clone and having trouble working out the logic for when the aliens reach the edge of the screen and drop down a level.

At the moment I have a direction variable set to 1 (for right). Every second the aliens move 10 pixels to the right. I've got it checking for the one of the aliens X coord being >= 900 (just to the left of the screen edge. At that point I set a variable named aliendrop to 1 which tells it to drop all aliens down 20 pixels and change the direction variable to 0 (the left).

Now this works, ish, except that there's a second until the aliens move back below 900 again. In that short period the section that moves the aliens down if the X is >= 900 is executed over and over.

Has anyone any ideas how I should structure it so that the ADD Y is only done once per direction.

I hope I explained it well, it's hurting my brains. lol

Thanks.vandinz2012-06-26 16:13:28
B
20
S
5
G
4
Posts: 208
Reputation: 3,985

### » Mon Jun 25, 2012 10:51 pm

its because X remains 900 !
try to add an action that change X to 899 or less below the drop actionkbdmaster2012-06-25 22:52:02
B
44
S
18
G
17
Posts: 2,249
Reputation: 17,585

### » Mon Jun 25, 2012 10:56 pm

I didn't really want to 'jump' the X coord to a value less than 900 as this would make it look like the aliens jerk back which isn't right anyway. I know I'm doing it wrong, there must be a better method to perform the action. I can't come up with one atm though :(
B
20
S
5
G
4
Posts: 208
Reputation: 3,985

### » Mon Jun 25, 2012 11:10 pm

Sorry , There is another method , I just forgot it :)
You can make the event play 1 time with an event
Here it is !
"The condition : Trigger once while true !"
It's a condition that you have to place last
You can find it in : System > Special Conditions

Note : PM me if it works ( you can pm people by addind in your post @+their name )
B
44
S
18
G
17
Posts: 2,249
Reputation: 17,585

### » Tue Jun 26, 2012 4:06 am

You could forgo variables altogether and simply use sprites as waypoint markers for the path? On collision the enemy sprite would change direction.

l>-------Vl
lV-------<l
l>-------Vl
lV-------<l
l>-------Vl
Mr E Bear2012-06-26 04:11:07
B
69
S
27
G
13
Posts: 697
Reputation: 12,780

### » Tue Jun 26, 2012 3:09 pm

Thanks guys. Your suggestion worked a treat KD but I've not run into another issue.

Here's the 'code' to check if the enemy sprite has passed a certain point. It works fine until the player kills all of a certain type. For example in the picture you can see the yellow alien sprite. If the player kills all them, the game then ignores this event and the aliens go off the screen!

I've set it as an OR block so the game checks if alien1 OR alien2 OR alien3 goes passed a point but it's behaving as though it's set as an AND. Have I set this right? Can you spot any problems in the way I've used the OR block?

Thanks again.

EDIT * - Here's the CAP file if it's any help - spaceinvaders.capxvandinz2012-06-26 15:14:11
B
20
S
5
G
4
Posts: 208
Reputation: 3,985

### » Wed Jun 27, 2012 12:40 am

I still can't figure this out. I've tried everything I can think of, read numerous threads on here and I can't see anything wrong with what I've created. So WHY does it treat the OR statements as AND? Is this a known bug?

When all of a certain sprite have been destroyed, is a 'blank' version placed somewhere by the engine that might be messing up the check? I'm pulling my hair out here! lol. vandinz2012-06-27 00:41:34
B
20
S
5
G
4
Posts: 208
Reputation: 3,985

### » Wed Jun 27, 2012 9:17 pm

OK one last try at bumping this thread. I hate doing that but I'm totally stuck at the moment and can't move on with this issue. PLEASE if anyone has any ideas they'll be greatly appreciated.
B
20
S
5
G
4
Posts: 208
Reputation: 3,985

### » Wed Jun 27, 2012 10:00 pm

Hmm, a perfectly laid out problem with a .capx included, why hasn't this been solved yet!?

Anyways, I think this should do it, let me know if I broke anything and I'll try again:

B
27
S
8
G
8
Posts: 903
Reputation: 8,452

### » Wed Jun 27, 2012 10:49 pm

I think the 'pick all' conditions are the problem. 'Pick all Sprite2' is false when there are no Sprite2 so that event won't run.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,870

Next