Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Very weird error in my game, can anybody help me??

This topic is 6027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there! I´m having a very weird problem with my DX App. I´m trying to make a 2D game for two simultaneous players on the same computer. The engine I´m using is a remake of Tricks of the Windows Game Programming Gurus´ engine, with the exception that is C++ based and the functions that deal with Bob objects are inside a class called Bob and the functions and variables that deal with each player are inside a class named Player. The screen is divided in two halves (upper and lower). The section that is giving me a great headache is when player one (upper half) gets inside the second player´s half and, consecuently, player two gets into player one´s half. I use a method inside Player called Render which is called once for each player object, so depending if one or two players are playing the game the method will be called once or twice, respectively. Its definition is as follows: int Player::Render(Player OtherPlayer) { int nx2,ny2; int index_dir = PlayerBob.Get_VarsI(PLAYER_INDEX_DIR); PlayerBob.Set_Curr_Frame(index_dir); if(ANERROR==PlayerBob.Draw(lpddsback)) return ANERROR; if(true==TwoPlayers) { int dx = int(OtherPlayer.Player_x - Player_x); int dy = int(OtherPlayer.Player_y - Player_y); if((abs(dx) < HALF_SCREEN_WIDTH) && (abs(dy) < (HALF_SCREEN_HEIGHT >> 1))) { OtherPlayer.GetBob().Get_Pos(nx2,ny2); DoublePlayer.Set_Pos(nx2-dx,ny2-dy); int opvarsi = OtherPlayer.GetBob().Get_VarsI(PLAYER_INDEX_DIR); DoublePlayer.Set_VarsI(PLAYER_INDEX_DIR,opvarsi); DoublePlayer.Set_Curr_Frame(opvarsi); if(ANERROR==DoublePlayer.Draw(lpddsback)) return ANERROR; } // End if. } // End if. Write_Error("Cuadro Actual: %d.\n",index_dir); Write_Error("Otro jugador: %d.\n",OtherPlayer.GetBob().Get_VarsI(PLAYER_INDEX_DIR)); return SUCCESS; } // End Player::Render. The parameter is the other player´s instance (if we have another player, otherwise just a copy of the first player). If we have just one player, the current frame is set and the object representing the player is drawn in the back buffer. If we have another player too, the function makes a couple of operations to determine if actually the other player is inside this half too. If it is, I use a global variable named DoublePlayer used for this situation, the function sets its position, its frame (based on the other player´s frame) and draw it to the back buffer. You may be asking where´s the weird thing? The weird thing that has been driving me crazy for the last 48 hours is the rendering of the second player. I don´t know why, but, for example, if I´m playing as the player 1 and I get into player 2´s area, player 1 and 2 objects are drawn in a correctly position, but player 2 is drawn with the same frame as player 1. So, say that I (as Player 1), I´m looking to the right and player 2 (which is stopped) is looking up, when the upper half of the screen is drawn, both players are drawn with the same frame (orientation), that is, in the upper half both players will be drawn with the same orientation as player nº 1 and in the lowe half both players will be drawn with the same orientation as player nº 2. Even more weird are the results thrown by the thousands of tests I made to the code. For example, if I replace this line: int opvarsi = OtherPlayer.GetBob().Get_VarsI(PLAYER_INDEX_DIR); by this one: int opvarsi = 20; The "intruder" object (in both halves, that is, player 1 in the lower half and player 2 in the upper half) is drawn with the frame number 20, which is correct. So why in the original code the "intruder" object maps the movement of the other player´s object? I have no idea. Here´s also the definition for the methods that are in charge of retrieving the direction of the player: Bob & GetBob(void) { return PlayerBob; // Privately defined inside class Player as Bob PlayerBob. } int Get_VarsI(int offset) { return varsI[offset]; } This method is inside class Bob, the offset used is PLAYER_INDEX_DIR (defined as const int PLAYER_INDEX_DIR = 0; ) and varsI is a private member inside PlayerBob defined as int varsI[16]. I made other kind of tests, such as writing to a log file, and, for example, if opvarsi took a value of 12 when it was assigned the int variable varsI[PLAYER_INDEX_DIR] from the other player (via the methods), the logfile wrote that opvarsi was 12, the OtherPlayer.GetBob().Get_VarsI(PLAYER_INDEX_DIR) was also 12 (it´s obvious, but...). Before setting DoublePlayer´s varsI variable and current frame with: DoublePlayer.Set_VarsI(PLAYER_INDEX_DIR,opvarsi); DoublePlayer.Set_Curr_Frame(opvarsi); DoublePlayer´s varsI[PLAYER_INDEX_DIR] and DoublePlayer´s curr_frame variable were actually 12. So I guess that the getting and retrieving methods are fine. If you need more details about the code just ask me, I really want to solve this problem! I´ll connect to the internet again in 24 hours (I have to pay for my browsing time). Thanks for your help!

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!