Example #1
0
 public TileEnvironment(Game game, PlayerEntity player, int width, int height)
     : base(game)
 {
     this.player = player;
     location = new Point((int)player.getLocation().X, (int)player.getLocation().Y);
     prevLocation = location;
     this.width = width;
     this.height = height;
     tileset = new Tile[width * height];
     texLoader = new TileTextureLoader();
 }
Example #2
0
        public void Update(PlayerEntity player, GameTime gt)
        {
            target = player.getLocation();
            moveDestination = new Rectangle((int)location.X, (int)location.Y, SIZE, SIZE);
            if (moveDestination.Intersects(player.collisionBox))
            {
                sprite.currentFrame = 0;
                if (!LeGame.AUDIO_IS_MUTED) laughSound.Play();
                isWalking = false;
            }
            else if (Vector2.Distance(location, target) >= FOLLOW_DISTANCE)
            {
                isWalking = false;
                sprite.currentFrame = 0;
            }
            else
            {
                isWalking = true;
                Vector2 direction = location - target;
                direction.Normalize();
                this.angle = Vector2ToRadian(direction) + (float)Math.PI;
                location -= direction * MOVEMENT_SPEED;
                if (laughSound.State == SoundState.Playing) laughSound.Stop();
            }

            if (isWalking) sprite.Update();
        }