public void Update(Player player)
 {
     if (player.isDestroyed && spawning == false)
     {
         SpawnPlayer(player);
     }
 }
Ejemplo n.º 2
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();
        }
        private void SearchAvailableSpawnPoint(Player player)
        {
            spawning = true;

            while (spawning)
            {
                int randomIndex = random.Next(0, spawnPoints.Count - 1);
                var randomSpawnPoint = spawnPoints[randomIndex];

                if (randomSpawnPoint.IsAvailable(Environment.TickCount))
                {
                    player.Respawn(randomSpawnPoint.X, randomSpawnPoint.Y);
                    spawning = false;
                }
            }
        }
 private void SpawnPlayer(Player player)
 {
     new Thread(() => SearchAvailableSpawnPoint(player)).Start();
 }
 private void AddPlayer(int x, int y)
 {
     player = new Player(x, y);
     allGameObjects.Add(player as GameObject);
 }