Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualLickatoad

Posted 14 February 2013 - 07:10 PM

Thanks very much for your help, i've nearly got it working. I've changed the bulletdir into the switch. 

Under init bullet if I manually enter the direction it fires perfectly but i'm now having a hard time getting the tanks direction in there. I've tried doing it 2 ways, as listed below.

 

    if (tank.dir == 0)
            bullet[i].bulletdir = 0;
    else if (tank.dir == 1)
            bullet[i].bulletdir = 1;
    else if (tank.dir == 2)
            bullet[i].bulletdir = 2;
    else if (tank.dir == 3)
            bullet[i].bulletdir = 3;


***** Or i've tried doing

bullet[i].bulletdir = tank.dir
 
 
 
 
 
*********Heres the updated switch (and I can probably remove the tankplayer &tank reference now)
 
void UpdateBullet(Bullet bullet[], int size, TankPlayer &tank)
 
{    
    for(int i = 0; i < size; i++)
 
    switch (bullet[i].bulletdir)
    {
        case 0: //up
                for(int i = 0; i < size; i++)
                {        
                    if(bullet[i].live)
                    {                        
                        bullet[i].bulletY -= bullet[i].bulletSpeed;
                        if(bullet[i].bulletY < 0)
                        bullet[i].live = false;
                    }
                }
            break;
        case 1: //right
                for(int i = 0; i < size; i++)
                {        
                    if(bullet[i].live)
                    {
                        bullet[i].bulletX += bullet[i].bulletSpeed;
                        if(bullet[i].bulletX > WIDTH)
                        bullet[i].live = false;
                    }
                }
            break;
        case 2: //down
            for(int i = 0; i < size; i++)
                {        
                    if(bullet[i].live)
                    {
                        bullet[i].bulletY += bullet[i].bulletSpeed;
                        if(bullet[i].bulletY > HEIGHT)
                        bullet[i].live = false;
                    }
                }
            break;
        case 3: //left
            for(int i = 0; i < size; i++)
                {        
                    if(bullet[i].live)
                    {
                        bullet[i].bulletX -= bullet[i].bulletSpeed;
                        if(bullet[i].bulletX < 0)
                        bullet[i].live = false;
                    }
                }
            break;
    }
}
 

 

 

 

 

Trying it either way only shoots right. 

 

Under InitTank where i've originally set the original tank direction to 1, it seems it's only keeping that figure when I shoot through the above statements and not updating it accordingly, or passing on the updated values.

 

I know it's going to be simple and i'm probably overthinking things. Thanks again for your help.


#1Lickatoad

Posted 14 February 2013 - 07:03 PM

Thanks very much for your help, i've nearly got it working. I've changed the bulletdir into the switch. 

Under init bullet if I manually enter the direction it fires perfectly but i'm now having a hard time getting the tanks direction in there. I've tried doing it 2 ways, as listed below.

 

    if (tank.dir == 0)
            bullet[i].bulletdir = 0;
    else if (tank.dir == 1)
            bullet[i].bulletdir = 1;
    else if (tank.dir == 2)
            bullet[i].bulletdir = 2;
    else if (tank.dir == 3)
            bullet[i].bulletdir = 3;


***** Or i've tried doing

bullet[i].bulletdir = tank.dir
 
 
 
 
 
*********Heres the updated switch (and I can probably remove the tankplayer &tank reference now)
 
void UpdateBullet(Bullet bullet[], int size, TankPlayer &tank)
 
{    
    for(int i = 0; i < size; i++)
 
    switch (bullet[i].bulletdir)
    {
        case 0: //up
                for(int i = 0; i < size; i++)
                {        
                    if(bullet[i].live)
                    {                        
                        bullet[i].bulletY -= bullet[i].bulletSpeed;
                        if(bullet[i].bulletY < 0)
                        bullet[i].live = false;
                    }
                }
            break;
        case 1: //right
                for(int i = 0; i < size; i++)
                {        
                    if(bullet[i].live)
                    {
                        bullet[i].bulletX += bullet[i].bulletSpeed;
                        if(bullet[i].bulletX > WIDTH)
                        bullet[i].live = false;
                    }
                }
            break;
        case 2: //down
            for(int i = 0; i < size; i++)
                {        
                    if(bullet[i].live)
                    {
                        bullet[i].bulletY += bullet[i].bulletSpeed;
                        if(bullet[i].bulletY > HEIGHT)
                        bullet[i].live = false;
                    }
                }
            break;
        case 3: //left
            for(int i = 0; i < size; i++)
                {        
                    if(bullet[i].live)
                    {
                        bullet[i].bulletX -= bullet[i].bulletSpeed;
                        if(bullet[i].bulletX < 0)
                        bullet[i].live = false;
                    }
                }
            break;
    }
}
 

 

 

 

 

Trying it either way only shoots right. 

 

I know it's going to be simple and i'm probably overthinking things. Thanks again for your help.


PARTNERS