The playerStats symbol, located in the playerStats layer of Scene 1 of HUDKit.fla, contains the health textField and health bar shape (healthN, health), weapon icon symbol (weapon), ammunition indicators for the HUD, and a low ammo indicator (reload).
Figure 6: playerStats Symbol The ammunition indicators are broken into six MovieClips, clipN, ammoN, ammo, ammoBG, grenade, and grenadeBG. textFields clipN and ammoN display the amount of remaining ammunition in the form of magazine clips for the weapon and loaded ammo.
The ammo/healthVehicle layer contains two symbols, ammo and ammoBG, each separated into an appropriately sub-layer. Both symbols contain ammunition indicator shapes below the health bar. Each of these symbols is divided into 51 Keyframes, each with one less bullet indicator than the previous Keyframe. GFx::Value::GotoAndStop() is used to visit different Keyframes of these MovieClips, changing the number of shapes displayed to reflect the state of the simulation.
The grenade/armor layer is set up similarly to the ammo layer with two symbols, grenade and grenadeBG, each separated into its own layer. Both symbols contain grenade indicator shapes. As in the ammunition indicators, each of these symbols is divided into 5 Keyframes. Frame 1 has 4 grenade shapes and Frame 5 has none. GFx::Value::GotoAndStop() is used to visit different Keyframes of these MovieClips, changing the number of shapes displayed to reflect the state of the simulation.
The following logic updates the playerStats symbol.
void FxHUDView::UpdatePlayerStats(FxHUDEnvironment *penv) { FxHUDPlayer* pplayer = penv->GetHUDPlayer(); // Load latest player info. unsigned ammoInClip = pplayer->GetNumAmmoInClip(); unsigned ammoClips = pplayer->GetNumClips(); unsigned clipSize = pplayer->GetMaxAmmoInClip(); unsigned grenades = pplayer->GetNumGrenades(); unsigned ammoFrames = 51; unsigned grenadeFrames = 5; String text; if(pplayer->GetHealth() != State.Health) { unsigned health = UInt(pplayer->GetHealth() * 100); Format(text, "{0}", health); HealthNMC.SetText(text); // Update the health text field. Value::DisplayInfo info; info.SetScale(Double(health), 100); HealthMC.SetDisplayInfo(info); // Update and scale the health bar. } if(ammoInClip != State.AmmoInClip) { Format(text, "{0}", ammoInClip); AmmoNMC.SetText(text); // Update the ammo text field. // The ammo is divided into two parts: the white bullet icons (AmmoMC) // and their respective backgrounds (AmmoBGMC). // To update the number of bullets currently in the clip, we use // GotoAndStop with AmmoMC and select the frame with the proper number // of white bullet icons. There are 51 frames in AmmoMC (defined above // in ammoFrames)and the first frame displays every bullet icon. // To display X number of bullets, we subtract X from the total number // of frames in AmmoMC (51) and GotoAndStop on the result. AmmoMC.GotoAndStop(ammoFrames - ammoInClip); } if(ammoClips != State.AmmoClips) { Format(text, "x{0}", ammoClips); ClipNMC.SetText(text); // Update the remaining ammo clips text field. } if(grenades != State.Grenades) { // Grenades are setup similar to Ammo. The first frame for the Grenades movieClip shows 4 white // grenade icons. The second frame shows 3. // To display X number of grenades, we subtract X from the total number // of frames in GrenadeMC (5) and GotoAndStop on the result. // Note: GrenadeMC actually contains 10 frames but 6-10 are unused by this implementation. GrenadeMC.GotoAndStop(grenadeFrames - grenades); } if (pplayer->GetWeaponType() != State.weaponType) { // Change the weapon icon if the player has changed weapons. unsigned weaponFrame = GetWeaponFrame(pplayer->GetWeaponType()); WeaponMC.GotoAndStop(weaponFrame); // Update the ammo background icons based on clipSize. if (clipSize != State.AmmoClipSize) AmmoBGMC.GotoAndStop(ammoFrames - clipSize); } // If the ammo in clip is less than 6 bullets, play the "Reload" indicator movieClip. if (ammoInClip <= 5) { // ReloadMC will play until we GotoAndStop on Frame 1, so no need to start the animation more than // once. if (!bReloadMCVisible) { bReloadMCVisible = true; ReloadMC.GotoAndPlay("on"); // Will cycle back to "on" frame when it reaches the end and play again. } } // If the reload indicator is displayed but there are more than six bullets // hide it and stop the animation by playing frame 1 of the movieClip. else if (bReloadMCVisible) { ReloadMC.GotoAndStop("1"); // Frame 1 contains stop(); bReloadMCVisible = false; } }
In ammo, Frame 1 has 50 bullet indicators and Frame 51 has 0 bullet indicators. Each time the player fires his weapon, ammoMC.GotoAndStop(ammoFrames - ammoInClip) is called to visit the appropriate Keyframe, removing one loaded bullet indicator from the HUD.
For ammoBG, ammoBGMC.GotoAndStop() is used to visit the Keyframe that displays X number of bullet indicator backgrounds. Here, X is based on clip size of the equipped weapon. For example, the Machine Gun has a clip size of 50. Therefore ammoBG.GotoAndStop(1) will display all 50 bullet indicator backgrounds shown in Frame 1. This MovieClip is only updated when the equipped weapon has changed since the last FxHUDView::UpdateView() call.