I am taking a great Dark Basic tutorial, and turning it into Dark GDK as I go along, as I am unwilling to pay $60 for an inferior compiler(DB). This has gone fine, until I needed it to display the ammo on the screen. In the tutorial, I needed to convert an integer to a string. I new to give: int ammo=5000; instead of: ammo#=5000. However, to display it on the screen, I needed to convert it to a string. This totally lost me, because I could tell right off the bat that the code they used wouldn't work for me, because it had many Dark Basic principles.
Here is the code they used:
"Enemy Health: "+str$(EnemyHP#)
Here is what I have so far in Dark GDK:
/*My first FPS
Created by arithehun
Date Started:4/24/10
*/
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 0 );
dbHideMouse();
dbPrint("Hi");
//Object Sphere. Decimals in oder
dbMakeObjectSphere(1,50);
dbColorObject(1,RGB(000,225,000));
dbMakeObjectSphere(2,50);
dbColorObject(2,RGB(000,000,225));
dbPositionObject(2,130,0,0);
//Object wall. Decimals in order
dbMakeObjectBox(3,100,100,5);
dbColorObject(3,RGB(225,000,000));
dbPositionObject(3,0,0,150);
//Shooting Limb
dbMakeObjectSphere(9999,30);
dbMakeMeshFromObject(1,9999);
dbDeleteObject(9999);
dbAddLimb(1,1,1);
dbOffsetLimb(1,1,0,0,500);
dbDeleteMesh(1);
//Position Camera
dbPositionCamera(0,500,-500);
dbPointCamera(0,0,0);
int enemyhp=5000;
int ammo=1000;
int maxammo=1000;
// our main loop
while ( LoopGDK ( ) )
{
if(dbUpKey()==1){
dbMoveObject(1,0.5f);
}
if(dbDownKey()==1){
dbMoveObject(1,-0.5f);
}
if(dbRightKey()==1){
dbMoveObjectRight(1,0.7f);
}
if(dbLeftKey()==1){
dbMoveObjectLeft(1,0.7f);
}
//Shooting
if(dbMouseClick()==1){
if(ammo>0){
int ammo();-1;
}
if(dbObjectExist(2)){
if(ammo>0){
if(dbIntersectObject(2, dbLimbPositionX(1,1), dbLimbPositionY(1,1), dbLimbPositionZ(1,1), dbObjectPositionX(1),dbObjectPositionY(1), dbObjectPositionZ(1))>0){
int enemyhp();-1;
}
}
}
}
if(enemyhp=0){
if(dbObjectExist(2)==1){
dbDeleteObject(2);
}
}
if(dbObjectExist(2)==1)
{
dbText ( 0, 0, "Ammo:");
}
dbSync ( );
}
// return back to windows
return;
}
And here is the finished project in Dark Basic:
`Created by <your name>
`Date Started: <current date>
`Setup Client Options
SYNC ON:SYNC RATE 0:HIDE MOUSE
`Create all media needed
` Our character
MAKE OBJECT SPHERE 1,50:COLOR OBJECT 1,RGB(000,255,000):POSITION OBJECT 1,0,0,-400
` An enemy
MAKE OBJECT SPHERE 2,50:COLOR OBJECT 2,RGB(255,000,000):POSITION OBJECT 2,130,0,0
` A large wall
MAKE OBJECT BOX 3 ,500,400,10:POSITION OBJECT 3,0,0,150
` An ammo crate
MAKE OBJECT BOX 4,15,20,50:COLOR OBJECT 4,RGB(000,255,255):POSITION OBJECT 4,-40,0,0
` Some ground to walk on
MAKE OBJECT PLAIN 5,1000,1000:XROTATE OBJECT 5,-90
`Make sure all the objects are on ground level
FOR Object = 1 TO 4
POSITION OBJECT Object, OBJECT POSITION X(Object), OBJECT SIZE Y(Object)/2,OBJECT POSITION Z(Object)
NEXT Object
`Add limb for intersection checks
MAKE OBJECT SPHERE 9999,10
MAKE MESH FROM OBJECT 1,9999
DELETE OBJECT 9999
`Bullet Intersection Limb
ADD LIMB 1,1,1
OFFSET LIMB 1,1,0,0,500
HIDE LIMB 1,1
`Front Intersection Limb
ADD LIMB 1,2,1
OFFSET LIMB 1,2,0,0,OBJECT SIZE Z(1)/2
HIDE LIMB 1,2
`Back Intersection Limb
ADD LIMB 1,3,1
OFFSET LIMB 1,3,0,0,-OBJECT SIZE Z(1)/2
HIDE LIMB 1,3
`Right Intersection Limb
ADD LIMB 1,4,1
OFFSET LIMB 1,4,OBJECT SIZE X(1)/2,0,0
HIDE LIMB 1,4
`Left Intersection Limb
ADD LIMB 1,5,1
OFFSET LIMB 1,5, -OBJECT SIZE X(1)/2,0,0
HIDE LIMB 1,5
`Define the main variables needed
EnemyHP=5000` Enemy's Health
Ammo=1000` Starting Ammo
MaxAmmo=1000` Maximum amount of Ammo
Clips=3` Starting Clips
MaxClips=3` Maximum amount of Clips
Jumping=0
ScreenWidth#=SCREEN WIDTH()
ScreenHeight#=SCREEN HEIGHT()
`Start main DO/LOOP
DO
`Screen FPS
FPS=SCREEN FPS()
TEXT 0,0,"FPS: "+STR$(FPS)
`Movement Controls
IF KEYSTATE(17)=1
XAngle#=OBJECT ANGLE X(1)
XROTATE OBJECT 1,0
MOVE OBJECT 1,.5
XROTATE OBJECT 1,XAngle#
ENDIF
IF KEYSTATE(31)=1
XAngle#=OBJECT ANGLE X(1)
XROTATE OBJECT 1,0
MOVE OBJECT 1,-.5
XROTATE OBJECT 1,XAngle#
ENDIF
IF KEYSTATE(30)=1 THEN MOVE OBJECT LEFT 1,.3
IF KEYSTATE(32)=1 THEN MOVE OBJECT RIGHT 1,.3
`Define variables for lag reduction
X#=OBJECT POSITION X(1)
Y#=OBJECT POSITION Y(1)
Z#=OBJECT POSITION Z(1)
`Camera Positioning
POSITION CAMERA X#,Y#,Z#
`Space key Controls
IF SPACEKEY()=1 AND Jumping=0 THEN Jump=1
`JUMP Variable Definition
IF Jump=1
Jump_Speed#=.5
Jumping=1
Jump=0
ENDIF
`Jumping
IF Jumping=1
DEC Jump_Speed#,.001
POSITION OBJECT 1,X#,Y#+Jump_Speed#, Z#
ENDIF
`Mouse Camera Movement
Camy#=Camy#+MOUSEMOVEX()*.1
Camx#=Camx#+MOUSEMOVEY()*.1
IF Camx#>90 AND Camx#<135 THEN Camx#=90
IF Camx#>270 AND Camx#<225 THEN Camx#=90
YROTATE CAMERA Camy#
XROTATE CAMERA Camx#
YROTATE OBJECT 1,Camy#
XROTATE OBJECT 1,Camx#
`Mouseclick Shooting
IF KEYSTATE(19)=0 AND MOUSECLICK()=1
IF Ammo>0 THEN DEC Ammo,1
IF OBJECT EXIST(2)=1
IF Ammo>0 AND INTERSECT OBJECT (2, LIMB POSITION X(1,1), LIMB POSITION Y(1,1), LIMB POSITION Z(1,1), X#,Y#,Z#)>0 THEN DEC EnemyHP,1
ENDIF
ENDIF
`Check if the enemy should die, if so delete it
IF EnemyHP=0 AND OBJECT EXIST(2)=1 THEN DELETE OBJECT 2
`Reloading (press R)
IF MOUSECLICK()=0 AND KEYSTATE(19)=1 AND Ammo<MaxAmmo AND Clips>0
Reload=1
ENDIF
`Reloading Part 2 (delay)
IF Reload=1 THEN INC Time#,.001
IF Time#>=1 THEN Ammo=MaxAmmo:DEC Clips,1:Time#=0:Reload=0
`Ammo Crate code (obtain ammo from ground)
IF OBJECT EXIST(4)=1
IF Ammo<MaxAmmo AND INTERSECT OBJECT (4, X#,Y#-50,Z#, X#,Y#,Z#)>0
INC Clips,(MaxClips-Clips)
INC Ammo,(MaxAmmo-Ammo)
DELETE OBJECT 4
ENDIF
ENDIF
`Display text above enemy and crate object
IF OBJECT EXIST(2)=1 THEN CENTER TEXT OBJECT SCREEN X(2),OBJECT SCREEN Y(2)-70,"Enemy Health: "+str$(EnemyHP)
IF OBJECT EXIST(4)=1 THEN CENTER TEXT OBJECT SCREEN X(4),OBJECT SCREEN Y(4)-20,"Ammo Crate"
`Display our Ammo and Clips on-screen
TEXT 0,ScreenHeight#-50,"Ammo: "+str$(Ammo)
TEXT 0,ScreenHeight#-40,"Clips: "+str$(Clips)
`Show that we're reloading
IF Reload=1 THEN CENTER TEXT ScreenWidth#/2,ScreenHeight#/2,"Reloading..."
`Add a target reticule to the screen
CIRCLE ScreenWidth#/2,ScreenHeight#/2,5
`Check for collision with objects, and handle appropriately
`Ground Intersection Check
IF INTERSECT OBJECT (5,X#,(Y#-OBJECT SIZE Y(1)/2),Z#,X#,Y#,Z#)>0
Jumping=0
ELSE
IF Jumping=0
Jumping=1: Jump_Speed=-1
ENDIF
ENDIF
`Front Intersection Check
IF INTERSECT OBJECT (3,LIMB POSITION X(1,2),LIMB POSITION Y(1,2),LIMB POSITION Z(1,2),X#,Y#,Z#)
`If intersection infront, move the user backwards
MOVE OBJECT 1,-1
ENDIF
`Back Intersection Check
IF INTERSECT OBJECT (3,LIMB POSITION X(1,3),LIMB POSITION Y(1,3),LIMB POSITION Z(1,3),X#,Y#,Z#)
`If intersection behind, move user forwards
MOVE OBJECT 1,1
ENDIF
`Right Intersection Check
IF INTERSECT OBJECT (3,LIMB POSITION X(1,4),LIMB POSITION Y(1,4),LIMB POSITION Z(1,4),X#,Y#,Z#)
`If intersection to the right, move the user left
MOVE OBJECT LEFT 1,1
ENDIF
`Left Intersection Check
IF INTERSECT OBJECT (3,LIMB POSITION X(1,5),LIMB POSITION Y(1,5),LIMB POSITION Z(1,5),X#,Y#,Z#)
`If intersection to the left, move user right
MOVE OBJECT RIGHT 1,1
ENDIF
`Refresh the screen(SYNC) and call the LOOP function
SYNC
LOOP
Does this help? And please help me! I was really having fun!
And thank you too.
I am new to Dark GDK. However, I love it! It is really easy, fun, and makes perfect sense.