Create a Flash Game like Nano War – step 2

In the 1st step we created the units and the engine to select them.

Now it’s time to write the code to let selected unit(s) send troops to other unit.

I created a new frame for the sphere object, a green circle, representing the target unit.

Let’s make a recap:

Frame 1: black circle, unselected unit

Frame 2: red circle, selected unit

Frame 3: green circle, target unit

Obviously, an unit cannot be target of itself

So, once we have one or more selected units, the script will have to:

If the player does not press the mouse

Draw a line from selected unit(s) to current mouse position

If the mouse is not over an unselected unit, leave all unselected units to frame 1

If the mouse is over an unselected unit, play frame 3 for that unit and leave all unselected units to frame 1

If the player presses the mouse

If the mouse is clicked outside an unselected unit, deselect all selected units

If the mose is clicked inside a unselected unit, deselect all selected units and select the new unit (during next part we’ll see how to move troops to this unit)

Here it is the script:

And this is the result

Download the source code and think about enemy’s AI… this will be the hardest part

  • Questo

    Nice as always it looks almost like the real game

    It seems there are bots on triquitips Thay are posting things like Powere level your character at! or Get all your virtual gold at today!(just out of curiosity why is triqui on all your things)

  • Pingback: User links about "radius" on iLinkShare()

  • slain4ever

    i think emanuele feronato IS triqui

  • Eliott Robson

    Hey Emanuele NICE! I was just wondering if you could help me implement this with my game i am making? Contact me at my e-mail address and i’ll post more information. It’s a top down zombie survival!

  • anon

    hi, what sort of code would i use to handle unit numbers and enemy AI, i am relatively new to scripting and don’t have a clue :)

  • GOOD GAME!!!