How to make walls like in RTS games?

This forum is currently in read-only mode.
From the Asset Store
10 isometric and animated Strategy Game Buildings in two Colors.
  • Has anyone tried to make (rts)game with ability to create walls while in game, like in the most of rts games?

    I would like it to work something like this...

    "Wallmaker" selected

    • On left mouse button clicked - Create wall_end.sprite to mouseXY
    • When left mouse is down - Create wall_middle.sprite on line between wall_end.sprite(or line starting point) and mouseXY(--->line ending point) points so that middle parts (16x16 tiles) fill the gab and align nicely.

    On left mouse button released - Paste the wall in the game.

    So it's basically like using line object but with textures. I think panel and tiled background objects don't work on this... And also the wall must be built in parts so that you can destroy it in parts.

    I probably could do this in some dirty way, but first I'm asking for the "clean" and the best way to do this (also saving my brains and time).

    I would also like to draw more complex wall at the same time, like...

    First click starting point for wall(tower?), second click for another tower, third click for another tower... and then create a wall between these points in order. Also I want to "preview" the wall before making it.

    Probably too complex to make example(-->.cap) for me but, maybe some explanation about the logic and how it could be made.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I won't bother going into great detail, because you're right... what you're asking for is pretty complex in terms of making an example cap. But I will give you this to start off with:

    You can draw boxes on a grid with the mouse.

    As for making lines of boxes in a series like you mentioned, you could create a system where the first mouse click places a "tower" sprite and gives it the number 1 in a PV called something like "myNumber", and sets a global called "currentTower" to the same number. Now you need to place a second tower, but it would make sense to only place it in a straight line away from the first, so you would have to come up with a formula to make sure that placement is disabled if the next tower is placed at an odd angle away from the first:

    + Always
        -> Enable next tower placement
    + TowerSprite.Value('myNumber') = global('currentTower')
        + (TowerSprite.X - cursorSprite.X) Not equal to 0
        + (TowerSprite.Y - cursorSprite.Y) Not equal to 0
            -> Disable next tower placement
    So, if the X position [i][b]or[/b][/i] the Y position of the cursor is different to the current tower, then it's okay to place the next tower because we know that at least one of the axes to the cursor is in a straight line away from the tower (i.e. is equal to 0).  So you allow a click, and place the next tower, and lable it's myNumber to global(currentTower)+1, and add 1 to global('currentTower').
    To draw between the two towers you need to find out how far away one is from the other so you can find out how many wall sprites need to be put into the space between them, then you need to loop through all the spaces and place walls.
    The easiest way would be to start at tower 1 and find out if tower 2 is up, down, left, or right from it.  Then you make a loop that advances the cursor 32 pixels in that direction.  If the cursor doesn't overlap the next tower, it places a wall.  If it does overlap the next tower, it stops the loop and begins the process again with tower 2 & 3, up to whatever number global('currentTower') is at.
    Anyway, that's how I would attempt it.  Hope that makes sense.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)