Change a sprite position regarding player position

Get help using Construct 2

Post » Mon Jun 11, 2012 12:14 pm

Greetings! I'm working on a vertical shoot'em up...

My game creates some enemies.
This enemy can generate an horizontal laser on the left, or on the right. Basically, it's the same laser, it's just changing its position and angle.

I would like it to create and maintain the laser to the right when the player.X > enemy.X, and vice versa.

When the player.X becomes < enemy.X, after 1 second the laser changes side.

I managed to do that for 1 enemy, but it doesn't work well with several enemies. There are some conflict between the laser instances. I don't really know how I should associate the laser to the enemy.

If someone can help me out regarding this issue...

Here are my crappy events :


And my capx : http://www.canapin.com/shooter/paper%20shooter.capx
The event are in the enemies event sheet.Canapin2012-06-11 13:52:27
B
5
S
1
Posts: 34
Reputation: 1,026

Post » Mon Jun 11, 2012 6:13 pm

I gave the laserShip an instance variable called laserUID to keep track of it's laserShipShot.



I like the artwork. I'm doing a breakout game in the same style (hand drawn on paper background). Though you're better at drawing than me.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Mon Jun 11, 2012 6:25 pm

I like the artwork aswell, nice style.

PS: I would consider using smaller background textures if I were you, they are now 2MB out of the total game size of 2.2MB. Not much of a point using tiled backgrounds when they don't repeat.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Mon Jun 11, 2012 6:57 pm

Thanks for your replies :)
I hope my GF will be motivated enough to do the artwork, she's
way better than me for sci-fi stuff. :D

Now the actual problem is this that if your move your ship quickly to the right of an enemy, and then to the left and you do that multiples times, it will execute all the instructions and the laser will quickly change its orientation the same number of times.

I tried to use a variable that increases periodicaly when the player X is > enemy X, and decreases periodicaly when the player X is < enemy X.

When the variable reaches 1 or 0, the laser changes its orientation.

Seems very, very simple (and I'm quite sure it is), but there is something I can't figure out, it doesn't work as it should be.

Here is a test .capx with only the required sprites and instructions (and without the variable), very clear and simple : http://www.canapin.com/shooter/test.capx

(If I stick on the "select nearest laser", I won't need to check UIDs I think)

That's why I think a variable could help. If you have any idea to how fix this... :)


edit a few hours later :

I've made another document which visible variables on the layout :

http://canapin.com/shooter/test2.capx

I don't understand why the variable "timer" perfectly works for the first enemy instance, but not for the next ones.

Is a "for each enemy" a good start or I am wrong?Canapin2012-06-11 20:24:55
B
5
S
1
Posts: 34
Reputation: 1,026

Post » Mon Jun 11, 2012 8:18 pm

Looks like I'm too late, but here's my solution anyways:

Canapin_test.capx (r93)
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Mon Jun 11, 2012 8:44 pm

You're not too late, I was wrong and edited my post... :(
I'm checking your solution !
B
5
S
1
Posts: 34
Reputation: 1,026

Post » Mon Jun 11, 2012 10:58 pm

I integrated your events in my game, it works almost perfectly. Sometimes, a ship doesn't move its laser on my side, but it's kind of rare and I can't reproduce the bug, so I'll keep it for a while.

Thank you very much !
B
5
S
1
Posts: 34
Reputation: 1,026


Return to How do I....?

Who is online

Users browsing this forum: makotto, randomly, Walessio and 25 guests