Exemple #1
0
 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
 {
     if (kolobok != null)
     {
         kolobok.Move(keyData);
     }
     return(base.ProcessCmdKey(ref msg, keyData));
 }
Exemple #2
0
        private void Update(TimeSpan dt)
        {
            this.Focus();
            gameTime = gameTime + dt.Milliseconds;

            List <Tank> tanks = (List <Tank>)data.GetTanks();

            for (int i = 0; i < tanks.Count; i++)
            {
                //Tank temp = data.TankMove(tanks[i]);
                //tanks[i] = temp;
                //tanks[i] = data.TankMove(tanks[i]);
                tanks[i].Move();
                if (tanks[i].fire)
                {
                    data.AddBullet(new Bullet(tanks[i], true));
                }
                CheckEntityBounds(tanks[i]);
            }
            data.UpdateTanks(tanks);

            Kolobok kolobok = data.GetKolobok();

            kolobok.Move();
            List <Bullet> bullets = (List <Bullet>)data.GetBullets();

            for (int i = 0; i < bullets.Count; i++)
            {
                bullets[i].Move();
            }
            data.UpdateBullets(bullets);

            CheckEntityBounds(kolobok);

            bullets = CheckEntityBounds(bullets);
            data.UpdateBullets(bullets);

            List <Apple> apples = (List <Apple>)data.GetApples();

            CheckEntityBounds(apples);

            logForm.RefreshLog();

            Map.Refresh();
        }
Exemple #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            apples     = Apple.RemoveHited(apples);
            bullets    = Bullet.RemoveHited(bullets);
            enemies    = EnemyTank.AddExplosion(enemies, this);
            walls      = GameObject.AddExplosion(walls, this);
            explosions = GameObject.RemoveHited(explosions, this);

            if (kolobok.IsHit)
            {
                StopGame();
                return;
            }

            while (apples.Count < 5)
            {
                AddApple();
            }

            List <GameObject> dump = new List <GameObject>();

            foreach (GameObject item in walls)
            {
                dump.Add(item);
            }

            foreach (GameObject item in water)
            {
                dump.Add(item);
            }

            foreach (EnemyTank item in enemies)
            {
                dump.Add(item);
            }

            privStep = now;
            now      = DateTime.Now;
            g.Clear(backgroundColor);

            pictureBox1.Image = bp;

            kolobok.Move(privStep, now, dump);
            kolobok.RemoveApples(apples);
            kolobok.CheckTankCollision(enemies);
            kolobok.CheckBulletCollision(bullets);
            kolobok.Draw(this);

            foreach (GameObject obj in walls)
            {
                obj.Draw(this);
            }

            foreach (GameObject obj in water)
            {
                obj.Draw(this);
            }

            foreach (Apple obj in apples)
            {
                obj.Draw(this);
            }

            foreach (Explosion obj in explosions)
            {
                obj.Draw(this);
            }

            foreach (EnemyTank obj in enemies)
            {
                obj.Move(privStep, now, dump);
                obj.CheckKolobok(kolobok, this);
                obj.Draw(this);
            }

            foreach (Bullet obj in bullets)
            {
                obj.Move(privStep, now, walls, enemies, kolobok);
                obj.Draw(this);
            }

            this.label2.Text = kolobok.Score.ToString();

            if (form2 != null)
            {
                form2.UpdateData(apples, enemies, kolobok);
            }
        }
Exemple #4
0
        private void timerOfGame_Tick(object sender, EventArgs e)
        {
            b = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            CheckCollisions();
            using (Graphics g = Graphics.FromImage(b))
            {
                for (int i = 0; i < walls.Count; i++)
                {
                    walls[i].Render(g);
                }

                water.Render(g);

                Point posOfPlayer = new Point(player.X, player.Y);
                player.Move();
                if (CheckCollisionsWithBounds(player, out int number, out int number2))
                {
                    player.X = posOfPlayer.X;
                    player.Y = posOfPlayer.Y;
                }
                player.Render(g);

                for (int i = 0; i < tanks.Count; i++)
                {
                    List <Point> posOfTank = tanks.Select(t => new Point(t.X, t.Y)).ToList();
                    tanks[i].Move();
                    int anotherTank = CheckCollisionWithAnotherTank(i);
                    if (anotherTank >= 0)
                    {
                        tanks[i].X           = posOfTank[i].X;
                        tanks[i].Y           = posOfTank[i].Y;
                        tanks[anotherTank].X = posOfTank[anotherTank].X;
                        tanks[anotherTank].Y = posOfTank[anotherTank].Y;
                    }
                    if (tanks[i].Fire())
                    {
                        bulletsOfTanks.Add(new Bullet(tanks[i].X, tanks[i].Y, tanks[i].direction, speed));
                    }
                    if (CheckCollisionsWithBounds(tanks[i], out int numb, out int numb2))
                    {
                        tanks[i].X = posOfTank[i].X;
                        tanks[i].Y = posOfTank[i].Y;
                    }
                    tanks[i].Render(g);
                }

                for (int i = 0; i < apples.Count; i++)
                {
                    apples[i].Render(g);
                }

                for (int i = 0; i < bulletsOfPlayer.Count; i++)
                {
                    bulletsOfPlayer[i].Move();
                    bulletsOfPlayer[i].Render(g);
                    if (CheckCollisionsWithBounds(bulletsOfPlayer[i], out int numberOfWall, out int numberOfWall2))
                    {
                        bulletsOfPlayer.RemoveAt(i);
                        if (numberOfWall >= 0)
                        {
                            detonations.Add(new Detonation(walls[numberOfWall].X, walls[numberOfWall].Y));
                            walls.RemoveAt(numberOfWall);
                            if (numberOfWall2 > 0)
                            {
                                walls.RemoveAt(numberOfWall2 - 1);
                            }
                        }
                    }
                }

                for (int i = 0; i < bulletsOfTanks.Count; i++)
                {
                    bulletsOfTanks[i].Move();
                    bulletsOfTanks[i].Render(g);
                    if (CheckCollisionsWithBounds(bulletsOfTanks[i], out int numbOfWall, out int numbOfWall2))
                    {
                        bulletsOfTanks.RemoveAt(i);
                        if (numbOfWall >= 0)
                        {
                            detonations.Add(new Detonation(walls[numbOfWall].X, walls[numbOfWall].Y));
                            walls.RemoveAt(numbOfWall);
                            if (numbOfWall2 > 0)
                            {
                                walls.RemoveAt(numbOfWall2 - 1);
                            }
                        }
                    }
                }

                for (int i = 0; i < detonations.Count; i++)
                {
                    detonations[i].Render(g);
                }
            }
            pictureBox1.Image = b;
            txtScore.Text     = "Apples: " + score;
            detonations.Clear();
        }