Author Topic: RTS Style Script  (Read 3112 times)

GameDeveloper

  • Guest
RTS Style Script
« on: 2006-01-27, 01:52:37 PM »
   I was wondering if there would be a way to make an RTS style script for a game I'm making.  I just need one where you can select multiple sprites (maybe by a box, or something more complex?), it switches them to follow a specific instance, and follow that instance when the player places it.  So, once all the sprites are a different instance, they would follow a flag that could be placed by the player.  Once that flag is placed, then all the sprites follow that specific flag sprite.  Is there a way to do this?  I have already found out how to build buildings and produce units, it's just I'd like it if the player could select multiple units.

  The real difficulty is the problem of selecting multiple units.  I'm not sure how to do this without scripting and I was wondering if there might be a way to do it with it.

   If anyone could help with this it would be greatly appreciated. (If you need me to be more specific, then please say so and I will)

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: RTS Style Script
« Reply #1 on: 2006-01-27, 02:48:18 PM »
Well, since you can't even use the mouse without scripting, selecting multiple units with the mouse would be impossible without script (and probably near impossible even without using the mouse, as well as completely a silly way to do it).

The selection seemed easy at first, but then I started thinking about how to do something as simple as draw the box on the screen, and frankly, I don't know how to do that.  But once you have the coordinates of the box, then creating an array of the sprites inside of that box would be relatively simple.

My advice:  Don't use the Scrolling Game Development Kit to make a Real Time Strategy game.
Edward Dassmesser

GameDeveloper

  • Guest
Re: RTS Style Script
« Reply #2 on: 2006-01-27, 03:14:24 PM »
   I realise the SGDK is not specifically made for RTS style games, but I just wanted to see if it could be done, or maybe I could push it to it's non-scripting limits.  I already made a simple RTS style game with SGDK, and it didn't use a mouse, and it turned out very well and was actually unique/fun, but you could only select one unit at a time, and it felt clunky.  I'm still going to try to make it with this engine.

Now, what you said also came to my mind (drawing a box on the screen), but this is also why I asked for a script on how to do this.  If the scripting cannot accomplish this in any concievable/easy way, then I could just make a very, very primitive RTS style game where you select a rather large box sprite--put it over the sprites--and anything that touches that get's selected, but I wanted to avoid this kind of clunky design.

   It would be greatly appreciated if some one who might have a solution to this could help me, but I do thank you for your suggestions Durnurd :).

(Also, just out of curiosity, is there a free engine that lets you create an RTS from the ground up?)
« Last Edit: 2006-01-27, 03:27:06 PM by GameDeveloper »

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: RTS Style Script
« Reply #3 on: 2006-01-27, 05:35:36 PM »
In order to draw the lines for the edges of the selection box, you can do what I did for drawing the lines in a path -- draw a series of little sprites along the line.

cbass

  • Expert
  • Regular
  • *****
  • Posts: 97
  • script this
    • View Profile
    • Squest RPG
Re: RTS Style Script
« Reply #4 on: 2006-01-27, 08:18:47 PM »
The way I would do it with script:

I would use the CurrentDisplay.DrawTile Method to draw all the tiles for the box.  First make a tileset a vertical and horizontal line going through the middle of the tile.  You would want the tileset relatively small to match the smallest possible box you want to make. (16x16?)

I like this method because its clean, and there are no sprites to clean up, or dynamic layers to worry about, and you can do it all in one event I beleive, either onmouse move or onafterspritesmove.

Ill even write you a little Psudo Code for the draw box part only:
Code: [Select]
OnMousemove 'Or every frame??
'if mouse button1 is depressed:
'make sure mouse is to the lower right of starting point, if not... do something to make it not screw up :P
For i = startX-screenscrollX to mouseX step 16
  ' if last Column to draw, do something to adjust x value to the left to match up corners
  CurrentDisplay.DrawTile HorizontalTile, i, startY-ScreenscrollY - 8
  CurrentDisplay.DrawTile HorizontalTile, i, MouseY + 8
 
  For j = startY-ScreenscrollY to MouseY step 16
    ' if last Row to draw, do some adjust y value to the -y to match up corners
    CurrentDisplay.DrawTile VerticalTile,startX-screenscrollX - 8, j
    CurrentDisplay.DrawTile VerticalTile,mouseX + 8, j
  Next j
Next i

else if mousebutton isnt depressed but was last frame:
  Call select units
end if

GameDeveloper

  • Guest
Re: RTS Style Script
« Reply #5 on: 2006-01-28, 01:24:26 PM »
   Alright, I think I can handle it from here.  Thank you all for your help, and thank you cbass for writing that code.  I'll try to make this right away.

cbass

  • Expert
  • Regular
  • *****
  • Posts: 97
  • script this
    • View Profile
    • Squest RPG
Re: RTS Style Script
« Reply #6 on: 2006-01-28, 04:48:19 PM »
yeah,

hopefully I gave you a good starting point.  I basically drew up what the code would look like but you have to replace all the stuff like "harizontalTile", " MouseX", and "ScreenscrollY" with the actual objects in gamedev.

If you haven't done so, this is a good time to look at the scripting reference in the help file.  Its confusing at first, but it should tell you how to spell and how to set up the hierarchies to find, for example "ScreenscrollY" which is "ProjectObj.GamePlayer.MapScrollY" (most objects are under ProjectObj.GamePlayer" or at least "ProjectObj.", So it is a good idea to put the lines With ProjectObj.GamePlayer / End with around most code, so you would only have to write in .MapScrollY to get the mapscrolly instead of writing the whole hierarchy out whenever u use it.

If you can fingure this script out yourself, you are well on your way to becoming a gamedev scripting guru :)

Hope this helps, good luck.