0 Favourites

[Solved] Put Building in the ground (Like RTS game)

  • Hi,

    Currently i've making a game like RTS (Real-Time Strategy) game. Now, i want to add 'put the building' event. So, can you help me? Thanks! And Sorry for My English.

  • aren't you just spawning an image on top of the background. just keep a record of what buildings you have where and upon startup create all the need "buildings".

  • Just do not forget to check for collisions before you spawn the building, otherwise you will end up with stacked buildings, one on top of the other.

    My suggestion in steps:

    Step 1 - every tick, have the new building sprite follow the cursor (MouseX, MouseY)

    Step 2 - Make the new building 50% opacity.

    Step 3 - every tick, check for collisions (AKA see if another building is already built on the spot you want to place the new one)

    Step 4 - If step 3 has passed (no collisions), then make the building glow green.

    If step 3 has not passed (collisions have turned up true) then make the building glow red and do not continue to step 5.

    Step 5 - If step 4 has passed successfully and the player clicks the e.g.LMB, then make the building's X,Y the same as the MouseX,MouseY.

    In general, what you try to do is a substantial process imo, not just a couple of quick events. You also have to factor in saving the position of the building if you want to create saved games or go back and forth between menus.

  • rho shirogr thanks for the reply! It's very Helpful

  • shirogr

    that's not needed as this is an RTS type game... once a slot has been built, then there should be nothing else that can be stacked.. I've done something similar.. I have an array of (say) 10 locations with a value, and actually what I did is put the same image down on each square and then set the animation frame to the structure I wanted. that way they are actually always there, but frame 0 is empty. however the trick then becomes how to know which structure is there when you want to do something with it, then you use instance variables to track as well.

    the above method is just a one event to create the display.. making use of it is something else..

  • rho

    We do not know if Regga354 wants to make a slot based rts like e.g. Kingdoms of Camelot (in which case your method is better) or if he wants to make a RTS like Command & Conquer where there are no slots, the buildings have various dimensions and the player can pretty much build wherever s/he wants (in which case I think my suggestion is more appropriate).

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • shirogr

    gotcha... I hadn't thought about a slotless implementation. good point

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)