Ejemplo n.º 1
0
        public Game()
        {
            GraphicsEngine.Init();
            level = new Level_1();
            playerBullets = new LinkedList<Bullet>();
            playerRockets = new LinkedList<Rocket>();
            enemyBullets = new LinkedList<Bullet>();
            enemies = new LinkedList<Enemy>();
            explosions = new LinkedList<Explosion>();

            // Init LinkedLists
            deleteRockets = new LinkedList<Rocket>();
            deleteEnemyBullets = new LinkedList<Bullet>();
            deleteExplosions = new LinkedList<Explosion>();
            deletePlayerRockets = new LinkedList<Rocket>();
            deleteEnemies = new LinkedList<Enemy>();

            if(Settings.chosenPlane == 0)
                p1 = new Player(new F20TigerShark(100, 100));
            else if(Settings.chosenPlane == 1)
                p1 = new Player(new F14TomCat(100, 100));
            else
                p1 = new Player(new A10ThunderBolt(100, 100));

            p1Controls.UP = System.Windows.Forms.Keys.Up;
            p1Controls.DOWN = System.Windows.Forms.Keys.Down;
            p1Controls.LEFT = System.Windows.Forms.Keys.Left;
            p1Controls.RIGHT = System.Windows.Forms.Keys.Right;
            p1Controls.A = System.Windows.Forms.Keys.A;
            p1Controls.B = System.Windows.Forms.Keys.S;

            GameInProgress = true;
            CanClose = false;
        }
Ejemplo n.º 2
0
        public void Move()
        {
            if (!GameInProgress)
            {
                TTL--;
                if (TTL <= 0)
                    return;
            }

            if (GameInProgress)
            {
                level.Tick();

                if (level.Enemies.Count != 0)
                if (level.Enemies.First.Value.Ticks == level.Ticks)
                {
                    LinkedListNode<EnemyWrapper> temp = level.Enemies.First;
                        while (temp != null && temp.Value.Ticks == level.Ticks)
                        {
                            enemies.AddLast(temp.Value.EnemyPlane);
                            temp = temp.Next;
                            level.Enemies.RemoveFirst();
                        }
                }
            }

            if (level.CanLevelUP)
                level = level.LevelUP();

            p1.Move();

            foreach (Explosion e in explosions)
            {
                if (e.Status == -1)
                {
                    deleteExplosions.AddFirst(e);
                    continue;
                }
                e.Move();
            }

            foreach (Enemy e in enemies)
            {
                e.Move();
                Bullet b = e.Fire(p1.plane.X, p1.plane.Y);
                if (b != null)
                    enemyBullets.AddFirst(b);
            }

            foreach (Rocket r in playerRockets)
            {
                if (r.X >= BoundsX - 50)
                {
                    deleteRockets.AddFirst(r);
                    continue;
                }
                r.Move();

            }

            foreach (Bullet b in enemyBullets)
            {
                if ((b.X >= BoundsX) || (b.X <= 0) || (b.Y <= 0) || (b.Y >= BoundsY))
                {
                    deleteEnemyBullets.AddFirst(b);
                    continue;
                }
                b.Move();
            }

            if (p1.plane.keys.ctrl == 1)
            {
                // Super Fire ...
            }

            if (p1.plane.keys.alt == 1)
            {
                Rocket r = p1.FireRocket();
                if (r != null)
                    playerRockets.AddLast(r); //ili AddLast?

            }

            foreach (Rocket r in deleteRockets)
                playerRockets.Remove(r);
            deleteRockets.Clear();

            foreach (Bullet b in deleteEnemyBullets)
                enemyBullets.Remove(b);
            deleteEnemyBullets.Clear();

            foreach (Explosion e in deleteExplosions)
                explosions.Remove(e);
            deleteExplosions.Clear();

            foreach (Enemy e in enemies)
            {
                foreach (Rocket r in playerRockets)
                {
                    if (e.Hit(r))
                    {
                        deletePlayerRockets.AddFirst(r);
                        e.Health -= r.Damage;
                        Score += 5;
                        if (e.Health <= 0)
                        {
                            deleteEnemies.AddFirst(e);
                            e.Health = -1;
                            explosions.AddFirst(new Explosion(e.X, e.Y));
                            Score += 10;
                        }
                        continue;
                    }
                }

                if (p1.plane.Hit(e))
                {
                    p1.Health = 100;
                    p1.Lives -= 1;
                    Score += 10;
                    deleteEnemies.AddFirst(e);
                    explosions.AddFirst(new Explosion(e.X, e.Y));
                    if (p1.Lives == 0)
                        GameOver();
                }
            }

            foreach (Bullet b in enemyBullets)
            {
                if (p1.plane.Hit(b))
                {
                    deleteEnemyBullets.AddFirst(b);
                    p1.Health -= b.Damage;
                    if (p1.Health <= 0)
                    {
                        p1.Lives -= 1;
                        p1.Health = 100;
                    }
                    if (p1.Lives == 0)
                        GameOver();
                }
            }

            foreach (Rocket r in deletePlayerRockets)
                playerRockets.Remove(r);
            deletePlayerRockets.Clear();

            foreach (Bullet b in deleteEnemyBullets)
                enemyBullets.Remove(b);
            deleteEnemyBullets.Clear();

            foreach (Enemy e in deleteEnemies)
                enemies.Remove(e);
            deleteEnemies.Clear();
        }