public class Camera
{
	public const sbyte FREE_MODE = 0;

	public const sbyte PLAYER_MODE = 1;

	private const sbyte BULLET_MODE = 2;

	private const sbyte AIRPLANE_MODE = 3;

	private const sbyte TARGETPOINT_MODE = 4;

	private const sbyte TARGETPOINT_MODE_NORETRICT = 5;

	private const sbyte LAZER_MODE = 6;

	private const sbyte METEOR_MODE = 7;

	private const sbyte MISSILE_RAIN_MODE = 8;

	public const sbyte FREE_MODE_TOUCH = 9;

	public const sbyte PLAYER_MODE_RPG = 10;

	public static sbyte mode;

	public static int shaking;

	private int vx = 15;

	private int vy = 15;

	public static int x;

	public static int y;

	public static int startx;

	public static int starty;

	private int player;

	private Bullet bullet;

	private int count;

	public int dx;

	public int dy;

	public static int dx2;

	public static int dy2;

	private int indexX;

	private int indexY;

	private int setIndexX;

	private int setIndexY;

	private int deltaY = 20;

	public Camera()
	{
		startx = 0;
		starty = 0;
		init();
	}

	public Camera(int x, int y)
	{
		init();
		setxy(x, y);
		startx = x;
		starty = y;
		setFreeMode();
	}

	public static void init()
	{
		shaking = 0;
	}

	public void setxy(int x, int y)
	{
		Camera.x = x;
		Camera.y = y;
	}

	public void setFreeMode()
	{
		mode = 0;
		dx2 = 0;
		dy2 = 0;
	}

	public void setPlayerMode(int target)
	{
		mode = 1;
		player = target;
	}

	public void setBulletMode(Bullet target)
	{
		if (CCanvas.gameScr.isSplash || mode != 9)
		{
			mode = 2;
			bullet = target;
		}
	}

	public void setMeteorMode(Bullet target)
	{
		if (CCanvas.gameScr.isSplash || mode != 9)
		{
			mode = 7;
			bullet = target;
		}
	}

	public void setAirPlaneMode()
	{
		if (CCanvas.gameScr.isSplash || mode != 9)
		{
			mode = 3;
		}
	}

	public void setLazerMode(Bullet target)
	{
		if (CCanvas.gameScr.isSplash || mode != 9)
		{
			mode = 6;
			bullet = target;
		}
	}

	public void setMRainMode(Bullet target)
	{
		if (CCanvas.gameScr.isSplash || mode != 9)
		{
			mode = 8;
			bullet = target;
		}
	}

	public void setTargetPointMode(int index_x, int index_y)
	{
		if (CCanvas.gameScr.isSplash || mode != 9)
		{
			mode = 4;
			setIndexX = index_x - CScreen.w / 2;
			setIndexY = index_y - CScreen.h / 2;
		}
	}

	public void setTargetPointModeNoRetrict(int index_x, int index_y)
	{
		if (CCanvas.gameScr.isSplash || mode != 9)
		{
			mode = 5;
			setIndexX = index_x - CScreen.w / 2;
			setIndexY = index_y - CScreen.h / 2;
		}
	}

