Real-Time Strategy Game with Touch Screen

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值