Ok I just started codeing and im not that fluent just yet. I used to code in GML(game makerv7 language). Which is kinda similare to a point. But I am planning on making a 3d side scroller shooter game and so far i have this code
// Dark GDK - The Game Creators - www.thegamecreators.com
// 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 ( 60 );
dbLoadObject ( "persontest.3ds", 1 ); //object modelorriginal
dbLoadObject ( "terrain1.3ds", 2 );
dbScaleObject (1 ,40,40,40);// scale the size of the //objectoriginal
dbMakeMatrix(10,200,200,10,10); //fake ground for now
dbLoopObject ( 1 ); // animation
dbSetObjectSpeed ( 1, 40 );
// our main loop
while ( LoopGDK ( ) )
{
//Position camera to object position
dbPositionCamera(dbObjectPositionX(1),dbObjectPositionY(1)+15,dbObjectPositionZ(1));
//Rotate Camera to side view
dbRotateCamera(dbObjectAngleX(1),dbObjectAngleY(1)-90,dbObjectAngleZ(1));
//Move camera back to see object
dbMoveCamera(-100);
//Later switch keys so that used wasd and space bar
//up key
//if (dbKeyState(31) == 1)
//{
// dbMoveObject(1, 0.5f);
//dbLoopObject ( int iID, int iStart, int iEnd ); jump animation
//}
//down key
//if (dbDownKey() == 1)
//{
// dbMoveObject(1, -0.5f);
//dbLoopObject ( int iID, int iStart, int iEnd ); play animation of crouching
//}
//"A" key
if (dbKeyState(30) == 1)
{
dbMoveObject (1, -0.5f);
//dbLoopObject ( int iID, int iStart, int iEnd ); play animation of running
}
//"D" key
if (dbKeyState(32) == 1)
{
dbMoveObject(1, 0.5f);
//dbLoopObject ( int iID, int iStart, int iEnd ); play animation of running
}
dbSync ( );
}
// return back to windows
return;
}
which this is the basic loading the 3d model character, and the 3d terrain. With left and right movement and the setting of the camera.
What i need help with is merging this code with that
float gravity = -0.008f;
float oldx,oldy,oldz,vx,vz,vy;
float radius = 0.10f;
void MovePlayer ( int mtype, ModelNumber )//just supply this with a mtype (move type) and model number (use mtype 0 only to check gravity)
{
float oldx = dbObjectPositionX(ModelNumber);
float oldy = dbObjectPositionY(ModelNumber);
float oldz = dbObjectPositionZ(ModelNumber);
float angy = dbObjectAngleY(ModelNumber);
float angx = dbObjectAngleX(ModelNumber);
vx = 0;
vy = 0;
vz = 0;
if (Mode == 1)
{
if (mtype == 0 )
{
vx = 0;
vz = 0;
}
if (mtype == 1 )
{
//vx = vx - dbCos(angy)/7;
//vz = vz + dbSin(angy)/7;
dbMoveObjectLeft( ModelNumber, 0.25f );
}
if (mtype == 2 )
{
//vx = vx + dbCos(angy)/7;
//vz = vz - dbSin(angy)/7;
dbMoveObjectRight( ModelNumber, 0.25f );
}
if (mtype == 3 )
{
//vx = vx + dbSin(angy)/7;
//vz = vz + dbCos(angy)/7;
dbMoveObject( ModelNumber, 0.25f );
}
if (mtype == 4 )
{
//vx = vx - dbSin(angy)/7;
//vz = vz - dbCos(angy)/7;
dbMoveObject( ModelNumber, -0.25f );
}
vy = dbObjectPositionY( 2 );
} else if (Mode == 2)
{
if (mtype == 3 )
{
//vx = vx + dbSin(angy)/7;
//vz = vz + dbCos(angy)/7;
dbMoveObject( ModelNumber, 25 );
}
if (mtype == 4 )
{
//vx = vx - dbSin(angy)/7;
//vz = vz - dbCos(angy)/7;
dbMoveObject( ModelNumber, -250 );
}
vy = dbObjectPositionY( ModelNumber );
}
float x = dbObjectPositionX( ModelNumber );
float y = vy;
float z = dbObjectPositionZ( ModelNumber );
int collide = SC_SphereSlideGroup( 1, oldx, oldy, oldz, x, y, z, radius, 0 );
if ( collide > 0 )
{
dbPositionObject( ModelNumber, SC_GetCollisionSlideX(), SC_GetCollisionSlideY(), SC_GetCollisionSlideZ() );
} else {
dbPositionObject( ModelNumber, x, y, z );
}
}
Which is a simple code that a friend of mine gave me for collisions. But it came with no comments to help me to figure it out. anyone have any clue on this?