GMS0012

hello all..
is it possible to group units (drawing a rectancle) while holding down the mouse button with XNA
i am planning to do a 2D game where i would need this..
if yes, please give me a hint how to do it...
thanks in advance
greg


Re: XNA Game Studio Express Grouping units like in a RTS game

GMS0012

. oops..sry



Re: XNA Game Studio Express Grouping units like in a RTS game

BlogusMaximus

Shouldn't be a problem, it's just a question of implementation.

XNA can certainly handle cursor location, mouse clicks and dragging. It's up to you to draw the box and figure out what objects are within in. Then its just a matter of assigning orders to those units. (I assume this is for a RTS game )







Re: XNA Game Studio Express Grouping units like in a RTS game

GMS0012

yes it is.. as said in the topic :)
i dont know how to draw a simple rectangle with xna.. didnt find a great help in this forum




Re: XNA Game Studio Express Grouping units like in a RTS game

Calvin Bell

Here is an idea for you. Since I haven't actually done it yet, I'm not sure if this is the best way to go about this.

Take the point where the user clicked and started dragging, and draw a line that starts at the click point and goes on the Y to wherever the mouse currently is (keep x at 0). Draw another line that does the same but reversed (draw on X, keep y at 0). Also, draw a line from the current mouse position up to the x that you started at and on the y to where you started at. That will give you a rectangle on your screen that will move when you move the mouse. When you detect that the mouse button has been lifted, change those 4 lines into a box(rectangle ), and loop through every unit on your screen to see if its in that box. I hope thats close because I wouldn't want to mislead someone.





Re: XNA Game Studio Express Grouping units like in a RTS game

BlogusMaximus

GMS0012 wrote:
yes it is.. as said in the topic :)


oops, sorry. missed that.





Re: XNA Game Studio Express Grouping units like in a RTS game

Nick Gravelyn

Calvin: That's pretty much how I would do it. You could also use XNA's BoundingBox class to help with determining which units are in the box (which you could make from a BoundingBox).

As far as grouping them, you could use subclass a System.Collections.ObjectModel.Collection<>. Then put the units into that. That would be my recommendation. Just create one and all all the intersecting units into it. Then you could make methods for your class like SetTarget() which would in turn set the target for all your units to a place. It would be an easy way to distribute methods to all the units.




Re: XNA Game Studio Express Grouping units like in a RTS game

GMS0012

@Calvin Bell
this is an idea... line by line...
or i put a transparent rectangle tile above it..




Re: XNA Game Studio Express Grouping units like in a RTS game

MShanahan

I would've gone with a nice trig function which would calculate the triangle and display just the outside lines....your way is much easier! :)



Re: XNA Game Studio Express Grouping units like in a RTS game

Calvin Bell

Nick, I'm surprised we can agree when I graduated from SVSU in Saginaw and I see you are from Grand Valley. :-P (BTW, I wasn't sure if you could make a bounding box out of that rectangle that you draw but since you can that makes things much easier!)





Re: XNA Game Studio Express Grouping units like in a RTS game

Calvin Bell

The bounding box idea sounds the best. It would be making a bounding box with the rectangle and then calling Intersects() for the box against all the units. If intersects equals true then add it to the group!





Re: XNA Game Studio Express Grouping units like in a RTS game

GMS0012

thanks for the ideas..
i will think about this :)
greg




Re: XNA Game Studio Express Grouping units like in a RTS game

GMS0012

what would you recommend for the client server model
tcp sockets/udp sockets
greg