#165376 - spinal_cord - Thu Dec 18, 2008 2:11 pm
Hi guys, As you can tell by the title, I'm having a little trouble attempting a multiplayer game. Currently All i'm trying to do is pass button presses from one ds to the other, then pass back the player location. I have no idea if this is the best (or even remotely correct) way to do things.
Anyway (please excuse the use of PAlib, I know a lot of people don't like it) After a couple of minutes, it goes a bit crap and dies. Can someone have a look and tell me what's going wrong?
Thanks.
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage
Anyway (please excuse the use of PAlib, I know a lot of people don't like it) After a couple of minutes, it goes a bit crap and dies. Can someone have a look and tell me what's going wrong?
Thanks.
Code: |
// Includes #include <PA9.h> // Include for PA_Lib #include "MessageQueue.h" // Includes for liblobby #include "802.11.h" #include "lobby.h" #include "gfx/all_gfx.h" #include "gfx/all_gfx.c" int player=0; // which player number you are int player2_x=0; // player2 x int player2_y=0; // player2 y char player2_action[2]; // player2 keypress int player1_x=0; // player1 x int player1_y=0; // player1 y char dat[10]; // We need a custom VBL function which is called every VBlank to update liblobby; if you want to play mp3's simultaneously, add a AS_SoundVBL(); in this function // and call PA_VBLFunctionInit(customVBL) instead of PA_VBLFunctionInit(AS_SoundVBL) when initializing aslib void customVBL(void) { IPC_RcvCompleteCheck(); LOBBY_Update(); } // The receive handler - it is called every time something is received on the stream which with it is registered void Receive(unsigned char *data, int length, LPLOBBY_USER from) { if(player==1) { player2_action[0] = data[0]; player2_action[1] = data[1]; } if(player==2) { PA_SetSpriteX(1,0,data[0]); } } // Function: main() int main(int argc, char ** argv) { PA_Init(); // Initializes PA_Lib PA_InitVBL(); // Initializes a standard VBL PA_InitText(0, 0); // Initialize libLobby and output some information ... PA_VBLFunctionInit(customVBL); if (!IPC_Init()) { PA_OutputText(0, 1, 3, "Couldn't IPC_Init()!"); return 1; } IPC_SetChannelCallback(0, &LWIFI_IPC_Callback); // PA_OutputText(0, 1, 2, "LOBBY_Init() ..."); LOBBY_Init(); // Register a stream handler for stream number 1; // Streams below number 0x8000 are "acknowledged streams", that means liblobby will make sure that everything you send reaches its destination. LOBBY_SetStreamHandler(0x0001, &Receive); ////////////////////////////////////// PA_OutputText(0, 1, 3, "Start Game = Up/n Join Game = Down"); while(player==0) { if(Pad.Newpress.Up)player=1; if(Pad.Newpress.Down)player=2; PA_WaitForVBL(); } PA_OutputText(0, 1, 10, "You are player %d",player); PA_OutputText(0,1,11,"Waiting for other player"); int max = LOBBY_GetNumberOfKnownUsers(); while(max<1 && dat[0] !=255) { max = LOBBY_GetNumberOfKnownUsers(); PA_WaitForVBL(); } /////////////////////////////////////// PA_EasyBgLoad(1,2,background); // snow foreground // some sprites... PA_LoadSprite16cPal(1, // Screen 0, // Palette number (void*)men_Pal); // Palette name PA_CreateSprite(1, // Screen 0, // Sprite number (void*)men_Sprite, // Sprite name OBJ_SIZE_32X32, // Sprite size 0, // 16 color mode 0, // Sprite palette number 50, 150); // X and Y position on the screen // main loop PA_OutputText(0, 1, 3, "Entering main loop ..."); while (1) { if(player==2) { // player 2 only sends the controls to player 1 dat[0] = 0; dat[1] = 0; if (Pad.Held.Up) {dat[0]=1;} // bit 1 if (Pad.Held.Down) {dat[0] |= 2;} // bit 2 if (Pad.Held.Left) {dat[0] |= 4;} // bit 3 if (Pad.Held.Right) {dat[0] |= 8;} // bit 4 if (Pad.Held.Start) {dat[0] |= 16;} // bit 5 if (Pad.Held.Select) {dat[0] |= 32;} // bit 6 if (Pad.Held.R) {dat[1] = 1;} // bit 7 if (Pad.Held.L) {dat[1] |= 2;} // bit 8 if (Pad.Held.A) {dat[1] |= 4;} // bit 9 if (Pad.Held.B) {dat[1] |= 8;} // bit 10 if (Pad.Held.X) {dat[1] |= 16;} // bit 11 if (Pad.Held.Y) {dat[1] |= 32;} // bit 12 LOBBY_SendToUser(LOBBY_GetUserByID(0),0x0001,(unsigned char *) dat,2); } if(player==1) { if(player2_action[0] & 4)player2_x--; // left if(player2_action[0] & 8)player2_x++; // right PA_OutputText(0, 1, 20, "Player 2 X: %d ", player2_x); PA_OutputText(0, 1, 21, "Player 2 Y: %d ", player2_y); dat[0]=player2_x; PA_SetSpriteX(1,0,dat[0]); LOBBY_SendToUser(LOBBY_GetUserByID(0),0x0001,(unsigned char *) dat,1); } // Write all connections to the screen int i=0; LPLOBBY_USER user = LOBBY_GetUserByID(i) ; PA_OutputText(0, 1, 5+i, "->%s (%s) ", LOBBY_GetUserName(user), LOBBY_IsTimedOut(user) ? "TIMEOUT" : "OK"); PA_WaitForVBL(); } return 0; } // End of main() |
_________________
I'm not a boring person, it's just that boring things keep happening to me.
Homepage