コード例 #1
0
ファイル: Camera.cs プロジェクト: TensAndTwenties/Ruin
        public static void panToCharacter(Character character, Camera camera, Map map, GraphicsDeviceManager graphics, int panSeconds=1)
        {
            // camera starts at P1. Camera moves a distance equal to the differencce between the camera's center at P1 and the chracter given.
            //get the current camera position and center.

            float ViewSizeX = graphics.GraphicsDevice.Viewport.Width;  // width of the current game viewport
            float ViewSizeY = graphics.GraphicsDevice.Viewport.Height; // height of the current game viewport

            Vector2 originalCameraPosition = camera.cameraLocation; //record the original position of the camera
            Vector2 originalCameraCenter = new Vector2(originalCameraPosition.X + ViewSizeX/2, originalCameraPosition.Y + ViewSizeY/2);

            int originalCharPosX = (int)character.position.X;
            int originalCharPosY = (int)character.position.Y;

            Tile OriginalCharTile = map.tiles[originalCharPosX, originalCharPosY];// character.position;

            int originalCharPosPixX = ((originalCharPosX * (Tile.width)) + ((originalCharPosY - 1) * (Tile.width / 2)) + (int)camera.cameraLocation.X);
            int originalCharPosPixY = ((originalCharPosY * (Tile.height / 2)) + (int)camera.cameraLocation.Y);

            Vector2 originalCharPosPix = new Vector2(originalCharPosPixX,originalCharPosPixY);

            //camera change equal to the difference in the camera center at p1 and the character's initial position

            Vector2 transformVector = originalCameraCenter - originalCharPosPix;

            //move the camera such that it reaches its final destination in panSeconds seconds
            //calculate pixels to move and sleep time such that the camera moves a distance x in panSeconds seconds

            panCameraToLocation(camera, transformVector);
            //camera.cameraLocation = transformVector;
        }
コード例 #2
0
ファイル: Camera.cs プロジェクト: TensAndTwenties/Ruin
        public static void panCameraToLocation(Camera camera, Vector2 location, double panSeconds = 0.5)
        {
            int panMilliseconds = (int)(panSeconds * 1000);
            Vector2 originalLocation = camera.cameraLocation;
            double timerInterval = 25;
            double panRate = (double)(Vector2.Distance(camera.cameraLocation,location))/panMilliseconds; //pixels per milliseconds
            int pixelChange = (int)Math.Round(panRate * timerInterval, 0, MidpointRounding.AwayFromZero);

            Timer timer = new Timer();
            timer.Elapsed += (timerSender, timerEvent) => panCameraToLocationEvent(timer, camera, location, pixelChange);//new ElapsedEventHandler(panCameraToLocationEvent);
            timer.Interval = timerInterval; //millisecond rate
            timer.Enabled = true;
        }
コード例 #3
0
ファイル: Camera.cs プロジェクト: TensAndTwenties/Ruin
        private static void panCameraToLocationEvent(object sender, Camera camera, Vector2 destination, int pixelChange)
        {
            //change vector = destination - original location
            Vector2 changeVector = destination - camera.cameraLocation;
            changeVector.Normalize();
            changeVector = changeVector * pixelChange;

            if (Vector2.Distance(camera.cameraLocation, destination) > 10)
            {
                //if its not close to the loction, move the camera pixelChange pixels towards the location.
                camera.cameraLocation = Vector2.Add(camera.cameraLocation, changeVector);
            }
            else
            {
                Timer timer = (Timer)sender;
                timer.Stop();
            }
            //stop when within 5 pixels of the target location. Unless the pixelChange vlue is larger than 10, this will work
        }
コード例 #4
0
ファイル: Game1.cs プロジェクト: TensAndTwenties/Ruin
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();

            battleMap = Map.buildDefaultMap(20, 20); //build map

            allCover = Cover.createTestCover(battleMap);
            allies = Character.createTestAllies(5, battleMap);
            enemies = Character.createTestEnemies(5, battleMap); //create teams of characters

            allCharacters.AddRange(allies);
            allCharacters.AddRange(enemies);

            playerTurn = true;

            gameCamera = new Camera(); //create camera

            mapWidth = battleMap.mapWidthInTiles();
            mapHeight = battleMap.mapHeightInTiles();
        }
