Hmm, first, when posting your code, use the code tags (There's a button at top right when writing your post). It'll preserve any formatting and make your code easier to read and understand. Like so:
void Shoot()
{
dbLoadImage("GunShot.png", 12);
dbMakeObjectBox (11, 7 , 7, 0);
dbPositionObject(11, dbObjectPositionX(1)-2, dbObjectPositionY(1)+8, dbObjectPositionZ(1)+24);
dbTextureObject (11 , 12);
dbSetObjectLight (11 , 0);
dbSetObjectEmissive(11 , 0x00646464);
dbSetObjectAmbience (11 , 0x00FFFFFF);
dbFadeObject(11, 8000);
dbSetObjectTransparency(11 , 1);
dbHideObject(11);
dbSetObjectCollisionOff(11);
dbLockObjectOn(11);
dbLoadSound("gun1.wav", 15);
dbPauseSound(15);
dbSetSoundSpeed(15,5000);
UpdateBullet();
if(bullets > 0)
{
if(dbMouseClick() == 1)
{
if(dbTimer() - ShootingTimer > 160)
{
if (BulletCount >= 30)
{
BulletCount = 0;
}
bullets--;
Bullet();
dbPlaySound(15);
dbShowObject(11);
dbRollObjectLeft(11,(float)(rand() % 360));
dbShowLight(0);
dbPositionLight(0,dbObjectPositionX(11), dbObjectPositionY(11), dbObjectPositionZ(11));
}
}
}
if(bullets < 1)
{
dbText(200,400, "PRESS R TO RELOAD");
}
if (dbKeyState(19) == 1)
{
reload();
}
}
void reload()
{
y = 30 - bullets;
for(int i = 0; i < y; i++)
{
bullets++;
}
}
void Bullet()
{
for (int i = 0; i < 30; i++)
{
BULLET[1] = BulletCount;
dbMakeObjectSphere(BULLET[1]+300,3);
}
BULLET[BulletCount][3] = dbTimer();
BULLET[BulletCount][2] = 1;
BULLET[BulletCount][4] = 1400;
dbPositionObject(BULLET[BulletCount][1]+300, dbCameraPositionX()+5, dbCameraPositionY(), dbCameraPositionZ()+10);
dbXRotateObject(BULLET[BulletCount][1]+300, fCameraAngleX);
dbYRotateObject(BULLET[BulletCount][1]+300, fCameraAngleY);
dbPositionObject(BULLET[BulletCount][0]+300, dbCameraPositionX() + 5, dbCameraPositionY(), dbCameraPositionZ()+10);
dbXRotateObject(BULLET[BulletCount][0]+300, fCameraAngleX);
dbYRotateObject(BULLET[BulletCount][0]+300, fCameraAngleY);
BulletCount++;
}
void UpdateBullet()
{
for (int i = 0; i < 30; i++)
{
if (dbObjectExist(BULLET[1]+300))
{
dbMoveObject(BULLET[0]+300, BulletSpeed);
dbMoveObject(BULLET[1]+300, BulletSpeed);
}
}
}
You've got several problems in the code, the main one being that you are getting mixed up with your object numbers when moving and rotating. You need to decide whether BULLET[BulletCount][0] or BULLET[BulletCount][1] contains your bullet object number
The Reload function is overcomplex and unecessary. You can just say:
bullets = 30;
I'll try and give you a template in psuedo code to help:
/////////////////////////////////////////////////////////////////////
//Initialisation, Executed once at Start Of Program:
EnvironmentSetup //Camera, Fog etc
InitialiseBulletArray //Better using a list, or a vector
MakeMasterBulletObject //Remember the object number you use for this master bullet. The master bullet does not appear in the game.
GameRunning = true
/////////////////////////////////////////////////////////////////////
//Main Game Loop
while( GameRunning == true )
{
CheckPlayerInput
UpdateBullets
UpdateScreen
}
EndProgram(); //Any tidying up or exit messages.
/////////////////////////////////////////////////////////////////////
//Functions called from Main Game Loop
CheckPlayerInput
{
if(Firebutton is pressed)
{
if(Player has ammunition left)
{
Create a New Bullet by cloning or instancing the MasterBullet Object, ensuring the new bullet has a unique object number
Add the new bullet to the bullet array/list
Position the new bullet at the muzzle of the gun, or wherever the bullet should start from
}
else
{
Automatically reload, Restore ammunition count to maximum
}
}
if(Reload button/key is pressed)
{
Restore ammunition count to maximum
}
if(Quit game button/key is pressed)
{
GameRunning = false;
}
}
UpdateBullets
{
for( each bullet in the bullet array/list )
{
Check if Bullet has hit something, if so remove it from the bullet list and exit this function
Check if Bullet has reached it's maximum distance or life time, if so remove it from the bullet list and exit this function
MoveBulletObject
}
}
It's not my fault!