Here, i'll post my 3 files :S (i've been working very hard day and night now for about a week on this(trying to quickly push into beta stages(nowhere near there yet(
))))
Main.cpp:
#include <DarkGDK.h>
#include <MikeNet.h>
#include <time.h>
#include <SC_Collision.h>
#include "Variables.h"
#include "Functions.h"
void DarkGDK ( void )
{
dbInk( 2, 2 );
SC_Start ( );
Setup_Game ( );
Setup_Player ( );
Net_Connect ( );
while ( LoopGDK ( ) )
{
seconds = time (0);
Net_Messages ( );
Net_Send ( );
Camera_Control ( );
Player_Control ( );
Screen_Print();
moveObject ( 3, 0 );
dbSync ( );
dbWait ( 1 );
}
for ( int i = 1; i < 1000; i++ )
{
dbDeleteObject ( i );
}
mnFinish ( -1 );
mnDeletePacket ( RecvPacket );
mnDeletePacket ( SendPacket );
return;
}
Functions.h:
void Handle_Collisions();
void Net_Connect()
{
int UdpRecvSize = 1024;
int TcpRecvSize = 1024;
RecvPacket = mnCreatePacket();
SendPacket = mnCreatePacket();
mnSetMemorySize(SendPacket,1024);
mnStart( 1, 0 );
int iConnect = mnConnect( 0, "127.0.0.1", 1337, "127.0.0.1", 1337, 10, true );
if ( iConnect == 1 )
{
char stuff6 [ 256 ] = "Connected!";
MaximumClients = mnGetMaxClients(0);
MaximumOperations = mnGetMaxOperations(0);
}
if ( iConnect == 0 )
{
char stuff6 [ 256 ] = "Timed Out!";
}
if ( iConnect == -1 )
{
char stuff6 [ 256 ] = "Error!";
}
}
void Net_Messages ()
{
int iTcpPackets = mnRecvTCP(0,RecvPacket,NULL);
if(iTcpPackets > 0)
{
int Operation = mnGetInt(RecvPacket);
int Player = mnGetInt(RecvPacket);
if(Operation == OP_NEWPLAYER)
{
if(dbObjectExist(Player) == 0)
{
dbMakeObjectCube(Player,50);
}
}
if(Operation == OP_LEFTPLAYER)
{
if(dbObjectExist(Player) == 1)
{
dbDeleteObject(Player);
}
}
}
for(int Player = 1;Player<=MaximumClients;Player++)
{
for(int Operation = 0;Operation<MaximumOperations;Operation++)
{
int UdpPackets = mnRecvUDP(0,RecvPacket,Player,Operation);
if(dbObjectExist(Player) == 1)
{
if(UdpPackets == 1)
{
float PosX = mnGetFloat(RecvPacket);
float PosY = mnGetFloat(RecvPacket);
float PosZ = mnGetFloat(RecvPacket);
float RotX = mnGetFloat(RecvPacket);
float RotY = mnGetFloat(RecvPacket);
float RotZ = mnGetFloat(RecvPacket);
dbPositionObject(Player,PosX,PosY,PosZ);
dbRotateObject(Player,RotX,RotY,RotZ);
}
}
}
}
}
void Net_Send ()
{
mnAddInt(SendPacket,OP_POSITIONPLAYER);
mnAddFloat(SendPacket,dbCameraPositionX());
mnAddFloat(SendPacket,dbCameraPositionY());
mnAddFloat(SendPacket,dbCameraPositionZ());
mnAddFloat(SendPacket,dbCameraAngleX());
mnAddFloat(SendPacket,dbCameraAngleY());
mnAddFloat(SendPacket,dbCameraAngleZ());
// Send packet
mnSendUDP(0,SendPacket,NULL,false,true);
}
void Setup_Game()
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbColorBackdrop ( 0 );
dbBackdropOff ( );
dbSetCameraRange ( 0.5f, 30000 );
dbSetDisplayMode ( 800, 600, 32 );
SetCurrentDirectory ( "media" );
dbLoadObject ( "Square.x", 1 );
SC_SetupObject ( 1, 1, 0 );
//dbScaleObject ( 1, 100, 100, 100 );
dbPositionObject ( 1, 0, 0, 0 );
dbSetObjectLight ( 1, 0 );
//SC_UpdateObject ( 1 );
}
void Setup_Player()
{
dbLoadObject ( "H-GI-Idle.x", 3 );
SC_SetupObject ( 3, 0, 0 );
dbPositionObject ( 3, 0, 10, 0 );
//SC_SetObjectCollisionOn ( 3 );
dbSetObjectSpeed ( 3, 30 );
dbLoopObject ( 3 );
dbMakeObjectSphere ( 4, 1 );
dbScaleObject ( 4, .001, .001, .001 );
dbPositionCamera ( dbObjectPositionX(4), dbObjectPositionY(4), dbObjectPositionZ(4) );
dbPositionObject ( 4, dbObjectPositionX(3), dbObjectPositionY(3) + 500, dbObjectPositionZ(3) );
//SC_UpdateObject ( 3 );
player[0] = 3;
player[1] = 100;
player[2] = 15;
player[3] = 20;
player[4] = 1;
player[5] = 0;
}
void Camera_Control()
{
float beforeclick1 = dbMouseMoveX();
float beforeclick2 = dbMouseMoveY();
if ( dbMouseClick() == 2 )
{
dbHideMouse();
dbXRotateObject ( 4, dbObjectAngleX(4) - (dbMouseMoveY() - beforeclick2)/4.0f );
dbYRotateObject ( 3, dbObjectAngleY(3) - (dbMouseMoveX() - beforeclick1)/4.0f );
}
if ( dbMouseClick() != 2 )
{
dbShowMouse();
}
dbPositionCamera ( dbObjectPositionX(4), dbObjectPositionY(4), dbObjectPositionZ(4) );
dbPositionObject ( 4, dbObjectPositionX(3), dbObjectPositionY(3) + 2, dbObjectPositionZ(3) );
dbMoveCamera ( -5 );
dbRotateCamera ( dbObjectAngleX(4), dbObjectAngleY(3) + 180, dbObjectAngleZ(4) );
}
void Create_NPC ( char model[32], int health, int level, float xpos, float ypos, float zpos, float rotx, float roty, float rotz )
{
int ournum = npcnum;
int ourmodel = npcmodel;
npcs[ournum][0] = ourmodel;
npcs[ournum][1] = health;
npcs[ournum][2] = xpos;
npcs[ournum][3] = ypos;
npcs[ournum][4] = zpos;
npcs[ournum][5] = level;
dbLoadObject ( model, ourmodel );
dbSetObjectSpeed ( ourmodel, 30 );
dbLoopObject ( ourmodel );
dbPositionObject( ourmodel, xpos, ypos, zpos );
dbRotateObject( ourmodel, rotx, roty, rotz );
SC_SetupObject ( ourmodel, 0, 0 );
npcmodel++;
npcnum++;
}
void moveObject( int objnum, int mtype )
{
float oldx = dbObjectPositionX(objnum);
float oldy = dbObjectPositionY(objnum);
float oldz = dbObjectPositionZ(objnum);
float angy = dbObjectAngleY(objnum);
vx = 0;
vz = 0;
if ( ground == 0 )
{
vy = vy + (gravity * 10);
}
if (mtype == 0 ) { vx = 0; vz = 0; }
if (mtype == 1 ) { vx = vx - dbCos(angy)/7; vz = vz + dbSin(angy)/7; }
if (mtype == 2 ) { vx = vx + dbCos(angy)/7; vz = vz - dbSin(angy)/7; }
if (mtype == 3 ) { vx = vx + dbSin(angy)/7; vz = vz + dbCos(angy)/7; }
if (mtype == 4 ) { vx = vx - dbSin(angy)/7; vz = vz - dbCos(angy)/7; }
float x = oldx + vx;
float y = oldy + vy;
float z = oldz + vz;
int collide = SC_SphereCastGroup( 1, oldx,oldy,oldz, oldx,oldy+vy,oldz, radius,0 );
if ( collide > 0 )
{
ground = 1;
vy = 0;
}
else
{
ground = 0;
}
collide = SC_SphereSlideGroup( 1, oldx,oldy,oldz, x,oldy,z, radius,0 );
if ( collide > 0 )
{
x = SC_GetCollisionSlideX();
oldy = SC_GetCollisionSlideY();
z = SC_GetCollisionSlideZ();
vx = 0;
vz = 0;
vy = 0;
ground = 1;
}
else
{
ground = 0;
}
dbPositionObject( objnum,x,oldy + vy,z );
SC_UpdateObject( objnum );
}
void Player_Control()
{
char stuff19 [ 256 ] = "Object ID = ";
if ( dbSpaceKey() == 1 )
{
moveObject( 3, 5 );
}
if ( dbKeyState(17) )
{
moveObject( 3, 4 );
}
if ( dbKeyState(31) )
{
moveObject( 3, 3 );
}
if ( dbMouseClick() == 2 )
{
if (dbKeyState(30))
{
moveObject( 3, 2 );
}
if (dbKeyState(32))
{
moveObject( 3, 1 );
}
}
if ( dbMouseClick() != 2 )
{
if (dbKeyState(30))
{
dbRotateObject( 3, 0, dbObjectAngleY(3) - 3, 0);
}
if (dbKeyState(32))
{
dbRotateObject( 3, 0, dbObjectAngleY(3) + 3, 0);
}
}
if ( dbMouseClick() == 1 )
{
int selobj = dbPickObject(dbMouseX(),dbMouseY(),1,1000);
i = 0;
strcat ( stuff19, dbStr ( selobj ) );
dbText ( 0, 50, stuff19 );
player[10] = 0;
player[11] = 0;
player[12] = 0;
player[13] = 0;
player[14] = 0;
if ( selobj >= 500 && selobj <= 1000 )
{
player[10] = npcs[selobj-500][5];
player[11] = npcs[selobj-500][1];
player[12] = npcs[selobj-500][2];
player[13] = npcs[selobj-500][3];
player[14] = npcs[selobj-500][4];
}
if ( dbKeyState(17) )
{
//time_t seconds;
//seconds = time (0);
if ( seconds >= timenow + 3 )
{
timenow = seconds;
Create_NPC ( "tiger.x", 100, 1, dbObjectPositionX(3), dbObjectPositionY(3)+0.70, dbObjectPositionZ(3), dbObjectAngleX(3), dbObjectAngleY(3), dbObjectAngleZ(3) );
}
}
if ( dbKeyState(31) )
{
//time_t seconds;
//seconds = time (0);
if ( seconds >= timenow + 3 )
{
timenow = seconds;
Create_NPC ( "M-Raptor-Idle.x", 500, 50, dbObjectPositionX(3), dbObjectPositionY(3), dbObjectPositionZ(3), dbObjectAngleX(3), dbObjectAngleY(3), dbObjectAngleZ(3) );
}
}
if (dbKeyState(30))
{
//time_t seconds;
//seconds = time (0);
if ( seconds >= timenow + 3 )
{
timenow = seconds;
Create_NPC ( "H-Zombie-Idle.x", 1000, 100, dbObjectPositionX(3), dbObjectPositionY(3), dbObjectPositionZ(3), dbObjectAngleX(3), dbObjectAngleY(3), dbObjectAngleZ(3) );
}
}
}
}
//void Check_Connection()
//{
// if ( seconds >= timenow2 )
// {
// timenow2 = seconds + 30;
// if ( !NetConnected() )
// {
// char ctxt [256] = "Not Connected!";
// }
// char ctxt [256] = "Connected!";
// }
// dbText ( 0, 200, ctxt );
//}
void Screen_Print()
{
char stuff3 [ 256 ] = "Player X Pos = ";
char stuff4 [ 256 ] = "Player Y Pos = ";
char stuff5 [ 256 ] = "Player Z Pos = ";
char stuff6 [ 256 ];
char stuff21 [ 256 ] = "NPC Level = ";
char stuff20 [ 256 ] = "NPC Health = ";
char stuff22 [ 256 ] = "NPC X = ";
char stuff23 [ 256 ] = "NPC Y = ";
char stuff24 [ 256 ] = "NPC Z = ";
char plyhp [ 256 ] = "Your Health = ";
char plyak [ 256 ] = "Your Attack = ";
char plydf [ 256 ] = "Your Defence = ";
char plylv [ 256 ] = "Your Level = ";
char plystatus [ 256 ] = "Attack Status = ";
strcat ( stuff3, dbStr ( dbObjectPositionX(3) ) );
strcat ( stuff4, dbStr ( dbObjectPositionY(3) ) );
strcat ( stuff5, dbStr ( dbObjectPositionZ(3) ) );
strcat ( stuff21, dbStr ( player[10] ) );
strcat ( stuff20, dbStr ( player[11] ) );
strcat ( stuff22, dbStr ( player[12] ) );
strcat ( stuff23, dbStr ( player[13] ) );
strcat ( stuff24, dbStr ( player[14] ) );
strcat ( plyhp, dbStr ( player[1] ) );
strcat ( plyak, dbStr ( player[2] ) );
strcat ( plydf, dbStr ( player[3] ) );
strcat ( plylv, dbStr ( player[4] ) );
strcat ( plystatus, dbStr ( player[5] ) );
dbText ( 0, 0, stuff3 );
dbText ( 0, 10, stuff4 );
dbText ( 0, 20, stuff5 );
//dbText ( 0, 40, stuff6 );
dbText ( 0, dbScreenHeight()/2, stuff21 );
dbText ( 0, dbScreenHeight()/2+10, stuff20 );
dbText ( 0, dbScreenHeight()/2+20, stuff22 );
dbText ( 0, dbScreenHeight()/2+30, stuff23 );
dbText ( 0, dbScreenHeight()/2+40, stuff24 );
dbText ( dbScreenWidth()-160, 0, plylv );
dbText ( dbScreenWidth()-160, 10, plyhp );
dbText ( dbScreenWidth()-160, 20, plyak );
dbText ( dbScreenWidth()-160, 30, plydf );
dbText ( dbScreenWidth()/2, 0, plystatus );
}
Variables.h:
unsigned short port = 1337;
char buffer[256];
char ctxt[256];
int selobj;
int i;
int npcnum = 0;
int npcmodel = 500;
int timenow = 0;
int timenow2 = 0;
float npcs[100][6];
int player[50];
int curi = 0;
float gravity = -0.008f;
float jpwr = 1;
float slope = 0.5f;
int ground = 0;
int jumptimer = 0;
float oldx,oldy,oldz,vx,vz,vy;
float radius = 0.12f;
time_t seconds;
int dx,dy,dz;
int MaximumClients;
int MaximumOperations;
long long int RecvPacket;
long long int SendPacket;
// Tcp
#define OP_NEWPLAYER 0
#define OP_LEFTPLAYER 1
// Udp
#define OP_POSITIONPLAYER 0
Let me know how i'm doing so far with only a weeks worth of c++ and dark gdk knowledge =D
Edit: Don't I have to purchase DarkNet for the latest version? I searched all up and down that thread for the latest version of MikeNet that I could get.
Edit:Edit: FYI my server program starts with no errors what so ever, and in case you didnt see before, the CubeWorld demo also gives this same error..
I <3 C++ & Dark GDK 4 2 maek mai gamezorz! =D