void update(int *bx, int *by, bool *running) { int keyIn = getKeyboardInput(); if(keyIn != 0) { switch(keyIn) { case 27: // [ESC] endGame(running); break; case 224: // Special key int keyIn2= getKeyboardInput(); switch(keyIn2) { case 75: // [<-] *bx = *bx-1; break; case 77: // [->] *bx = *bx+1; break; case 80: // [ v ] *by = *by+1; break; } break; } } else *by = *by+1; }
void main(void) { View v = View(); v.clear(); v.clearfreeze(); Stein *s1 = new Stein('I'); while(running) { Sleep(refreshRate); v.clear(); int keyIn = getKeyboardInput(); if(keyIn != 0) { switch(keyIn) { case 27: // [ESC] endGame(&running); break; case 224: // Special key int keyIn2= getKeyboardInput(); switch(keyIn2) { case 75: // [<-] s1->move(-1,0); break; case 77: // [->] s1->move(1,0); break; case 80: // [ v ] s1->rotate(); break; } break; } } else { s1->move(0,1); } s1->show(&v); if (s1->checkcol(&v) == 1) { s1->freeze(&v); delete s1; s1 = new Stein('L'); } v.zeichne(); v.linecheck(); } }
int main(void) { /* Related object data */ system_t* system; player_t* player1; player_t* player2; alt_timestamp_start(); int start_time = alt_timestamp(); int wind; int restart = 0; /* initialize all hardware dev */ system = system_init(VIDEO_PIXEL_BUFFER_DMA_NAME, "/dev/video_character_buffer_with_dma_0", ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_NAME, PS2_0_NAME); if (!alt_up_sd_card_is_Present()) { printf("SD card not present\n"); return -2; } else { printf("SD card detected.\n"); } if (!alt_up_sd_card_is_FAT16()) { printf("SD card is not FAT16.\n"); return -3; } else { printf("SD card is FAT 16.\n"); } fireSound = initSoundbank("shotgun.wav"); explosionSound = initSoundbank("big_bomb.wav"); printf("Done Initializing\n"); int end_time = alt_timestamp(); srand(end_time - start_time); clearScreen(system); printf("Press enter to start game"); restartGame(system); while (restart == 1) { /* initialize required objects */ player1 = makePlayer(1, "Lomash"); player2 = makePlayer(2, "TJ"); /* * Draw the screen for the first time. */ store_background_data(); draw_background(system); drawPlayers(system); draw_ground(system); draw_windbox(system); draw_player1GUI(system); draw_player2GUI(system); update_wind(system, wind); draw_health(player1, system); draw_health(player2, system); update_power(player1, system); update_power(player2, system); usleep(2000000); // sleep to wait for video buffer to load while (TRUE) { printf( "\n\n\n\n===========================================================\n"); printf("Player 1 Health = %d \t\t Player 2 Health = %d\n", player1->health, player2->health); wind = rand() % 11 - 5; draw_windbox(system); update_wind(system, wind); // Player 1's turn player_1_jump(system); player_1_jump(system); printf("Getting Player 1 Power.\n"); getKeyboardInput(1, player1, system); // Power skipOneEnter(system); printf("Getting Player 1 Angle.\n"); getKeyboardInput(2, player1, system); // Angle // Player 1 Animation printf("Starting animation\n"); clear_angle_drawer(system); animate_cannon1(system); playSound(fireSound, system->audio); switch (animateShooting(system, player1, wind)) { // different value for result case 1: { update_health(player2, system, -DAMAGE); printf( "Player 1 hit player 2.\n Remaining Health for Player 2: %d\n", player2->health); break; } case 2: { update_health(player1, system, -DAMAGE); printf( "Player 1 hit player 1.\n Remaining Health for Player 1: %d\n", player1->health); break; } default: { break; } } printf("Ended animation\n"); // Post-animation Calculation if (player1->health <= 0 || player2->health <= 0) { break; } // Player 2's turn wind = rand() % 11 - 5; draw_windbox(system); update_wind(system, wind); player_2_jump(system); player_2_jump(system); printf("Getting Player 2 Velocity.\n"); getKeyboardInput(1, player2, system); // Player 2 Angle-Selection skipOneEnter(system); printf("Getting Player 2 Angle.\n"); getKeyboardInput(2, player2, system); // Player 2 Animation printf("Starting animation\n"); clear_angle_drawer(system); animate_cannon2(system); playSound(fireSound, system->audio); // Post-animation Calculation switch (animateShooting(system, player2, wind)) { // different value for result case 1: { update_health(player1, system, -DAMAGE); printf( "Player 2 hit player 1.\n Remaining Health for Player 1: %d\n", player1->health); break; } case 2: { update_health(player2, system, -DAMAGE); printf( "Player 2 hit player 2.\n Remaining Health for Player 2: %d\n", player2->health); break; } default: { break; } } if (player1->health <= 0 || player2->health <= 0) { break; } }; /* * Find out who won. */ if (player1->health <= 0) { printf("Player 2 Wins!!! \n"); draw_P2WIN(system); } else if (player2->health <= 0) { printf("Player 1 Wins!!!\n"); draw_P1WIN(system); } else { printf("we shouldn't be here.\n"); } restart = restartGame(system); } return 0; // FIN }
void InputOptionsState::step_impl() { IMGUI& imgui = IMGUI::getSingleton(); imgui.doCursor(); imgui.doImage(GEN_ID, Vector2(400.0, 300.0), "background"); imgui.doOverlay(GEN_ID, Vector2(0.0, 0.0), Vector2(800.0, 600.0)); std::string lastActionKey = InputManager::getSingleton()->getLastActionKey(); // left player side: imgui.doText(GEN_ID, Vector2(34.0, 10.0), TextManager::OP_LEFT_PLAYER); if (imgui.doButton(GEN_ID, Vector2(80.0, 60.0), getDeviceName(mLeftBlobbyDevice))) { if (mLeftBlobbyDevice == "mouse") { mLeftBlobbyDevice = "keyboard"; } else if (mLeftBlobbyDevice == "keyboard") { mLeftBlobbyDevice = "joystick"; } else if (mLeftBlobbyDevice == "joystick") { if (mRightBlobbyDevice != "mouse") { mLeftBlobbyDevice = "mouse"; } else { mLeftBlobbyDevice = "keyboard"; } } } //if mouse device is selected: if (mLeftBlobbyDevice == "mouse") { handleMouseInput(0, mLeftBlobbyMouseJumpbutton); } if ((mLeftBlobbyMouseJumpbutton == -2) && (InputManager::getSingleton()->getLastMouseButton() == -1)) mLeftBlobbyMouseJumpbutton = -1; //if keyboard device is selected: if (mLeftBlobbyDevice == "keyboard") { handleKeyboardInput(0, lastActionKey, mLeftBlobbyKeyboard); } //if joystick device is selected: if (mLeftBlobbyDevice == "joystick") { handleJoystickInput(0, mLeftBlobbyJoystick); } //right player side: imgui.doText(GEN_ID, Vector2(434.0, 10.0), TextManager::OP_RIGHT_PLAYER); if (imgui.doButton(GEN_ID, Vector2(480.0, 60.0), getDeviceName(mRightBlobbyDevice))) { if (mRightBlobbyDevice == "mouse") { mRightBlobbyDevice = "keyboard"; } else if (mRightBlobbyDevice == "keyboard") { mRightBlobbyDevice = "joystick"; } else if (mRightBlobbyDevice == "joystick") { if (mLeftBlobbyDevice != "mouse") { mRightBlobbyDevice = "mouse"; } else { mRightBlobbyDevice = "keyboard"; } } } //if mouse device is selected: if (mRightBlobbyDevice == "mouse") { handleMouseInput(400, mRightBlobbyMouseJumpbutton); } if ((mRightBlobbyMouseJumpbutton == -2) && (InputManager::getSingleton()->getLastMouseButton() == -1)) mRightBlobbyMouseJumpbutton = -1; //if keyboard device is selected: if (mRightBlobbyDevice == "keyboard") { handleKeyboardInput(400, lastActionKey, mRightBlobbyKeyboard); } //if joystick device is selected: if (mRightBlobbyDevice == "joystick") { handleJoystickInput(400, mRightBlobbyJoystick); } //check if a capture window is open, to set all widgets inactive: if (mLeftBlobbyKeyboard[IA_LEFT] != "" && mLeftBlobbyKeyboard[IA_RIGHT] != "" && mLeftBlobbyKeyboard[IA_JUMP] != "" && mLeftBlobbyJoystick[IA_LEFT] != "" && mLeftBlobbyJoystick[IA_RIGHT] != "" && mLeftBlobbyJoystick[IA_JUMP] != "" && mLeftBlobbyMouseJumpbutton != -1 && mRightBlobbyKeyboard[IA_LEFT] != "" && mRightBlobbyKeyboard[IA_RIGHT] != "" && mRightBlobbyKeyboard[IA_JUMP] != "" && mRightBlobbyJoystick[IA_LEFT] != "" && mRightBlobbyJoystick[IA_RIGHT] != "" && mRightBlobbyJoystick[IA_JUMP] != "" && mRightBlobbyMouseJumpbutton != -1) { imgui.doCursor(true); imgui.doInactiveMode(false); } else { imgui.doInactiveMode(true); imgui.doCursor(false); } //Capture dialogs: getMouseInput(mLeftBlobbyMouseJumpbutton, TextManager::OP_JUMPING); getKeyboardInput(mLeftBlobbyKeyboard[IA_LEFT], TextManager::OP_MOVING_LEFT, lastActionKey); getKeyboardInput(mLeftBlobbyKeyboard[IA_RIGHT], TextManager::OP_MOVING_RIGHT, lastActionKey); getKeyboardInput(mLeftBlobbyKeyboard[IA_JUMP], TextManager::OP_JUMPING, lastActionKey); getJoystickInput(mLeftBlobbyJoystick[IA_LEFT], TextManager::OP_MOVING_LEFT); getJoystickInput(mLeftBlobbyJoystick[IA_RIGHT], TextManager::OP_MOVING_RIGHT); getJoystickInput(mLeftBlobbyJoystick[IA_JUMP], TextManager::OP_JUMPING); getMouseInput(mRightBlobbyMouseJumpbutton, TextManager::OP_JUMPING); getKeyboardInput(mRightBlobbyKeyboard[IA_LEFT], TextManager::OP_MOVING_LEFT, lastActionKey); getKeyboardInput(mRightBlobbyKeyboard[IA_RIGHT], TextManager::OP_MOVING_RIGHT, lastActionKey); getKeyboardInput(mRightBlobbyKeyboard[IA_JUMP], TextManager::OP_JUMPING, lastActionKey); getJoystickInput(mRightBlobbyJoystick[IA_LEFT], TextManager::OP_MOVING_LEFT); getJoystickInput(mRightBlobbyJoystick[IA_RIGHT], TextManager::OP_MOVING_RIGHT); getJoystickInput(mRightBlobbyJoystick[IA_JUMP], TextManager::OP_JUMPING); if (imgui.doButton(GEN_ID, Vector2(224.0, 530.0), TextManager::LBL_OK)) { save(); switchState(new OptionState()); } if (imgui.doButton(GEN_ID, Vector2(424.0, 530.0), TextManager::LBL_CANCEL)) { switchState(new OptionState()); } }