Tuesday, November 15, 2011

Tying up loose SmashPc ends

Last night I put my game as it sits on the blog.  I wanted to tie up the last few steps I added.

Here's the latest source code:
SmashPc 11-15-11

First, the Rocket, I added Smoke trails. I added the <SmokeTrails> tag to the SmashPcWeapons.xml.
I also added this Smoke element to the SmashPcItems.xml:
<Smoke Type="Fadeout"> <Image>smoke-small.png</Image> <Interact>No</Interact> <Value>0</Value> <TimeToLive>500</TimeToLive> <Rotate>0</Rotate> </Smoke>

In SmashPcBullet::Draw(), I added this check at the end:
// If we're drawing smoketrails, then lay one down, and set it to fade out if (mbSmokeTrail) { cpVect Loc = mpBody->p; GameLevel::tLevelItem LevelItem; LevelItem.ItemName = "Smoke"; // Set location at back of bullet Loc.x -= cos(mpBody->a)*mpImage->GetWidth()/2; Loc.y -= sin(mpBody->a)*mpImage->GetHeight()/2; LevelItem.Location = Loc; LevelItem.ImageName = ""; // get it from xml SmashPcItem *pSmokeItem = new SmashPcItem(mGameData, mpApp, LevelItem, mpSpace); mGameData.AddActiveItem(pSmokeItem); }

Basically, we add a "Smoke" item every time we update drawing the rocket.  Since the TimeToLive is short, though, it won't be on the screen long.

Now, if we check in SmashPcItem::Draw(), we do this:
// if the type is FadeOut, then lessen tghe alpha if (mpItemDetails->Type == "Fadeout") { sf::Color AlphaColor(0, 0, 0, 255); U32 u32TimeDiff = (timeGetTime() - mu32StartTime)+1; AlphaColor.a = 255 - ((255*u32TimeDiff)/mu32TimeToLive); PhysicalObject::Draw(PlayerLoc, AlphaColor); }

This basically continually lowers the alpha on the image, based on the time to live, and the amount of time it has left to live.  So, this give the "Smoke Trail" as seen in this screen shot:

The other stuff I did was handle changing levels, releasing an item when you kill a specific enemy, game over, and game won.  This wasn't actually a big deal, but I took short cuts.  I really should have created another configuration file that defines the levels, and modified the EnemySpawn items to detail what item to release.

Here's the code, in the main loop before pOurPlayer->CheckInput(), that handles these pieces:

if (pOurPlayer->mu32Health == 0) { // Check for Lives? if (u32Lives > 0) { Sleep(1000); u32Lives--; delete pOurPlayer; pOurPlayer = new SmashPcPlayer(GameData, &App, pMap->GetSpace(), pMap->GetSpawnLocation(), &Weapon); } else { // just quit I guess GameSound::Play("GameOver"); Sleep(4000); break; } } if (GameData.IsLevelOver()) { U32 u32OldArmor = pOurPlayer->mu32Armor; BOOL bGameOver = FALSE; // Change Level if (Level == NumLevels) { bGameOver = TRUE; } else { Level++; } // Call the intermission function // also handles end-game Intermission(&App, pMap, pOurPlayer, &GameData, bGameOver, u32ScreenX, u32ScreenY); // Reset GameData to make sure everything is cleared GameData.Reset(); delete pOurPlayer; delete pMap; // Create new amp with new level data pMap = new SmashPcMap(Levelnames[Level-1].c_str(), GameData, &App); Weapon.AssignSpace(pMap->GetSpace()); // Start player at new spawn locations pOurPlayer = new SmashPcPlayer(GameData, &App, pMap->GetSpace(), pMap->GetSpawnLocation(), &Weapon); // reset old armor pOurPlayer->mu32Armor = u32OldArmor; }

We check 1st if our guy is dead.  if so, delay a second (the SmashPcPlayer->NotifyHit() handles playing the death sound), then restart the guy.  If we're out of lives, play the Game Over sound and then quit.

Then, I check if we've killed all the enemies in the level, and if so, Call the Intermission() function, which basically continues to draw the level, plays music, and puts up the "Level Complete" (or the "You've Won") status.  Reset the GameData (which clears off all items and bullets from the active lists), deletes the player and map, and re-creates the map with the next level.

We tell the Weapon class there's a new Physics Space, create a new player in the new map, and reset the armor.

That's basically it!  The next post will be a kind of postmortem, going of the specifics, and what I could've done better.

No comments:

Post a Comment