Ejemplo n.º 1
0
        private bool Nearby(Point playerLocation, Enemy enemy, Direction direction, int distance)
        {
            bool isNearby = false;
            Rectangle enemySpriteBoundary = new Rectangle(enemy.Location, enemy.SpriteSize);
            Rectangle playerAttackArea = new Rectangle();

            switch (direction) {
                case Direction.Up:
                    playerAttackArea.Location = new Point(playerLocation.X,
                                                          playerLocation.Y
                                                            - distance);
                    playerAttackArea.Width = game.PlayerSpriteSize.Width;
                    playerAttackArea.Height = distance;
                    break;
                case Direction.Right:
                    playerAttackArea.Location = new Point(playerLocation.X
                                                            + game.PlayerSpriteSize.Width,
                                                          playerLocation.Y);
                    playerAttackArea.Width = distance;
                    playerAttackArea.Height = game.PlayerSpriteSize.Height;
                    break;
                case Direction.Down:
                    playerAttackArea.Location = new Point(playerLocation.X,
                                                          playerLocation.Y
                                                            + game.PlayerSpriteSize.Height);
                    playerAttackArea.Width = game.PlayerSpriteSize.Width;
                    playerAttackArea.Height = distance;
                    break;
                case Direction.Left:
                    playerAttackArea.Location = new Point(playerLocation.X
                                                            + distance,
                                                          playerLocation.Y);
                    playerAttackArea.Width = distance;
                    playerAttackArea.Height = game.PlayerSpriteSize.Height;
                    break;
            }

            if (playerAttackArea.IntersectsWith(enemySpriteBoundary)) {
                isNearby = true;
            }

            return isNearby;
        }
Ejemplo n.º 2
0
        public bool UpdateEnemySprite(Enemy enemy, PictureBox enemySprite, Label enemyHitPoints)
        {
            bool enemySpriteUpdated = false;

            enemyHitPoints.Text = enemy.HitPoints.ToString();

            if (enemy.HitPoints > 0) {
                enemySprite.Location = enemy.Location;
                enemySprite.Visible = true;
                enemySpriteUpdated = true;
            } else {
                enemySprite.Visible = false;
            }

            return enemySpriteUpdated;
        }