Hello everyone!
I've run into a problem. I'm trying to make a game and I spawn four objects right now. The first three are fine and spawn on XYZ 0,0,0. When I do dbMakeObjectSphere for the forth one, it still creates it, but it shifts my whole Z-axis by 50 points. So if previously the origin would be 0,0,0 now it becomes 0,0,-50. I use a rectangle box for the floor, so I don't know if that might be fixed with an actual Terrain or a World. Any ideas how to hardcode my axis or a way around this?
Code:
Main:
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include "Invader Text.h"
#include "Hero.h"
#include "Main.h"
#include "Hero Bullet.h"
// the main entry point for the application is this function
//void gameSetup(void);
//void moveChar(void);
bool shoot=false;
int mx,my,mz=0;
int mm3dX,mm3dZ=0;
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
gameSetup();
dbLoadImage ( "fire.bmp", 1);
//dbCreateAnimatedSprite ( 1, "animatedsprite.png", 4, 4, 1 );
//dbSprite ( 1, 0, 0, 1 );
dbMakeObjectBox(2,.2,.2,.2);
dbMakeObjectBox(1,100,0,100);
dbMakeObjectSphere(3,1.5);
heroSpawn();
//dbMakeFireParticles(1,1,50,5,5,5,10,10,10);
//dbSetParticleGravity(1,9.8);
dbMakeCamera(1);
dbPositionCamera(1,0,100,100);
//dbXRotateCamera(1,45);
dbPointCamera(1,0,0,0);
dbPositionObject(1,0,-0.3,0.15);
dbPositionObject(3,0,+0.2,0);
//dbPositionObject(4,1,1,1);
dbLoadEffect("DetailMapping.dbs",1,1);
dbSetObjectEffect(1,1);
//dbHideMouse();
dbMakeParticles(1,1,100,20.0f);
dbSetParticleSpeed ( 1, 0.01f );
dbSetParticleGravity ( 1, 2 );
dbPositionParticles(1,0,-53,0);
dbSetParticleLife(1,110);
dbSetParticleFloor(1,1);
// our main loop
while ( LoopGDK ( ) )
{
// update the screen
//MOUSE---
mx=dbMouseX();
my=dbMouseY();
mouseConvert();
//--------
if(dbMouseClick()==2)
{
hBulletSpawn(5); //Causes a bullet to spawn. This is what messes up the Z axis.
}
//hBulletMove();
//InvaderText(200,200,10,"It works!",false,false);
//dbShowParticles(1);
heroMove();
//dbPositionParticleEmissions(1,0,0,0);
dbPositionParticleEmissions ( 1, ( mX ( ) -10 ) / 40.0f * 20, ( 10 - mY ( ) ) / 40.0f * 20, 10 * 20 );
//dbGhostParticlesOn(1,1,3);
//dbSetObjectToObjectOrientation(3,4);
dbPointObject(3,heroX(),0.2,heroZ());
dbMoveObject(3,0.5);
//if(shoot)dbPositionObject(3,dbObjectPositionX(3)+mx,dbObjectPositionY(3),dbObjectPositionZ(3)+mz);
//moveChar();
dbSync ( );
}
// return back to windows
return;
}
void moveChar(void){
//mz=(dbMouseZ());
//dbPositionObject(2,dbMouseX(),dbMouseY(),dbMouseZ());
// dbPositionObject(2,dbObjectPositionX(2),dbObjectPositionY(2)+0.01,dbObjectPositionZ(2));
//dbPlaySprite ( 1, 1, 16, 60 );
//}
}
void gameSetup ( void )
{
// set the display to 1024 x 768 with 32bit depth
dbSetDisplayMode ( 1024 , 768 , 32 );
dbSetWindowPosition((1600-1024)/2,(1200-768)/2);
// turn sync on, so our game waits for the screen to finish drawing before displaying, also handles backbuffer automatically for us
dbSyncOn();
// lets run at a nice 60 frames per second - automatically!
dbSyncRate(60);
// full screen windowed mode
//dbMaximiseWindow();
}
int getRand(int min,int max)
{
return (min + rand()%(max-min)+1); //returns a random value between min and max
}
int mX(){
return mx;
}
int mY(){
return my;
}
void mouseConvert()
{
double pickVector = dbPickObject ( mX (), mY (), 1, 1 ) ;
float xHit = dbGetPickVectorX() - dbCameraPositionX(); //Pick the x and z location on 3d terrain of mouse location
float zHit = dbGetPickVectorZ() - dbCameraPositionZ()*1.67;//-dbCameraPositionY();
mm3dX=xHit;
mm3dZ=zHit;
char* xtext =dbStr((int)xHit);
dbText(150,50,xtext);
dbText(120,50,"mx:");
char* ytext =dbStr((int)zHit);
dbText(150,65,ytext);
dbText(120,65,"mz:");
}
int m3dX(){
return mm3dX;
}
int m3dZ(){
return mm3dZ;
}
Hero Bullet:
#include "DarkGDK.h"
#include "Hero.h"
#include "Main.h"
#include "Hero Bullet.h"
double g_hBulletX=0;
double g_hBulletY=0.1;
double g_hBulletZ=0;
double g_hBulletSpeed=1.0;
bool bmove=false;
double bxx,bzz=0;
int ii=0;
double hBulletX(void)
{
return g_hBulletX;
}
double hBulletZ(void){
return g_hBulletZ;
}
void hBulletSpawn(int i){
ii=i;
dbMakeObjectSphere(ii,4); //Spawns the sphere and throws off the Z axis!
//dbLoadImage("",2);
//dbTextureObject(i,2);
//dbPositionObject(4,g_heroX,g_HeroY,g_HeroZ);
dbPositionObject(ii,0,0.1,0);
dbPositionObject(ii,heroX(),0.1,heroZ());
//double pickVector = dbPickObject ( mX (), mY (), 1, 1 ) ;
//float xxHit = dbGetPickVectorX() - dbCameraPositionX(); //Pick the x and z location on 3d terrain of mouse location
//float zzHit = dbGetPickVectorZ() - dbCameraPositionZ();//*1.67;//-dbCameraPositionY();
//dbPositionObject(4,xHit,0.1,zHit);
bxx=m3dX();
bzz=m3dZ();
}
void hBulletMove(){
g_hBulletX=dbObjectPositionX(ii);
g_hBulletZ=dbObjectPositionZ(ii);
char* xtext =dbStr(static_cast<int>(g_hBulletX));
dbText(150,20,xtext);
char* ytext =dbStr(static_cast<int>(g_hBulletZ));
dbText(150,35,ytext);
dbPointObject(ii,bxx,0.1,bzz);
dbMoveObject(ii,0.5);
//if (dbObjectPositionX(4)>-50 && dbObjectPositionX(4)<50 && dbObjectPositionZ(4)>-50 && dbObjectPositionZ(4)<50)
//if(xx==dbObjectPositionX(ii)&& zz==dbObjectPositionZ(ii))
//move=false;
//else if(move){
// }
//if(bmove==false){
// bxx=xHit;
// bzz=zHit;
//move=true;
//}
}
Thanks