コード例 #1
0
        public static void BossAttackMove(Virus virus)
        {
            //for (int i = 0; i < 5; i++)
            //{
            //    NormalVirus nv = new NormalVirus();
            //}
            //virus.timerEnd = DateTime.Now.AddSeconds(10);

            //// erste Attacke 5 Viren von jedem Typ außer mutiert einen Spawnen unter und über (wenn mögliche Stelle) Boss
            //// zweite Attacke 3 aggressive Viren spawnen auf selbe weise?
            //// dritte Attacke große rote Kugel in richtung Spieler schießen

            //// nie mehr als 8 viren gleichzeitig im level?
        }
コード例 #2
0
 public static void MoveBoss(Virus virus)
 {
     if (virus.Bounds.X > GameState.GameBoardWidth - virus.Bounds.Width - 50)
     {
         virus.Left -= 1;
     }
     else
     {
         if (virus.Bounds.Y > virus.TargetPosition.Y)
         {
             virus.Top -= 1;
         }
         else
         {
             virus.Top += 1;
         }
         if (virus.Bounds.Y == virus.TargetPosition.Y)
         {
             virus.RecalculateRandomPositionBoss();
         }
     }
 }
コード例 #3
0
        public void TeleportVirus(Virus virus, int ChaX, int ChaY)
        {
            Rectangle playerSafeZone = new Rectangle(ChaX - Game.instance.pbCharacterBounds.Width, ChaY - Game.instance.pbCharacterBounds.Height, Game.instance.pbCharacterBounds.Width * 3, Game.instance.pbCharacterBounds.Height * 3);
            Rectangle r;
            Point     newLocation;
            int       x;
            int       y;

            do
            {
                x           = randomizer.Next(0, GameState.GameBoardWidth - virus.Width);
                y           = randomizer.Next(0, GameState.GroundLevel);
                newLocation = new Point(x, y);

                r = new Rectangle(x, y, virus.Width, virus.Height);
            } while (IsThisAFreeSpace(r) == false || r.IntersectsWith(playerSafeZone));

            virus.Location = newLocation;

            DateTime timerStart = DateTime.Now;

            timerEnd = timerStart.AddSeconds(5);
        }
コード例 #4
0
        public void Logic(object sender, EventArgs e)
        {
            if (!Game.instance.lblLevelDisplay.Text.Equals("Level 3"))
            {
                Virus.SpawnVirus();
            }

            if (UiComponents.Viruses.Count == 0 && GameState.BossFight == false)
            {
                Virus.BossFight();
            }


            // regelt Bewegung der Viren
            foreach (var virus in UiComponents.Viruses)
            {
                MoveVirusToTargetPosition(virus);
                if (virus.IsTargetPositionReached())
                {
                    virus.RecalculateTargetPosition();
                }
            }

            // regelt dass Teleporter und Divider zeitbasiertes Event ausführen
            for (int i = UiComponents.Viruses.Count - 1; i >= 0; i--)
            {
                var virus = UiComponents.Viruses[i];

                if (virus is DividerVirus)
                {
                    if (DateTime.Now >= virus.timerEnd && virus.Size.Width > 70)
                    {
                        virus.DivideAction(virus);
                    }
                }
                if (virus is TeleporterVirus)
                {
                    if (DateTime.Now >= virus.timerEnd)
                    {
                        virus.TeleportVirus(virus, CharacterLogic.chaLocX, CharacterLogic.chaLocY);
                    }
                }
                if (virus is BossVirus)
                {
                    if (DateTime.Now >= virus.timerEnd)
                    {
                        BossVirus.BossAttackMove(virus);
                    }
                }
            }


            // regelt Schaden bekommen wenn Spieler von Viren berührt wird
            for (int i = UiComponents.Viruses.Count - 1; i >= 0; i--)
            {
                if (UiComponents.Viruses[i].Bounds.IntersectsWith(Game.instance.pbCharacterBounds.Bounds))
                {
                    if (UiComponents.Viruses[i] is MutatedVirus)
                    {
                        GameState.PlayerHealth -= 3;
                    }
                    else
                    {
                        GameState.PlayerHealth -= 1;
                    }

                    Game.instance.Controls.Remove(UiComponents.Viruses[i]);
                    UiComponents.Viruses[i].Dispose();
                    UiComponents.Viruses.Remove(UiComponents.Viruses[i]);

                    Game.instance.DisplayHealth();
                }
            }
        }
コード例 #5
0
 public static void RemoveVirus(Virus virus)
 {
     Viruses.Remove(virus);
     Components.Remove(virus);
 }
コード例 #6
0
 public static void AddVirus(Virus virus)
 {
     Viruses.Add(virus);
     Components.Add(virus);
 }
