using
directives to the top of the class file:using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics;
#region Constructor public ComputerTerminal( Sprite activeSprite, Sprite inactiveSprite, Vector2 mapLocation) { MapLocation = mapLocation; this.activeSprite = activeSprite; this.inactiveSprite = inactiveSprite; } #endregion
#region Public Methods public bool IsCircleColliding(Vector2 otherCenter, float radius) { if (!Active) { return false; } return activeSprite.IsCircleColliding(otherCenter, radius); } public void Deactivate() { Active = false; } public void Update(GameTime gameTime) { if (Active) { float elapsed = (float)gameTime.ElapsedGameTime. TotalSeconds; LastSpawnCounter += elapsed; if (LastSpawnCounter > minSpawnTime) { LastSpawnCounter = 0; } activeSprite.Update(gameTime); } else { inactiveSprite.Update(gameTime); } } public void Draw(SpriteBatch spriteBatch) { if (Active) { activeSprite.Draw(spriteBatch); } else { inactiveSprite.Draw(spriteBatch); } } player goals implementation, robot rampage projectplayer goals implementation, robot rampage projectcomputer terminals, building#endregion
The two possible states of each ComputerTerminal are represented by the two sprites activeSprite
and inactiveSprite
. We also cache the map-square-based location of the ComputerTerminal in the MapLocation
vector. We will use this variable when we spawn enemy robots.
Other than Update()
and Draw()
, we have two public methods. IsCircleColliding()
returns false
if the terminal is not active. Otherwise, it passes the call on to the IsCircleColliding()
method of activeSprite
. The Deactivate()
method simply sets Active
to false
.
During the Update()
method, we check to see if the sprite is active. If it is, the spawn time mechanism is updated. Currently, when it is time to spawn a new robot our Update()
code just resets the timer. We will be revisiting this method after we have constructed our enemy robots. Either the activeSprite
or the inactiveSprite
(depending on the state of the Active
variable) is passed the Update()
call before the method exits.
Similarly, the Draw()
method uses the Active
variable to determine which of the Sprite objects to pass the Draw()
call to.
Now that we have defined the ComputerTerminal class, we need to create a way for them to appear on the game map. We will do this with a new class called GoalManager, which will be responsible for spawning computer terminals in accessible locations and monitoring to see when the player has shut down a computer terminal.
3.145.111.183