RTS back and forth movement

For questions about using Classic.

Post » Wed Jun 30, 2010 2:25 am

Hello,

Still fairly new to all this, but I finally attempted something more than just a test to see how stuff works. (well, I guess I did make a very simple breakout game too..)

I wanted to make a starcraft style resource harvesting cycle, but wasn't able to overcome one problem.

I had a mine, a carrier, and a main building. It started by sending the carrier by RTS to the mine. Once the 'arrived at location" event happened, the carrier's resource variable would increment by one, and the mine's variable would decrease by one. This all worked fine.

The problem came in when I tried to send the carrier back to the main building. Since the 'arrived at location' event isn't indexed or specific to a particular object, I have no way of knowing *which* object the carrier was standing by, so it kept triggering both the 'pickup' and 'dropoff' code.

I tried several ways of using variables to try to keep track of where the carrier had been sent, and not allowing it to begin movement back to where it was already standing. I also tried using a condition depending on whether or not the carrier was actually carrying something.

I tried using collision to tell which object the carrier had arrived at, but it doesn't appear that works during RTS movements, and my attempts to create a collision detection box wasn't helping either.

None of this worked out, and I feel that I'm making it far more difficult than it needs to be.

I don't have the cap file anymore, as I had other ideas to try, and in the end, nothing worked.

How would you approach this ?

Thanks,
Z
B
3
G
2
Posts: 35
Reputation: 745

Post » Wed Jun 30, 2010 5:34 am

Have you tried families yet?
Image Image
B
161
S
48
G
90
Posts: 7,348
Reputation: 66,751

Post » Wed Jun 30, 2010 7:06 am

Try this .cap, and see if it doesn't do what you're looking to do. (please forgive my 30-second placeholder graphics)

download/file.php?id=635
B
2
S
1
G
2
Posts: 48
Reputation: 896

Post » Wed Jun 30, 2010 1:53 pm

Newt, I have not tried families. I'm not familiar (no pun intended) with them yet.

Tube, your example works perfectly, though it's more complex than I expected it would have to be. If only RTS would return what object or location it had arrived at, this could be much simpler, I expect. Ahh well, I'll work with this. Thank you for your help :)

EDIT: Well, maybe not that much simpler, I guess. All it would eliminate would be the destination variables, and the RTS returned variables would still have to be part of a condition anyway. A couple lines shorter, but not such a big deal.

Z
B
3
G
2
Posts: 35
Reputation: 745

Post » Wed Jun 30, 2010 5:31 pm

Hehe, I tried to do just that few weeks ago as a construct exercise. I succeed halfly and then dropped it. Here, take this and see if you can use it for your needs.

http://www.box.net/shared/m53if41ypb
[there is much debug events in or just miss-tries, take only what you need, the rest is rubbish and it still has problems]

Since then I found on this forum the state machine plugin which would made this project even simpler.
B
2
G
2
Posts: 23
Reputation: 696

Post » Wed Jun 30, 2010 6:26 pm

The graphics and code are a tad primitive, but it is commented and only has six events :D .
http://download200.mediafire.com/n4if5b ... y5/rts.cap
The crystals don't feature resource amounts (I didn't have much time), but that's super easy to add.
B
2
G
3
Posts: 25
Reputation: 900

Post » Wed Jun 30, 2010 6:31 pm

Wow, so much help! Thanks guys :)

I do have one more question. Is there somewhere that has some documentation on the picture editor? I know that it's probably not the best for creating anything beyond basic images, but I do have some questions about it nonetheless.

EDIT: I'm also looking for some information on how to detect things within a circle around an object, and how to find the nearest kind of 'whatever' object.

Thanks,
Z
B
3
G
2
Posts: 35
Reputation: 745

Post » Wed Jun 30, 2010 6:46 pm

Just use the system expression "distance".
Distance(thing.x, thing.y, otherthing.x, otherthing.y)
B
2
G
3
Posts: 25
Reputation: 900

Post » Wed Jun 30, 2010 8:45 pm

[quote="Zaaephod":2r9ve8b9]Wow, so much help! Thanks guys :)

I do have one more question. Is there somewhere that has some documentation on the picture editor? I know that it's probably not the best for creating anything beyond basic images, but I do have some questions about it nonetheless.

EDIT: I'm also looking for some information on how to detect things within a circle around an object, and how to find the nearest kind of 'whatever' object.

Thanks,
Z[/quote:2r9ve8b9]

The picture editor within Construct is basically a slightly fancied-up version of Paint, so I don't think there's really any in-depth documentation for it. You're probably better off using Photoshop (if you can afford it) or Gimp (if you can't) just so that you have things like filters, layers, and all the other features that will help make your graphics look passable.

As for finding the nearest "whatever" it's a lot easier than you'd think. Just make a new condition, the base object is your "whatever" (and that can even be a family, if you're using them!), and give the coordinates you're searching from (likely the X and Y of the object you're searching near, such as your carrier in this example). And, as Oko indicated, you can use Distance to see just how far away that thing is, so if that's outside the radius you'd like to use you can just ignore it altogether.

P.S. Sorry if my solution to your original problem was a little lengthy; I wanted it to give a half-decent graphical representation of what was going on behind the scenes, hence all the text boxes and so forth. There are slightly better, if less intuitive ways to do it, and I tend to err on the side of verbosity when making things for other people's benefit. Too many years of writing C++, I think :)
B
2
S
1
G
2
Posts: 48
Reputation: 896

Post » Wed Jun 30, 2010 9:54 pm

There are also some things that you can use in expressions for each object/behavior that might not be obvious. The RTS behavior has X and Y destinations that you can read, for example. You can find these by selecting objects while in an expression entry.

As an example, you could pick any blue family member that is within 25 pixels of the carrier's intended destination and make it flash, like so:

+ Blue: Pick by distance(Carrier[RTS].DestX, Carrier[RTS].DestY, Blue.X, Blue.Y) < 25
-> Blue: Flash for 2 seconds with 0.25 seconds interval

It uses the 'Pick by expression' condition. Also, you can have each family member have a unique value in a 'type' private variable that will let you further identify or pick them. And there is a 'Pick nearest' condition for objects or families that you can use.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests