void Player::die(Actor *source) { std::string msg = "You were killed by a "; msg += source->m_name; m_level->m_messages->showMessage(msg,MESSAGE_NOTIFICATION); m_level->m_messages->showMessage("You are dead...",MESSAGE_NOTIFICATION); m_level->m_playerAlive = false; CallbackOverlay winScreen(7,50, "You are dead...", 0, &drawDeathScreen, &handleWinScreen); winScreen.main(m_level); }
int main(void) { int i; int diceRoll = 0; int diceRoll2 = 0; int bet = 0; int payOut = 0; int count = 0; u16 myPalette[] = {BLACK, WHITE, RED, GREEN, BLUE}; //Make Colors for(i=0; i<16384/2; i++) //Stores Text Tiles { CHARBLOCKBASE[1].tileimg[i] = fontdata_8x8[i*2] | (fontdata_8x8[i*2+1]<<8); } for(i=0; i<1600/2; i++) //Stores Dice Tiles { CHARBLOCKBASE[0].tileimg[i] = dice_8x8[i*2] | (dice_8x8[i*2+1]<<8); } for(i=0; i<5; i++) //Stores Palette Colors { PALETTE[i] = myPalette[i]; } REG_DISPCTL = MODE0 | BG0_ENABLE | BG1_ENABLE; REG_BG0HOFS = 0; REG_BG0VOFS = 0; REG_BG0CNT = BG_SIZE0 | SBB(30) | COLOR256 | CBB(0); //Layer for Dice REG_BG1CNT = BG_SIZE0 | SBB(31) | COLOR256 | CBB(1); //Layer for Text STATE gameState = TITLE; //Sets Initial Game State while(1) { switch(gameState) { case TITLE: titleScreen(); while(KEY_DOWN_NOW(BUTTON_START)){}; while(!KEY_DOWN_NOW(BUTTON_START)) { count++; //Time Count for Seeding } srand(count);//Random Seed gameState = CHOOSELINE; clearTextScreen(); waitForVblank(); break; case CHOOSELINE: chooseLineScreen(); //Checks for Bet Type while(!KEY_DOWN_NOW(BUTTON_A) && !KEY_DOWN_NOW(BUTTON_B)){} if(KEY_DOWN_NOW(BUTTON_A)) { gameState = PASSLINEBET; } if(KEY_DOWN_NOW(BUTTON_B)) { gameState = DONTPASSLINEBET; } while(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_B)){} clearTextScreen(); waitForVblank(); break; case PASSLINEBET: passLineScreen(); //Checks for Bet Amount while(!KEY_DOWN_NOW(BUTTON_A) && !KEY_DOWN_NOW(BUTTON_B)){} if(KEY_DOWN_NOW(BUTTON_A)) { bet = 5; } if(KEY_DOWN_NOW(BUTTON_B)) { bet = 25; } while(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_B)){} //Rolls Dice and Computes Results putText(12,0,"Bet Accepted"); waitForVblank(); putText(14,0, "Rolling"); waitForVblank(); diceRoll = rollDice(18,2,50); waitForVblank(); if(diceRoll == 7 || diceRoll == 11) { gameState = WIN; } else if(diceRoll == 2 || diceRoll == 3 || diceRoll == 12) { gameState = LOSE; } else { putText(16,0,"Press Start to Roll Again"); waitForVblank(); while(!KEY_DOWN_NOW(BUTTON_START)) { } diceRoll2 = rollDice(18,9,50); waitForVblank(); if(diceRoll == diceRoll2) { gameState = WIN; } else if(diceRoll == 7) { gameState = LOSE; } else { gameState = LOSE; } } putText(12,16,"Press Start"); putText(14,16,"to See Result"); waitForVblank(); while(!KEY_DOWN_NOW(BUTTON_START)) { } clearTextScreen(); clearMainScreen(); waitForVblank(); break; case DONTPASSLINEBET: dontPassLineScreen(); //Checks for Bet Amount while(!KEY_DOWN_NOW(BUTTON_A) && !KEY_DOWN_NOW(BUTTON_B)){} if(KEY_DOWN_NOW(BUTTON_A)) { bet = 5; } if(KEY_DOWN_NOW(BUTTON_B)) { bet = 25; } while(KEY_DOWN_NOW(BUTTON_A) || KEY_DOWN_NOW(BUTTON_B)){} //Rolls Dice and Computes Results putText(12,0,"Bet Accepted"); waitForVblank(); putText(14,0, "Rolling"); waitForVblank(); diceRoll = rollDice(18,2,50); waitForVblank(); if(diceRoll == 7 || diceRoll == 11) { gameState = LOSE; } else if(diceRoll == 2 || diceRoll == 3 || diceRoll == 12) { gameState = WIN; } else { putText(16,0,"Press Start to Roll Again"); waitForVblank(); while(!KEY_DOWN_NOW(BUTTON_START)) { } diceRoll2 = rollDice(18,9,50); waitForVblank(); if(diceRoll == diceRoll2) { gameState = LOSE; } else if(diceRoll == 7) { gameState = WIN; } else { gameState = WIN; } } putText(12,16,"Press Start"); putText(14,16,"to See Result"); waitForVblank(); while(!KEY_DOWN_NOW(BUTTON_START)) { } clearTextScreen(); clearMainScreen(); waitForVblank(); break; case WIN: payOut = 2*bet; winScreen(payOut); while(KEY_DOWN_NOW(BUTTON_START)){} while(!KEY_DOWN_NOW(BUTTON_START)) { } gameState = TITLE; clearTextScreen(); waitForVblank(); break; case LOSE: loseScreen(); while(KEY_DOWN_NOW(BUTTON_START)){} while(!KEY_DOWN_NOW(BUTTON_START)) { } gameState = TITLE; clearTextScreen(); waitForVblank(); break; } } return 0; }
void Player::doPickUp() { bool showNothingMessage = true; if(m_level->m_dungeon->getGlyph(m_x,m_y) == 28) { m_level->m_messages->showMessage("You absorb the shard of knowledge",MESSAGE_NOTIFICATION); int manaAmount = m_hd/7 + 1; increaseMana(manaAmount); int w = m_level->m_dungeon->m_width; m_level->m_dungeon->m_tiles[m_x+m_y*w] = m_level->m_tileFactory.getTile("Crystal Floor"); showNothingMessage = false; } if(m_level->m_dungeon->getGlyph(m_x,m_y) == 31) { m_level->m_messages->showMessage("Congratulations",MESSAGE_NOTIFICATION); m_level->m_messages->showMessage("You have obtained the Orb of Knowledge",MESSAGE_NOTIFICATION); int w = m_level->m_dungeon->m_width; m_level->m_dungeon->m_tiles[m_x+m_y*w] = m_level->m_tileFactory.getTile("Crystal Floor"); showNothingMessage = false; m_level->m_playerWon = true; CallbackOverlay winScreen(7,50, "You Win!", 0, &drawWinScreen, &handleWinScreen); winScreen.main(m_level); } bool pickedUp = false; std::vector<int> tags; tags.push_back(ITEM_PICK_UP); std::vector<Actor *> actors = m_level->getActors(m_x,m_y,tags); if(m_inventory.size()<26) { if(actors.size()>0) { showNothingMessage = false; std::vector<ListDefinition>itemList; char letter = 'a'; for(unsigned int i=0; i<actors.size(); i++,letter++) { Actor *actor = actors[i]; std::stringstream st; st << actor->m_name; if(actor->hasTag(ITEM_STACK)) { st << " x"; st << actor->m_amount; } itemList.push_back(ListDefinition(LIST_ENTRY, letter, st.str())); } ListOverlay itemOverlay(30, 30, "Pick up what?", itemList.size()>1, true, itemList); itemOverlay.main(m_level); for(unsigned int i=0; i<itemOverlay.m_definition.size(); i++) { ListDefinition &def = itemOverlay.m_definition[i]; if(def.m_selected) { Actor *item = actors[i]; if(item != 0) { std::string msg = "You pick up the "; msg += item->m_name; m_level->m_messages->showMessage(msg,MESSAGE_NOTIFICATION); pickUp(item); m_level->removeActor(item); pickedUp = true; } } } } if(showNothingMessage) { m_level->m_messages->showMessage("There is nothing here to pick up",MESSAGE_NOTIFICATION); } if(pickedUp) act(); } else { if(showNothingMessage) { m_level->m_messages->showMessage("You cannot carry more things",MESSAGE_NOTIFICATION); } } }
int main() { REG_DISPCTL = MODE3 | BG2_ENABLE; int scene = 0; int frameCounter = 0; int timer = 0; int winCondition = 0; int pressed = 0; int pressedLF = 0; int next = 0; //int timeBuffer[41]; //int d = 0; //int count = 0; MOVOBJ ballon = {80, 60, 0, 0, 10, RED}; while(1) // game loop { waitForVblank(); frameCounter++; pressedLF = 0; if (KEY_DOWN_NOW(BUTTON_SELECT)) { fillScreen(BLACK); scene = 0; ballon.size = 10; } if (scene == 0) { titleScreen(); drawString(145, 50, "Press <ENTER> to Start", RED); if (KEY_DOWN_NOW(BUTTON_START)) { scene = 1; timer = 1; fillScreen(BLACK); } } if (scene == 1) { drawRect(ballon.row, ballon.col, ballon.size, ballon.size, RED); drawString(130,80, "Press A!!!", RED); drawString(20, 50, "Blow up the balloon!", RED); if (timer % 3 == 0) { if (winCondition == 0) { scene = 500; fillScreen(BLACK); gameOver(); timer = 1; winCondition = 0; } } if (KEY_DOWN_NOW(BUTTON_A) && pressedLF == 0) { ballon.size = ballon.size + 1; pressedLF = 1; } if (ballon.size == 50) { winCondition = 0; scene = 700; fillScreen(BLACK); scene = 2; } } if (scene == 2) { drawString(10, 80, "Eat the cake!", WHITE); if (timer == 2) { //drawCake(); } next = playLevel2(); if (timer % 4 == 0) { if (winCondition == 0) { scene = 500; drawRect(0,0,240, 160, BLACK); gameOver(); timer = 1; } } if (next == 1) { scene = 700; fillScreen(BLACK); winScreen(); } } if (scene == 500) { //gameOver(); drawString(145, 50, "Better Luck Next Time!", RED); pressed = 0; } if (scene == 700) { drawString(30, 50, "Fine! You beat me...", RED); pressed = 0; } if (frameCounter % 160 == 0) { timer++; } } }
int main() { /* Set display control register to Mode 3 and BG2 */ REG_DISPCTL = MODE3 | BG2_ENABLE; //Sets game up reset(); while(FOREVER) { // Check for paddle movement & collision paddle[0].pcol = paddleInputAndCollision(paddle[0].pcol); //Ball Movement and Collisions ballMovementAndCollision(theBalls, theBricks, paddle[0].pcol, paddle[0].prow, i, k); waitForVblank(); // Erase, Draw New Paddle, and change Paddle position values drawRect3(paddle[0].poldrow, paddle[0].poldcol, PHEIGHT, PWIDTH, BLACK); drawRect3(paddle[0].prow, paddle[0].pcol, PHEIGHT, PWIDTH, paddle[0].color); paddle[0].poldrow = paddle[0].prow; paddle[0].poldcol = paddle[0].pcol; //Loop through each Ball Struct for(i=0; i<NUM; i++) { // Erase old ball & poaddle drawRect3(theBalls[i].oldrow, theBalls[i].oldcol, theBalls[i].size, theBalls [i].size, BLACK); //Checks to see if ball is currently visible and draws it if it is if(theBalls[i].visible == 1) { // Draw new ball & paddle drawRect3(theBalls[i].row, theBalls[i].col, theBalls[i].size, theBalls[i].size, theBalls[i].color); // Transfer values theBalls[i].oldrow = theBalls[i].row; theBalls[i].oldcol = theBalls[i].col; } } //Checks to see if all balls have hit the bottom for(i = 0; i < NUM; i++) ballCount += !theBalls[i].visible; if(ballCount == NUM) //Lose if all balls hit the bottom { //Erases screen elements drawRect3(paddle[0].prow, paddle[0].pcol, PHEIGHT, PWIDTH, BLACK); for(i = 0; i < NUM; i++) { drawRect3(theBalls[i].oldrow, theBalls[i].oldcol, theBalls[i].size, theBalls [i].size, BLACK); theBalls[i].visible = 0; } loseScreen(); //lose screen reset(); //reset game } else //Win if all bricks are hit { ballCount = 0; for(k = 0; k < NUMBRICKS; k++) //Calculates number of bricks hit { brickCount += !theBricks[k].visible; } if(brickCount == NUMBRICKS) //Checks to see if all bricks are hit { //Erase Screen Elements drawRect3(paddle[0].prow, paddle[0].pcol, PHEIGHT, PWIDTH, BLACK); for(i = 0; i < NUM; i++) { drawRect3(theBalls[i].oldrow, theBalls[i].oldcol, theBalls[i].size, theBalls [i].size, BLACK); theBalls[i].visible = 0; } winScreen(); //win screen reset(); //reset game } else brickCount = 0; } } return 0; }