|
Circles followng player |
Sadako
Member #17,047
March 2019
|
So basically I made 2 characters. one is my player and another one is An AI. ``` if (fireballFollow2) |
Chris Katko
Member #1,881
January 2002
|
Is that the exact code from your game? Because if you hand typed it, you may have missed a typo that is the source of the bug. Like if you did if(fireballfollow2 = true){} you're setting it true every time and setting it to player x/y every time, and then adding +50 so it's always player_x + 50 and player_y + 50. -----sig: |
Peter Hull
Member #1,136
March 2001
|
I think it's because the block of code you have on lines 107..140 (which I believe is intended to reset the position of player 2's fireball) gets called every timer tick, instead of just when player 2 is going to fire. Hence the fireball never gets anywhere. Also, do you know about switch? Hope that helps.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Welcome to a.cc and hello. Did you know that an enum is another data type? You can declare variables of enum type. 1enum DIRECTION {
2 DIR_NONE = -1,
3 DIR_NORTH = 0,
4 DIR_EAST = 1,
5 DIR_SOUTH = 2,
6 DIR_WEST = 3
7};
8
9DIRECTION playerdir = DIR_NORTH;
10
11int* playery = &py1;
12int* playerx = &px1;
13
14if (playerdir != DIR_NONE) {
15 if (playerdir % 2 == 0) {
16 // NS
17 *playery += yspeed*(playerdir == DIR_NORTH)?-1:1;
18 }
19 else {
20 // EW
21 *playerx += xspeed*(playerdir == DIR_EAST)?1:-1;
22 }
23}
See how simple your code can be? Look into using pointers and arrays and bit flags. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Peter Hull
Member #1,136
March 2001
|
Also please don't make 2 topics with the same title. Life is confusing enough without this.
|
Sadako
Member #17,047
March 2019
|
So I've fixed the code like u guys said however so on "level 2" of game when I pressed enter the player2 is only firing circle on left side when it should fire 2 circle at the same time. Left and Right |
Peter Hull
Member #1,136
March 2001
|
OK this is just advice so don't take it the wrong way. I looked at the code and I found it hard to follow. I think it will become unmanageable as your game gets more complex. Without adding any more language features just now (structs and whatever will help in the future..), try to identify all the 'things' in the program and what variables each one needs. Then group these together and name them consistently. In practical terms I noticed that when destroyBG gets set to true it never gets set back to false and the code reloads the 'bg2.png' bitmap every cycle which looks wrong to me. Also, you can start a new topic every time you have a new question, or continue on the old one but don't do both! [edit] Line 367-389, this doesn't look right; 1 if (fireballUpLV2)
2 {
3 al_draw_circle(cX3, cY3, 20, al_map_rgb(200, 200, 50), 5);
4 cY3 -= speed + 5;
5
6 }
7 else if (fireballDownLV2)
8 {
9 al_draw_circle(cX3, cY3, 20, al_map_rgb(200, 200, 50), 5);
10 cY3 += speed + 5;
11
12 }
13 else if (fireballLeftLV2)
14 {
15 al_draw_circle(cX3, cY3, 20, al_map_rgb(200, 200, 50), 5);
16 cX3 -= speed + 5;
17
18 }
19 else if (fireballRight2)
20 {
21 al_draw_circle(cX3, cY3, 20, al_map_rgb(200, 200, 50), 5);
22 cX3 += speed + 5;
23 }
fireballRight2 should be fireballRightLV2 ? This is what I mean about 'patterns'
|
|