Team XTC Games

RTS Tutorial


Navigate
News
About
Links
Games
3DBubbleBobble
Dark Konflict
Hotcars
3D Draughts
Pong
Tools
3DObjectViewer
DBSoundCreator
Auto Clicker
Check IP
DBPro
Tutorials
Plugins

RTS Tutorial

<< RTS Tutorial - Chapter 1 - Page 1

Exploring the new rts world

Ok so we have a matrix that our units can move around on but let's work on some user control. The most basic control an RTS player has is exploring the terrain by moving the mouse close to the edges of the screen. So let's get that going next.

rem setup sync rate
sync rate 60
sync on

rem make a matrix for the ground
mapsize=1024
make matrix 1,mapsize,mapsize,16,16
load image "images\bg.bmp",1
prepare matrix texture 1,1,4,4

rem color background black
color backdrop 0

rem setup camera
xrotate camera 60
scrollspeed=5
camx#=512
camz#=512

do

rem player camera controls
if mousex()>screen width()-10 then inc camx#,scrollspeed
if mousex()<10 then dec camx#,scrollspeed
if mousey()<10 then inc camz#,scrollspeed
if mousey()>screen height()-10 then dec camz#,scrollspeed

rem position camera
position camera camx#,200,camz#

sync

loop

xrotate camera 60
scrollspeed=5
camx#=512
camz#=512

First we rotate the camera 60 degrees on the x axis. This will point it down towards the ground and will stay fixed for the entire game. The scrollspeed variable is how fast we want to scroll the view. Change to lower value for a slower scroll or a higher value for a faster scroll. The camx# and camz# variables will hold the x and y positions of the camera. Using float variables will give us smooth and precise movement for our camera. We'll set both of these variables to 512 so our camera starts in the centre of our map. Now we need to check for when the mouse is close to the edge of the screen and move our camera and thus our view.

if mousex()>screen width()-10 then inc camx#,scrollspeed
if mousex()<10 then dec camx#,scrollspeed
if mousey()<10 then inc camz#,scrollspeed
if mousey()>screen height()-10 then dec camz#,scrollspeed

This code will check if the mouses position is within 10 pixels from the four edges of the screen and will change the camera's position by the scrollspeed value.

Great we can now look around our map by moving the mouse close to the screens edge. If you haven't already compile the code and take it for a quick spin. You can play around with the scrollspeed value to try different speeds but a value of 5 should be a nice speed for our RTS game.

It looks like we can move the view off our map though. We better put in some limitations to keep it in the playing area. After all we don't want the player moving the camera miles off the map and getting lost. Change the following lines like so.

rem player camera controls
if camx#<mapsize-120 and mousex()>screen width()-10 then inc camx#,scrollspeed
if camx#>120 and mousex()<10 then dec camx#,scrollspeed
if camz#<mapsize-200 and mousey()<10 then inc camz#,scrollspeed
if camz#>-20 and mousey()>screen height()-10 then dec camz#,scrollspeed

This will keep our player within the playing area limits. Run the code and move to the edges of the map to see what happens.

Well this is the end of chapter one, I'll upload the next chapter as soon as I have it ready.


Copyright 2005 - 2007 Team XTC Games
Web Design Ireland