Results 1 to 7 of 7

Thread: [MX04] RTS help...

  1. #1
    3
    posts
    Are you at you're post?

    [MX04] RTS help...

    To be honest with you guys, I'm an intermediate level actionscripter, and I realize this is probably insane for me to attempt at this time. I should learn much more, but I wanted to try...

    I'm trying to put together an RTS game, and I realize that there is no real way to explain how to make one except to say you need:
    -characters
    -buildings
    -backgrounds
    -units
    -an engine etc...
    -enemy AI

    So I was just wondering how to write some of the things that have to do with each, such as:
    -how to give the user the ability to select and deselect units/objects
    -how to give the user the ability to send the unit to a certain spot on the map

    If you know a good tutorial on the web for any of this, please let me know.
    thanks.
    Last edited by tk-421; June 18th, 2008 at 07:51 PM.

  2. #2
    Do you have a specific problem with selecting units? This seems fairly straightforward.

    As for giving units directions where to go, this will require reading up on pathfinding. See the sticky at the top of this forum. Basically, when you want unit A to go to point X on the map, the unit must calculate a path to get there. Usually this is done on a map that has been divided into nodes/cells, then finding the "cheapest" series of nodes from A to X. The most popular algorithm for this is called A* (A-star).

  3. #3
    3
    posts
    Are you at you're post?
    Let's say I had a unit, and I wanted to write that if it was clicked on it would be selected, and if the user clicked on the unit again, it would become deselected. I tried applying the "selected" function because I remember seeing it in some rts source code somewhere, but I did not get too far. Does the "selected" function have anything to do with this?

  4. #4
    Hi

    You might use classes for the differents entites's type. For this kind of game, i think it's VERY important to use OOP.

    For example, you would have a class named "Batiment", who could specify :
    - unit's type of production
    - damage
    - build price

    Then, you can derive this class to create others sorts of buildings :
    A class "Archers factory" :
    - archers
    - build price = 300
    - damage = 0 (%)

    It is the same concept for units : a class Unit (health, hit damage, speed,...) which would be derived on "Archer", "Footman", ....
    Typically, for application, units 'll be movieclip, so selection/deselection would be simples "onPress" function. Inside, just do that test :
    if (this.selected) this.selected= true; else this.selected= false;

  5. Hey, I was once at the same position as you are now, except I had no idea at all how to program. My first attempt was to be able to select/deselect units and have the to move. On www.wonima.demon.nl you can play the "game" in which I achieved that. After that I moved on with more difficult things. I now have a pretty solid engine, lots of units, terrain, even aircraft units (though not in the version online I believe). I haven't worked on this game for quite a while (school + moved on the better programming languages). But I think I can give you some advice.

    The problem with an RTS is, is that there are many objects at the same. Flash renders very slow, especially if you use movieclips. So you have got to keep in mind you have to do everything with as little cpu power as possible. Of course, if you don't do this for other applications it's just bad coding, you should always seek the fastest way. But with a flash rts it's just so much more important. So bitmap rendering is a must, always.

    As I said, I now have a pretty solid engine. One function is called every frame on a static interval looping trough several arrays

    checkGameStatus(); // are players dead, power status etc
    clearScreen(); // used to clear the screen, bitmap rendering techniques you really can't miss
    playerInput();
    gameLoop(); // this loops trough all the arrays of units.
    ai.artificialThink(); // the ai


    I wouldn't bother with the AI for now if I were you. You just need to have the objects with good properties. Without OOP you are nowhere. Mine have a lot for example the stats variables:

    id // unique number to recognize units
    health // how many hitpoints it has, if this is below zero the unit is dead. Max health can be found in a nice and sweet statistics class.
    damage // rather the attack power of the unit.
    speed // or maybe maximum velocity, though, I wouldn't bother with stuff like that and have just one movement speed
    team // very important, used when you are selecting.

    Then you have the status variables such as isReloading and isSelected for example.

    I wouldn't start right away with the difficult stuff, just be sure units can move for example. Then implant some kind of firing device. When you don't have a lot of experience just slowly expand your game. No need to plan the whole game because you just don't know how you will handle it all. When you have more experience you can start on paper for example.

    Now, the selecting stuff isn't that hard.
    onMouseUp = function () { checkMouseClick (); }

    // with checkMouseClick():
    static function checkMouseClick (){
    for (Unit unit in allUnitsArray)
    {
    var selectingUnit = false;
    if (_root._xmouse > unit.topLeft && _root._xmouse < unit.topRight && .. etc {
    unit.isSelected = true;
    selectingUnit = true;
    }
    if (!selectingUnit)
    {
    for (Unit unit in selectedUnitsArray)
    {
    unit.gotoLocation.X = _root._xmouse;
    unit.gotoLocation.Y = _root._ymouse;
    }
    }
    }


    Just, to give you an idea. I just typed it out of my head.

    To summarize:
    - Learn how to use bitmap rendering
    - Learn OOP (if you don't know it already)
    - Start slow.

  6. #6
    Agree with you!

    Maybe beginning with ground display (and scrolling) would be a good way. (take a look for strille's scrolling engine with his sonic game demo).
    Later, i advice you to try to use the MVC model pattern. To explain it simply, separate all functions which will managing the human interactions, the displaying controller an data observer. It will be easier to proceed.

    Good luck

  7. #7
    3
    posts
    Are you at you're post?
    strille's scrolling engine is genius and i got the selecting/deselecting to work as well.

    thanks guys!
    Last edited by tk-421; June 18th, 2008 at 07:49 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012