/// <summary> /// Update the Attack item /// </summary> /// <param name="dt"> A delta time since the last update was called</param> /// <param name="input">A GenericInput to process.</param> public override void Update(TimeSpan dt, GenericInput input) { //on keyboard input determine the Hero's direction if (input is GenericKeyboardInput) { GenericKeyboardInput gki = (GenericKeyboardInput)input; DirectionIn = new Vector2(DirectionX, DirectionY); DetermineDirection(gki); DirectionOut = new Vector2(DirectionX, DirectionY); AnimateHero(); } //on mouse click launch an attack if (input is MouseGenericInput) { MouseGenericInput mgi = (MouseGenericInput)input; if (mgi.MouseInputType == MouseGenericInput.MouseGenericInputType.MouseClick && (DirectionX * DirectionX + DirectionY * DirectionY) != 0) { // create the scene switch message to switch the current scene to the top score scene Message_Attack heroAttack = new Message_Attack("Arrow", this.DirectionX, this.DirectionY, Location, Message_Attack.AttackType.Hero_Arrow, ArrowRange, ArrowDamage); MessageManager.AddMessageItem(heroAttack); } } //update hero location SetLocation(dt); HealthBar = new Windows.Foundation.Rect(Location.X - 10, Location.Y - 10, 50, 5); }
public override void Update(TimeSpan dt, GenericInput input) { base.Update(dt, input); SpawnTimer = DateTime.Now - LastSpawn; if (SpawnTimer.TotalMilliseconds > TimeBetweenSpawns) { Message_SpawnMinions spawn = new Message_SpawnMinions(Level); MessageManager.AddMessageItem(spawn); LastSpawn = DateTime.Now; } }
/// <summary> /// Update the Attack item /// </summary> /// <param name="dt"> A delta time since the last update was called</param> /// <param name="input">A GenericInput to process.</param> public override void Update(TimeSpan dt, GenericInput input) { //boss moves towards hero HeroDirectionVector(); //boss attacks on a timer TimeSinceAttack = DateTime.Now - LastAttack; if (TimeSinceAttack.TotalMilliseconds > TimeBetweenAttacks) { Message_Attack VillainAttack = new Message_Attack("Villain_Attack", DirectionX, DirectionY, this.Location, Message_Attack.AttackType.Minion_Arrow, Range, Damage); MessageManager.AddMessageItem(VillainAttack); LastAttack = DateTime.Now; } //Update bosses location on call to update SetLocation(dt); }
/// <summary> /// Set up the initial state of the scene /// </summary> public override void SetupScene() { // design the scene manually GenericItem title = new GenericItem("Title"); title.Location = new System.Numerics.Vector2(500, 100); title.SetBitmapFromImageDictionary("GameOver"); this.AddObject(title); CenterObject(title, true, false); _start_button = new EvilutionButton("Main Menu", Colors.White, 350, 50); CenterObject(_start_button); this.AddObject(_start_button); if (StoryBoard.SceneHistory.Count > 0) { Score = StoryBoard.SceneHistory.Peek().Score; } _score_label = new EvilutionLabel("SCORE: " + Score, Colors.White, (uint)(this._width * 0.90f), 100); _score_label.Y = _start_button.Y - 200; _score_label.FontSize = 50; CenterObject(_score_label, true, false); this.AddObject(_score_label); // event callbacks _start_button.ButtonClick += _start_button_ButtonClick; void _start_button_ButtonClick(object sender, EvilutionButton_Event e) { // create the scene switch message to switch the current scene to the main game scene Message_SceneSwitch mss = new Message_SceneSwitch("Generic Title Scene"); MessageManager.AddMessageItem(mss); } }
/// <summary> /// Setup the initial state of the scene /// </summary> public override void SetupScene() { // design the scene manually //Title scene is the only sene that starts playing audio by default if (AudioManager.AudioDictionary.TryGetValue("Generic Title Scene", out mp)) { mp.Play(); } //Evilution Title GenericItem title = new GenericItem("Title"); title.Location = new System.Numerics.Vector2(500, 200); title.SetBitmapFromImageDictionary("Title"); this.AddObject(title); CenterObject(title, true, false); //Buttons _start_button = new EvilutionButton("New Game", Colors.White, 350, 50); _top_score_button = new EvilutionButton("Top Scores", Colors.White, 350, 50); _credits_button = new EvilutionButton("Credits", Colors.DarkGray, 350, 50); //Center Buttons CenterObject(_start_button); _top_score_button.Location = new Vector2(_start_button.Location.X, _start_button.Location.Y + _start_button.Size.Height + 10); _credits_button.Location = new Vector2(_top_score_button.Location.X, _top_score_button.Location.Y + _top_score_button.Size.Height + 10); this.AddObject(_start_button); this.AddObject(_top_score_button); this.AddObject(_credits_button); // event callbacks _start_button.ButtonClick += _start_button_ButtonClick; _top_score_button.ButtonClick += _top_score_button_ButtonClick; _credits_button.ButtonClick += _credits_button_ButtonClick; void _credits_button_ButtonClick(object sender, EvilutionButton_Event e) { // create the scene switch message to switch the current scene to the credits scene Message_SceneSwitch mss = new Message_SceneSwitch("Credits Scene"); MessageManager.AddMessageItem(mss); } void _top_score_button_ButtonClick(object sender, EvilutionButton_Event e) { // create the scene switch message to switch the current scene to the top score scene Message_SceneSwitch mss = new Message_SceneSwitch("Top Score Scene"); MessageManager.AddMessageItem(mss); } void _start_button_ButtonClick(object sender, EvilutionButton_Event e) { // create the scene switch message to switch the current scene to the main game scene Message_SceneSwitch mss = new Message_SceneSwitch("Main Game Scene"); MessageManager.AddMessageItem(mss); } }
/// <summary> /// Update the scene based on inputs /// </summary> /// <param name="dt"> A delta time since the last update was called </param> /// <param name="input"> Generic input </param> public override void Update(TimeSpan dt, GenericInput input) { if (mp.PlaybackSession.PlaybackState != MediaPlaybackState.Playing) { mp.PlaybackSession.Position = TimeSpan.Zero; mp.Play(); } foreach (Hero hero in heros) { //update each generic item hero.Update(dt, input); } foreach (Villain villain in villains) { villain.Update(dt, input); //reset the bosses hit image to default image after 300ms of no hits if (villain is Boss) { villain.TimeSinceCollision = DateTime.Now - villain.LastCollision; if (villain.TimeSinceCollision.TotalMilliseconds > 300 && villain.HurtImage) { villain.SetBitmapFromImageDictionary("Boss"); } } //update the hero's location to each villain foreach (Hero hero in heros) { villain.HeroLocation = hero.Location; } } foreach (GenericItem gi in objects) { //update each generic item gi.Update(dt, input); //find out if any of the attacks hit the villains or hero if (gi is Attack) { Attack attack = (Attack)gi; switch (attack.Type) { case (Attack.AttackType.Hero_Arrow): { foreach (Villain villain in villains) { var villainRect = villain.BoundingRectangle; villainRect.Intersect(gi.BoundingRectangle); if (!villainRect.IsEmpty) { villain.TimeSinceCollision = DateTime.Now - villain.LastCollision; if (villain.TimeSinceCollision.TotalMilliseconds > villain.iFrames) { Message_Collision villain_collision = new Message_Collision("Arrow", gi, villain); MessageManager.AddMessageItem(villain_collision); villain.LastCollision = DateTime.Now; if (villain is Boss) { villain.SetBitmapFromImageDictionary("BossHurt"); villain.HurtImage = true; } } } } break; } case (Attack.AttackType.Boss_Arrow): { foreach (Hero hero in heros) { var heroRect = hero.BoundingRectangle; heroRect.Intersect(gi.BoundingRectangle); if (!heroRect.IsEmpty) { hero.TimeSinceCollision = DateTime.Now - hero.LastCollision; if (hero.TimeSinceCollision.TotalMilliseconds > hero.iFrames) { Message_Collision hero_collision = new Message_Collision("Arrow", gi, hero); MessageManager.AddMessageItem(hero_collision); hero.LastCollision = DateTime.Now; } } } break; } } } } }
/// <summary> /// Updates the scene based on incoming messages /// </summary> /// <param name="dt">Delta time since thew last update was called</param> /// <param name="message"> incoming message</param> public override void Update(TimeSpan dt, GenericMessage message) { foreach (GenericItem gi in objects) { //update each generic item gi.Update(dt, message); } foreach (Hero hero in heros) { //update each generic item hero.Update(dt, message); } foreach (Villain villain in villains) { //update each generic item villain.Update(dt, message); } if (message is Message_Attack) { Message_Attack mhe = (Message_Attack)message; switch (mhe.Type) { case (Message_Attack.AttackType.Hero_Arrow): { //(Terry)TODO: add rotation to arrows, this might require using something other than CanvasBitmap images Attack attack = new Attack(mhe.Name, mhe.DirectionX, mhe.DirectionY, mhe.Location, Attack.AttackType.Hero_Arrow, mhe.Range, mhe.Damage); attack.SetBitmapFromImageDictionary("Arrow"); this.AddObject(attack); break; } case (Message_Attack.AttackType.Minion_Arrow): { Attack arrow = new Attack(mhe.Name, mhe.DirectionX, mhe.DirectionY, mhe.Location, Attack.AttackType.Boss_Arrow, mhe.Range, mhe.Damage); arrow.SetBitmapFromImageDictionary("Arrow"); this.AddObject(arrow); break; } } } //if two generic items on the canvas have collided find out what collided and apply aprpriate damage if (message is Message_Collision) { Message_Collision attackInfo = (Message_Collision)message; if (attackInfo.CollisionObject is Attack) { Attack attack = (Attack)attackInfo.CollisionObject; //if the boss is hit by an attack, increase score, reduce bosses health and remove the attack if (attackInfo.Victim is Boss) { Boss boss = (Boss)attackInfo.Victim; boss.CurrentHealth -= attack.Damage; Score += attack.Damage; _score_label.UpdateText("SCORE: " + Score); objects.Remove(attackInfo.CollisionObject); if (boss.CurrentHealth <= 0.0f) { boss.Level += 1; boss.MaxHealth += 100; boss.CurrentHealth = boss.MaxHealth; } } // if the attack hit a minion, remove the attack and the minion else if (attackInfo.Victim is Villain) { Villain villain = (Villain)attackInfo.Victim; villains.Remove(villain); objects.Remove(attackInfo.CollisionObject); } //if the attack hit the hero, reduce hero's health and check for game over else if (attackInfo.Victim is Hero) { Hero hero = (Hero)attackInfo.Victim; hero.CurrentHealth -= attack.Damage; objects.Remove(attackInfo.CollisionObject); if (hero.CurrentHealth <= 0) { heros.Remove(hero); //add tombstone image where hero died? // If all heroes (spelled correctly this time) have died it's game over if (heros.Count <= 0) { game_over = true; } } } } } // switch to game over scene if (game_over) { Message_SceneSwitch mss = new Message_SceneSwitch("Game Over Scene"); MessageManager.AddMessageItem(mss); } if (message is Message_SpawnMinions) { Message_SpawnMinions spawn = (Message_SpawnMinions)message; Random r = new Random(); for (int i = 0; i < spawn.NumberOfMinions; i++) { Villain villain = new Villain("minion"); villain.Location = new System.Numerics.Vector2(r.Next(0, _width), r.Next(0, _height)); villain.SetBitmapFromImageDictionary("MinionLeft"); this.AddObject(villain); } } }