Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / 3d Bullet Function in C++

Author
Message
tag104367
12
Years of Service
User Offline
Joined: 1st Feb 2012
Location:
Posted: 2nd Feb 2012 00:58 Edited at: 2nd Feb 2012 01:35
i am just messing around with Dark Gdk and C++ but i cant seem to get a function to update my bullets to work correctly. this is what happens when i click once it shoots a sphere perfectly fine and it works just like it should and i can do it over and over as long as a wait like 2-3 seconds in between each shot. if i shoot it automatic it creates a sphere moves it a little then creates the next sphere directly in front of the last one and then so on. my bullets delete and everything its just i cant seem to figure out why they wont update correctly my code for everything to do with shooting is as follows

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[i][1] = BulletCount;
dbMakeObjectSphere(BULLET[i][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[i][1]+300)){
dbMoveObject(BULLET[i][0]+300, BulletSpeed);
dbMoveObject(BULLET[i][1]+300, BulletSpeed);
}
}
}


now i know the coding isnt great im going to break everything up into classes and sort everything out when i am done figuring out how to get it to work don't ask why i do this i just do so if you can help with my problem and see why my bullets aren't updating then please help me out it is getting very frustrating thanks
McLaine
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location:
Posted: 7th Feb 2012 15:02 Edited at: 7th Feb 2012 15:10
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:



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:



It's not my fault!

Login to post a reply

Server time is: 2024-04-27 03:57:44
Your offset time is: 2024-04-27 03:57:44