i don't know if that helps, but i have been making RTS on C++ using DarkGDK library, so commands should be similar to DBPro (dbGetTerrainGroundHeight(C++ dark gdk library)= get terrain ground height (inDBPro)) and maybe u find some useful functions.
In code snippet there is full code (which used to work on C++ 2008 express edition, but now i have 2010 so it doesn't work anymore, drop some errors)
(sorry if code is not in code snippet, i try to make this for first time
and there are no tutorials for making posts)
//Headers
#include <windows.h>
#include "DarkGDK.h"
#include <math.h>
#include <windows.h>
#include <stdio.h>
using namespace std;
//Definitions
#define _WIN32_WINNT 0x0500
//Clases/klases
class MyFirstObject { // Class for all objects settings
public:
int
TypeDigit,
Team,
Condition, //(0-not exist, 1-able to all, 2-empty, 3-unable to fight, 4-unable to move,
// 5-able to construct, 6 unable to construct)
CostIron,
CostOil,
CostMinerals,
CostMoney,
Scale,
Image,
MaxFuel,
Fuel,
MaxAmmo,
Ammo;
float
Speed,
Armor,
Damage,
Hp,
ObjectHeight,
Dx, Dz; // Destination coordinates
};
class MyStaticObject { // Class for all objects settings
public:
int
TypeDigit,
Team,
Condition,
CostIron,
CostOil,
CostMinerals,
Scale;
float
Hp,
Armor,
Damage;
};
//Arrays/masyvai
MyFirstObject Object[20]; // Array of Objects with their settings
MyStaticObject StaticObject[20];
int ResourcesMoney[4];
int ResourcesMoneyIncome[4];
int ResourcesIron[4];
int ResourcesIronIncome[4];
int ResourcesMinerals[4];
int ResourcesMineralsIncome[4];
int ResourcesOil[4];
int ResourcesOilIncome[4];
int ResourcesFuel[4];
//Functions/funkcijos
void dbPositionObjectMap (int ID);
void SetMyObject (int ID);
void SetMyStaticObject (int ID);
void DarkGDK ( void );
void MoveMyObject (void);
void LoadMyOwnObject (int TypeDigit);
void ChoseObject(void);
void GameMenuHandler(void);
void LoadMap(void);
void SetGraphic(void);
void LoadSprites(void);
void MoveCamera(void);
void MouseClicks(void);
void LoadSomeObjects(void);
void FixIfOutsideMap(void);
void PointerHandler(void);
void EscapeMenu(void);
void IfCreateGroundUnit (void);
void CreateBuilding (void);
void CreateDefences (void);
void CreateInfantry (void);
void CreateAirUnit (void);
void CreateShip (void);
void IfPushButton1(void);
///Constants/konstantos
const int ObjectsNum = 50;
const int StaticObjectsNum = 50;
const int EffectObjectsNum= 50;
const float MyTerrainScale=4.0;
//Global variables/globalus kintamieji
float MyCameraSpeed= 1.0;
bool Uzimta=true;
bool Exit=false;
int PointerID=ObjectsNum + StaticObjectsNum + EffectObjectsNum;
int ObjectNum=9;
int ActiveID=3;
float MSX=1,MSZ;
float OldObjectPositionX;
float OldObjectPositionY;
float OldObjectPositionZ;
float OldCamAngleY;
float OldCamAngleX;
float CameraAngleY;
float CameraAngleX;
float CameraHeight= 50;
float GameMenuLimit;
float GameMenuLimit1;
float GameMenuLimit2;
int MaxX=479;
int MaxY=639;
float ObjectPositionX2;
float ObjectPositionZ2;
int PixelsX=800;
int PixelsY=600;
int MyOwnDisplayMode=1;
float ClickMinX=MaxX;
float ClickMinY=MaxY;
float ClickMaxX=0;
float ClickMaxY=0;
bool MouseClicking, MouseClicked;
int ActiveButton1=1;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Program Start @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void DarkGDK ( void )
{
/*for (int d=0;d<ObjectsNum;d++)
Object[d].Condition=0;*/
dbHideWindow();
dbMaximizeWindow();
dbDisableEscapeKey ( );
dbSetDir("models\\");
dbSetImageColorKey ( 255, 0, 255 );
dbPrint ( "Please wait loading map..." );
dbSync ( );
LoadSprites();
LoadMap();
dbSync ( );
LoadSomeObjects(); // iskart ikelia keleta objektu
dbLoadObject ( "explode.x", PointerID+1 );
SetMyObject (PointerID+1);
dbScaleObject ( PointerID+1, 5, 20, 5 );
dbLoadObject ( "explode.x", PointerID );
SetMyObject (PointerID);
dbScaleObject ( PointerID, 5, 20, 5 );
//OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO MAIN LOOP START OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
while ( LoopGDK ( ) )
{
MoveCamera();
// find the ground height of the terrain
float fHeight = dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) );
// reposition the camera so it is directly above the ground
dbPositionCamera ( dbCameraPositionX ( ), fHeight + CameraHeight, dbCameraPositionZ ( ) );
PointerHandler();
MouseClicks();
MoveMyObject ();
GameMenuHandler();
//Check if any of objects are outside the map
FixIfOutsideMap();
// update the terrain
dbUpdateTerrain ( );
// update the screen
dbSync ( );
if (dbEscapeKey()) EscapeMenu();
if (Exit) return;
}
//OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO MAIN LOOP END OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Program End @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void dbPositionObjectMap (int ID) // put object on the map. x and z coordinates got through dbObjectPositionX/Z
{ //Y coordinate got through dbGetTerrainGroundHeight
dbPositionObject ( ID, dbObjectPositionX ( ID ),dbGetTerrainGroundHeight ( 1, dbObjectPositionX ( ID ), dbObjectPositionZ ( ID ) )+ Object[ID].ObjectHeight, dbObjectPositionZ ( ID ) );
}
void SetMyObject (int ID) //Object settings
{
Object[ID].Scale=70;
dbSetObjectLight ( ID, 0 );
dbScaleObject ( ID, Object[ID].Scale, Object[ID].Scale, Object[ID].Scale );
dbLoopObject ( ID );
Object[ID].Speed=( -0.25 );
dbSetObjectSpeed(ID,20);
dbPositionObject (ID, ID*20, 20, 60);
Object[ID].Dx=ID*20;
Object[ID].Dz=60;
dbYRotateObject ( ID, 180);
}
void SetMyStaticObject (int ID) //Static Object settings
{
Object[ID].Scale=140;
dbSetObjectLight ( ID, 0 );
dbScaleObject ( ID, Object[ID].Scale, Object[ID].Scale, Object[ID].Scale );
dbLoopObject ( ID );
dbPositionObject (ID, (ID-ObjectsNum)*20, 20, 60);
}
void MoveMyObject (void)
{
float OldObjectY;
int c=3;
for (c;c<ObjectsNum-1;c++)
{
if (Object[c].Dx>dbObjectPositionX(c)+0.1 || Object[c].Dx<dbObjectPositionX(c)-0.1)
{
OldObjectY=dbObjectAngleY ( c );
dbPointObject (c, Object[c].Dx,dbGetTerrainGroundHeight ( 1, dbObjectPositionX ( c ), dbObjectPositionZ ( c ) )+ Object[c].ObjectHeight , Object[c].Dz );
dbYRotateObject(c,dbObjectAngleY ( c )+180);
dbMoveObject ( c , Object[c].Speed );
}
}
}
void LoadMyOwnObject (int TypeDigit)
{
Uzimta=true;
int a=4;
int ID;
while ( a<ObjectsNum&&Uzimta)
{
if (Object[a].Condition==0||Object[a].Condition==NULL)
{
ID=a;
Uzimta=false;
};
a++;
};
if (Uzimta==true)
{
dbPrint("daugiau objektu ikelti negalima");
}
else
switch ( TypeDigit)
{
case 1:{dbLoadObject ( "L-Big 4x4-Move.x" , ID );Object[ID].Speed=-0.2;Object[ID].Scale=70;Object[ID].Image=7;}break;
case 2: {/*dbLoadObject ( "Wiesel.x" , ID );*/}break;
case 3: {/*dbLoadObject ( "M35.x" , ID );*/}break;
case 4: {/*dbLoadObject ( "AAV.x" , ID );*/}break;
case 5: {/*dbLoadObject ( "Bradley.x" , ID );*/}break;
case 6: {dbLoadObject ( "h-tank.x" , ID );Object[ID].Speed=-0.1;Object[ID].Scale=70;Object[ID].Image=5;}break;
case 7: {/*dbLoadObject ( "Avenger.x" , ID );*/}break;
case 8: {/*dbLoadObject ( "Cougar.x" , ID );*/}break;
case 9: {/*dbLoadObject ( "Paladin.x" , ID );*/}break;
case 10: {/*dbLoadObject ( "ITV.x" , ID );*/}break;
case 11: {/*dbLoadObject ( "EFV.x" , ID );*/}break;
case 12: {/*dbLoadObject ( "Gun Truck.x" , ID );*/}break;
case 13: {/*dbLoadObject ( "M88RV.x" , ID );*/}break;
case 14: {/*dbLoadObject ( "NLOS.x" , ID );*/}break;
case 15: {/*dbLoadObject ( "M9ACE.x" , ID );*/}break;
case 16: {/*dbLoadObject ( "M270.x" , ID );*/}break;
case 17: {/*dbLoadObject ( "Counter RAM.x" , ID );*/}break;
case 18: {/*dbLoadObject ( "SWORDS.x" , ID );*/}break;
default: dbPrint ("Object not loaded");
};
dbSetObjectLight ( ID, 0 );
dbScaleObject ( ID, Object[ID].Scale, Object[ID].Scale, Object[ID].Scale);
dbLoopObject ( ID );
dbPositionObject (ID, ID*20, 20, 60);
dbYRotateObject ( ID, 180);
Object[ID].Condition=1;
Object[ID].Dx=ID*20;
Object[ID].Dz=60;
}
void ChoseObject()
{
bool Found=false;
int i=3;
for (i;i<PointerID-1;++i)
{
if ((dbObjectPositionX ( i )>dbObjectPositionX (PointerID+1)-2)&&
(dbObjectPositionX ( i )<dbObjectPositionX (PointerID+1)+2)&&
(dbObjectPositionZ ( i )>dbObjectPositionZ (PointerID+1)-2)&&
(dbObjectPositionZ ( i )<dbObjectPositionZ (PointerID+1)+2))
{
ActiveID=i;
Found=true;
if (ActiveID>ObjectsNum)IfCreateGroundUnit();
if (ActiveID<ObjectsNum){};
}
}
dbSprite(3,50,850,Object[ActiveID].Image);
if (!Found){ ActiveID=NULL; dbHideSprite(3);dbSetSpriteImage(19,13);dbSetSpriteImage(20,9);}
else dbShowSprite(3);
}
void GameMenuHandler(void)
{
};
void LoadMap(void)
{
// switch on sync rate and set to a maximum of 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
// increase the cameras range
dbSetCameraRange ( 1.0f, 30000.0f );
// two textures are going to be used for the terrain, the first
// will be the diffuse part and the second will be used to
// create extra detail on the terrain
dbLoadImage ( "texture.jpg", 1 );
dbLoadImage ( "detail.jpg", 2 );
// function dbSetupTerrain, will perform some internal
// work that allows us to get started
dbSetupTerrain ( );
// now we can get started on making the terrain object
dbMakeObjectTerrain ( 1 );
// here we pass in a heightmap that will be used to create the terrain
dbSetTerrainHeightMap ( 1, "map2.bmp" );
// now we set the scale, this will have the effect of making
// the terrain large on the X and Z axis but quite small on the Y
dbSetTerrainScale ( 1, MyTerrainScale, /*0.03*/ 0.1* MyTerrainScale, MyTerrainScale );
// adjust the lighting for the terrain
dbSetTerrainLight ( 1, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f );
// in this call we're telling the terrain that its diffuse texture
// will come from image 1 and its detail texture will come from
// image 2
dbSetTerrainTexture ( 1, 1, 2 );
// At this point terrain gets created and added into your world
dbBuildTerrain ( 1 );
// with the terrain in place we can now load a skybox
dbLoadObject ( "skybox2.x", 2 );
// we dont need it to respond to light so switch light off
dbSetObjectLight ( 2, 0 );
// make the skybox much larger
dbScaleObject ( 2, 30000, 30000, 30000 );
// position the camera
dbPositionCamera ( 100, 50, 100 );
dbPositionMouse (int (PixelsX/2), int(PixelsY/2));
// adjust texture properties of sky box
dbSetObjectTexture ( 2, 3, 1 );
};
void SetGraphic(void)
{
};
void LoadSprites(void)
{
if (MyOwnDisplayMode==1)
{
dbSetDisplayMode ( 1280 , 1024 , 32 );
PixelsX=1280;
PixelsY=1024;
GameMenuLimit=820;
GameMenuLimit1=300;
GameMenuLimit2=1100;
dbLoadImage ( "GameMenu1280x1024_full.bmp", 3 );
dbSprite (1,0,PixelsY-dbGetImageHeight(3),3);
dbLoadImage ( "GameMap1280x1024.bmp", 4 );
dbSprite (2,PixelsX-dbGetImageWidth(4),0,4);
dbLoadImage ( "ResourceLine1280x1024.bmp", 30 );
dbSprite (37,0,0,30);
dbLoadImage ( "abramtanky.bmp", 5 );
dbLoadImage ( "abramtankg.bmp", 6 );
dbLoadImage ( "hummer.bmp", 7 );
dbLoadImage ( "jetfighter.bmp", 8 );
dbLoadImage ( "factory.bmp", 11 );
dbLoadImage ( "LeftButton1280x1024empty.bmp", 13 );
dbLoadImage ( "LeftButtonBottom1280x1024empty.bmp", 14 );
dbLoadImage ( "RightButton1280x1024empty.bmp", 9 );
dbLoadImage ( "RightButtonBottom1280x1024empty.bmp", 15 );
dbSprite (19,PixelsX-dbGetImageWidth(9)-dbGetImageWidth(13),291,13);
dbSprite (20,PixelsX-dbGetImageWidth(9),291,9);
dbSprite (21,PixelsX-dbGetImageWidth(9)-dbGetImageWidth(13),291+77,13);
dbSprite (22,PixelsX-dbGetImageWidth(9),291+77,9);
dbSprite (23,PixelsX-dbGetImageWidth(9)-dbGetImageWidth(13),291+77*2,13);
dbSprite (24,PixelsX-dbGetImageWidth(9),291+77*2,9);
dbSprite (25,PixelsX-dbGetImageWidth(9)-dbGetImageWidth(13),291+77*3,13);
dbSprite (26,PixelsX-dbGetImageWidth(9),291+77*3,9);
dbSprite (27,PixelsX-dbGetImageWidth(9)-dbGetImageWidth(13),291+77*4,13);
dbSprite (28,PixelsX-dbGetImageWidth(9),291+77*4,9);
dbSprite (29,PixelsX-dbGetImageWidth(9)-dbGetImageWidth(13),291+77*5,13);
dbSprite (30,PixelsX-dbGetImageWidth(9),291+77*5,9);
dbSprite (37,PixelsX-dbGetImageWidth(9)-dbGetImageWidth(13),291+77*6,13);
dbSprite (38,PixelsX-dbGetImageWidth(9),291+77*6,9);
dbSprite (39,PixelsX-dbGetImageWidth(9)-dbGetImageWidth(13),291+77*7,13);
dbSprite (40,PixelsX-dbGetImageWidth(9),291+77*7,9);
dbSprite (41,PixelsX-dbGetImageWidth(9)-dbGetImageWidth(13),291+77*8,14);
dbSprite (42,PixelsX-dbGetImageWidth(9),291+77*8,15);
dbLoadImage ( "AbramsButton1280x1024.bmp", 10 );
dbLoadImage ( "AbramsButton1280x1024_active.bmp", 16 );
dbLoadImage ( "hummerButton1280x1024.bmp", 12 );
dbLoadImage ( "hummerButton1280x1024_active.bmp", 29 );
dbLoadImage ( "Button1_1_1280x1024.bmp", 17 );
dbSprite(31, 1280-192, 248, 17);
dbLoadImage ( "Button1_2_1280x1024.bmp", 18 );
dbSprite(32, 1280-164, 248, 18);
dbLoadImage ( "Button1_3_1280x1024.bmp", 19 );
dbSprite(33, 1280-133, 248, 19);
dbLoadImage ( "Button1_4_1280x1024.bmp", 20 );
dbSprite(34, 1280-102, 248, 20);
dbLoadImage ( "Button1_5_1280x1024.bmp", 21 );
dbSprite(35, 1280-73, 248, 21);
dbLoadImage ( "Button1_6_1280x1024.bmp", 22 );
dbSprite(36, 1280-42, 248, 22);
dbLoadImage ( "Button1_1_1280x1024_active.bmp", 23 );
dbLoadImage ( "Button1_2_1280x1024_active.bmp", 24 );
dbLoadImage ( "Button1_3_1280x1024_active.bmp", 25 );
dbLoadImage ( "Button1_4_1280x1024_active.bmp", 26 );
dbLoadImage ( "Button1_5_1280x1024_active.bmp", 27 );
dbLoadImage ( "Button1_6_1280x1024_active.bmp", 28 );
}
if (MyOwnDisplayMode==2)
{
PixelsX=800;
PixelsY=600;
}
};
void MoveCamera(void)
{
MyCameraSpeed=0.02+ (dbCameraPositionY ( )-dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) ))/15;
// let the user move the camera around with the arrow keys
if ( dbUpKey() )
{
dbMoveCamera ( 0 , MyCameraSpeed );
};
if ( dbDownKey() )
{
dbMoveCamera ( 0 , -MyCameraSpeed );
};
if ( dbLeftKey() )
{
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) -90 );
dbMoveCamera ( 0 , MyCameraSpeed );
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) +90 );
};
if ( dbRightKey() )
{
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) + 90 );
dbMoveCamera ( 0 , MyCameraSpeed );
dbYRotateCamera ( 0 , dbCameraAngleY( 0 ) -90 );
};
CameraHeight+= dbMouseMoveZ()*(dbCameraPositionY ( )-dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) ))/1000;
/*if ( dbKeyState( 57 )== 1 )
{
float OldCamAngleY = dbCameraAngleY ( 0 );
float OldCamAngleX = dbCameraAngleX ( 0 );
CameraAngleY = dbWrapValue ( ( dbCameraAngleY ( 0 ) + dbMouseMoveX ( ) * 0.4f ) );
CameraAngleX = dbWrapValue ( ( dbCameraAngleX ( 0 ) + dbMouseMoveY ( ) * 0.4f ) );
if ( CameraAngleX > 80 && CameraAngleX <180 ) CameraAngleX = 80;
if ( CameraAngleX < 270 && CameraAngleX > 180 ) CameraAngleX = 270;
dbYRotateCamera ( 0 , dbCurveAngle ( CameraAngleY , OldCamAngleY , 6 ) );
dbXRotateCamera ( 0 , dbCurveAngle ( CameraAngleX , OldCamAngleX , 6 ) );
dbPositionCamera ( 0 , dbCameraPositionX ( 0 ) , 40 , dbCameraPositionZ ( 0 ) );
dbSetPointLight ( 0 , dbCameraPositionX ( 0 ) , 80 , dbCameraPositionZ ( 0 ) );
};*/
if (dbCameraPositionX ( )<1)
{dbPositionCamera(0, 1, dbCameraPositionY ( ), dbCameraPositionZ ( ));};
if (dbCameraPositionX ( )>255*MyTerrainScale)
{dbPositionCamera(0, 254*MyTerrainScale, dbCameraPositionY ( ), dbCameraPositionZ ());};
if (dbCameraPositionZ ( )<-50)
{dbPositionCamera(0, dbCameraPositionX ( ), dbCameraPositionY ( ),-50);};
if (dbCameraPositionZ ( )>255*MyTerrainScale-dbCameraPositionY ()*2)
{dbPositionCamera(0, dbCameraPositionX ( ), dbCameraPositionY ( ), 254*MyTerrainScale-dbCameraPositionY ()*2);};
if (dbCameraPositionY ( )<dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) )+5)
{dbPositionCamera(0, dbCameraPositionX ( ), dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) )+5 , dbCameraPositionZ ( 0 ));};
if (dbCameraPositionY ( )>dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) )+100)
{dbPositionCamera(0, dbCameraPositionX ( ), dbGetTerrainGroundHeight ( 1, dbCameraPositionX ( ), dbCameraPositionZ ( ) )+100 , dbCameraPositionZ ( 0 ));};
};
void MouseClicks(void)
{
OldObjectPositionX=dbCameraPositionX();
OldObjectPositionZ=dbCameraPositionZ();
OldObjectPositionY=dbCameraPositionY();
if (dbMouseY()<1024-225&&dbMouseX()<1280-210)
{
//dbHideMouse();
if ( dbMouseClick() == 1 )
{
ChoseObject();
};
if ( dbMouseClick() == 2 )
{
dbPositionObject( PointerID ,dbObjectPositionX (PointerID+1),dbGetTerrainGroundHeight ( 1, dbObjectPositionX (PointerID+1),dbObjectPositionZ (PointerID+1) ) ,dbObjectPositionZ(PointerID+1) );
Object[ActiveID].Dx=dbObjectPositionX(PointerID);
Object[ActiveID].Dz=dbObjectPositionZ(PointerID);
}
}
else
{
IfPushButton1();
if (ActiveButton1=1)
{
IfCreateGroundUnit();
};
//dbShowMouse();
};
dbPositionCamera(OldObjectPositionX,OldObjectPositionY,OldObjectPositionZ);
dbXRotateCamera (30);
};
void LoadSomeObjects(void)
{
OldObjectPositionX=dbCameraPositionX();
OldObjectPositionZ=dbCameraPositionZ();
OldObjectPositionY=dbCameraPositionY();
dbLoadObject ( "build3.3DS", ObjectsNum+1 );
Object[ObjectsNum+1].Condition=1;
Object[ObjectsNum+1].Image=11;
SetMyStaticObject (ObjectsNum+1);
Object[ObjectsNum+1].Team=1;
dbScaleObject ( ObjectsNum+1, 2, 2, 3 );
Object[ObjectsNum+1].Condition=5;
dbLoadObject ( "build3.3DS", ObjectsNum+2 );
Object[ObjectsNum+2].Condition=1;
Object[ObjectsNum+2].Image=11;
SetMyStaticObject (ObjectsNum+2);
Object[ObjectsNum+2].Team=2;
dbScaleObject ( ObjectsNum+2, 3, 2, 2 );
Object[ObjectsNum+2].Condition=5;
Object[ObjectsNum+2].TypeDigit=1;
dbPositionCamera(OldObjectPositionX,OldObjectPositionY,OldObjectPositionZ);
dbXRotateCamera (30);
};
void FixIfOutsideMap(void)
{
int n=PointerID-1;
for (n; n>0;n--)
{
dbPositionObject ( n+2, dbObjectPositionX(n+2),dbGetTerrainGroundHeight ( 1, dbObjectPositionX ( n+2 ), dbObjectPositionZ ( n+2 ) )+ Object[n+2].ObjectHeight, dbObjectPositionZ ( n+2 ) );
if (dbObjectPositionX ( n+2 )<5)dbPositionObject ( n+2, 5,dbGetTerrainGroundHeight ( 1, dbObjectPositionX ( n+2 ), dbObjectPositionZ ( n+2 ) )+ Object[n+2].ObjectHeight, dbObjectPositionZ ( n+2 ) );
if (dbObjectPositionX ( n+2 )>250*MyTerrainScale)dbPositionObject ( n+2, 250*MyTerrainScale,dbGetTerrainGroundHeight ( 1, dbObjectPositionX ( n+2 ), dbObjectPositionZ ( n+2 ) )+ Object[n+2].ObjectHeight, dbObjectPositionZ ( n+2 ) );
if (dbObjectPositionZ ( n+2 )<5)dbPositionObject ( n+2, dbObjectPositionX ( n+2 ),dbGetTerrainGroundHeight ( 1, dbObjectPositionX ( n+2 ), dbObjectPositionZ ( n+2 ) )+ Object[n+2].ObjectHeight, 5 );
if (dbObjectPositionZ ( n+2 )>250*MyTerrainScale)dbPositionObject ( n+2, dbObjectPositionX ( n+2 ),dbGetTerrainGroundHeight ( 1, dbObjectPositionX ( n+2 ), dbObjectPositionZ ( n+2 ) )+ Object[n+2].ObjectHeight, 250*MyTerrainScale );
}
};
void PointerHandler(void)
{
while(dbObjectScreenX(PointerID+1)<dbMouseX()-0.3 && dbObjectPositionX(PointerID+1)<250*MyTerrainScale)
dbMoveObjectLeft(PointerID+1,0.1);
while(dbObjectScreenX(PointerID+1)>dbMouseX()+0.3 && dbObjectPositionX(PointerID+1)>5)
dbMoveObjectRight(PointerID+1,0.1);
while(dbObjectScreenY(PointerID+1)<dbMouseY()-0.3&& dbObjectPositionZ(PointerID+1)>5 )
dbMoveObject(PointerID+1,0.1+(dbObjectPositionZ(PointerID+1)-dbCameraPositionZ())*0.02);
while(dbObjectScreenY(PointerID+1)>dbMouseY()+0.3&& dbObjectPositionZ(PointerID+1)<250*MyTerrainScale )
dbMoveObject(PointerID+1,-0.1-(dbObjectPositionZ(PointerID+1)-dbCameraPositionZ())*0.02);
dbPositionObject( PointerID+1 ,dbObjectPositionX (PointerID+1),dbGetTerrainGroundHeight ( 1, dbObjectPositionX (PointerID+1),dbObjectPositionZ (PointerID+1) ) ,dbObjectPositionZ (PointerID+1) );
};
void EscapeMenu(void)
{
if (dbKeyState(28)==1) Exit=true;
};
void IfPushButton1(void)
{
if (dbMouseClick()==1 && dbMouseY()<274 && dbMouseY()>248 )
{
if (dbMouseX()>1280-197 && dbMouseX()<1280-170 )
{
dbSetSpriteImage(31,23);
dbSetSpriteImage(32,18);
dbSetSpriteImage(33,19);
dbSetSpriteImage(34,20);
dbSetSpriteImage(35,21);
dbSetSpriteImage(36,22);
dbSetSpriteImage(19,13);
dbSetSpriteImage(20,9);
ActiveButton1=1;
}
if (dbMouseX()>1280-170 && dbMouseX()<1280-138 )
{
dbSetSpriteImage(31,17);
dbSetSpriteImage(32,24);
dbSetSpriteImage(33,19);
dbSetSpriteImage(34,20);
dbSetSpriteImage(35,21);
dbSetSpriteImage(36,22);
dbSetSpriteImage(19,13);
dbSetSpriteImage(20,9);
ActiveButton1=2;
}
if (dbMouseX()>1280-138 && dbMouseX()<1280-107)
{
dbSetSpriteImage(31,17);
dbSetSpriteImage(32,18);
dbSetSpriteImage(33,25);
dbSetSpriteImage(34,20);
dbSetSpriteImage(35,21);
dbSetSpriteImage(36,22);
dbSetSpriteImage(19,13);
dbSetSpriteImage(20,9);
ActiveButton1=3;
}
if (dbMouseX()>1280-107 && dbMouseX()<1280-78)
{
dbSetSpriteImage(31,17);
dbSetSpriteImage(32,18);
dbSetSpriteImage(33,19);
dbSetSpriteImage(34,26);
dbSetSpriteImage(35,21);
dbSetSpriteImage(36,22);
dbSetSpriteImage(19,12);
dbSetSpriteImage(20,10);
ActiveButton1=4;
}
if (dbMouseX()>1280-78 && dbMouseX()<1280-43)
{
dbSetSpriteImage(31,17);
dbSetSpriteImage(32,18);
dbSetSpriteImage(33,19);
dbSetSpriteImage(34,20);
dbSetSpriteImage(35,27);
dbSetSpriteImage(36,22);
dbSetSpriteImage(19,13);
dbSetSpriteImage(20,9);
ActiveButton1=5;
}
if (dbMouseX()>1280-43 && dbMouseX()<1280-12)
{
dbSetSpriteImage(31,17);
dbSetSpriteImage(32,18);
dbSetSpriteImage(33,19);
dbSetSpriteImage(34,20);
dbSetSpriteImage(35,21);
dbSetSpriteImage(36,28);
dbSetSpriteImage(19,13);
dbSetSpriteImage(20,9);
ActiveButton1=6;
}
}
}
void CreateBuildings(void)
{
};
void CreateDefences (void)
{};
void CreateInfantry (void)
{};
void IfCreateGroundUnit (void)
{
/*for (int a=0;a<StaticObjectsNum;a++)
{
if(Object[ObjectsNum+a])
if (AbleToBuild)
{*/
dbSetSpriteImage(19,12);
dbSetSpriteImage(20,10);
if ( dbMouseX()>1280-210 && dbMouseY()>310 && dbMouseY()<900)
{
if (dbMouseY()<310+84&&dbMouseX()<1280-104)
{
dbSetSpriteImage(19,29);
dbSetSpriteImage(20,10);
if (dbMouseClick()==1)
{
while(dbMouseClick()==1)
{};
dbPrint("LoadObject Hummer");
LoadMyOwnObject(1);
}
}
else if(dbMouseY()<310+84&&dbMouseX()>1280-104)
{
dbSetSpriteImage(19,12);
dbSetSpriteImage(20,16);
if (dbMouseClick()==1)
{
while(dbMouseClick()==1)
{};
dbPrint("LoadObject tank");
LoadMyOwnObject(6);
}
}
//};
};
};
void CreateAirUnit (void)
{};
void CreateShip (void)
{};
I used sprites for buttons:
1)loaded some sprites as buttons and maked "ActiveButton" variable which can contain number of button i have.
2)if mouse pointer is on the sprite(sprite x,y is 1 coordinate and (x+-width of sprite), (y+-height of sprite) is another), i change sprite picture so button looks like pressed
3)if mouse is clicked, i check if pointer is in fields where are buttons or whether there is 3d graphics: maked variables where are button fields boundaries (egzample: if (mouse y is less than 200 pixels)then run function which checks over which button (sprite)mouse is):
void IfPushButton1(void)
{
if (dbMouseClick()==1 && dbMouseY()<274 && dbMouseY()>248 )
{
if (dbMouseX()>1280-197 && dbMouseX()<1280-170 )
{
dbSetSpriteImage(31,23);
dbSetSpriteImage(32,18);
dbSetSpriteImage(33,19);
dbSetSpriteImage(34,20);
dbSetSpriteImage(35,21);
dbSetSpriteImage(36,22);
dbSetSpriteImage(19,13);
dbSetSpriteImage(20,9);
ActiveButton1=1;
}
if (dbMouseX()>1280-170 && dbMouseX()<1280-138 )
{
dbSetSpriteImage(31,17);
dbSetSpriteImage(32,24);
dbSetSpriteImage(33,19);
dbSetSpriteImage(34,20);
dbSetSpriteImage(35,21);
dbSetSpriteImage(36,22);
dbSetSpriteImage(19,13);
dbSetSpriteImage(20,9);
ActiveButton1=2;
}
if (dbMouseX()>1280-138 && dbMouseX()<1280-107)
{
dbSetSpriteImage(31,17);
dbSetSpriteImage(32,18);
dbSetSpriteImage(33,25);
dbSetSpriteImage(34,20);
dbSetSpriteImage(35,21);
dbSetSpriteImage(36,22);
dbSetSpriteImage(19,13);
dbSetSpriteImage(20,9);
ActiveButton1=3;
}
if (dbMouseX()>1280-107 && dbMouseX()<1280-78)
{
dbSetSpriteImage(31,17);
dbSetSpriteImage(32,18);
dbSetSpriteImage(33,19);
dbSetSpriteImage(34,26);
dbSetSpriteImage(35,21);
dbSetSpriteImage(36,22);
dbSetSpriteImage(19,12);
dbSetSpriteImage(20,10);
ActiveButton1=4;
}
if (dbMouseX()>1280-78 && dbMouseX()<1280-43)
{
dbSetSpriteImage(31,17);
dbSetSpriteImage(32,18);
dbSetSpriteImage(33,19);
dbSetSpriteImage(34,20);
dbSetSpriteImage(35,27);
dbSetSpriteImage(36,22);
dbSetSpriteImage(19,13);
dbSetSpriteImage(20,9);
ActiveButton1=5;
}
if (dbMouseX()>1280-43 && dbMouseX()<1280-12)
{
dbSetSpriteImage(31,17);
dbSetSpriteImage(32,18);
dbSetSpriteImage(33,19);
dbSetSpriteImage(34,20);
dbSetSpriteImage(35,21);
dbSetSpriteImage(36,28);
dbSetSpriteImage(19,13);
dbSetSpriteImage(20,9);
ActiveButton1=6;
}
}
}
as i remember this function used to show 1 of few buttons pushed- was kind a building mode to show menu of chosable objects to make eg. if pushed 1st button u can chose to build vehicles, if another- ships and etc.
4) now u can insert your functions to place buildings, use special attacks on enemies, repair friendly units or whatever program should do when buttons are pushed
i added .exe file to download and see what this code can do including textures and objects
and sorry if it is not clear enough what code do- when programed it, didnt knew someone else will read it
so didn't add too much of comments and some words are in lithuanian language...
PS there is a good tutorial to make menus and buttons http://forum.thegamecreators.com/?m=forum_view&t=106004&b=10&p=0