hello, ive ran into a rather wierd problem and i think it might either have to do with my structs, or the way i am blitting my bitmaps to the buffer, but i had the game working fine so far until i added a new struct into my header file. I added the struct for a "bigball", but when i go to blit the ball to the screen it messes up the coordinates for my second player, and for some reason the ball and the second player both go to the same position... if anyone has the time, id appreciate it if they would take a look at my code...
this is my header file named header.h
And this is my main.cpp
1 | #ifndef _HEADER_H |
2 | #define _HEADER_H |
3 | |
4 | #include <allegro.h> |
5 | |
6 | struct tagPlayers |
7 | { |
8 | float x,y; |
9 | float speed; |
10 | int grabx,graby; |
11 | int frame,row; |
12 | int anim_timer,anim_delay; |
13 | int alive; |
14 | }player[2]; // change this to 2 |
15 | |
16 | struct tagBigBalls |
17 | { |
18 | float x,y; |
19 | float y_vel; |
20 | float speed; |
21 | int alive; |
22 | }bigball[1]; |
23 | |
24 | #endif |
you need to initilise your players with the total number of elements, which is 2(1+1) as opposed to 1(0+1). stupid I know, but thats how it is.
but player[2] means that there is three players then doesnt it? or do you not use the 0?
yeah, you still address the first one using 0, but you initialise it with the total number of elements, not the final elements address.
ok, so i would put player[1]...
and then when i set the variables or used them later i would use...
player[1].x = 50;
^but player[1].x is really meaning player[0].x in the struct?
or would i just keep everything else the same, and only change the struct player[2];
I'm dumb!
im a bit confused here...:(
EDIT:
DUDE!
nevermind! i got it to work by just changing what you said to in the first reply!
thanx so much! I'm dumb!
now it makes sense to me.
when you have a struct sorta like this
struct tagPlayers { float x,y; float alive; int frame; }player[2];
the player[2] at the end means theres gonna be 2 players, player[0] is one and player[1] is two
thanx a bunch again
yep - you got it. no probs.