Need help shooting projectile at character in C language

The code below handles the direction my boss is facing, then allows him to animate in such direction. What I need help on is whenever he crosses paths with the characters coordinates, he shoots in the direction of the character.

Character coords are denoted with character[i].xCoord and character[i].yCoord.

Oh yeah, the shooting animations are when i = 4 through i = 7.

Any help would be AMAZING! Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  void boss_animation()
{       
    for (int i = 0; i < 4; i++){
        if( ! boss[i].drawable)
            continue;
    //Puts image of character on screen based on inputs from struct
    readimagefile(boss[i].frames[boss[i].currentFrame],
        boss[i].xCoord,
        boss[i].yCoord,
        boss[i].xCoord + boss[i].charWidth,
        boss[i].yCoord + boss[i].charHeight );
    boss[i].currentFrame++; //increments the "frame" by one, thus only animating one image at a time
    if(boss[i].currentFrame == boss[i].animationFrames){
        boss[i].currentFrame = 0;} //When frame 4 is reached, it resorts back to first frame and restarts
        //character[i].drawable = 0;}
    boss[i].xCoord += boss[i].xMove;
    boss[i].yCoord += boss[i].yMove;    
    }       
        for (int i = 4; i < 8; i++){
        if( ! boss[i].drawable)
            continue;
    if(i == 4){
        while(boss[i].xCoord < 733) {
            //Puts image of character on screen based on inputs from struct
    readimagefile(boss[i].frames[boss[i].currentFrame],
        boss[i].xCoord,
        boss[i].yCoord,
        boss[i].xCoord + boss[i].charWidth,
        boss[i].yCoord + boss[i].charHeight );
    boss[i].currentFrame++; //increments the "frame" by one, thus only animating one image at a time
    if(boss[i].currentFrame == boss[i].animationFrames){
        boss[i].currentFrame = 0;}
    boss[i].xCoord = boss[i].xCoord + 10;}}
    else if(i == 5){
        while(boss[i].xCoord > 30){
            //Puts image of character on screen based on inputs from struct
    readimagefile(boss[i].frames[boss[i].currentFrame],
        boss[i].xCoord,
        boss[i].yCoord,
        boss[i].xCoord + boss[i].charWidth,
        boss[i].yCoord + boss[i].charHeight );
    boss[i].currentFrame++; //increments the "frame" by one, thus only animating one image at a time
    if(boss[i].currentFrame == boss[i].animationFrames){
        boss[i].currentFrame = 0;}
    boss[i].xCoord = boss[i].xCoord - 10;}}
    else if(i == 6){
        while(boss[i].yCoord > 60){
            //Puts image of character on screen based on inputs from struct
    readimagefile(boss[i].frames[boss[i].currentFrame],
        boss[i].xCoord,
        boss[i].yCoord,
        boss[i].xCoord + boss[i].charWidth,
        boss[i].yCoord + boss[i].charHeight );
    boss[i].currentFrame++; //increments the "frame" by one, thus only animating one image at a time
    if(boss[i].currentFrame == boss[i].animationFrames){
        boss[i].currentFrame = 0;}
    boss[i].yCoord = boss[i].yCoord - 10;}}
    else if(i == 7){
        while(boss[i].yCoord < 682){
            //Puts image of character on screen based on inputs from struct
    readimagefile(boss[i].frames[boss[i].currentFrame],
        boss[i].xCoord,
        boss[i].yCoord,
        boss[i].xCoord + boss[i].charWidth,
        boss[i].yCoord + boss[i].charHeight );
    boss[i].currentFrame++; //increments the "frame" by one, thus only animating one image at a time
    if(boss[i].currentFrame == boss[i].animationFrames){
        boss[i].currentFrame = 0;}
    boss[i].yCoord = boss[i].yCoord + 10;}}
    //putimage(0, 0, bkimage, COPY_PUT);
    //Sleep(10);
    }   
}
void playBoss(){
    int olddirection = 0, newdirection = 0;
    int bossDirection;
    int health = 500;
    int activate = 0;
    initSectors2();
    initSectors3();
    do {
        bossDirection = rand() % 4;
        if(bossDirection == 0)
            newdirection = 0;
        if(bossDirection == 1)
            newdirection = 1;
        if(bossDirection == 2)
            newdirection = 2;
        if(bossDirection == 3)
            newdirection = 3;
        if(boss[newdirection].xCoord == character[newdirection].xCoord || boss[newdirection].yCoord == character[newdirection].yCoord){
            if(newdirection == 0){
                newdirection = 4;}
            else if(newdirection == 1){
                newdirection = 5;}
            else if(newdirection == 2){
                newdirection = 6;}
            else if(newdirection == 3){
                newdirection = 7;}
        }
    if(olddirection != newdirection){
        boss[newdirection].xCoord = boss[olddirection].xCoord;
        boss[newdirection].yCoord = boss[olddirection].yCoord;
        boss[olddirection].drawable = 0;
        boss[newdirection].drawable = 1;
        boss[newdirection].currentFrame = 0;
        if(newdirection == 0 || newdirection == 1 || newdirection == 2 || newdirection == 3){
        olddirection = newdirection;}
    }
    checkSectorsBoss();
    shadowballSectors();
    boss_animation();
    Sleep(70);
        check_boss();
    activate = 1;
    }
    while(health > 0);
}
Anyone at all? :(

It has been quite a head scratcher for me... It seems so easy, to just check for coordinates but it has not proven to be so!
noooooooo one??
Please indent your code.
Try to abstract a little.

1
2
3
4
5
6
7
8
9
/*        if(bossDirection == 0)
            newdirection = 0;
        if(bossDirection == 1)
            newdirection = 1;
        if(bossDirection == 2)
            newdirection = 2;
        if(bossDirection == 3)
            newdirection = 3;*/
        newdirection = bossDirection;
Well... it is indented? and your second "recommendation cuts out a few lines of code, but is unnecessary and is not the issue at present.

But thanks.
> Well... it is indented?
No, it is not. By instance, ¿where does the while loop of line 47 end?

> your second "recommendation cuts out a few lines of code
That is not the recommendation.
Make your code clearer and self documented.
Topic archived. No new replies allowed.