void Terrain::Create( void ) { // Create new maps from Maps directory WCHAR pathBuffer[MAX_PATH]; GetCurrentDirectory(MAX_PATH-1, pathBuffer); std::wstring path(pathBuffer); path += L"\\Maps\\"; WIN32_FIND_DATA file; HANDLE h = FindFirstFile((std::wstring(path) += L"*.txt").c_str(), &file); if (!h) return; do { if ((file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) continue; m_maps.push_back(Map()); m_maps.back().Serialize(std::wstring(path) += file.cFileName); } while (FindNextFile(h, &file)); FindClose(h); NextMap(); }
void BemGame::ProcessMap( Actor* act ) { // Check the current map location and calculate the next. // Turn if we need to. int nX, nY; // Advance the x and y to reflect current map coordinates: switch ( act->dir ) { case NORTH: act->mapY++; break; case SOUTH: act->mapY--; break; case EAST: act->mapX++; break; case WEST: act->mapX--; break; default: GLASSERT( 0 ); } // See where we are going next: int sign = 1; if ( tick & 0x01 ) sign = -1; while ( !NextMap( act->dir, act->mapX, act->mapY, &nX, &nY ) ) { act->dir += sign; act->dir &= 3; } act->sprite->SetAction( dirMap[ act->dir ] ); }
// // Update // void Game::Update() { list<Sprite *>::iterator it; Sprite *curSpr; static bool HPwarning = false; static int chan = NULL; if(showExitConfirm) return; UpdateMessages(); if(player->GetWeapon()==0) RELOAD_TIME = 650; if(player->GetWeapon()==1) RELOAD_TIME = 280; // Update sprites for(it = sprites.begin(); it != sprites.end(); it++) { curSpr = *it; if(curSpr->GetId() == ET_FURBY) { Furby *fb = (Furby *)curSpr; fb->Update(raycaster); } else if(curSpr->GetId() == SHOT_INDEX) { Shot *shot = (Shot *)curSpr; shot->Update(raycaster); if(shot->PointCollWith(raycaster->GetPosX(), raycaster->GetPosY())) { if(player->GetHealth() != 0) { framework->PlaySound(PlayerHurt); } AddMessage("You got hit by a shot from a furby!"); player->DecrementHealth(10); it = sprites.erase(it); } if(shot->IsVanished()) it = sprites.erase(it); } else if(curSpr->GetId() == DEATH_ANIMATION_INDEX) { DeathAnimation *da = (DeathAnimation *)curSpr; da->Update(); if(da->HasEnded()) { float itsX, itsY; itsX = da->GetPosX(); itsY = da->GetPosY(); delete da; it = sprites.erase(it); Sprite *corpse = new Sprite(spriteImgs[2], itsX, itsY, 2); sprites.push_back(corpse); } } if(curSpr->GetId() == ET_SKULL) { Skull *sk = (Skull *)curSpr; sk->Update(raycaster); } else if(curSpr->GetId() == SK_SHOT_INDEX) { SkullShot *skullshot = (SkullShot *)curSpr; skullshot->Update(raycaster); if(skullshot->PointCollWith(raycaster->GetPosX(), raycaster->GetPosY())) { if(player->GetHealth() !=0) { framework->PlaySound(PlayerHurt); } AddMessage("You got hit by a shot from a Skull!"); player->DecrementHealth(20); it = sprites.erase(it); } if(skullshot->IsVanished()) it = sprites.erase(it); } else if(curSpr->GetId() == SKDEATH_ANIMATION_INDEX) { SKDeathAnimation *skda = (SKDeathAnimation *)curSpr; skda->Update(); if(skda->HasEnded()) { float itsX, itsY; itsX = skda->GetPosX(); itsY = skda->GetPosY(); delete skda; it = sprites.erase(it); Sprite *skcorpse = new Sprite(spriteImgs[20], itsX, itsY, 2); sprites.push_back(skcorpse); } } } if(player->GetHealth() <= 30 && HPwarning == false) { chan = framework->PlaySound(HeartBeat, -1); Mix_Volume(chan, MIX_MAX_VOLUME); HPwarning = true; } if(player->GetHealth() > 30 && HPwarning == true) { Mix_HaltChannel(chan); HPwarning = false; } if(player->GetHealth() == 0) { framework->PlaySound(PlayerDead); GameOver(); } if(raycaster->MapChangeNeeded()) NextMap(); }