	public void update()
	{
		if (CCanvas.curScr == CCanvas.gameScr && !GameScr.res.Equals(string.Empty))
		{
			return;
		}
		startx = x;
		starty = y;
		indexX = 0;
		indexY = 0;
		switch (mode)
		{
		case 0:
		case 9:
			x += dx2;
			if (dx2 != 0)
			{
				dx2 = 0;
			}
			y += dy2;
			if (dy2 != 0)
			{
				dy2 = 0;
			}
			break;
		case 1:
			if (PM.p[player] != null)
			{
				if (CPlayer.isDrag)
				{
					return;
				}
				indexX = PM.p[player].x - CCanvas.hw;
				indexY = PM.p[player].y - CCanvas.hh - 12;
				checkIndex(3);
			}
			break;
		case 2:
			if (bullet.type != 37 || bullet.yPaint[bullet.paintCount] > -50)
			{
				indexX = bullet.xPaint[bullet.paintCount] - CCanvas.hw;
				indexY = bullet.yPaint[bullet.paintCount] - CCanvas.hh;
				if (bullet.type != 37)
				{
					checkIndex(2);
				}
				else
				{
					checkIndex(1);
				}
			}
			break;
		case 3:
			indexX = BM.airPlaneX - CScreen.w / 4;
			indexY = BM.airPlaneY - CCanvas.hh;
			checkIndex(2);
			break;
		case 6:
			indexX = bullet.xPaint[bullet.paintCount] - CCanvas.hw;
			indexY = bullet.yPaint[bullet.paintCount] - CScreen.h / 3;
			checkIndex(1);
			break;
		case 7:
			indexX = bullet.xPaint[bullet.paintCount] - CCanvas.hw;
			indexY = bullet.yPaint[bullet.paintCount] - CScreen.h / 3;
			checkIndex(1);
			break;
		case 8:
			indexX = PM.getCurPlayer().x - CCanvas.hw;
			indexY = bullet.yPaint[bullet.paintCount] - CCanvas.hh;
			checkIndex(2);
			break;
		case 4:
			indexX = setIndexX;
			indexY = setIndexY;
			checkIndex(2);
			break;
		case 5:
			indexX = setIndexX;
			indexY = setIndexY;
			checkIndex(3);
			break;
		case 10:
			if (PM.getMyPlayer2() != null)
			{
				indexX = PM.getMyPlayer2().x - CCanvas.hw;
				indexY = PM.getMyPlayer2().y - CCanvas.hh - ((CCanvas.h < 200) ? 40 : 0);
				if (PM.getMyPlayer2().state == 1)
				{
					x = PM.getMyPlayer2().x - CCanvas.hw;
					y = PM.getMyPlayer2().y - CCanvas.hh - ((CCanvas.h < 200) ? 40 : 0);
				}
				checkIndex(3);
			}
			break;
		}
		if (shaking != 0)
		{
			if (shaking == 1)
			{
				x += CRes.random(-5, 5);
				y += CRes.random(-5, 5);
			}
			else if (shaking == 2)
			{
				x += CRes.random(-20, 20);
				y += CRes.random(-20, 20);
			}
			else if (shaking == 3 || shaking == 4)
			{
				if (CCanvas.gameTick % 3 == 0)
				{
					y += deltaY;
				}
				else
				{
					y -= deltaY;
				}
				if (count % 2 == 0)
				{
					deltaY--;
				}
				if (deltaY < 0)
				{
					deltaY = 0;
				}
			}
			count++;
			if (count > ((shaking != 3 && shaking != 4) ? 5 : ((shaking != 4) ? 10 : 30)) * ((!CScreen.isUseHighFrameRate()) ? 1 : 2))
			{
				deltaY = 20;
				shaking = 0;
				count = 0;
			}
		}
		if (CCanvas.curScr == CCanvas.gameScr && mode != 5)
		{
			restrict(0, MM.mapWidth, -1000, MM.mapHeight);
		}
	}

	private void checkIndex(int rangeBit)
	{
		if (x != indexX)
		{
			dx = x - indexX;
			x -= dx >> (rangeBit & 0x1F);
		}
		if (y != indexY)
		{
			dy = y - indexY;
			y -= dy >> (rangeBit & 0x1F);
		}
	}

	public static void restrict(int left, int right, int up, int down)
	{
		if (y < up)
		{
			y = up;
		}
		if (y > down - CScreen.h)
		{
			y = down - CScreen.h;
			starty = y;
		}
		if (x < left)
		{
			x = left;
		}
		if (x > right - CScreen.w)
		{
			x = right - CScreen.w;
		}
	}

	public static void translate(mGraphics g)
	{
		g.translate(-x, -y);
	}

	public static void reTranslate(mGraphics g)
	{
		g.translate(-g.getTranslateX(), -g.getTranslateY());
	}

	public static void setPlayerModeRPG()
	{
		mode = 10;
	}
}