コード例 #7
0
ファイル: Game.cs プロジェクト: renmassonne/C--SpielProjekt
//Methode um "hineingehen" in Level zu simulieren und Level zu starten
        private void StartLevel()
        {
            pbCharacterBounds.Location = new Point(-100, GameState.GroundLevel);

            pbCharacterBounds.Image   = Properties.Resources.characterRight;
            pbCharacterBounds.Visible = true;

            System.Windows.Forms.Timer start = new System.Windows.Forms.Timer();
            start.Enabled   = true;
            start.Interval  = 20;
            start.Tick     += new EventHandler(MoveFirstSteps);
            GameState.Score = 0;



            void MoveFirstSteps(object sender, EventArgs e)
            {
                if (pbCharacterBounds.Location.X < 100)
                {
                    pbCharacterBounds.Left += 3;
                }
                else
                {
                    start.Enabled = false;

                    if (GameState.PlayerHealth == 3)
                    {
                        pbHealth.Visible  = true;
                        pbHealth1.Visible = true;
                        pbHealth2.Visible = true;
                    }
                    else if (GameState.PlayerHealth == 2)
                    {
                        pbHealth.Visible  = false;
                        pbHealth1.Visible = true;
                        pbHealth2.Visible = true;
                    }
                    else if (GameState.PlayerHealth == 1)
                    {
                        pbHealth.Visible  = false;
                        pbHealth1.Visible = false;
                        pbHealth2.Visible = true;
                    }
                    //pbHealth.Visible = true;
                    //pbHealth1.Visible = true;
                    //fpbHealth2.Visible = true;
                    lblLevelDisplay.Visible = true;



                    virusTimer.Enabled = true;
                    gameTimer.Enabled  = true;

                    if (lblLevelDisplay.Text.Equals("Level 1"))
                    {
                        PlayTime.Start();
                    }
                    if (lblLevelDisplay.Text.Equals("Level 3"))
                    {
                        Virus.StartBossLevel();
                    }



                    GameTimer              = DateTime.Now;
                    PointObjectTimer       = GameTimer.AddSeconds(10);
                    MutatedVirusSpawnTimer = GameTimer.AddSeconds(25);



                    this.KeyDown += new KeyEventHandler(new KeyDownEventHandler().Game_KeyDown);
                    this.KeyUp   += new KeyEventHandler(new KeyUpEventHandler().Game_KeyUp);
                }
            }
        }
コード例 #8
0
        public void DivideAction(Virus virus)
        {
            DividerVirus dvKlein1 = new DividerVirus();
            DividerVirus dvKlein2 = new DividerVirus();

            ((ISupportInitialize)(dvKlein1)).BeginInit();
            dvKlein1.MouseClick += new MouseEventHandler(Game.instance.MouseClickShootBullet);
            dvKlein1.BackColor   = Color.Transparent;
            dvKlein1.Parent      = Game.instance.pbBackGround;

            // evtl noch einen Killswitch einbauen, sodass es in seltenen Fällen, bei denen absoulut kein Platz in der randomZone ist es zu keinem loop kommt
            Rectangle r;
            Point     newLocation;
            int       x;
            int       y;

            do
            {
                x           = randomizer.Next(virus.Bounds.X - virus.Bounds.Width, virus.Bounds.X + virus.Bounds.Width * 2);
                y           = randomizer.Next(virus.Bounds.Y - virus.Bounds.Height, virus.Bounds.Y + virus.Bounds.Width * 2);
                newLocation = new Point(x, y);


                r = new Rectangle(x, y, 70, 50);
            } while (IsThisAFreeSpace(r) == false);

            dvKlein1.VirusHealth    = 1;
            dvKlein1.Location       = newLocation;
            dvKlein1.Size           = new Size(70, 50);
            dvKlein1.DoubleBuffered = true;
            dvKlein1.Points         = 1;
            UiComponents.AddVirus(dvKlein1);
            ((ISupportInitialize)(dvKlein1)).EndInit();

            ((ISupportInitialize)(dvKlein2)).BeginInit();
            dvKlein2.MouseClick += new MouseEventHandler(Game.instance.MouseClickShootBullet);
            dvKlein2.BackColor   = Color.Transparent;
            dvKlein2.Parent      = Game.instance.pbBackGround;
            // evtl noch einen Killswitch einbauen, sodass es in seltenen Fällen, bei denen absoulut kein Platz in der randomZone ist es zu keinem loop kommt
            do
            {
                x           = randomizer.Next(virus.Bounds.X - virus.Bounds.Width, virus.Bounds.X + virus.Bounds.Width * 2);
                y           = randomizer.Next(virus.Bounds.Y - virus.Bounds.Height, virus.Bounds.Y + virus.Bounds.Width * 2);
                newLocation = new Point(x, y);

                r = new Rectangle(x, y, 70, 50);
            } while (IsThisAFreeSpace(r) == false);
            dvKlein2.Location = newLocation;

            dvKlein2.Size           = new Size(70, 50);
            dvKlein2.DoubleBuffered = true;
            dvKlein2.VirusHealth    = 1;
            dvKlein2.Points         = 1;
            UiComponents.AddVirus(dvKlein2);
            ((ISupportInitialize)(dvKlein2)).EndInit();

            dvKlein1.RecalculateTargetPosition();
            dvKlein2.RecalculateTargetPosition();

            Game.instance.Controls.Remove(virus);
            UiComponents.Viruses.Remove(virus);
            virus.Dispose();
        }