A different type of RTS programming part 1: Selecting and construction.
Submitted:|| 3rd July, 2003
Yea, this is my first attempt at an article. Im currently developing an RTS, and I might as well Share my engines with others. Im starting this article out thinking that you already have your sprites ready. As you see now, I start my RTS programing with construction.
Ok. I have four objects on the screen, A house looking thing (which is where my units are built) I have a list box (for selecting what to build), I have a button (for construction purposes) and a plane (for constructing).
First before I do anything, I have to setup the list. So far the only thing you can construct is a plane, which is the first thing on my list. How do I get the plane to construct? Thats what I'll explain now.
The first event I have on my list is:
START OF FRAME = HIDE LIST and LOSE FOCUS ON LIST
MAKE BUTTON INVISIBLE and
I do this so only the house is visible and no other units are on screen. Now, for selecting this specific building I have this event (user animation 1 is its 'selected' animation).
USER CLICKS WITH LEFT BUTTON ON (HOUSE) = CHANGE ANIMATION SEQUENCE (HOUSE) TO USER ANIMATION 1
Now to bring the construction menu and button up.
(HOUSE) ANIMATION USER ANIMATION 1 IS PLAYING + ONLY ONE
ACTION WHEN EVENT LOOPS = SHOW LIST and GET FOCUS ON LIST
MAKE BUTTON REAPPEAR and
That event makes the list and the button reappear for using. To make the menu leave.....you need these two events.
USER CLICKS WITH RIGHT BUTTON: CHANGE ANIMATION OF (HOUSE)
Then you need:
(HOUSE) ANIMATION STOPPED IS PLAYING + ONLY ONE ACTION WHEN
EVENT LOOPS = LOSE FOCUS ON LIST and HIDE LIST
MAKE BUTTON DISAPPEAR and DEHIGHLIGHT BUTTON
With this done....we can now select and deselect the house (our counstruction site for now). Now lets focus on the menu of the HOUSE.
Now we need to create a counter for our building time ( whic is 13 secs for the plane). Minimum and initial value of counter is 1 and the maximum is 13. Since we now have this done, we can make the command for building the PLANE.
BUTTON (CONSTRUCION BUTTON) ClICKED + LIST SELECT (LIST)
EQUALS 0 = SET INTERNAL FLAG 0 OF (HOUSE) ON
Setting the internal flag on tells what unit to build. Now we need the counter to increase once every second:
INTERNAL FLAG 0 OF (HOUSE) IS ON + EVERY 01"-00 = ADD 1 TO COUNTER.
All we need to do now is have the object created and the counter and flags reset..which can be done by this:
(COUNTER) EQUALS 13 + INTERNAL FLAG 0 OF (HOUSE) IS ON =
CREATE (PLANE) AT 15,-5 FROM (HOUSE)
SET INTERNAL FLAG 0 OF (HOUSE) OFF
SET (COUNTER) TO 1
Now you can succesfully create a construction place! Next article I will explain how to add more units to the construction place and I will get into moving some of the units!
If you have any problems with this Article or if you want to give me ways of improving my articles, feel free to do so in the comments section. I'll try to make it more understandable if you need me too.
See you until PART 2!