Options

Programming - Creating the "select a target" user interface

RiemannLivesRiemannLives Registered User regular
tldr: This thread is about how to solve a particular programming problem relevant to game dev. I am working in C# / XNA but suggestions in any language would be greatly appreciated.



Consider a top-down view strategy game. Whether it is real time, turn based or a hybrid of the two the situation will arise where the user has selected a unit and needs to instruct it where to move, shoot or perform some other action with a target position. Often there will be obstacles or modifiers (range limits, walls, trees, other units) to contend with.

In my current project I want to make it a bit easier to make these decisions by drawing a line from the currently selected unit to the current position of the cursor. This line would be color coded to indicate the chance of success of the action and what things might be getting in the way.

EG: When choosing a target for a ranged attack, the line would be green if there is a high chance of success and shade into red as success becomes less likely (due to long range or other game factors). Furthermore, the shading on the line is drawn out in such a way that the user can tell where these obstacles are. It starts out green at the source and shades to red or black as it goes along and encounters penalties or total obstacles.

I should point out that the system I am thinking of here is not tile-based.

This has been used to good effect in such games as Warhammer Squad Command and the Close Combat series for the PC.

Where I could use some guidance is how to go about structuring my map data and what kind of algorithm to use for generating this colored line. EG: Links to articles, how-tos, example code etc... I have a few basic ideas about how to go about this but everything I have come up with so far is a very brute-force approach and will likely cause performance problems.

Attacked by tweeeeeeees!
RiemannLives on

Posts

  • Options
    Mr.FragBaitMr.FragBait Registered User regular
    edited April 2009
    We kinda have a thread for programming questions.


    Some of these links might be of help, as stolen from the SA game thread. I might be able to help if you have more specific questions on implementation.

    Mr.FragBait on
  • Options
    ObsObs __BANNED USERS regular
    edited April 2009
    You probably need to create a matrix that translates a mouses coordinates on screen to the position on the map, which you probably have. Or probably use a vector of some sort to determine the point where the mouse click would intersect the landscape if the game view is angled. Then you need to perhaps trace a line from the unit to where that position is. The points where it encounters obstacles are noted and you would change the color of the line after that point when you render a frame. You also do necessary calculations for range here as well, etc. Do this calculation for every frame in the game.

    Doesn't seem that hard, unless I've misunderstood the problem.

    Obs on
  • Options
    SeguerSeguer of the Void Sydney, AustraliaRegistered User regular
    edited April 2009
    Might also want to have a look at rays.

    Seguer on
Sign In or Register to comment.