Ignore:
Timestamp:
2012-07-04 13:57:59 (8 years ago)
Author:
dezhidki
Message:

Updated camera motion

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.cs

    r3525 r3538  
    1515    public const double ROOMWIDTH = 800 - ROOMTHICKNESS; 
    1616    public const double ROOMHEIGHT = 450; 
    17      
     17 
    1818    public static Vector roomSize = new Vector(ROOMWIDTH, ROOMHEIGHT); 
    1919    private Player player; 
    2020    private LevelGenerator generator; 
     21    public LevelGenerator LevelGen { get { return generator; } } 
     22 
     23    private Vector cameraPosMission; 
     24    private Vector cameraVelocity, newPos; 
     25    private bool moveCamera = false; 
    2126 
    2227    public override void Begin() 
     
    3136        generator.buildDungeon(); 
    3237        Room centerRoom = generator.getRoomAt((int)(generator.CenterRoom.X), (int)(generator.CenterRoom.Y)); 
    33         Camera.Position = centerRoom.Position + new Vector(ROOMWIDTH/2 + ROOMTHICKNESS/2, -ROOMHEIGHT/2 + ROOMTHICKNESS/4); 
     38        Camera.Position = centerRoom.Position + new Vector(ROOMWIDTH / 2 + ROOMTHICKNESS / 2, -ROOMHEIGHT / 2 + ROOMTHICKNESS / 4); 
     39      //  Camera.Zoom(0.5); 
    3440 
    3541        player = new Player(this, Vector.Zero); 
    3642        setupPlayer(); 
     43        AddCollisionHandler(player, player.performCollision); 
    3744 
    3845        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli"); 
    3946        Keyboard.Listen(Key.R, ButtonState.Pressed, regenerateLevel, null); 
     47    } 
     48 
     49    public void moveToRoom(Room room) 
     50    { 
     51        //  Camera.Position = room.Position + new Vector(ROOMWIDTH / 2 + ROOMTHICKNESS / 2, -ROOMHEIGHT / 2 + ROOMTHICKNESS / 4); 
     52        // Camera.Velocity = new Vector(0, 1); 
     53        Vector currentpos = player.currentRoom.Position + new Vector(ROOMWIDTH / 2 + ROOMTHICKNESS / 2, -ROOMHEIGHT / 2 + ROOMTHICKNESS / 4); 
     54        Vector newpos = room.Position + new Vector(ROOMWIDTH / 2 + ROOMTHICKNESS / 2, -ROOMHEIGHT / 2 + ROOMTHICKNESS / 4); 
     55 
     56        moveCameraTo(newpos - currentpos); 
     57        player.Position = generator.getRoomAt(room.PosOnGrid).Position + new Vector(ROOMWIDTH / 2, -ROOMHEIGHT / 2); 
     58    } 
     59 
     60    public void moveCameraTo(Vector pos) 
     61    { 
     62        cameraPosMission = pos; 
     63        newPos = Camera.Position + pos; 
     64        cameraVelocity = pos; 
     65        moveCamera = true; 
     66    } 
     67 
     68    private void moveCameraPart() 
     69    { 
     70        Camera.Velocity = cameraVelocity; 
     71        Vector remainingLenght = Camera.Position - newPos; 
     72        if ((int)remainingLenght.X == 0 && (int)remainingLenght.Y == 0) 
     73        { 
     74            Camera.Position = newPos; 
     75            moveCamera = false; 
     76        } 
     77         
    4078    } 
    4179 
     
    71109            return; // Skipataan "virheelisiä" tickea ja huijataan peliä niin kuin pahat merimiehet (dirty pirates, Arr) 
    72110        } 
     111        if (moveCamera) 
     112        { 
     113            moveCameraPart(); 
     114        } 
     115        else 
     116        { 
     117            cameraPosMission = Vector.Zero; 
     118            cameraVelocity = Vector.Zero; 
     119            newPos = Vector.Zero; 
     120            Camera.Velocity = cameraVelocity; 
     121        } 
    73122 
    74123        player.Update(time); 
Note: See TracChangeset for help on using the changeset viewer.