void GameModel::Update(double dt) { switch (m_gameState) { case GAME_STATE::IDLE: //Movement if (commands[MOVE_UP]) player->moveUp(); if (commands[MOVE_DOWN]) player->moveDown(); if (commands[MOVE_LEFT]) player->moveLeft(); if (commands[MOVE_RIGHT]) player->moveRight(); if (commands[SHIFT]) player->SetSpeed(8); if (!commands[SHIFT]) player->SetSpeed(3); if (!player->getAcceleration().IsZero()) { m_gameState = GAME_STATE::PLAYER_TURN; steps++; break; } //Open inventory if (commands[INVENT]) { m_gameState = GAME_STATE::INVENTORY; break; } //Item interaction with player if (itemTouched(player) >= 0 && itemTouched(player) < Inventory::TOTAL_ITEM) { if (itemTouched(player) == Inventory::KEY) numKey++; inventory.inventory.AddToInvent(itemTouched(player)); speech.talking = true; speech.Obtain("SpeechText//Obtain.txt", true, inventory.inventory.DefaultItem[itemTouched(player)].getName()); m_itemMap->SetTile(player->getPosition().x, player->getPosition().y, -1); m_gameState = GAME_STATE::SPEECH; break; } //Item interaction with enemies for (std::vector<AI *>::iterator it = AIList.begin(); it != AIList.end(); ++it) { if (itemTouched((*it)) > Inventory::TOTAL_ITEM && itemTouched((*it)) < Inventory::TOTAL_ITEM * 2) { if (itemTouched((*it)) == Inventory::TRAP + Inventory::TOTAL_ITEM) { (*it)->setAiActive(false); m_itemMap->SetTile((*it)->getPosition().x, (*it)->getPosition().y, -1); } } } //Initiate character speech if (commands[SPEECH_NEXTLINE]) { speech.talking = true; const char* temp = speech.CharacterText[ModelSwitch].c_str(); speech.Dialogue(temp); m_gameState = GAME_STATE::SPEECH; break; } //Laser switch if (commands[ACTION]) { if (!player->getDirection().IsZero()) { Vector3 switchPosition = player->getPosition() + player->getDirection(); if (m_tileMap->getTile(switchPosition.x, switchPosition.y) == 299) laserswitch(); } } if ((numKey == totalKey && touchdoor) || died) win = true; if (commands[ACTION] && win) goNext = true; if (!player->getDirection().IsZero()) { if (m_itemMap->getTile(player->getPosition().x, player->getPosition().y) == 50 || m_itemMap->getTile(player->getPosition().x, player->getPosition().y) == 183 || m_itemMap->getTile(player->getPosition().x, player->getPosition().y) == 176 || m_itemMap->getTile(player->getPosition().x, player->getPosition().y) == 88) touchdoor = true; else touchdoor = false; } break; case GAME_STATE::PLAYER_TURN: player->Update(dt, m_tileMap); if (player->getVelocity().IsZero()) { m_gameState = GAME_STATE::AI_TURN; for (std::vector<AI *>::iterator it = AIList.begin(); it != AIList.end(); ++it) { if (checkLineOfSight((*it)->getPosition(), player->getPosition(), m_tileMap)) { (*it)->UpdatePath(player->getPosition(), m_tileMap, ModelSwitch); AITarget = AITARGET::PLAYER; } else if (checkLineOfSight((*it)->getPosition(), hologram, m_tileMap)) { (*it)->UpdatePath(hologram, m_tileMap, ModelSwitch); AITarget = AITARGET::HOLOGRAM; } else { if (AITarget == AITARGET::HOLOGRAM) (*it)->SetStateReturning(); (*it)->UpdatePath(player->getPosition(), m_tileMap, ModelSwitch); } } } break; case GAME_STATE::AI_TURN: { int AIStopped = 0; for (std::vector<AI *>::iterator it = AIList.begin(); it != AIList.end(); ++it) { if ((*it)->getAiActive()) { (*it)->Update(dt); if ((*it)->getSpot() == true) ModelSwitch = 0; if ((*it)->getPosition() == player->getPosition()) died = true; } if (AIList[0]->getVelocity().IsZero()) AIStopped++; } if (AIStopped == AIList.size()) m_gameState = GAME_STATE::IDLE; } break; case GAME_STATE::INVENTORY: if (commands[INVENT]) { m_gameState = GAME_STATE::IDLE; break; } if (commands[ACTION]) { if (inventory.inventory.getItem(inventory.InvCount)->getID() >= Inventory::ITEM_TYPE::MIRROR && inventory.inventory.getItem(inventory.InvCount)->getID() <= Inventory::ITEM_TYPE::THROWABLE) m_gameState = PLACE_ITEM; else if (inventory.inventory.getItem(inventory.InvCount)->getID() >= Inventory::ITEM_TYPE::PLAYERB_BOX && inventory.inventory.getItem(inventory.InvCount)->getID() <= Inventory::ITEM_TYPE::WITCH_BOX) { ModelSwitch = inventory.inventory.getItem(inventory.InvCount)->getID() - 4; speech.talking = true; speech.Obtain("SpeechText//Obtain.txt", false, inventory.inventory.getItem(inventory.InvCount)->getName()); inventory.inventory.UseItem(inventory.InvCount); m_gameState = GAME_STATE::SPEECH;; } } if (commands[MOVE_UP]) inventory.MoveUp(); if (commands[MOVE_DOWN]) inventory.MoveDown(); if (commands[MOVE_LEFT]) inventory.MoveLeft(); if (commands[MOVE_RIGHT]) inventory.MoveRight(); break; case GAME_STATE::PLACE_ITEM: if ((inventory.inventory.getItem(inventory.InvCount)->getID() <= inventory.inventory.THROWABLE && inventory.inventory.getItem(inventory.InvCount)->getID() >= inventory.inventory.MIRROR)) { if (commands[COMMANDS::MOVE_UP]) player->idleUp(); if (commands[COMMANDS::MOVE_DOWN]) player->idleDown(); if (commands[COMMANDS::MOVE_LEFT]) player->idleLeft(); if (commands[COMMANDS::MOVE_RIGHT]) player->idleRight(); if (commands[COMMANDS::ACTION]) { Vector3 placePosition = player->getPosition() + player->getDirection(); if (m_itemMap->getTile(placePosition.x, placePosition.y) < 0) { m_itemMap->SetTile(placePosition.x, placePosition.y, inventory.inventory.getItem(inventory.InvCount)->getID() + Inventory::TOTAL_ITEM); if (inventory.inventory.getItem(inventory.InvCount)->getID() == Inventory::MIRROR) mirror.push_back(placePosition); if (inventory.inventory.getItem(inventory.InvCount)->getID() == Inventory::HOLOGRAM) hologram = placePosition; } speech.talking = true; speech.Obtain("SpeechText//Obtain.txt", false, inventory.inventory.getItem(inventory.InvCount)->getName()); inventory.inventory.UseItem(inventory.InvCount); m_gameState = GAME_STATE::SPEECH; } } break; case GAME_STATE::SPEECH: if (!speech.talking && InstructText) { for (int n = 0; n < speech.InstructionText.size(); n++) { if (speech.InstructionText[n] == InstructFile) { speech.talking = true; const char* temp = speech.InstructionText[n].c_str(); speech.Dialogue(temp); speech.InstructionText[n] = " "; } } InstructFile = ""; if (temp_InstructFile != "") { InstructFile = temp_InstructFile; } else { InstructText = false; } } if (commands[SPEECH_NEXTLINE] && speech.talking) { speech.KeyPressed = true; } if (speech.talking) speech.Update(dt); else m_gameState = GAME_STATE::IDLE; break; } m_mapOffset_x = player->getPosition().x - (float)m_tileMap->getNumOfTilesWidth() / 2.f; m_mapOffset_x = Math::Clamp(m_mapOffset_x, 0.f, (float)(m_tileMap->getMapWidth() - m_tileMap->getNumOfTilesWidth())); m_mapOffset_y = player->getPosition().y - (float)m_tileMap->getNumOfTilesHeight() / 2.f; m_mapOffset_y = Math::Clamp(m_mapOffset_y, 0.f, (float)(m_tileMap->getMapHeight() - m_tileMap->getNumOfTilesHeight())); for (int count = 0; count < NUM_COMMANDS; ++count) commands[count] = false; }
void CMenu::displayMenu(void) { u16 position_castle(36); s8 l_i; // Reset the background system PA_ResetBgSys(); // Initialize the text at the top and bottom screens PA_InitText(1,0); PA_Init16cBg(1, 1); //PA_Init16cBg(1, 1); //PA_InitCustomText(1, 0, PA_Text); //PA_InitText(0,0); PA_Init16cBg(0, 1); // Load the grass background at the top screen PA_EasyBgLoad(1, 2, grass); // Set the screens' brightness to white PA_SetBrightness(1, 31); PA_SetBrightness(0, 31); // Load the title background at the top screen PA_EasyBgLoad(1, 3, title); // Change the brightness of the top screen to neutral (fading) for (l_i = 31; l_i >= 0; l_i--) { PA_SetBrightness(1, l_i); PA_WaitForVBL(); PA_WaitForVBL(); } // Create the sprites for the two castles below the grass level PA_DualCreateSprite(SPRITE_NB_CASTLE1_PART1, (void*)topcastle_Sprite, OBJ_SIZE_64X64, 1, PALETTE_NB_CASTLE, 69, 192-position_castle); PA_DualCreateSprite(SPRITE_NB_CASTLE1_PART2, (void*)castle_Sprite, OBJ_SIZE_64X64, 1, PALETTE_NB_CASTLE, 69, 192+64-position_castle); PA_DualCreateSprite(SPRITE_NB_CASTLE2_PART1, (void*)topcastle_Sprite, OBJ_SIZE_64X64, 1, PALETTE_NB_CASTLE, 151, 192-position_castle); PA_DualCreateSprite(SPRITE_NB_CASTLE2_PART2, (void*)castle_Sprite, OBJ_SIZE_64X64, 1, PALETTE_NB_CASTLE, 151, 192+64-position_castle); // Display the castle sprites behind the grass PA_DualSetSpritePrio (SPRITE_NB_CASTLE1_PART1, 3); PA_DualSetSpritePrio (SPRITE_NB_CASTLE1_PART2, 3); PA_DualSetSpritePrio (SPRITE_NB_CASTLE2_PART1, 3); PA_DualSetSpritePrio (SPRITE_NB_CASTLE2_PART2, 3); // Move gradually the castle sprites above the grass for (position_castle = 36; position_castle <= 90; position_castle++) { PA_WaitForVBL(); PA_DualSetSpriteXY(SPRITE_NB_CASTLE1_PART1, 69, 192-position_castle); PA_DualSetSpriteXY(SPRITE_NB_CASTLE1_PART2, 69, 192+64-position_castle); PA_DualSetSpriteXY(SPRITE_NB_CASTLE2_PART1, 151, 192-position_castle); PA_DualSetSpriteXY(SPRITE_NB_CASTLE2_PART2, 151, 192+64-position_castle); } // Display the main menu PA_EasyBgLoad(0, 0, menu2); PA_SetBrightness(0, 0); // Wait for a player's action m_itemTouched = NO_MODE; while ((m_itemTouched == NO_MODE) || (m_itemTouched == MODE_TWOPLAYERS) || (m_itemTouched == BACK)) { m_itemTouched = itemTouched(); if (m_itemTouched == MODE_INSTRUCTIONS) displayInstructions(); if (m_itemTouched == MODE_TWOPLAYERS) { PA_DeleteBg (0, 0); PA_EasyBgLoad(0, 0, hotseat_wifi); } if (m_itemTouched == BACK) { PA_DeleteBg (0, 0); PA_EasyBgLoad(0, 0, menu2); } PA_WaitForVBL(); } // Delete the castle sprites PA_DualDeleteSprite(SPRITE_NB_CASTLE1_PART1); PA_DualDeleteSprite(SPRITE_NB_CASTLE1_PART2); PA_DualDeleteSprite(SPRITE_NB_CASTLE2_PART1); PA_DualDeleteSprite(SPRITE_NB_CASTLE2_PART2); // Load the empty bottom screen PA_EasyBgLoad(0, 3, bottomscreen); // Activate the Wifi if (m_itemTouched == MODE_WIFI) { PA_DeleteBg (0, 0); PA_EasyBgLoad(1, 2, opponentchoice); l_wifi.goToState(WIFI_STATE_ACTIVE); m_playerOrder = l_wifi.connection(); } // Fading to white at the top screen for (l_i = 0; l_i <=31; l_i++) { PA_SetBrightness(1, l_i); PA_WaitForVBL(); PA_WaitForVBL(); } // Start to play the music #ifndef DEBUG AS_SetMP3Loop(true); AS_SetMP3Volume(m_musicVolume); AS_MP3DirectPlay((u8*)sound9, (u32)sound9_size); #endif CGame l_game; // Main game object // Initialise the game object where m_itemTouched corresponds to the game mode l_game.initGame(m_musicVolume, m_cardSpeed, m_itemTouched, m_playerOrder); // Infinite loop to keep the program running bool finish = false; while(!finish) { // Play the game finish = l_game.play(&m_musicVolume, &m_cardSpeed); PA_WaitForVBL(); } // Stop the music #ifndef DEBUG AS_MP3Stop(); #endif }
bool COptions::display(int *p_musicVolume, int *p_cardSpeed) { // Display the options menu with the resume button selected PA_EasyBgLoad(0, 2, optionsresume); // Set the values for the music volume and card speed // with the function parameters m_musicVolume = *p_musicVolume; m_cardSpeed = *p_cardSpeed; // Display the item sprite at the position that corresponds to the current // music volume switch (m_musicVolume) { case 0: PA_CreateSprite(0, INDEX_SPRITE_NB_ITEM_MUSIC, (void*)item_Sprite, OBJ_SIZE_32X32, 1, PALETTE_NB_ITEM, 137, 52); break; case 60: PA_CreateSprite(0, INDEX_SPRITE_NB_ITEM_MUSIC, (void*)item_Sprite, OBJ_SIZE_32X32, 1, PALETTE_NB_ITEM, 176, 52); break; case 127: PA_CreateSprite(0, INDEX_SPRITE_NB_ITEM_MUSIC, (void*)item_Sprite, OBJ_SIZE_32X32, 1, PALETTE_NB_ITEM, 213, 52); break; default: PA_CreateSprite(0, INDEX_SPRITE_NB_ITEM_MUSIC, (void*)item_Sprite, OBJ_SIZE_32X32, 1, PALETTE_NB_ITEM, 176, 52); break; } // Clone the music volume item sprite to get the card speed item sprite PA_CloneSprite(0, INDEX_SPRITE_NB_ITEM_SPEED, INDEX_SPRITE_NB_ITEM_MUSIC); // Display the cloned item sprite at the position that corresponds // to the current card speed switch (m_cardSpeed) { case 5: PA_SetSpriteXY(0, INDEX_SPRITE_NB_ITEM_SPEED, 137, 99); break; case 10: PA_SetSpriteXY(0, INDEX_SPRITE_NB_ITEM_SPEED, 176, 99); break; case 20: PA_SetSpriteXY(0, INDEX_SPRITE_NB_ITEM_SPEED, 213, 99); break; default: PA_SetSpriteXY(0, INDEX_SPRITE_NB_ITEM_SPEED, 176, 99); break; } // Set the item sprites mode to alpha blending PA_SetSpriteMode(0, INDEX_SPRITE_NB_ITEM_MUSIC, 1); PA_SetSpriteMode(0, INDEX_SPRITE_NB_ITEM_SPEED, 1); // Change the background to the corresponding player's action m_itemTouched = -1; PA_WaitForVBL(); while (!Pad.Newpress.Start) { m_itemTouched = itemTouched(); // Perform the action and return the // player's selection switch(m_itemTouched) { case 1: PA_EasyBgLoad(0, 1, optionsresume); break; case 2: PA_EasyBgLoad(0, 1, optionsmusic); break; case 3: PA_EasyBgLoad(0, 1, optionsspeed); break; case 4: PA_EasyBgLoad(0, 1, optionsno); break; case 5: PA_EasyBgLoad(0, 1, optionsno); break; case 6: PA_EasyBgLoad(0, 1, optionsyes); break; default: break; } // Quit the loop if the player chooses to resume or quit the game if ((m_itemTouched == 1) || (m_itemTouched == 5) || (m_itemTouched == 6)) break; PA_WaitForVBL(); } // Delete the item sprites PA_DeleteSprite(0, INDEX_SPRITE_NB_ITEM_SPEED); PA_DeleteSprite(0, INDEX_SPRITE_NB_ITEM_MUSIC); // Retrieve the music volume and card speed *p_musicVolume = m_musicVolume; *p_cardSpeed = m_cardSpeed; // Return the state of the game switch(m_itemTouched) { case 0: // Resume the game return false; break; case 5: // Resume the game return false; break; case 6: // Quit the game return true; break; default: break; } return false; }