Tower Defense

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply Page  12>
Author
999 Rep
Post Options Post Options   Quote sparkdad Quote  Post ReplyReply Direct Link To This Post Topic: Tower Defense
    Posted: 03 Jul 2012 at 4:59am
I have asked several questions here in the last couple of days and of course here is another one!

I have followed several pieces of advice here on the forum and this is what I have made.

https://docs.google.com/open?id=0B5puA55FudSeLUJqVjlGQUItc2M

If you run the layout you will notice that at some point the towers will shoot the enemy that is farthest to the right but will NOT shoot the ones on the left.

So the TOWERS on the FAR right shoot but middle and left towers do not.

Any thoughts?
Back to Top
7,061 Rep
Post Options Post Options   Quote R0J0hound Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jul 2012 at 6:08am
I think you have a typo in Event 5.
You used this condition:
StoneTower: pick closest to (StoneTower.X, StoneTower.Y)
You should use this instead:
Enemy: pick closest to (StoneTower.X, StoneTower.Y)
Back to Top
999 Rep
Post Options Post Options   Quote sparkdad Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jul 2012 at 12:59pm
Thanks ROJO! You were right! It works perfect now!

Last thing if you might look. I have a mouseover event for the towers to display information. It will eventually show a context menu for upgrading etc.

It only seems to work on the middle tower for some reason!

Any thoughts? It is in the MouseControls Group.
Back to Top
1,712 Rep
Post Options Post Options   Quote Khalan Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jul 2012 at 2:59pm
I think you can get rid of the Pick IID event for the StoneTower; I believe the system has already got the correct ID based on the mouse cursor.
Back to Top
999 Rep
Post Options Post Options   Quote sparkdad Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jul 2012 at 3:07pm
Thanks to all that have helped! OK. So mouse events are fixed, although I switched to click instead of mouseover for interface reasons.

https://docs.google.com/open?id=0B5puA55FudSeTTA1ZVNvMmhwYlk

The problem now is that once an enemy reaches the castle the health bars do not update correctly.

When you run the game...

LEFT CLICK on the circles on the map to build towers.

RIGHT CLICK to destroy a tower.

All works fine until one enemy reaches the end.

I suppose the problem is in the destruction of the enemy and hp bar.

Thoughts?
Back to Top

Moderator
28,468 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jul 2012 at 3:33pm
Actually, when you set your action "Destroy lifebar" atm, it picks all lifebars of all enemies.

To correct :
Add an instance variable "Parent" to the lifebar.
In event 16 (group "enemy spawn") add an action "Lifebar: set Parent to enemy.UID"

In event 28 (group "enemy reaches castle") add a condition "Lifebar: value Parent is equal to enemy.UID

Only the current lifebar for the current enemy will be destroyed.

You can also add a pin behavior to the lifebar and pin it to the enemy.

=>





(You can notice I deleted the condition "Pick enemy IID" since it is not relevant as the correct instance is already picked by the condition "on collision".)
Back to Top
999 Rep
Post Options Post Options   Quote sparkdad Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jul 2012 at 3:57pm
Awesome! Thank you! I am getting better at Construct Events but still have some work to go! I appreciate the communities help!
Back to Top
999 Rep
Post Options Post Options   Quote sparkdad Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jul 2012 at 9:01pm
Another problem!!!!

Now I am creating the Context Menu at build spots. When you mouseover a build spot it highlights. Once you click it a red box pops up that will eventually contain towers that an be built.

When you click on the red box ( or eventually icons of towers ) it should build a tower on the BUILD SPOT that was originally clicked.

This is working fine. When the event is OVER it should get rid of the BUILDSPOT that the tower was built on : ) but it gets rid of ALL of the build spots!

Thought?

https://docs.google.com/open?id=0B5puA55FudSebWFFRUt2T1p4VG8
Back to Top
999 Rep
Post Options Post Options   Quote sparkdad Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jul 2012 at 9:43pm
UPDATE #2


DID NOT WORK!!!!

I think that I am going to rewrite and use animations for the rollover to take the complication out of some of this.

I will note when done.


Edited by sparkdad - 03 Jul 2012 at 11:01pm
Back to Top

Moderator
28,468 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jul 2012 at 11:24pm
Not sure the file you linked in your last post is the correct one.
It's no more a Tower Defense, it is a shooter.

Perhaps you should upload your capx to dropbox it's easy as managing its own hard drive.

As for your issue, you mention again that all instances of an object disappear when you use an action "Destroy".
I guess it is once again a picking problem.
You don't use conditions such that only the "current" instance gets picked and destroyed.
That's a guess without having seen the code though.

If I follow your logic correctly, once a TOWER is built, its BUILDSPOT is destroyed, so, logically, there should never be a TOWER overlapping a BUILDSPOT.

You can then use a subevent "BUILDSPOT is overlapping TOWER" and an action BUILDSPOT: Destroy

This will destroy any BUILDSPOT that has a TOWER over itself.



Have a close look at the topics listed in the how do I FAQ at the section "Picking/selecting instance(s)".

The subject is treated in many ways and with different approaches.
Hope it might help you.
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down