Team XTC Games

RTS Tutorial


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

RTS Tutorial

After many requests from players of my own RTS game Dark Konflict I have decided to finally sit down and write a tutorial to help other people out there make their own real time strategy games. When reading through this tutorial you will see some code boxes. These will help you position your code correctly in your program. The new code will be brighter to show you clearly which code has been added.

OK, so here is what you will need for this tutorial.

  • DarkBASIC Professional
  • RTS Tutorial Pack - Contains the media needed for the tutorial and complete chapter1 source code. This will be updated each chapter until the tutorial is complete.

Chapter 1 - Creating our rts game world

Right let's get stuck in, open up your DB Pro Editor. The first thing I do when creating any game or application is to create my main loop and set up the sync rate.

rem set sync rate
sync rate 60
sync rate on

do

sync
loop

This is the basic code structure in place and you can compile and run this program safely. Now let's get to some fun stuff. That's the great thing with DarkBASIC, the fun stuff comes quickly with only a small bit of coding.

Creating a new rts world

The next thing I usually do when making a game is create the world where everything will take place. So we need to make some ground for our units to move around on. There are a few different ways you could go about creating the ground but I'll use a matrix for this tutorial. The great thing about using a matrix is that it will be easy to create the ground without having to model a terrain in a modeling program or make a height map.

rem set sync rate
sync rate 60
sync rate on

rem make a matrix for the ground
mapsize=1024
make matrix 1,mapsize,mapsize,16,16

do

sync

loop

mapsize=1024
make matrix 1,mapsize,mapsize,16,16

3D LandscapeThis will make a matrix that is 1024x1204 in size and is broken up into a 16x16 grid. You can compile and run the code to see your new matrix in place. The mapsize variable will hold a value for the size of the map so that it's easier to identify in our code. If we wanted to make different map sizes we would certainly need to use a variable or even two for rectangular shaped maps. The 16x16 grid is like a quality setting, we could use 32x32 or 64x64 if we wanted a higher quality terrain but we'll stick with 16x16 for simplicity and speed. This will matter more when we start to add some hills and detail to our matrix.

Ok if you run the program you should now see a matrix as shown in the screenshot.

It doesn't look much like ground yet though so let's apply a texture and we'll change the blue background to black as well like most other RTS games.

rem set sync rate
sync rate 60
sync rate on

rem make a matrix for the ground
mapsize=1024
make matrix 1,mapsize,mapsize,16,16

load image "images\terrain.bmp",1
prepare matrix texture 1,1,4,4

rem color background black
color backdrop 0

do

sync

loop

load image "images\bg.bmp",1
prepare matrix texture 1,1,4,4

This code will load our terrain bitmap image file into image number 1. We then use prepare matrix texture to apply the image to the matrix. Our terrain bitmap contains 16 different tiles that we can use to texture each matrix tile. We have to set this information in prepare matrix texture hence 4,4 so later we can put different texture tiles under our buildings. Note that when you use this command the first tile is automatically applied to your matrix. If you run the program again you should see something closer to what our world should look like.

RTS Tutorial - Chapter 1 - Page 2 >>


Copyright 2005 - 2007 Team XTC Games
Web Design Ireland