Example #1
0
        public GameLevel(Game game, GamePlayState gameState, string levenName)
            : base(game)
        {
            this.gameState = gameState;
            levelRaw = ContentPreImporter.GetLevel(levenName);
            levelRend = new LevelRenderer(game, levelRaw);
            levelCollisions = new LevelCollisions(game, levelRaw);
            font = ContentPreImporter.GetFont("TextFont");

            Vector3 playerPos = Vector3.Zero;
            int enemyFound = 0;
            //Build the game level creating the enemies, player and pickups
            for (int y = 0; y < levelRaw.Depth; y++)
            {
                for (int x = 0; x < levelRaw.Width; x++)
                {
                    if (levelRaw.GetAt(x, y).ToString().ToLower() == "p")
                        player = new Player(game, new Vector3(x, 0, y));
                    else if (levelRaw.GetAt(x, y).ToString().ToLower() == "e")
                    {
                        //Depending on the difficulty only add certain enemies
                        enemyFound++;
                        if ((enemyFound % GlobalSettings.EnemyFrequency) == 0)
                        {
                            objects.Add(new RedHead(game, new Vector3(x, 0, y), levelRaw));
                            enemies++;
                        }
                    }
                    else if (levelRaw.GetAt(x, y).ToString().ToLower() == "g")
                    {
                        enemyFound++;
                        if ((enemyFound % GlobalSettings.EnemyFrequency) == 0)
                        {
                            objects.Add(new GreenGhost(game, new Vector3(x, 0, y), levelRaw));
                            enemies++;
                        }
                    }
                    else if (levelRaw.GetAt(x, y).ToString().ToLower() == "h")
                    {
                        objects.Add(new Health(game, new Vector3(x, 0, y)));
                    }
                }
            }

            skybox = new Skybox(Game, 50, ContentPreImporter.GetTexture("grimmnight_small"));
            //Corner of the box if front left, so to place player in right place we need to add .5 to the left and .5 to the front
            objects.Add(player);
            // TODO: Construct any child components here
        }
Example #2
0
        //Check for collisions and call above if so
        public void Update(GameTime gameTime, Player player)
        {
            if (boundingBox.Intersects(player.BoundingBox))
            {
                DoEffect(player);
            }

            //Make it always face the player
            amountOfRotation = -(float)(Math.Atan2(player.Position.Z - position.Z, player.Position.X - position.X) - MathHelper.ToRadians(90));

            billboard.RotateY(amountOfRotation);
            billboard.Update(gameTime);

            base.Update(gameTime);
        }
Example #3
0
 //Add the code for anything this pickup does
 public abstract void DoEffect(Player p);
Example #4
0
        public void Update(GameTime gameTime, Player player, bool seesPlayer)
        {
            //If the enemy sees the player, update the target to the tile the player is on
            if (seesPlayer)
            {
                target = new Vector3((float)Math.Round(player.Position.X), 0, (float)Math.Round(player.Position.Z));
            }

            //If its on the target assign a new random target
            if (target == position)
            {
                target = position + new Vector3((float)rand.NextDouble() - 0.5f, 0, (float)rand.NextDouble() - 0.5f) * 20;
            }

            //If it hits the player, damage the player and reset its position
            if (boundingBox.Intersects(player.BoundingBox))
            {
                position = GetRandomPosition();
                target = position + new Vector3((float)rand.NextDouble() - 0.5f, 0, (float)rand.NextDouble() - 0.5f) * 20;
                player.Hit(Damage);
            }

            //Keep it always facing the player
            amountOfRotation = -(float)(Math.Atan2(target.Z - position.Z, target.X - position.X) - MathHelper.ToRadians(90));

            //Move forward
            Matrix forwardMovement = Matrix.CreateRotationY(amountOfRotation);
            Vector3 v = new Vector3(0, 0, ForwardSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds);
            v = Vector3.Transform(v, forwardMovement);

            velocity += v;
            MoveForward(gameTime);
            boundingBox = new BoundingBox(position + boxMin, position + boxMax);
            billboard.Move(position + new Vector3(0, 0.25f, 0));
            billboard.RotateY(amountOfRotation);
            billboard.Update(gameTime);

            base.Update(gameTime);
        }