diff --git a/source/Globals.h b/source/Globals.h index ab1b14b..8c884e9 100644 --- a/source/Globals.h +++ b/source/Globals.h @@ -28,6 +28,7 @@ #define MENU_SETTINGS_TP 13 #define MENU_DUNGEON 14 #define MENU_NPC 15 +#define MENU_MULTIPLAYER 16 #define NPC_GIRL 0 #define NPC_PRIEST 1 @@ -136,6 +137,7 @@ char* currentCraftTitle; s16 curInvSel; bool quitGame; s8 currentSelection; +bool isRemote; u16 daytime; int day; diff --git a/source/Menu.c b/source/Menu.c index b4d73f1..6041dd1 100644 --- a/source/Menu.c +++ b/source/Menu.c @@ -1,7 +1,7 @@ #include "Menu.h" -char options[][12] = {"Start Game", "How To Play","Settings", "About", "Exit"}; -char pOptions[][24] = {"Return to game", "Save Progress", "Exit to title"}; +char options[][12] = {"Start Game", "Join Game", "How To Play","Settings", "About", "Exit"}; +char pOptions[][24] = {"Return to game", "Save Progress", "Host World", "Exit to title"}; char keybOptions[][24] = {"Exit and Save", "Exit and Don't save","Reset to default"}; char setOptions[][24] = {"Rebind Buttons", "Texture packs", "Debug Text: ", "N3DS Speedup: ", "Return to title"}; @@ -380,8 +380,8 @@ void tickMenu(int menu){ if(!areYouSure && !areYouSureSave){ if(pauseSaveDisplayTimer > 0) --pauseSaveDisplayTimer; if (k_pause.clicked || k_decline.clicked) currentMenu = MENU_NONE; - if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=2;} - if (k_down.clicked){ ++currentSelection; if(currentSelection > 2)currentSelection=0;} + if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=3;} + if (k_down.clicked){ ++currentSelection; if(currentSelection > 3)currentSelection=0;} if (k_accept.clicked){ switch(currentSelection){ case 0: @@ -391,6 +391,10 @@ void tickMenu(int menu){ if(currentLevel!=5) areYouSureSave = true; break; case 2: + networkHost(); + currentMenu = MENU_NONE; + break; + case 3: areYouSure = true; break; } @@ -412,6 +416,8 @@ void tickMenu(int menu){ sf2d_set_clear_color(0xFF); currentSelection = 0; currentMenu = MENU_TITLE; + + networkDisconnect(); playMusic(music_menu); } else if (k_decline.clicked){ @@ -561,10 +567,11 @@ void tickMenu(int menu){ enteringName = true; } else { memset(¤tFileName, 0, 255); // reset currentFileName - sprintf(currentFileName,"%s.wld",fileNames[currentSelection]); - playSound(snd_test); - initGame = 1; - currentMenu = MENU_NONE; + sprintf(currentFileName,"%s.wld",fileNames[currentSelection]); + playSound(snd_test); + initGame = 1; + currentMenu = MENU_NONE; + isRemote = false; } } } else if (areYouSure){ @@ -588,6 +595,7 @@ void tickMenu(int menu){ playSound(snd_test); initGame = 2; ++worldFileCount; + isRemote = false; } } if((k_touch.px != 0 || k_touch.py != 0) && touchDelay == 0){ @@ -636,7 +644,7 @@ void tickMenu(int menu){ } if(k_decline.clicked){ currentMenu = MENU_TITLE; - currentSelection = 2; + currentSelection = 3; } if(k_accept.clicked){ switch(currentSelection){ @@ -708,8 +716,8 @@ void tickMenu(int menu){ } } - if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=4;} - if (k_down.clicked){ ++currentSelection; if(currentSelection > 4)currentSelection=0;} + if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=5;} + if (k_down.clicked){ ++currentSelection; if(currentSelection > 5)currentSelection=0;} if(k_accept.clicked){ switch(currentSelection){ @@ -721,17 +729,21 @@ void tickMenu(int menu){ areYouSure = false; break; case 1: + currentMenu = MENU_MULTIPLAYER; + currentSelection = 0; + break; + case 2: sprintf(pageText,"Page: %d/%d",pageNum+1,maxPageNum+1); currentMenu = MENU_TUTORIAL; break; - case 2: + case 3: currentSelection = 0; currentMenu = MENU_SETTINGS; break; - case 3: + case 4: currentMenu = MENU_ABOUT; break; - case 4: + case 5: quitGame = true; break; } @@ -740,7 +752,7 @@ void tickMenu(int menu){ break; case MENU_TUTORIAL: if(k_decline.clicked){ - currentSelection = 1; + currentSelection = 2; currentMenu = MENU_TITLE; } if(k_menuNext.clicked){ @@ -760,6 +772,25 @@ void tickMenu(int menu){ case MENU_NPC: tickNPCMenu(); break; + case MENU_MULTIPLAYER: + networkScan(); + + if (k_decline.clicked){ + currentMenu = MENU_TITLE; + currentSelection = 1; + } + if (k_up.clicked){ --currentSelection; if(currentSelection < 0) currentSelection = (networkGetScanCount()>0 ? networkGetScanCount()-1 : 0);} + if (k_down.clicked){ ++currentSelection; if(currentSelection >= networkGetScanCount()) currentSelection=0;} + + if(k_accept.clicked){ + //TODO: Join World + if(networkConnect(currentSelection)) { + initGame = 1; + currentMenu = MENU_NONE; + isRemote = true; + } + } + break; } } @@ -873,96 +904,96 @@ void renderMenu(int menu,int xscr,int yscr){ sf2d_end_frame(); break; case MENU_LOADGAME: - sf2d_start_frame(GFX_TOP, GFX_LEFT); - sf2d_draw_rectangle(0, 0, 400, 240, 0xFF0C0C0C); //You might think "real" black would be better, but it actually looks better that way - - if(!enteringName){ // World select - offsetX = 0;offsetY = (currentSelection * 32) - 48; - drawText("Select a file",122,-16); - for(i = 0; i < worldFileCount + 1; ++i){ - int color = 0xFF921020; - char * text = fileNames[i]; - if(i == worldFileCount){ - text = "Generate New World"; - color = 0xFF209210; - } - if(i != currentSelection) color &= 0xFF7F7F7F; // Darken color. - else { - if(areYouSure)color = 0xFF1010DF; - } - - char scoreText[24]; - sprintf(scoreText,"Score: %d",fileScore[i]); - - renderFrame(1,i*4,24,(i*4)+4,color); - if(i != worldFileCount){ - drawText(text,(400-(strlen(text)*12))/2,i*64+12); - drawText(scoreText,(400-(strlen(scoreText)*12))/2,i*64+32); - } else { - drawText(text,(400-(strlen(text)*12))/2,i*64+24); - } - if(fileWin[i] && i != worldFileCount) render16(18,i*32+8,24,208,0); // Render crown - } - offsetX = 0;offsetY = 0; - } else { // Enter new world name. - drawText("Enter a name",128,16); - drawText(fileNames[worldFileCount],(400-(strlen(fileNames[worldFileCount])*12))/2, 48); - - if(errorFileName > 0){ - switch(errorFileName){// Error: Filename cannot already exist. - case 1: drawTextColor("ERROR: Length cannot be 0!",(400-26*12)/2,200,0xFF1010AF); break; - case 2: drawTextColor("ERROR: You need Letters/Numbers!",(400-32*12)/2,200,0xFF1010AF); break; - case 3: drawTextColor("ERROR: Filename already exists!",(400-31*12)/2,200,0xFF1010AF); break; - } - } - } - sf2d_end_frame(); - sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); - sf2d_draw_rectangle(0, 0, 320, 240, 0xFF0C0C0C); //You might think "real" black would be better, but it actually looks better that way - - if(!enteringName){ // World select - if(!areYouSure){ - drawTextColor("Load World",100,12,0xFF3FFFFF); - drawText("Press or to scroll", 28, 50); - renderButtonIcon(k_up.input & -k_up.input, 98, 48, 1); - renderButtonIcon(k_down.input & -k_down.input, 160, 48, 1); - drawText("Press to load world", (320-21*12)/2, 100); - renderButtonIcon(k_accept.input & -k_accept.input, 104, 98, 1); - drawText("Press to return", 58, 150); - renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1); - if(currentSelection != worldFileCount){ - drawText("Press to delete",(320-17*12)/2, 200); - renderButtonIcon(k_delete.input & -k_delete.input, 128, 198, 1); - } - } else { - drawTextColor("Delete File?",88,12,0xFF3F3FFF); - drawText("Press to confirm", (320-18*12)/2, 100); - renderButtonIcon(k_accept.input & -k_accept.input, 122, 98, 1); - drawText("Press to return", 58, 150); - renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1); - } - - } else { // Draw the "keyboard" - drawTextColor("Touch the keypad below",(320-22*12)/2,12,0xFF33FFFF); - - sf2d_draw_rectangle(0, 50, 320, 110, 0xFF7F7FBF); - - if(touchDelay > 0){ - sf2d_draw_rectangle(touchX, touchY, touchW, touchH, 0xFF0000AF); - } - - drawSizedText(guiText0,4, 60, 2); - drawSizedText(guiText1,4, 80, 2); - drawSizedText(guiText2,12, 100, 2); - drawSizedText(guiText3,28, 120, 2); - drawSizedText(guiText4,12, 140, 2); - - drawText("Press to confirm", (320-18*12)/2, 180); - renderButtonIcon(k_accept.input & -k_accept.input, 122, 178, 1); - drawText("Press to return", 58, 210); - renderButtonIcon(k_decline.input & -k_decline.input, 128, 208, 1); - } - sf2d_end_frame(); + sf2d_start_frame(GFX_TOP, GFX_LEFT); + sf2d_draw_rectangle(0, 0, 400, 240, 0xFF0C0C0C); //You might think "real" black would be better, but it actually looks better that way + + if(!enteringName){ // World select + offsetX = 0;offsetY = (currentSelection * 32) - 48; + drawText("Select a file",122,-16); + for(i = 0; i < worldFileCount + 1; ++i){ + int color = 0xFF921020; + char * text = fileNames[i]; + if(i == worldFileCount){ + text = "Generate New World"; + color = 0xFF209210; + } + if(i != currentSelection) color &= 0xFF7F7F7F; // Darken color. + else { + if(areYouSure)color = 0xFF1010DF; + } + + char scoreText[24]; + sprintf(scoreText,"Score: %d",fileScore[i]); + + renderFrame(1,i*4,24,(i*4)+4,color); + if(i != worldFileCount){ + drawText(text,(400-(strlen(text)*12))/2,i*64+12); + drawText(scoreText,(400-(strlen(scoreText)*12))/2,i*64+32); + } else { + drawText(text,(400-(strlen(text)*12))/2,i*64+24); + } + if(fileWin[i] && i != worldFileCount) render16(18,i*32+8,24,208,0); // Render crown + } + offsetX = 0;offsetY = 0; + } else { // Enter new world name. + drawText("Enter a name",128,16); + drawText(fileNames[worldFileCount],(400-(strlen(fileNames[worldFileCount])*12))/2, 48); + + if(errorFileName > 0){ + switch(errorFileName){// Error: Filename cannot already exist. + case 1: drawTextColor("ERROR: Length cannot be 0!",(400-26*12)/2,200,0xFF1010AF); break; + case 2: drawTextColor("ERROR: You need Letters/Numbers!",(400-32*12)/2,200,0xFF1010AF); break; + case 3: drawTextColor("ERROR: Filename already exists!",(400-31*12)/2,200,0xFF1010AF); break; + } + } + } + sf2d_end_frame(); + sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); + sf2d_draw_rectangle(0, 0, 320, 240, 0xFF0C0C0C); //You might think "real" black would be better, but it actually looks better that way + + if(!enteringName){ // World select + if(!areYouSure){ + drawTextColor("Load World",100,12,0xFF3FFFFF); + drawText("Press or to scroll", 28, 50); + renderButtonIcon(k_up.input & -k_up.input, 98, 48, 1); + renderButtonIcon(k_down.input & -k_down.input, 160, 48, 1); + drawText("Press to load world", (320-21*12)/2, 100); + renderButtonIcon(k_accept.input & -k_accept.input, 104, 98, 1); + drawText("Press to return", 58, 150); + renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1); + if(currentSelection != worldFileCount){ + drawText("Press to delete",(320-17*12)/2, 200); + renderButtonIcon(k_delete.input & -k_delete.input, 128, 198, 1); + } + } else { + drawTextColor("Delete File?",88,12,0xFF3F3FFF); + drawText("Press to confirm", (320-18*12)/2, 100); + renderButtonIcon(k_accept.input & -k_accept.input, 122, 98, 1); + drawText("Press to return", 58, 150); + renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1); + } + + } else { // Draw the "keyboard" + drawTextColor("Touch the keypad below",(320-22*12)/2,12,0xFF33FFFF); + + sf2d_draw_rectangle(0, 50, 320, 110, 0xFF7F7FBF); + + if(touchDelay > 0){ + sf2d_draw_rectangle(touchX, touchY, touchW, touchH, 0xFF0000AF); + } + + drawSizedText(guiText0,4, 60, 2); + drawSizedText(guiText1,4, 80, 2); + drawSizedText(guiText2,12, 100, 2); + drawSizedText(guiText3,28, 120, 2); + drawSizedText(guiText4,12, 140, 2); + + drawText("Press to confirm", (320-18*12)/2, 180); + renderButtonIcon(k_accept.input & -k_accept.input, 122, 178, 1); + drawText("Press to return", 58, 210); + renderButtonIcon(k_decline.input & -k_decline.input, 128, 208, 1); + } + sf2d_end_frame(); break; case MENU_SETTINGS_REBIND: sf2d_start_frame(GFX_TOP, GFX_LEFT); @@ -1064,7 +1095,7 @@ void renderMenu(int menu,int xscr,int yscr){ offsetX = 0;offsetY = 0; renderFrame(1,1,24,14,0xFF1010AF); drawText("Paused",164,32); - for(i = 2; i >= 0; --i){ + for(i = 3; i >= 0; --i){ char* msg = pOptions[i]; u32 color = 0xFF7F7F7F; if(i == currentSelection) color = 0xFFFFFFFF; @@ -1072,7 +1103,7 @@ void renderMenu(int menu,int xscr,int yscr){ color = 0xFF7F7FFF; if(i == currentSelection) color = 0xFFAFAFFF; } - drawTextColor(msg,(400 - (strlen(msg) * 12))/2, (i * 24) + 100, color); + drawTextColor(msg,(400 - (strlen(msg) * 12))/2, (i * 24) + 88, color); } if(pauseSaveDisplayTimer > 0) drawTextColor("Game Saved!", (400-(11*12))/2, 64,0xFF20FF20); @@ -1355,12 +1386,12 @@ void renderMenu(int menu,int xscr,int yscr){ renderTitle(76,16); - for(i = 4; i >= 0; --i){ + for(i = 5; i >= 0; --i){ char* msg = options[i]; u32 color = 0xFF7F7F7F; if(i == currentSelection) color = 0xFFFFFFFF; - drawSizedTextColor(msg,((200 - (strlen(msg) * 8))/2) + 1, (((8 + i) * 20 - 50) >> 1) + 1,2.0, 0xFF000000); - drawSizedTextColor(msg,(200 - (strlen(msg) * 8))/2, ((8 + i) * 20 - 50) >> 1,2.0, color); + drawSizedTextColor(msg,((200 - (strlen(msg) * 8))/2) + 1, (((8 + i) * 20 - 58) >> 1) + 1,2.0, 0xFF000000); + drawSizedTextColor(msg,(200 - (strlen(msg) * 8))/2, ((8 + i) * 20 - 58) >> 1,2.0, color); } drawText(versionText,2,225); @@ -1382,7 +1413,9 @@ void renderMenu(int menu,int xscr,int yscr){ switch(currentSelection){ case 0: // "Start Game" break; - case 1: // "How To Play" + case 1: // "Join Game" + break; + case 2: // "How To Play" startX = 72;startY = 54; render16(startX,startY,96,208,0);//C-PAD startX = 72;startY = 37; @@ -1399,11 +1432,11 @@ void renderMenu(int menu,int xscr,int yscr){ render16(startX,startY,160,208,0);//C-PAD right drawTextColor("Learn the basics",64,24,0xFF7FFFFF); break; - case 2: // "Settings" + case 3: // "Settings" drawTextColor("Modify the game's feel",(320 - (22 * 12))/2,24,0xFF7FFFFF); renderc(48,48,0,112,64,32,0); break; - case 3: // "About" + case 4: // "About" drawTextColor("Who made this game?",(320 - (19 * 12))/2,24,0xFF7FFFFF); // Secret code ;) @@ -1419,7 +1452,7 @@ void renderMenu(int menu,int xscr,int yscr){ //drawSizedText("(Totally not a secret code or anything)",4,160,1); break; - case 4: // "Exit" + case 5: // "Exit" drawTextColor("Exit to the homebrew menu",(320 - (25 * 12))/2,24,0xFF7FFFFF); drawTextColor("(bye-bye)",(320 - (9 * 12))/2,100,0xFF7FFFFF); break; @@ -1439,6 +1472,41 @@ void renderMenu(int menu,int xscr,int yscr){ renderNPCMenu(xscr, yscr); sf2d_end_frame(); break; + case MENU_MULTIPLAYER: + sf2d_start_frame(GFX_TOP, GFX_LEFT); + sf2d_draw_rectangle(0, 0, 400, 240, 0xFF0C0C0C); //You might think "real" black would be better, but it actually looks better that way + + offsetX = 0;offsetY = (currentSelection * 32) - 48; + drawText("Select a world",122,-16); + for(i = 0; i < networkGetScanCount(); ++i){ + int color = 0xFF921020; + char * text = malloc((50+8+1) * sizeof(char)); + memset(text, 0, (50+8+1) * sizeof(char)); + networkGetScanName(text, i); + strcpy(text, "'s World"); + + if(i != currentSelection) color &= 0xFF7F7F7F; // Darken color. + + renderFrame(1,i*4,24,(i*4)+4,color); + drawText(text,(400-(strlen(text)*12))/2,i*64+24); + + free(text); + } + offsetX = 0;offsetY = 0; + sf2d_end_frame(); + sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); + sf2d_draw_rectangle(0, 0, 320, 240, 0xFF0C0C0C); //You might think "real" black would be better, but it actually looks better that way + + drawTextColor("Searching for Worlds",40,12,0xFF3FFFFF); + drawText("Press or to scroll", 28, 50); + renderButtonIcon(k_up.input & -k_up.input, 98, 48, 1); + renderButtonIcon(k_down.input & -k_down.input, 160, 48, 1); + drawText("Press to join world", (320-21*12)/2, 100); + renderButtonIcon(k_accept.input & -k_accept.input, 104, 98, 1); + drawText("Press to return", 58, 150); + renderButtonIcon(k_decline.input & -k_decline.input, 128, 148, 1); + sf2d_end_frame(); + break; } } diff --git a/source/Menu.h b/source/Menu.h index bd764d7..ca0c38b 100644 --- a/source/Menu.h +++ b/source/Menu.h @@ -3,6 +3,7 @@ #include "MenuTutorial.h" #include "texturepack.h" #include "Quests.h" +#include "Network.h" void initMenus(); diff --git a/source/Network.c b/source/Network.c index 934a20e..d2a44c9 100644 --- a/source/Network.c +++ b/source/Network.c @@ -1,5 +1,6 @@ #include "Network.h" +#include "PacketHandler.h" #include #include #include @@ -186,10 +187,7 @@ void networkRecieve() { if(actualSize) { networkPacket *packet = (networkPacket*) networkBuffer; - //TODO: Differenciate the packets and process them - if(packet->analyze.type==0) { - - } + processPacket(packet, packet->analyze.type); } } } diff --git a/source/Network.h b/source/Network.h index 697cdb8..10eec2f 100644 --- a/source/Network.h +++ b/source/Network.h @@ -10,15 +10,36 @@ #define NETWORK_MAXPLAYERS UDS_MAXNODES +//packet type ids +#define PACKET_REQUEST_MAPDATA 1 +#define PACKET_MAPDATA 2 + //TODO: Every other packet struct should start with a u8 type to match this typedef struct { u8 type; } packetAnalyze; +typedef struct { + u8 type; + + u8 level; +} packetRequestMapData; + +typedef struct { + u8 type; + + u8 level; + u8 offset; //-> data is at offset*128 to offset*128+127 + + u8 map[128]; + u8 data[128]; +} packetMapData; + typedef struct { union { packetAnalyze analyze; - + packetRequestMapData requestMapData; + packetMapData mapData; }; } networkPacket; diff --git a/source/PacketHandler.c b/source/PacketHandler.c new file mode 100644 index 0000000..f444379 --- /dev/null +++ b/source/PacketHandler.c @@ -0,0 +1,10 @@ +#include "PacketHandler.h" + +void processPacket(networkPacket *packet, u8 type) { + //TODO: Differenciate the packets and process them + if(type==PACKET_REQUEST_MAPDATA) { + + } else if(type==PACKET_MAPDATA) { + + } +} diff --git a/source/PacketHandler.h b/source/PacketHandler.h new file mode 100644 index 0000000..911a669 --- /dev/null +++ b/source/PacketHandler.h @@ -0,0 +1,5 @@ +#pragma once + +#include "Network.h" + +void processPacket(networkPacket *packet, u8 type); diff --git a/source/main.c b/source/main.c index 80d22e0..a19fdcd 100644 --- a/source/main.c +++ b/source/main.c @@ -41,7 +41,7 @@ void initNewMap() { createAndValidateUndergroundMap(128, 128, 3, 4, map[4], data[4]); } -void setupGame(bool loadUpWorld) { +void setupGame(bool loadUpWorld, bool remote) { currentLevel = 1; // Reset entity manager. @@ -50,29 +50,41 @@ void setupGame(bool loadUpWorld) { initMiniMapData(); - if (!loadUpWorld) { - initNewMap(); - initPlayer(); - resetQuests(); - airWizardHealthDisplay = 2000; - int i; - for (i = 0; i < 5; ++i) { - trySpawn(500, i); - } - addEntityToList(newAirWizardEntity(630, 820, 0), &eManager); - daytime = 6000; - day = 0; - season = 0; - rain = false; - } else { - initPlayer(); - resetQuests(); - loadWorld(currentFileName, &eManager, &player, (u8*) map, (u8*) data); - } - - updateMusic(currentLevel, daytime); + if(!remote) { + if (!loadUpWorld) { + initNewMap(); + initPlayer(); + resetQuests(); + airWizardHealthDisplay = 2000; + int i; + for (i = 0; i < 5; ++i) { + trySpawn(500, i); + } + addEntityToList(newAirWizardEntity(630, 820, 0), &eManager); + daytime = 6000; + day = 0; + season = 0; + rain = false; + } else { + initPlayer(); + resetQuests(); + loadWorld(currentFileName, &eManager, &player, (u8*) map, (u8*) data); + } + + updateMusic(currentLevel, daytime); - initMiniMap(loadUpWorld); + initMiniMap(loadUpWorld); + } else { + //TODO: Can Packets get dropped - if yes, should resending be handled by network functions (so I dont need to do it everywhere) + networkPacket packet = { + .requestMapData = { + .type = PACKET_REQUEST_MAPDATA, + .level = 1 + } + }; + networkSend(&packet, sizeof(packetRequestMapData)); + } + shouldRenderMap = false; mScrollX = 0; mScrollY = 0; @@ -102,72 +114,74 @@ void setupBGMap(bool loadUpWorld) { int xscr = 0, yscr = 0; void tick() { - if (player.p.isDead) { - if (player.p.endTimer < 1) { - currentMenu = MENU_LOSE; - } - --player.p.endTimer; - return; - } else if (player.p.hasWon) { - if (player.p.endTimer < 1) { - currentMenu = MENU_WIN; - } - --player.p.endTimer; - return; - } - - tickTouchMap(); - tickTouchQuickSelect(); - - ++daytime; - //daytime += 20; - if(daytime>=24000) { - daytime -= 24000; - ++day; - //TODO: maybe make season length not as hardcoded + make the transition better (fade to black and back maybe?) - if(day%7==0) { - ++season; - if(season==4) season = 0; + //TODO: Some stuff DOES need to happen even on client side + if(!isRemote) { + if (player.p.isDead) { + if (player.p.endTimer < 1) { + currentMenu = MENU_LOSE; + } + --player.p.endTimer; + return; + } else if (player.p.hasWon) { + if (player.p.endTimer < 1) { + currentMenu = MENU_WIN; + } + --player.p.endTimer; + return; } - rain = false; - if(season!=3 && rand()%5==0) rain = true; - } - if(daytime==6000 && currentLevel==1) { - playMusic(music_floor1); - } else if(daytime==19000 && currentLevel==1) { - playMusic(music_floor1_night); - } - - int i; - for (i = 0; i < 324; ++i) { - int xx = rand() & 127; - int yy = rand() & 127; - tickTile(xx, yy); - } - tickPlayer(); - xscr = player.x - 100; - yscr = player.y - 56; - if (xscr < 16) - xscr = 16; - else if (xscr > 1832) - xscr = 1832; - if (yscr < 16) - yscr = 16; - else if (yscr > 1912) - yscr = 1912; - - if(eManager.lastSlot[currentLevel]<80 && currentLevel != 5) { - trySpawn(1, currentLevel); - } + + tickTouchMap(); + tickTouchQuickSelect(); - for (i = 0; i < eManager.lastSlot[currentLevel]; ++i) { - Entity * e = &eManager.entities[currentLevel][i]; - if ((e->type != ENTITY_ZOMBIE && e->type != ENTITY_SKELETON && e->type != ENTITY_KNIGHT && e->type != ENTITY_SLIME && e->type != ENTITY_PASSIVE) - || (e->type == ENTITY_GLOWWORM && (daytime>6000 || daytime<18000)) - || (e->x > player.x - 160 && e->y > player.y - 125 && e->x < player.x + 160 && e->y < player.y + 125)) - tickEntity(e); - } + ++daytime; + //daytime += 20; + if(daytime>=24000) { + daytime -= 24000; + ++day; + //TODO: maybe make season length not as hardcoded + make the transition better (fade to black and back maybe?) + if(day%7==0) { + ++season; + if(season==4) season = 0; + } + rain = false; + if(season!=3 && rand()%5==0) rain = true; + } + if(daytime==6000 && currentLevel==1) { + playMusic(music_floor1); + } else if(daytime==19000 && currentLevel==1) { + playMusic(music_floor1_night); + } + + int i; + for (i = 0; i < 324; ++i) { + int xx = rand() & 127; + int yy = rand() & 127; + tickTile(xx, yy); + } + tickPlayer(); + xscr = player.x - 100; + yscr = player.y - 56; + if (xscr < 16) + xscr = 16; + else if (xscr > 1832) + xscr = 1832; + if (yscr < 16) + yscr = 16; + else if (yscr > 1912) + yscr = 1912; + + if(eManager.lastSlot[currentLevel]<80 && currentLevel != 5) { + trySpawn(1, currentLevel); + } + for (i = 0; i < eManager.lastSlot[currentLevel]; ++i) { + Entity * e = &eManager.entities[currentLevel][i]; + if ((e->type != ENTITY_ZOMBIE && e->type != ENTITY_SKELETON && e->type != ENTITY_KNIGHT && e->type != ENTITY_SLIME && e->type != ENTITY_PASSIVE) + || (e->type == ENTITY_GLOWWORM && (daytime>6000 || daytime<18000)) + || (e->x > player.x - 160 && e->y > player.y - 125 && e->x < player.x + 160 && e->y < player.y + 125)) + tickEntity(e); + } + } } char debugText[34]; @@ -265,9 +279,11 @@ int main() { if (quitGame) break; - if (initGame > 0) setupGame(initGame == 1 ? true : false); + if (initGame > 0) setupGame(initGame == 1 ? true : false, isRemote); if (initBGMap > 0) setupBGMap(initBGMap == 1 ? true : false); + networkRecieve(); + if (currentMenu == 0) { tick(); sf2d_start_frame(GFX_TOP, GFX_LEFT);