Exemple #1
0
        public override void Update(GameTime gameTime, GameLevel currentLevel)
        {
            if (currentState == EnemyState.Battle)
            {
                Sword.InitiateAttack();
            }

            Sword.Update(gameTime, currentLevel);
            base.Update(gameTime, currentLevel);
        }
Exemple #2
0
        private void LoadLevels()
        {
            foreach (KeyValuePair<string, string> mapPair in this.mapFiles)
            {
                Song song = null;
                if (songFiles.ContainsKey(mapPair.Key))
                {
                    song = this.game.Content.Load<Song>(songFiles[mapPair.Key]);
                }

                List<EnemyCharacter> enemies = this.mapMaker.GetEnemies(mapPair.Value, this.playerCharacter, this.gameplayScreen);
                List<LevelObject> levelObjects = this.mapMaker.GetObjects(mapPair.Value);
                GameLevel level = new GameLevel(mapPair.Key, this.mapMaker.BuildMap(mapPair.Value), song, playerCharacter, enemies, levelObjects);
                gameLevels.Add(mapPair.Key, level);
            }
        }
Exemple #3
0
        public bool Move(GameTime gameTime, GameLevel currentLevel, out bool hasCollided)
        {
            Rectangle cameraView = gameplayScreen.CameraView;
            bool hasMoved;

            switch (currentState)
            {
                case EnemyState.Patrol:

                    if (HasReachedTarget())
                    {
                        // choose random new target
                        currentTarget = patrolTargets[rand.Next(patrolTargets.Count)];
                        hasMoved = false;
                        hasCollided = false;
                    }
                    else
                    {
                        MoveTowardTarget(currentTarget, currentLevel.LevelMap, gameTime, out hasMoved, out hasCollided);
                    }
                    break;

                case EnemyState.Detection:

                    if (!PlayerInAttackRange())
                    {
                        // move towards player
                        MoveTowardPlayer(currentLevel.LevelMap, gameTime, out hasMoved, out hasCollided);
                    }
                    else
                    {
                        hasMoved = false;
                        hasCollided = false;
                    }
                    break;

                default:
                    hasMoved = false;
                    hasCollided = false;
                    break;
            }

            return hasMoved;
        }
Exemple #4
0
        public virtual void Update(GameTime gameTime, GameLevel currentLevel)
        {
            // act based on state
            bool hasCollided;
            if (PlayerInVisionRange())
            {
                if (PlayerInAttackRange())
                {
                    currentState = EnemyState.Battle;
                }
                else
                {
                    currentState = EnemyState.Detection;
                }
            }
            else
            {
                currentState = EnemyState.Patrol;
            }

            Move(gameTime, currentLevel, out hasCollided);
        }
Exemple #5
0
        public void Update(GameTime gameTime, MoveDirection moveDirection, GameLevel currentLevel, bool playerPressedAttack)
        {
            if (playerPressedAttack)
            {
                Sword.InitiateAttack();
            }

            Sword.Update(gameTime, currentLevel);
            base.Update(gameTime, moveDirection, currentLevel.LevelMap);
        }
Exemple #6
0
 public void Update(GameTime gameTime, GameLevel currentLevel)
 {
     PlayerCharacter.Update(gameTime, KeyInputDirection, currentLevel, PressedAttack());
 }
Exemple #7
0
        public void Update(GameTime gameTime, GameLevel currentLevel)
        {
            bool shouldStopTorture = false;

            if (Animating)
            {

                // set anchor position of sword to be at the center of the character
                anchorPosition.X = swordOwner.Position.X + (swordOwner.CharacterSprite.FrameSize.X / 2);
                anchorPosition.Y = swordOwner.Position.Y + (swordOwner.CharacterSprite.FrameSize.Y / 2);

                // update frame if time to do so, based on framerate
                timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
                if (timeSinceLastFrame > msPerFrame)
                {
                    // reset time since last frame
                    timeSinceLastFrame = 0;
                    if (rotation + DEFAULT_ROTATION_INCREMENT < (2 * Math.PI))
                    {
                        rotation += DEFAULT_ROTATION_INCREMENT;
                    }
                    else
                    {
                        rotation = 0;
                        Animating = false;
                        shouldStopTorture = true;
                        charactersHit.Clear();
                    }
                }

                if (swordOwner is MainCharacter)
                {
                    // check if attack hits enemy
                    foreach (CombatableCharacter character in currentLevel.Enemies)
                    {
                        if (Intersects(character, currentLevel))
                        {
                            character.IsInPain = true;
                            if (!charactersHit.Contains(character))
                            {
                                swordOwner.Attack(character);
                                charactersHit.Add(character);
                                Console.WriteLine("Enemy hit! HP = {0}", character.HitPoints);
                            }
                        }
                        else
                        {
                            character.IsInPain = false;
                        }
                    }
                }
                else
                {
                    EnemyCharacter enemy = swordOwner as EnemyCharacter;
                    if (Intersects(enemy.PlayerCharacter, currentLevel))
                    {
                        enemy.PlayerCharacter.IsInPain = true;
                        enemy.Attack(enemy.PlayerCharacter);
                        if (!charactersHit.Contains(enemy.PlayerCharacter))
                        {
                            charactersHit.Add(enemy.PlayerCharacter);
                        }
                        Console.WriteLine("Player hit! HP = {0}", enemy.PlayerCharacter.HitPoints);
                    }
                    else
                    {
                        enemy.PlayerCharacter.IsInPain = false;
                    }
                }
            }

            if (shouldStopTorture)
            {
                foreach (CombatableCharacter character in currentLevel.Enemies)
                {
                    character.IsInPain = false;
                }
                currentLevel.PlayerCharacter.IsInPain = false;
            }
        }
Exemple #8
0
        // source: http://xbox.create.msdn.com/en-US/education/catalog/tutorial/collision_2d_perpixel_transformed
        public bool Intersects(CombatableCharacter character, GameLevel currentLevel)
        {
            bool intersectionOccured = false;

            // Update the character's transform
            Matrix characterTransform =
                Matrix.CreateTranslation(new Vector3(character.Position, 0.0f));

            // Build the sword's transform
            Matrix swordTransform =
                Matrix.CreateTranslation(new Vector3(-rotationPoint, 0.0f)) *
                Matrix.CreateScale(scale) *
                Matrix.CreateRotationZ(rotation) *
                Matrix.CreateTranslation(new Vector3(anchorPosition, 0.0f));

            // Calculate the bounding rectangle of this block in world space
            int anchorOffset = (int)(rotationPoint.Y - texture.Height);
            Rectangle swordRectangle = CalculateBoundingRectangle(
                     new Rectangle(0, 0,
                         (int)(anchorOffset + texture.Width),
                         (int)(anchorOffset + texture.Height)),
                     swordTransform);

            // The per-pixel check is expensive, so check the bounding rectangles
            // first to prevent testing pixels when collisions are impossible.
            if (character.AsRectangle().Intersects(swordRectangle))
            {
                // Check collision with person
                if (IntersectPixels(characterTransform, character.CharacterSprite.Texture.Width,
                                    character.CharacterSprite.Texture.Height, character.TextureData,
                                    swordTransform, texture.Width,
                                    texture.Height, textureData))
                {
                    intersectionOccured = true;

                }
            }

            return intersectionOccured;
        }