Changeset 3562


Ignore:
Timestamp:
2012-07-04 18:29:51 (11 years ago)
Author:
dezhidki
Message:

Made player really go through the door, nor just spawn in the middle of the room when going through door

Location:
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame
Files:
3 edited

Legend:

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

    r3538 r3562  
    2828            keyboard = game.Keyboard; 
    2929            CanRotate = false; 
    30             currentRoom =  game.LevelGen.getRoomAt(game.LevelGen.CenterRoom); 
    3130            setupKeys(); 
    3231        } 
     
    5150            { 
    5251                room = game.LevelGen.getRoomAt(currentRoom.PosOnGrid + RoomDirection.getOffsetFromDir(RoomDirection.North)); 
    53                 game.moveToRoom(room); 
     52                game.moveToRoom(room, RoomDirection.North); 
    5453                currentRoom = room; 
    5554            }else 
     
    5756                { 
    5857                    room = game.LevelGen.getRoomAt(currentRoom.PosOnGrid + RoomDirection.getOffsetFromDir(RoomDirection.East)); 
    59                     game.moveToRoom(room); 
     58                    game.moveToRoom(room, RoomDirection.East); 
    6059                    currentRoom = room; 
    6160                } 
     
    6463                    { 
    6564                        room = game.LevelGen.getRoomAt(currentRoom.PosOnGrid + RoomDirection.getOffsetFromDir(RoomDirection.South)); 
    66                         game.moveToRoom(room); 
     65                        game.moveToRoom(room, RoomDirection.South); 
    6766                        currentRoom = room; 
    6867                    } 
     
    7170                        { 
    7271                            room = game.LevelGen.getRoomAt(currentRoom.PosOnGrid + RoomDirection.getOffsetFromDir(RoomDirection.West)); 
    73                             game.moveToRoom(room); 
     72                            game.moveToRoom(room, RoomDirection.West); 
    7473                            currentRoom = room; 
    7574                        } 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Room.cs

    r3547 r3562  
    1717        private bool isBuilt = false; 
    1818        protected IPhysicsObject[,] insideObjects; 
    19         protected IPhysicsObject[] doors = new IPhysicsObject[4]; 
     19        protected PhysicsObject[] doors = new PhysicsObject[4]; 
    2020        protected double blockWidth, blockHeight; 
    2121        protected double insideWidth, insideHeight; 
     
    155155        } 
    156156 
     157        public PhysicsObject getDoor(int dir) 
     158        { 
     159            PhysicsObject result = null; 
     160            for (int i = 0; i < doors.Length; i++ ) 
     161            { 
     162                PhysicsObject door = doors[i]; 
     163                if (door != null && (int)door.Tag == dir) 
     164                { 
     165                    result = door; 
     166                    return result; 
     167                } 
     168 
     169            } 
     170            return result; 
     171        } 
     172 
    157173        public void createBorders() 
    158174        { 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.cs

    r3547 r3562  
    4545    } 
    4646 
    47     public void moveToRoom(Room room) 
     47    public void moveToRoom(Room room, int dir) 
    4848    { 
    4949        currentPos = player.currentRoom.Position + new Vector(ROOMWIDTH / 2 + ROOMTHICKNESS / 2, -ROOMHEIGHT / 2 + ROOMTHICKNESS / 4); 
    5050        newPos = room.Position + new Vector(ROOMWIDTH / 2 + ROOMTHICKNESS / 2, -ROOMHEIGHT / 2 + ROOMTHICKNESS / 4); 
    5151        moveCameraTo(newPos - currentPos); 
    52         player.Position = generator.getRoomAt(room.PosOnGrid).Position + new Vector(ROOMWIDTH / 2, -ROOMHEIGHT / 2); 
     52        player.Position = player.currentRoom.getDoor(dir).Position + RoomDirection.getOffsetFromWorldDir(dir) * 130; 
    5353    } 
    5454 
     
    6464        Camera.Velocity = cameraVelocity; 
    6565        Vector remainingLenght = Camera.Position - newPos; 
    66         // Console.WriteLine(Math.Abs(remainingLenght.X)+", " + Math.Abs(remainingLenght.Y)); 
    6766        if (Math.Abs((int)remainingLenght.X) < 20 && Math.Abs((int)remainingLenght.Y) < 20) 
    6867        { 
     
    7372            moveCamera = false; 
    7473        } 
    75  
    7674    } 
    7775 
    7876    private void setupPlayer() 
    7977    { 
    80         player.Position = generator.getRoomAt((int)(generator.CenterRoom.X), (int)(generator.CenterRoom.Y)).Position + new Vector(ROOMWIDTH / 2, -ROOMHEIGHT / 2); 
     78        player.Position = generator.getRoomAt(generator.CenterRoom).Position + new Vector(ROOMWIDTH / 2, -ROOMHEIGHT / 2); 
     79        player.currentRoom = generator.getRoomAt(generator.CenterRoom); 
    8180        Add(player, 1); 
    8281    } 
     
    8887        generator.generateRandomLevel(10, 15); 
    8988        generator.buildDungeon(); 
     89        player.currentRoom = generator.getRoomAt(generator.CenterRoom); 
    9090    } 
    9191 
Note: See TracChangeset for help on using the changeset viewer.