The availability of Ultrabook and Win 8 Tablets create a new frontier for PC gaming; one that brings touch and sensors inputs to parity with mouse and keyboard. New game genres are appearing that specifically leverage these input methods. The Real-Time Strategy (RTS) genre is one of the PC stalwarts. Though mouse and keyboard are the most precise input mechanisms available, all of the needed actions can be reasonably modeled by touch. This sample is a small RTS game which shows how touch inputs can be added alongside mouse and keyboard inputs for a full device input experience.
Controlling the sample
The controls summary is presented in the following table
One tap or left mouse button + move | Pan the view |
Hold two taps + move or mouse wheel | Zoom In/Zoom Out |
Hold three taps or right mouse button + move | Select units |
Single tap or left mouse click | Move command |
Double tap or double left mouse click | Attack command |
Click/touch on the minimap | Move the camera to the specified point |
Arrow keys | Pan the view |
Page Up/Page Down | Zoom In / Zoom Out |
The screen can be panned using left mouse button or one-tap touch. Minimap in the upper left corner shows the current camera location, object positions and the current view outline. The minimap also enables the user to quickly move the camera to any location by clicking on it with the left mouse button or one-tap touch. Arrow keys can also be used to pan the view.
The scene can be rendered with different zoom levels: from extreme close-up showing all details of every particular unit to strategic views showing almost all the battle scene.
The view can be zoomed in/out using mouse wheel or two-tap touch. Page Up / Page Down keys can also be used.
The sample enables the user to select one or more units using right mouse button or three-tap touch.
All units within the frame get selected. Selected units are marked with blue selection outline:
Selected units can be given move or attack commands. Move command for one or group of selected units is given by single left mouse button click or single touch on the terrain surface. After the command is given, the units start moving towards the designated point following the terrain surface.
Attack command is given with double left mouse click or double touch on the terrain surface point. After that, the selected units start attacking the point. After each explosion, the terrain at the point is slightly deformed and texture is updated.
Units at the point being attack are damaged. Each damage reduces the unit’s health which is indicated in the health bar rendered above the unit. Eventually the unit will be destroyed and explode creating a big hole in terrain surface.
Current command can be cancelled using the Stop button. All units in the scene can be selected using Select All button.
Some technical details
- WM_TOUCH is handled to respond to touch events
- The sample keeps current input mode (like selection or scrolling) and switches between the modes depending on the user input
- Basic collision detection between units is implemented using uniform grid:
- The whole terrain is subdivided into the grid of equal-size square cells
- Each grid cell supports a list of objects in this cell
- When a unit is moved from one cell to another, the grid is updated accordingly
- To check for a collision, each object’s bounding sphere is tested against all units in the object’s cell and its immediate neighbors
- Each unit is rendered using one of the three levels of detail:
- High-resolution geometric model for close-ups
- Low-resolution geometric model for high point of view
- Single sprite for very high points of view
- The selection of the appropriate LOD is performed using estimated unit screen-space size
- For terrain rendering, the method described in Touch Terrain sample is used