Пример #1
0
        private Graphics render; // Used to render the current frame

        #endregion Fields

        #region Constructors

        public Game(Graphics g)
        {
            frame = new Bitmap(800, 600);
            frameRender = Graphics.FromImage(frame);
            render = g;
            gameThread = new GameThread();
            player = new Player(0, 0);
        }
        private bool started; // Is game started

        #endregion Fields

        #region Constructors

        public Game(Graphics g, Label lblPoints, Label lblLives, Label lblGameOver, Panel menu)
        {
            frame = new Bitmap(800, 600);
            frameRender = Graphics.FromImage(frame);
            render = g;
            gameThread = new GameThread();
            bitMap = GameTeamProject.Properties.Resources.sprites;

            // Labels
            this.lblPoints = lblPoints;
            points = 0;
            this.lblLives = lblLives;
            lives = 1;
            lblLives.Text = "Lives: " + lives;
            this.lblGameOver = lblGameOver;
            this.lblGameOver.Hide();

            mainMenu = menu;

            // Game objects
            player = new Player(0, 0);
            enemies = new List<Enemy>();

            // Map generation
            mapGenerator = new MapGenerator("../../default.lvl");

            Task mapGeneratorTask = Task.Run(() =>
            {
                mapGenerator.Generate();
            });

            mapGeneratorTask.Wait();

            ironWalls = mapGenerator.GetIronWalls();
            destroyableWalls = mapGenerator.GetDestroyableWalls();
            enemySpawnPoints = mapGenerator.GetEnemySpawnPoints();
            playerSpawnPoint = mapGenerator.GetPlayerSpawnPoints();

            // Spawners
            enemySpawner = new EnemySpawner();
            playerSpawner = new PlayerSpawner();

            foreach (var spawnPoint in enemySpawnPoints)
            {
                enemySpawner.AddSpawnPoint(spawnPoint);
            }

            playerSpawner.AddSpawnPoint(playerSpawnPoint);

            // Collision
            allGameObjects = new List<GameObject>();
            InitCollisionEngine();
        }