コード例 #5
0
ファイル: Camera.cs プロジェクト: TensAndTwenties/Ruin
        public static void PanToCharacter(Character targetChar, Camera camera, Map map, float viewportWidth, float viewportHeight)
        {
            int originalCharPosPixX = (((int)targetChar.position.X * (Tile.width /2)) + (((int)targetChar.position.Y - 1) * (Tile.width / 2)) + (int)camera.cameraLocation.X);
            int originalCharPosPixY = (((int)targetChar.position.Y * (Tile.height / 2)) - (((int)targetChar.position.X - 1) * (Tile.height /2)) + (int)camera.cameraLocation.Y);

            Vector2 targetCharPosition = new Vector2(originalCharPosPixX, originalCharPosPixY);

            Vector2 originalCameraPosition = camera.cameraLocation;

            Vector2 originalCameraCenter = new Vector2(originalCameraPosition.X + viewportWidth / 2, originalCameraPosition.Y + viewportHeight / 2);

            Vector2 cameraPanVector = originalCameraCenter - targetCharPosition;
            Vector2 normalizedCameraPanVector = cameraPanVector;
            normalizedCameraPanVector.Normalize();

            camera.normalizedCameraPanVector = normalizedCameraPanVector;
            camera.cameraPanVector = cameraPanVector;
            camera.cameraDestination = targetCharPosition;
            camera.cameraState = cameraState.panningToTarget;
        }
コード例 #6
0
ファイル: Camera.cs プロジェクト: TensAndTwenties/Ruin
        public static void panToDestination(Camera camera)
        {
            /*Vector2 changeVector = destination - camera.cameraLocation;
            changeVector.Normalize();
            changeVector = changeVector * pixelChange;
            */

            /*
            Vector2 currentCameraLocation = camera.cameraLocation;
            Vector2 changeVector = camera.normalizedCameraPanVector * (int)camera.cameraSpeed;
            */

            Vector2 currentCameraLocation = camera.cameraLocation;
            Vector2 changeVector = camera.cameraPanVector - currentCameraLocation;
            changeVector.Normalize();
            changeVector = changeVector * (int)camera.cameraSpeed;

            //Vector2 newCameraLocation = currentCameraLocation - changeVector;

            if (Vector2.Distance(currentCameraLocation, camera.cameraPanVector) > changeVector.Length())
            {
                camera.cameraLocation = Vector2.Add(camera.cameraLocation, changeVector);
            } else
            {
                camera.cameraLocation = camera.cameraPanVector;
                camera.cameraState = cameraState.still;
            }
        }
コード例 #7
0
ファイル: Game1.cs プロジェクト: TensAndTwenties/Ruin
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();

            battleMap = Map.buildDefaultMap(20, 20); //build map

            playState = new PlayState(battleMap);
            playState.viewportWidth = graphics.GraphicsDevice.Viewport.Width;
            playState.viewportHeight = graphics.GraphicsDevice.Viewport.Height;

            /*allCover = Cover.createTestCover(battleMap);
            allies = Character.createTestAllies(5, battleMap);
            enemies = Character.createTestEnemies(5, battleMap); //create teams of characters

            allCharacters.AddRange(allies);
            allCharacters.AddRange(enemies);

            playerTurn = true;*/

            gameCamera = new Camera(); //create camera

            mapWidth = battleMap.mapWidthInTiles();
            mapHeight = battleMap.mapHeightInTiles();
        }
コード例 #8
0
ファイル: Character.cs プロジェクト: TensAndTwenties/Ruin
 public static void selectCharacter(Character character, Camera camera, Map map, GraphicsDeviceManager graphics)
 {
     character.selected = true;
     Camera.panToCharacter(character, camera, map, graphics);
 }