rapid fire on touch release

Get help using Construct 2

Post » Sun Oct 08, 2017 3:54 pm

Now that I have bullets, the objective is to knock out incoming badGuys (in the form of blocks((at this stage)).
The badGuys randomly spawns at the top of the screen and slowly descends.

WHAT AM I TRYING TO DO?
. each badGuy has a Instance variable (health). I used PIN to pin a textbox to that badGuy.
.. when a ball strikes, the badGuy's health goes down.
... if badGuy's health is <=0, he is destroyed && so is the textbox that's pinned.

The issue(s) I'm having:
. some badGuy's lose their health textbox
. other's inherit other badGuy's loss.

Hope this make's sense. I'm not sure if this is caused by over-lapping badGuy sprites?????

I've updated the URL to show you what's happening.
http://robfreeman.co.uk/demo/
B
5
S
2
Posts: 64
Reputation: 632

Post » Mon Oct 09, 2017 1:29 am

Add 'Text2' and 'bad' to the same container.
These two objects will be created together, destroyed together and logically linked to each other.
When you create bad, text2 will appear automatically. You destroy bad and text2 will be destroyed too.
So remove steps where you create/destroy text2, you only need to pin it.

Also, when you have to repeat the same code twice, this means you need to move it into a function.
Create a function "SpawnBad" and call it when you need to spawn a new enemy.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
71
Posts: 1,081
Reputation: 38,725

Post » Tue Oct 10, 2017 8:46 pm

Wow dop2000, your suggestions are really super helpful.
I don't know why I didn't use a function, I have used them before.

As for the container (wow)... that almost fixed it... my game has developed a bizarre issue.
When i run in debug, 2 badGuys are created - one scrolling right & the correct one scrolling down.

Any ideas? I've posted http://robfreeman.co.uk/demo/

Thanks,
Roberto
B
5
S
2
Posts: 64
Reputation: 632

Post » Tue Oct 10, 2017 9:09 pm

As I said in my previous comment, you don't need to destroy text2 and you don't need to create text2!
Remove entire event 16, and remove "create Text2" from event 18.

When you create Text2, another pair of Bad+Text2 is created (as they are in the same container). That's why you have some sprites scrolling to the right.

Also, why are you destroying and then immediately creating the spCannon? What's the point?
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
71
Posts: 1,081
Reputation: 38,725

Post » Wed Oct 11, 2017 4:06 pm

Thanks sooooo much dop2000, I've learnt a lot from You & Bruno. I managed to clean up my messy code.
B
5
S
2
Posts: 64
Reputation: 632

Post » Sun Oct 15, 2017 7:49 pm

Hi Guys,
Hope you don't mind me pinging you. I found a bug, which (surprise, surprise) i can't figure out. If the angle of the spCannon is between 190 - 360, spCannon breaks (as in, produces no more buttlets). other, if the shots are fired down, then it breaks (despite the fact - bullets destroy when outside of layout.

Any ideas?

Roerbto
B
5
S
2
Posts: 64
Reputation: 632

Post » Sun Oct 15, 2017 8:21 pm

I added spCannon Is between 10 and 170 degrees (because I forgot default sprite always points at 0) and Set angle towards(Touch(0).X, Touch(0).Y) on Every tick.

This works, but i wonder if you guys would have done same?

Thanks,
Roberto
B
5
S
2
Posts: 64
Reputation: 632

Post » Mon Oct 16, 2017 3:32 am

In C2 any angle greater than 180 becomes negative angle. Say if you set bullet angle of motion to 190 and then later check it, it shows as -170. This always messes up my calculations.. So I'm sure your bug is somehow related to this.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
71
Posts: 1,081
Reputation: 38,725

Previous

Return to How do I....?

Who is online

Users browsing this forum: corporatedrone and 29 guests