void decomposeReorderMatras ( const IndicClassTable *classTable, le_int32 beginSyllable, le_int32 nextSyllable, le_int32 inv_count ) { le_int32 i; LEErrorCode success = LE_NO_ERROR; for ( i = beginSyllable ; i < nextSyllable ; i++ ) { if ( classTable->isMatra(fOutChars[i+inv_count])) { IndicClassTable::CharClass matraClass = classTable->getCharClass(fOutChars[i+inv_count]); if ( classTable->isSplitMatra(matraClass)) { le_int32 saveIndex = fGlyphStorage.getCharIndex(i+inv_count,success); le_uint32 saveAuxData = fGlyphStorage.getAuxData(i+inv_count,success); const SplitMatra *splitMatra = classTable->getSplitMatra(matraClass); int j; for (j = 0 ; *(splitMatra)[j] != 0 ; j++) { LEUnicode piece = (*splitMatra)[j]; if ( j == 0 ) { fOutChars[i+inv_count] = piece; matraClass = classTable->getCharClass(piece); } else { insertCharacter(piece,i+1+inv_count,saveIndex,saveAuxData); nextSyllable++; } } } if ((matraClass & CF_POS_MASK) == CF_POS_BEFORE) { moveCharacter(i+inv_count,beginSyllable+inv_count); } } } }
/* This is the update function double dt - This is the amount of time in seconds since the previous call was made Game logic should be done here. Such as collision checks, determining the position of your game characters, status updates, etc If there are any calls to write to the console here, then you are doing it wrong. If your game has multiple states, you should determine the current state, and call the relevant function here. */ void update(double dt) { // get the delta time elapsedTime += dt; deltaTime = dt; processUserInput(); // checks if you should change states or do something else with the game, e.g. pause, exit moveCharacter(); // moves the character, collision detection, physics, etc // sound can be played here too. }
void CSPhysXObject_Character::frame(const float &elapsedtime) { float et = elapsedtime; // add the gravity each frame PxVec3 disp(0,0,0); if (!m_Jumping) disp = PxVec3(0, -32.0f, 0); vector3df tf = getTotalForce(); m_TotalForce = vector3df(0, 0, 0); disp += PxVec3(tf.X, tf.Y, tf.Z); disp.y += getHeight(et); PxU32 collisionFlags = moveCharacter(disp, et, 0); if (collisionFlags & PxControllerFlag::eCOLLISION_DOWN) stopJump(); }
void gameplay(){ processUserInput(); // checks if you should change states or do something else with the game, e.g. pause, exit // Cobwebbed if (cobwebToken == 0){ moveCharacter(); // moves the character, collision detection, physics, etc } invincibility(); if (Monster == STARTGAME){ monsterDamage(); // check ghost damage } traps(); // check traps monsterSpawn(); // check for monster spawn guardMovement(); monstersMoveChecker(); // Moving trap function // sound can be played here too. // When the player dies and the gamestate switches to the game over screen if (player.health <= 0){ g_eGameState = GAMEOVER; PlaySound(L"sounds/dietheme.wav", NULL, SND_ASYNC | SND_LOOP); } // When the boss dies and the gamestate switches to the victory screen if (Bhealth <= 0){ g_eGameState = VICTORY; PlaySound(L"sounds/victorytheme.wav", NULL, SND_ASYNC | SND_LOOP); } // When player not in boss room if (gamesoundToken == 0){ if (level != BOSSROOM){ PlaySound(L"sounds/gametheme.wav", NULL, SND_ASYNC | SND_LOOP); gamesoundToken++; } } // When player in boss room if (level == BOSSROOM){ if (bossSoundToken == 0){ PlaySound(L"sounds/bosstheme.wav", NULL, SND_ASYNC | SND_LOOP); bossSoundToken++; } } }
/*This is the update function double dt - This is the amount of time in seconds since the previous call was made Game logic should be done here. Such as collision checks, determining the position of your game characters, status updates, etc If there are any calls to write to the console here, then you are doing it wrong. If your game has multiple states, you should determine the current state, and call the relevant function here.*/ void update(double dt) { //Gets the delta time elapsedTime += dt; deltaTime = dt; //Updates the world grid. Only do it once per level. Set bupdateWorldGrid to true whenever you load a new level. //It will turn itself off after it update once. if (bupdateWorldGrid == true) { updateWorldGrid(g_levelNumber); bupdateWorldGrid = false; } //Updates the position of the camera. moveCameraTo(); //Checks if you should change states or do something else with the game, e.g. pause, exit. processUserInput(); //Sets the position of the teleporters in the level and check if the player can teleport through them in this frame. setItemsInLevel(); //Updates the position of the monsters and if the player is killed by them. monsterUpdate(); //Moves the character, collision detection, physics, etc moveCharacter(); //Updates the position of the box. Ensure that this is called AFTER moveCharacter to prevent glitches. boxesUpdate(); //Checks if the player has walked over an item. detectItemsCollision(); //Update the bullet(?) bulletUpdate(); }
int KyraEngine_v2::o2_moveCharacter(EMCState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v2::o2_moveCharacter(%p) (%d, %d, %d)", (const void *)script, stackPos(0), stackPos(1), stackPos(2)); moveCharacter(stackPos(0), stackPos(1), stackPos(2)); return 0; }
bool IsoClient::event(SDL_Event & event) { static int oldx = 0; static int oldy = 0; static float oldRot = 0; static float oldElv = 0; static float oldScl = 0; bool eaten = gui->event(event); if (eaten) { return true; } switch(event.type) { case SDL_MOUSEMOTION: if (event.motion.state & SDL_BUTTON(2)) { //int w = renderer.getWidth(); //int h = renderer.getHeight(); const float x = event.motion.x; const float y = event.motion.y; float newRot = ((x - oldx) * 360.0f) / renderer.getWidth(); if (oldy > renderer.getHeight()/2) { newRot = oldRot + newRot; } else { newRot = oldRot - newRot; } while (newRot >= 360.0f) { newRot -= 360.0f; }; float newElv = ((y - oldy) * 90.0f) / renderer.getHeight(); newElv = oldElv + newElv; if (newElv < 0) { newElv = 0.0f; } if (newElv > 90) { newElv = 90.0f; } renderer.setRotation(newRot); renderer.setElevation(newElv); return true; } else if (event.motion.state & SDL_BUTTON(3)) { const float y = event.motion.y; const float h = renderer.getHeight(); float newScl = ((h + y - oldy) / h) * oldScl; renderer.setScale(newScl); return true; } break; case SDL_MOUSEBUTTONDOWN: if ((event.button.button == SDL_BUTTON_MIDDLE) || (event.button.button == SDL_BUTTON_RIGHT)) { oldx = event.button.x; oldy = event.button.y; oldRot = renderer.getRotation(); oldElv = renderer.getElevation(); oldScl = renderer.getScale(); } if (event.button.button == SDL_BUTTON_LEFT && inGame) { Eris::Entity * we = m_view->getTopLevel(); Eris::Entity * e = renderer.selectWorld(we, event.motion.x, event.motion.y); if (e == we) { const int x = event.motion.x; const int y = renderer.getHeight() - event.motion.y; renderer.origin(); const float z = renderer.getZ(x, y); // Check that the point clicked on is not in the far // distance if (z < 0.9) { moveCharacter(renderer.getWorldCoord(x, y, z)); } } else if (e != 0) { m_avatar->touch(e); } } return true; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_0: renderer.setElevation(30.0); renderer.setRotation(45.0); return true; break; case SDLK_RETURN: if ((event.key.keysym.mod & KMOD_LALT) || (event.key.keysym.mod & KMOD_LALT)) { renderer.toggleFullscreen(); } break; default: break; } break; } return false; }
void KyraEngine_MR::enterNewSceneUnk1(int facing, int unk1, int unk2) { int x = 0, y = 0; int x2 = 0, y2 = 0; bool needProc = true; if (_mainCharX == -1 && _mainCharY == -1) { switch (facing+1) { case 1: case 2: case 8: x2 = _sceneEnterX3; y2 = _sceneEnterY3; break; case 3: x2 = _sceneEnterX4; y2 = _sceneEnterY4; break; case 4: case 5: case 6: x2 = _sceneEnterX1; y2 = _sceneEnterY1; break; case 7: x2 = _sceneEnterX2; y2 = _sceneEnterY2; break; default: x2 = y2 = -1; } if (x2 >= 316) x2 = 312; if (y2 >= 185) y2 = 183; if (x2 <= 4) x2 = 8; } if (_mainCharX >= 0) { x = x2 = _mainCharX; needProc = false; } if (_mainCharY >= 0) { y = y2 = _mainCharY; needProc = false; } _mainCharX = _mainCharY = -1; if (unk1 && needProc) { x = x2; y = y2; switch (facing) { case 0: y2 = 191; break; case 2: x2 = -24; break; case 4: y2 = y - 4; break; case 6: x2 = 343; break; default: break; } } x2 &= ~3; x &= ~3; y2 &= ~1; y &= ~1; _mainCharacter.facing = facing; _mainCharacter.x1 = _mainCharacter.x2 = x2; _mainCharacter.y1 = _mainCharacter.y2 = y2; initSceneAnims(unk2); if (_mainCharacter.sceneId == 9 && !_soundDigital->isPlaying(_musicSoundChannel)) snd_playWanderScoreViaMap(_sceneList[_mainCharacter.sceneId].sound, 0); if (!unk2) snd_playWanderScoreViaMap(_sceneList[_mainCharacter.sceneId].sound, 0); if (unk1 && !unk2 && _mainCharacter.animFrame != 87) moveCharacter(facing, x, y); }
int levelTwo() { moving = 0; SDL_RenderClear(gt_graphics_get_active_renderer()); ResetBuffer(); backOffset = ((int)camera.x+3200)%3200; offset = ((int)camera.x+1600)%1600; drawSprite(moonBack,0,vec2d(0,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoBackTrees,0,vec2d(-backOffset,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoFrontTrees,0,vec2d(-offset,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoFloor,0,vec2d(-offset,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoFrontTrees,0,vec2d(-offset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoBackTrees,0,vec2d(-backOffset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoFloor,0,vec2d(-offset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); entity_think_all(); entity_touch_all(); entity_update_all(); entity_draw_all(); if(player->position.x >= 300) { camera.x = player->position.x - 300; } if(player->position.x < 300) { camera.x = 0; } if(xDistance == 12000.00) { done = 1; } healthBar(); NextFrame(); SDL_PumpEvents(); diff = (gt_graphics_now - gt_graphics_then); if(playerData.shotTimer>0) { playerData.shotTimer -= diff; } keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_ESCAPE]) { done = 1; } else if(keys[SDL_SCANCODE_W]) { moving = 1; moveCharacter(DIR_UP,player); yDistance = player->position.y; } else if(keys[SDL_SCANCODE_A]) { moving = 1; moveCharacter(DIR_LEFT,player); xDistance = player->position.x; } else if(keys[SDL_SCANCODE_D]) { moving = 1; moveCharacter(DIR_RIGHT,player); xDistance = player->position.x; } else if(keys[SDL_SCANCODE_S]) { moving = 1; moveCharacter(DIR_DOWN,player); yDistance = player->position.y; } else if(keys[SDL_SCANCODE_1]) { fire_Pistol(); } else if(keys[SDL_SCANCODE_2]) { fire_Shotgun(); } else if(keys[SDL_SCANCODE_3]) { fire_Machinegun(); } else if(keys[SDL_SCANCODE_4]) { fire_Heavy_Machinegun(); } else if(keys[SDL_SCANCODE_P]) { saveState(); } else if(keys[SDL_SCANCODE_O]) { loadState(); } if(moving == 0) { resetAnimation(player, 0); } return 0; }
void mode1Loop(Input *pIn,GameOptions* pGameOptions,Screen* pScreen, GameState* pGameState){ MusicManager musicManager; audioInitialization(&musicManager); Mix_PlayMusic(musicManager.music[musicManager.currentMusic], -1); //Jouer infiniment la musique TTFManager ttfManager; ttfInitialization(pScreen,&ttfManager); initPauseText(pScreen, &ttfManager); Character character; characterInitialization(&character,pScreen); Enemies enemies; enemiesInitialization(&enemies,pScreen); Unit seed; initSeed(&seed,pScreen); randomMove(&seed); Collision collision; TimeManager timeManager; timeManager.debutTicks = (long) SDL_GetTicks(); timeManager.playingTime=0; long frame = 0; long frameTime = 0; long delay = 0; int score = 0; Texte scoreTexte = {0}; scoreTexte.rec.x=865; scoreTexte.rec.y=580; scoreTexte.rec.w=0; scoreTexte.rec.h=30; pGameState->lost = 0; //On set la taille du BG du mode pGameOptions->BGRec.x = 0; pGameOptions->BGRec.y = 0; pGameOptions->BGRec.w = PLAYING_AREA_WIDTH; pGameOptions->BGRec.h = PLAYING_AREA_HEIGHT; updateTTFManager(pScreen,&ttfManager,&timeManager,&enemies); updateSeedScore(pScreen, &scoreTexte, score, &ttfManager); while(!pGameState->menu && !pIn->quit && !pGameState->lost){ frameTime = (long) SDL_GetTicks(); frame++; updateInput(pIn); checkCollision(&character,&enemies,&collision,pGameState); moveEnemies(&enemies); moveCharacter(pIn,&collision,&character); //On ajoute un ennemi régulièrement if (frame%240 == 0){ addOneEnemy(&enemies); } //On met à jours l'afficheur du temps de jeu mais pas trop souvent if(frame%20 == 0){ updateTTFManager(pScreen,&ttfManager,&timeManager,&enemies); } //Est ce que le joueur à trouver une seed ? if(checkUnitCollisionWIthCharacter(&seed, &character)){ score ++; randomMove(&seed); updateSeedScore(pScreen, &scoreTexte, score, &ttfManager); } //On affiche l'ensemble SDL_RenderClear(pScreen->renderer); updateScreen(&character,&enemies,pScreen,&ttfManager,pGameOptions); SDL_RenderCopy(pScreen->renderer,seed.pTexture, NULL, &seed.rec); SDL_RenderCopy(pScreen->renderer,scoreTexte.pTexture, NULL, &scoreTexte.rec); SDL_RenderPresent(pScreen->renderer); //Si on vérifie si le joueur veux mettre en pause(P) ou quitter (Q) if(pIn->keys[SDL_SCANCODE_P]){ pGameState->pause=1; pIn->keys[SDL_SCANCODE_P]=0; } if(pIn->keys[SDL_SCANCODE_Q]){ pGameState->menu=1; } //boucle de pause if(pGameState->pause){ //il faut arrêter replacer le compteur de temps après la pause long pauseDebut = (long) SDL_GetTicks(); //on print dans le renderer ce qu'on veut afficher pendant la pause updateScreen(&character,&enemies,pScreen,&ttfManager,pGameOptions); SDL_RenderCopy(pScreen->renderer, ttfManager.pauseTextL1, NULL, &ttfManager.pauseTextL1Rec); SDL_RenderCopy(pScreen->renderer, ttfManager.pauseTextL2, NULL, &ttfManager.pauseTextL2Rec); SDL_RenderCopy(pScreen->renderer, ttfManager.pauseTextL3, NULL, &ttfManager.pauseTextL3Rec); SDL_RenderCopy(pScreen->renderer,seed.pTexture, NULL, &seed.rec); pauseLoop(pGameState,pIn,pScreen); timeManager.debutTicks += (long) SDL_GetTicks() - pauseDebut; } //Code pour attendre une durée de frame fixe delay = pScreen->frameDuration - (long) SDL_GetTicks() + frameTime; if (delay > 0) { SDL_Delay(delay); } } //Si le joueur sort du jeu car il a perdu la partie courante if(pGameState->lost){ pGameState->waiting=1; //Petit son de défaite Mix_PauseMusic(); Mix_PlayChannel(1, musicManager.sound[0], 0); //On print l'affichage de fin de partie updateScreen(&character,&enemies,pScreen,&ttfManager,pGameOptions); SDL_RenderCopy(pScreen->renderer, ttfManager.playAgain, NULL, &ttfManager.playAgainRec); SDL_RenderCopy(pScreen->renderer, ttfManager.BAM, NULL, &ttfManager.BAMRec); SDL_RenderCopy(pScreen->renderer,seed.pTexture, NULL, &seed.rec); //On attend que l'utilisateur décide de rejouer ou non endGameLoop(pIn,pGameState,pScreen); } }
void mode0Loop(Input *pIn,GameState *pGameState,Character *pCharacter,Enemies *pEnemies,Screen *pScreen,Collision *pCollision,MusicManager *pMusicManager,TTFManager * pTTFManager,TimeManager *pTimeManager,GameOptions* pGameOptions){ long frame = 0; long frameTime = 0; long delay = 0; enemiesInitialization(pEnemies,pScreen); pGameState->lost = 0; pTimeManager->debutTicks = (long) SDL_GetTicks(); pTimeManager->playingTime=0; Mix_PlayMusic(pMusicManager->music[pMusicManager->currentMusic], -1); //Jouer infiniment la musique //On set la taille du BG du mode pGameOptions->BGRec.x = 0; pGameOptions->BGRec.y = 0; pGameOptions->BGRec.w = PLAYING_AREA_WIDTH; pGameOptions->BGRec.h = PLAYING_AREA_HEIGHT; while(!pGameState->menu && !pIn->quit && !pGameState->lost){ frameTime = (long) SDL_GetTicks(); frame++; //On ajoute un ennemi régulièrement if (frame%240 == 0){ addOneEnemy(pEnemies); } //On vérifie les collisions checkCollision(pCharacter,pEnemies,pCollision,pGameState); //On met à jour les entrées claviers updateInput(pIn); //On déplace les objets du jeu moveEnemies(pEnemies); moveCharacter(pIn,pCollision,pCharacter); //On met à jours l'afficheur du temps de jeu mais pas trop souvent if(frame%20 == 0){ updateTTFManager(pScreen,pTTFManager,pTimeManager,pEnemies); } //On réaffiche l'ensemble SDL_RenderClear(pScreen->renderer); updateScreen(pCharacter,pEnemies,pScreen,pTTFManager,pGameOptions); SDL_RenderPresent(pScreen->renderer); //Si on a appuyé sur p on rentre dans la boucle de pause if(pIn->keys[SDL_SCANCODE_P]){ pGameState->pause=1; pIn->keys[SDL_SCANCODE_P]=0; } if(pIn->keys[SDL_SCANCODE_Q]){ pGameState->menu=1; } if(pGameState->pause){ //il faut arrêter replacer le compteur de temps après la pause long pauseDebut = (long) SDL_GetTicks(); //on print dans le renderer ce qu'on veut afficher pendant la pause updateScreen(pCharacter,pEnemies,pScreen,pTTFManager,pGameOptions); SDL_RenderCopy(pScreen->renderer, pTTFManager->pauseTextL1, NULL, &pTTFManager->pauseTextL1Rec); SDL_RenderCopy(pScreen->renderer, pTTFManager->pauseTextL2, NULL, &pTTFManager->pauseTextL2Rec); SDL_RenderCopy(pScreen->renderer, pTTFManager->pauseTextL3, NULL, &pTTFManager->pauseTextL3Rec); pauseLoop(pGameState,pIn,pScreen); pTimeManager->debutTicks += (long) SDL_GetTicks() - pauseDebut; } //Code pour attendre une durée de frame fixe delay = pScreen->frameDuration - (long) SDL_GetTicks() + frameTime; if (delay > 0) { SDL_Delay(delay); } } //Le joueur a perdu la partie courante if(pGameState->lost){ pGameState->waiting=1; //Petit son de défaite et on stoppe la musique courante Mix_PauseMusic(); Mix_PlayChannel(1, pMusicManager->sound[0], 0); if(pMusicManager->currentMusic==0){ pMusicManager->currentMusic=1; } else pMusicManager->currentMusic=0; //On print l'affichage de fin de partie updateScreen(pCharacter,pEnemies,pScreen,pTTFManager,pGameOptions); SDL_RenderCopy(pScreen->renderer, pTTFManager->playAgain, NULL, &pTTFManager->playAgainRec); SDL_RenderCopy(pScreen->renderer, pTTFManager->BAM, NULL, &pTTFManager->BAMRec); //On attend que l'utilisateur décide de rejouer ou non endGameLoop(pIn,pGameState,pScreen); } }
/** * runs through all active tiles(tiles within 'area'), and updates them * according to the characters and mines on them. * * @note we may want to reset "this{Tile, Mine, Character}" after each yCount (xCount?) * @note this function is turning out to be bigger and and more complex than I * thought. We may want to break it up into more manageable peices. * * @return true on success */ bool World::update() { if (DEBUG > 1) { printf("World::update(): in World::update()\n"); } // variables to be used int xCount = 0; int yCount = 0; // area is defined in constructor and header Tile *thisTile = NULL; Mine *thisMine = NULL; Character *thisCharacter = NULL; updatetime++; // static bool goalExists; static sf::Clock timer; int curentTime = timer.getElapsedTime().asMilliseconds(); if (DEBUG > 1) { printf("timer is: %d \r ",curentTime); } // curentTime = timer.getElapsedTime().asMilliseconds(); // Allready has this value. if(curentTime > 100) { timer.restart(); curentTime = timer.getElapsedTime().asSeconds(); // start of operations //#pragma omp for schedule(dynamic) // #pragma omp parallel for for (yCount = 0; yCount < area; yCount++) { for (xCount = 0; xCount < area; xCount++) { thisTile = map[xCount][yCount]; if (!thisTile->getIsWall()) { if ((thisMine = thisTile->getHasMine())) { if (thisMine->visibilityCountDown() > 0) { thisTile->setFloor(1); } else { thisTile->setFloor(0); } } if (thisTile->getIsGoal()) { thisTile->setFloor(2); goalExists = true; if (thisTile->getHasCharacter()) { thisTile->getHasCharacter()->updatePoints(2); thisTile->setGoal(false); goalExists = false; if (DEBUG > 1) { printf("World::Update(): Character hit flag\n"); } } } #pragma omp critical(characterMovement) { if ((thisCharacter = thisTile->getHasCharacter())) { if(thisCharacter->getLastUpdate() != updatetime) { // scoreboard->setNewElement(thisCharacter->getID(), thisCharacter->getPoints()); thisCharacter->useController(thisCharacter, window); if (thisCharacter->getMinePlaced()) { placeMine(thisCharacter, thisTile); } if (moveCharacter(thisCharacter, xCount, yCount)) { thisTile->setCharacter(NULL); } thisCharacter->resetDirection(); } if (goalExists) { if (thisCharacter->getIsNpc()) { if ((thisCharacter->getLastAiUpdate() <= updatetime-(14-difficulty)) || !thisCharacter->isStack()) { //#pragma omp critical(astar) //{ npcController.aStar(map, thisCharacter); //} thisCharacter->setLastAiUpdate(updatetime); } } } thisCharacter->setLastUpdate(updatetime); } } } // end if (!thisTile->getIsWall()) } // end xCount // int th_id = omp_get_thread_num(); // printf ("World::update: numTh: %d, thId: %d\r", // omp_get_num_threads(), th_id); } // end yCount if (!goalExists) // If there is no goal then make one; { setGoal(); } //scoreboard->printList(); } return true; }
int main() { initializeCrap(); install_int_ex(increment_speed_counter,BPS_TO_TIMER(120)); int screenMode = 0; //0 for windowed, 1 for fullscreen srand((unsigned)time(NULL)); BITMAP *buffer = create_bitmap(800,600); BITMAP *titleimg = load_bitmap("quiximgTitle.bmp",NULL); BITMAP *imgPlayers = load_bitmap("quiximgPlayerSet.bmp",NULL); MIDI *song = load_midi("quixsong.mid"); PlayerObject poPlayer[4]; LaserObject loLaser[4]; LevelObject Level; MenuObject Menu; float scrollerX = -150.0, scrollerY = 5.0; int winner; poPlayer[0].setControlScheme(0); poPlayer[1].setControlScheme(1); poPlayer[2].setControlScheme(2); poPlayer[3].setControlScheme(3); poPlayer[0].samSound = load_sample("quixp1Death.wav"); poPlayer[1].samSound = load_sample("quixp2Death.wav"); poPlayer[2].samSound = load_sample("quixp3Death.wav"); poPlayer[3].samSound = load_sample("quixp4Death.wav"); poPlayer[0].setX(32); poPlayer[0].setY(32); poPlayer[0].setDir('l'); poPlayer[1].setX(32); poPlayer[1].setY(544); poPlayer[1].setDir('l'); poPlayer[2].setX(736); poPlayer[2].setY(544); poPlayer[2].setDir('r'); poPlayer[3].setX(736); poPlayer[3].setY(32); poPlayer[3].setDir('r'); int mouseDown[21]; //Kind of a crappy array --- Each button is a # //and it's set to true if that button was clicked. for (int i = 0; i < 20; i++) { mouseDown[i] = false; } while ( !Menu.isDone() ) { while (speed_counter > 0) { /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~ MENU SCREEN ~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ if ( Menu.getEnabled() == true ) { if (key[KEY_Z]) { if (Menu.getFullscreen() == true) { Menu.changeScreenSize(0); Menu.setFullscreen(false); } else { Menu.changeScreenSize(1); Menu.setFullscreen(true); } } if (mouse_b & 1) { mouseDownClick(&Menu, mouseDown); } else { mouseUp(&Menu, mouseDown, poPlayer, &Level, song); } } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~ IN-GAME ~~~~~~~~~~~~~~~~~~~~~~~ */ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ else { //Player Input1 if (key[KEY_ESC]) { play_midi(NULL, false); if (Menu.fragLimitHit == true) { Menu.fragLimitHit == false; for (int i=0; i<4; i++) { poPlayer[i].resetScore(); poPlayer[i].resetDeaths(); } poPlayer[0].setX(32); poPlayer[0].setY(32); poPlayer[0].setDir('l'); poPlayer[1].setX(32); poPlayer[1].setY(544); poPlayer[1].setDir('l'); poPlayer[2].setX(736); poPlayer[2].setY(544); poPlayer[2].setDir('r'); poPlayer[3].setX(736); poPlayer[3].setY(32); poPlayer[3].setDir('r'); Menu.fragLimitHit = false; Menu.resetPressed = false; mouseDown[19] = false; } Level.setEnabled(false); Menu.setEnabled(true); } for (int i=0; i<4; i++) { if (poPlayer[i].getControlScheme() == 0) { if (key[KEY_W]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_A]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_S]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_D]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_F]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 1) { if (key[KEY_I]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_J]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_K]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_L]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_H]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 2) { if (key[KEY_UP]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_LEFT]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_DOWN]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_RIGHT]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_RCONTROL]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if (poPlayer[i].getControlScheme() == 3) { if (key[KEY_8_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'u'); } if (key[KEY_4_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'l'); } if (key[KEY_2_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'd'); } if (key[KEY_6_PAD]) { moveCharacter(Level, &poPlayer[i], i, 'r'); } if (key[KEY_PLUS_PAD]) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 4) { //Joystick #1 poll_joystick(); if (joy[0].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[0].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[0].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[0].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[0].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 5) { //Joystick #2 poll_joystick(); if (joy[1].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[1].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[1].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[1].stick[0].axis[0].d2) {moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[1].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 6) { //Joystick #3 poll_joystick(); if (joy[2].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[2].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[2].stick[0].axis[1].d2) {moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[2].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[2].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } else if(poPlayer[i].getControlScheme() == 7) { //Joystick #4 poll_joystick(); if (joy[3].stick[0].axis[1].d1) { moveCharacter(Level, &poPlayer[i], i, 'u'); } //Up if (joy[3].stick[0].axis[0].d1) { moveCharacter(Level, &poPlayer[i], i, 'l'); } //Left if (joy[3].stick[0].axis[1].d2) { moveCharacter(Level, &poPlayer[i], i, 'd'); } //Down if (joy[3].stick[0].axis[0].d2) { moveCharacter(Level, &poPlayer[i], i, 'r'); } //Right if (joy[3].button[0].b || joy[0].button[1].b || joy[0].button[2].b) { if ( loLaser[i].getEnabled() == false ) { shootLaser( &loLaser[i], poPlayer[i]); } } } } if (Level.timeForAPowerupTimer >= 60) { Level.timeForAPowerupTimer = 0; } else { Level.timeForAPowerupTimer++; } } if ( Level.getFrame() < 32 ) { Level.setFrame( Level.getFrame() + 1 ); } else { Level.setFrame(0); } //Score Bar if (Level.getFragLimit() != 0 && Level.getEnabled() == true) { scrollerX += 0.5; if (scrollerX >= 1200.0) { scrollerX = -150.0; } } for (int i=0; i<4; i++) { //Res circle if (poPlayer[i].getRespawnCounter() >= 0) { poPlayer[i].setRespawnCounter( poPlayer[i].getRespawnCounter() + 1); } //"Laser" movement if (loLaser[i].getEnabled() == true) { if (loLaser[i].getDir() == 'u') { loLaser[i].moveUp('l'); } else if (loLaser[i].getDir() == 'd') { loLaser[i].moveDown('l'); } else if (loLaser[i].getDir() == 'l') { loLaser[i].moveLeft('l'); } else if (loLaser[i].getDir() == 'r') { loLaser[i].moveRight('l'); } checkCollision(&loLaser[i], poPlayer, i, Level); } if ((poPlayer[i].returnScore() == Level.getFragLimit()) && (Level.getFragLimit() > 0)) { //Frag Limit hit Menu.fragLimitHit = true; winner = i; } } speed_counter--; }//while (speed_counter > 0) if ( Menu.getEnabled() == true ) { drawMenuStuff(buffer, Menu, titleimg, imgPlayers, Level); } else if (Menu.fragLimitHit == true) { //Show win window! floodfill (buffer, 0, 0, makecol(0,0,0)); textprintf(buffer,font,348,203,makecol(100,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,347,202,makecol(150,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,346,201,makecol(200,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,345,200,makecol(255,0,0), "Player %i Wins!", winner+1 ); textprintf(buffer,font,330,250,makecol(255,0,0), "Player 1 score: %i", poPlayer[0].returnScore() ); textprintf(buffer,font,330,260,makecol(255,0,0), "Player 2 score: %i", poPlayer[1].returnScore() ); textprintf(buffer,font,330,270,makecol(255,0,0), "Player 3 score: %i", poPlayer[2].returnScore() ); textprintf(buffer,font,330,280,makecol(255,0,0), "Player 4 score: %i", poPlayer[3].returnScore() ); textprintf(buffer,font,330,249,makecol(255,255,255), "Player 1 score: %i", poPlayer[0].returnScore() ); textprintf(buffer,font,330,259,makecol(255,255,255), "Player 2 score: %i", poPlayer[1].returnScore() ); textprintf(buffer,font,330,269,makecol(255,255,255), "Player 3 score: %i", poPlayer[2].returnScore() ); textprintf(buffer,font,330,279,makecol(255,255,255), "Player 4 score: %i", poPlayer[3].returnScore() ); textout_centre(buffer, font, "Hit esc to continue", 400, 300, makecol(255,255,255)); } else { generateBackground(buffer, Level); drawCharacters(poPlayer, Level, buffer); drawScoreBar(buffer, poPlayer, scrollerX, scrollerY, Level); if (loLaser[0].getEnabled() == true) { drawLaser(loLaser[0], buffer, Level, 0); } if (loLaser[1].getEnabled() == true) { drawLaser(loLaser[1], buffer, Level, 1); } if (loLaser[2].getEnabled() == true) { drawLaser(loLaser[2], buffer, Level, 2); } if (loLaser[3].getEnabled() == true) { drawLaser(loLaser[3], buffer, Level, 3); } } acquire_screen(); blit(buffer, screen, 0, 0, 0, 0, 800, 600); clear_bitmap(buffer); release_screen(); }//while ( !Menu.isDone() ) return 0; return 0; }
void gameplay() // gameplay logic { processUserInput(); // checks if you should change states or do something else with the game, e.g. pause, exit moveCharacter(); // moves the character, collision detection, physics, etc // sound can be played here too. }