public static void InitializeController()
        {
            window = Program.MainWindow;

            // Subscribe to the notify event
            window.ViewNotification += Window_ViewNotification;
            player = Player.PlayerInstance;
            player.Initialize();
            // Lazy initialization of projectile pool
            projectilePool = ProjectilePool.Instance;
            projectilePool.Initialize();

            /*for (int i = 0; i < MapLoader.MonstersCount; i++)
            {
                IndexPair startPoint = new IndexPair(MapLoader.Monsters[i].StartPoint.X, MapLoader.Monsters[i].StartPoint.Y);
                IndexPair endPoint = new IndexPair(MapLoader.Monsters[i].EndPoint.X, MapLoader.Monsters[i].EndPoint.Y);
                Monster mon = new Monster(startPoint, endPoint);
                movingObjects.Add(mon);
            }*/

            for (int i = 0; i < MapLoader.BombsCount; i++)
            {
                IndexPair start = new IndexPair(MapLoader.Bombs[i].StartPoint.X, MapLoader.Bombs[i].StartPoint.Y);
                BombA bomb = new BombA(start);
                constantObjects.Add(bomb);
            }

            for (int i = 0; i < MapLoader.CoinsCount; i++)
            {
                IndexPair start = new IndexPair(MapLoader.Coins[i].StartPoint.X, MapLoader.Coins[i].StartPoint.Y);
                CoinGift coin = new CoinGift(start);
                constantObjects.Add(coin);
            }

            for (int i = 0; i < MapLoader.BulletsCount; i++)
            {
                IndexPair start = new IndexPair(MapLoader.Bullets[i].StartPoint.X, MapLoader.Bullets[i].StartPoint.Y);
                BulletGift bullet = new BulletGift(start);
                constantObjects.Add(bullet);
            }

            movingObjects.Add(player);
            backgroundIllusionTimer.Interval = 100;
            backgroundIllusionTimer.Elapsed += BackgroundIllusionTimer_Elapsed;
            backgroundIllusionTimer.Enabled = true;

#if !DEBUG

#endif
            drawGraphics += DrawMovingBackground;
            drawGraphics += MapLoader.DrawGameFlares;
            drawGraphics += MapLoader.DrawLevelFloor;
            drawGraphics += MapLoader.DrawLevelObstacles;
            drawGraphics += player.UpdateGraphics;
            drawGraphics += UpdateTiles;
            drawGraphics += DrawShots;
        }
Beispiel #2
0
        /// <summary>
        /// Moves on the 2D Cartesian coordinates, conversion is on checking and drawing only
        /// </summary>
        /// <param name="direction"></param>
        /// <param name="deltaHorizontal"></param>
        /// <param name="deltaVertical"></param>
        private void Move(Directions direction)
        {
            IndexPair temp = playerCoordinates;

            switch (direction)
            {
            case Directions.Up:
                temp.I--;
                break;

            case Directions.Down:
                temp.I++;
                break;

            case Directions.Left:
                temp.J--;
                break;

            case Directions.Right:
                temp.J++;
                break;

            default:
                break;
            }

            // Wall detection
            if (MapLoader.IsWalkable(temp) || MapLoader.Level[temp.I, temp.J] == 6 || MapLoader.Level[temp.I, temp.J] == 7)
            {
                playerCoordinates = temp;
                playerAnimation.AnimationPosition = temp.IndexesToCorrdinates();
                Direction = direction;
                if (MapLoader.Level[temp.I, temp.J] == 7)
                {
                    ProjectilePool pool = ProjectilePool.Instance;
                    IWeapon        y    = pool.Acquire(Position, false);
                    System.Windows.Forms.MessageBox.Show("Gift");
                }
                if (MapLoader.Level[temp.I, temp.J] == 6)
                {
                    playerCoordinates = temp;
                    playerAnimation.AnimationPosition = temp.IndexesToCorrdinates();
                    Direction = direction;

                    System.Threading.Tasks.Task.Run(() =>
                    {
                        System.Threading.Thread.Sleep(100);
                        Program.MainWindow.RefreshTimer.Enabled = false;
                        System.Windows.Forms.MessageBox.Show("Game Over");
                    });
                }
            }
        }