Esempio n. 1
0
        public Sprite CollideWithHazards(Player hero, Hazards hazards, float deltaTime, Game1 theGame)
        {
            Sprite playerPrediction = PlayerPrediction(hero.playerSprite, deltaTime);

            playerPrediction.position += hero.playerSprite.velocity * deltaTime;

            if (IsColliding(playerPrediction, hazards.hazardsSprite))
            {
                hero.KillPlayer();
            }
            return(hero.playerSprite);
        }
        void LoadObjects()
        {
            foreach (TiledMapObjectLayer layer in map.ObjectLayers)
            {
                if (layer.Name == "Respawn")
                {
                    TiledMapObject thing = layer.Objects[0];
                    if (thing != null)
                    {
                        Sprite respawn = new Sprite();
                        respawn.position  = new Vector2(thing.Position.X, thing.Position.Y);
                        currentCheckpoint = respawn;
                    }
                }

                if (layer.Name == "Enemies")
                {
                    foreach (TiledMapObject thing in layer.Objects)
                    {
                        Enemy   enemy = new Enemy();
                        Vector2 tiles = new Vector2((int)(thing.Position.X / tileHeight), (int)(thing.Position.Y / tileHeight));
                        enemy.enemySprite.position = tiles * tileHeight;
                        enemy.Load(Content, this);
                        enemies.Add(enemy);
                    }
                }

                if (layer.Name == "Key")
                {
                    TiledMapObject thing = layer.Objects[0];
                    if (thing != null)
                    {
                        Key key = new Key();
                        key.keySprite.position = new Vector2(thing.Position.X, thing.Position.Y);
                        key.Load(Content, this);
                        unlock = key;
                    }
                }

                if (layer.Name == "Goal")
                {
                    TiledMapObject thing = layer.Objects[0];
                    if (thing != null)
                    {
                        Chest chest = new Chest();
                        chest.chestSprite.position = new Vector2(thing.Position.X, thing.Position.Y);
                        chest.Load(Content, this);
                        goal = chest;
                    }
                }

                if (layer.Name == "Hazards")
                {
                    foreach (TiledMapObject thing in layer.Objects)
                    {
                        Hazards hazard = new Hazards();
                        Vector2 tiles  = new Vector2((int)(thing.Position.X / tileHeight), (int)(thing.Position.Y / tileHeight));
                        hazard.hazardsSprite.position = tiles * tileHeight;
                        hazard.Load(Content, this);
                        hazards.Add(hazard);
                    }
                }
            }
        }