@Override
	public void update(int delta) {
		float speed = normSpeed;
		if (isHooked){
			speed = runSpeed;
			attackTime += delta;
			if (attackTime >= despawnTime){
				isDespawned = true;
				return;
			}
		}
		//randomly determines the next move to make if idling.
		if (isIdle && !isMoving && tilesToMove <= 0){
			Random r = new Random();
			int k = r.nextInt(200);
			if (k == 0){
				tilesToMove = r.nextInt(12) + 1;
				setFacing(Facing.EAST);
				move(Facing.EAST);
			}
			else if (k == 1){
				tilesToMove = r.nextInt(12) + 1;
				setFacing(Facing.WEST);
				move(Facing.WEST);
			}
			else if (k == 2){
				tilesToMove = r.nextInt(12) + 1;
				setFacing(Facing.SOUTH);
				move(Facing.SOUTH);
			}
			else if(k == 3){
				tilesToMove = r.nextInt(12) + 1;
				setFacing(Facing.NORTH);
				move(Facing.NORTH);
			}
		}
		if (!isIdle && isHooked && !isMoving){
			Vector2f v = hookedPlayer.getLocation();
			Vector2f m = getLocation();
			float dx = Math.abs(v.x - m.x);
			float dy = Math.abs(v.y - m.y);
			if (boundingRect.intersects(hookedPlayer)){
				float x = v.x + 16;
				float y = v.y + 16;
				dx = Math.abs(x - center.x);
				dy = Math.abs(y - center.y);
				
				if (dx > dy){
					if (center.x < v.x){
						setFacing(Facing.EAST);
					}
					else{
						setFacing(Facing.WEST);
					}
				}
				else{
					if (center.y < v.y){
						setFacing(Facing.SOUTH);
					}
					else{
						setFacing(Facing.NORTH);
					}
				}
				attack();
				return;
			}
			
			if (dx >= dy){
				if (m.x < v.x){
					setFacing(Facing.EAST);
					move(Facing.EAST);
				}
				else{
					setFacing(Facing.WEST);
					move(Facing.WEST);
				}
			}
			else{
				if (m.y < v.y){
					setFacing(Facing.SOUTH);
					move(Facing.SOUTH);
				}
				else{
					setFacing(Facing.NORTH);
					move(Facing.NORTH);
				}
			}
		}
		if (isMoving){
			anim.update(delta);
			Facing face = getFacing();
			if (face == Facing.EAST){
				movingValueX += speed * delta;
				if (movingValueX >= targetX){
					isMoving = false;
					setX(getX() + targetX);
				}
			}
			else if (face == Facing.WEST){
				movingValueX -= speed * delta;
				if (movingValueX <= targetX){
					isMoving = false;
					setX(getX() - targetX);
				}
			}
			else if (face == Facing.SOUTH){
				movingValueY += speed * delta;
				if (movingValueY >= targetY){
					isMoving = false;
					setY(getY() + targetY);
				}
			}
			else{
				movingValueY -= speed * delta;
				if (movingValueY <= targetY){
					isMoving = false;
					setY(getY() - targetY);
				}
			}
			if (!isMoving){
				movingValueX = 0;
				movingValueY = 0;
				setTileX(targetTileX);
				setTileY(targetTileY);
			}
		}
		else if (!isMoving && tilesToMove > 0){
			tilesToMove -= 1;
			move(getFacing());
		}
	}