Ignore:
Timestamp:
2012-07-04 10:50:43 (9 years ago)
Author:
dezhidki
Message:

Added basic camera logic.
Added basic templates for Doors

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

Legend:

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

    r3515 r3525  
    1717        public bool isMoving = false; 
    1818        private Keyboard keyboard; 
    19         private double speed = 200; 
     19        public double speed = 200; 
    2020 
    2121        public Player(Game game, Vector pos) 
     
    2424            keyboard = game.Keyboard; 
    2525            CanRotate = false; 
     26           // MakeStatic(); 
    2627            setupKeys(); 
    2728        } 
     
    4041        } 
    4142 
    42         public void tick() 
     43        public override void Update(Time time) 
    4344        { 
    44             if (isMoving) 
     45            if (!isMoving) 
    4546            { 
    4647                movementVector = Vector.Zero; 
     
    4849            } 
    4950 
    50             isMoving = false;   
     51            isMoving = false; 
     52 
     53            base.Update(time); 
    5154        } 
    5255 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Room.cs

    r3517 r3525  
    1010    abstract class Room 
    1111    { 
    12          
    13        public Vector Position; 
     12 
     13        public Vector Position; 
    1414        public double width, height, thickness; 
    1515        protected List<IPhysicsObject> roomObjects = new List<IPhysicsObject>(); 
     
    2222        public Game Game { get; set; } 
    2323        public Vector PosOnGrid { get; set; } 
     24        public PhysicsObject wall; 
    2425 
    2526        public Room(Game game, Vector pos, Vector size, double thickness) 
     
    3132            this.thickness = thickness; 
    3233 
    33             insidePos = VecMath.add(pos, new Vector(thickness, -thickness)); 
     34            insidePos = VecMath.add(Position, new Vector(thickness, -thickness)); 
    3435            insideWidth = width - thickness; 
    3536            insideHeight = height - thickness; 
     
    8182        public void addBlock(IPhysicsObject obj, int bx, int by) 
    8283        { 
    83             if (bx > bWidth || bx < 0 || by > bHeight || by < 0 || insideObjects[bx, by] != null) throw new Exception("Can't put block to " + bx + " , " + by); 
     84            if (bx >= bWidth || bx < 0 || by >= bHeight || by < 0 || insideObjects[bx, by] != null) throw new Exception("Can't put block to " + bx + " , " + by); 
    8485            obj.Left = insidePos.X + (bx * blockWidth); 
    85             obj.Top = insidePos.Y + (by * blockHeight); 
     86            obj.Top = insidePos.Y - (by * blockHeight); 
    8687            insideObjects[bx, by] = obj; 
     88        } 
     89 
     90        public void addBlockAt(IPhysicsObject obj, double x, double y) 
     91        { 
     92            obj.Left = Position.X + x; 
     93            obj.Top = Position.Y + y; 
     94            roomObjects.Add(obj); 
     95        } 
     96 
     97 
     98        // En vitsinyt käyttää enempää aikaa tämän parantamiseksi. Helppo ja toimiva 
     99        public void addDoors(int[] directions) 
     100        { 
     101            if(directions.Length > 4) throw new ArgumentException("Argument's length must be 4!"); 
     102 
     103            for (int i = 0; i < directions.Length; i++) 
     104            { 
     105                if(directions[i] == -1) continue; 
     106 
     107                if (directions[i] == RoomDirection.North) 
     108                { 
     109                    PhysicsObject doorTop = PhysicsObject.CreateStaticObject(thickness, thickness); 
     110                    doorTop.Position = Position + new Vector((width + thickness) / 2, -thickness / 2); 
     111                    doorTop.Tag = "Top Door"; 
     112                    roomObjects.Add(doorTop); 
     113                }else 
     114                    if (directions[i] == RoomDirection.East) 
     115                    { 
     116                        PhysicsObject doorRight = PhysicsObject.CreateStaticObject(thickness, thickness); 
     117                        doorRight.Position = Position + new Vector(width + thickness / 2, -(height + thickness) / 2); 
     118                        doorRight.Tag = "Right Door"; 
     119                        roomObjects.Add(doorRight); 
     120                    } 
     121                    else 
     122                        if (directions[i] == RoomDirection.South) 
     123                        { 
     124                            PhysicsObject doorBottom = PhysicsObject.CreateStaticObject(thickness, thickness); 
     125                            doorBottom.Position = Position + new Vector((thickness + width) / 2, -height - thickness / 2); 
     126                            doorBottom.Tag = "Bottom Door"; 
     127                            roomObjects.Add(doorBottom); 
     128                        } 
     129                        else 
     130                            if (directions[i] == RoomDirection.West) 
     131                            { 
     132                                PhysicsObject doorLeft = PhysicsObject.CreateStaticObject(thickness, thickness); 
     133                                doorLeft.Position = Position + new Vector(thickness / 2, -height / 2 - thickness / 2); 
     134                                doorLeft.Tag = "Left Door"; 
     135                                roomObjects.Add(doorLeft); 
     136                            } 
     137            }     
    87138        } 
    88139 
     
    96147            wallDown.Color = Color.Black; 
    97148            PhysicsObject wallRight = createWall(VecMath.add(Position, new Vector(width, -thickness)), thickness, height - thickness); 
     149            wallRight.Color = Color.Orange; 
    98150            roomObjects.Add(wallTop); 
    99151            roomObjects.Add(wallLeft); 
     
    104156        public PhysicsObject createWall(Vector pos, double width, double height) 
    105157        { 
    106             PhysicsObject wall = PhysicsObject.CreateStaticObject(width, height); 
     158            wall = PhysicsObject.CreateStaticObject(width, height); 
    107159            wall.Left = pos.X; 
    108160            wall.Top = pos.Y; 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TestRoom.cs

    r3489 r3525  
    1919        public override void initRoom() 
    2020        { 
     21            int[] doorLocations = { RoomDirection.North, RoomDirection.South, RoomDirection.West, RoomDirection.East }; 
    2122            createBorders(); 
    2223            roomObjects.Add(createBackground()); 
     24            addDoors(doorLocations); 
     25        //    PhysicsObject testblock = PhysicsObject.CreateStaticObject(blockWidth, blockHeight); 
     26          //  addBlock(testblock, 0, 1); 
    2327          //  addBlock(new PhysicsObject(blockWidth, blockHeight), 0, 0); 
    2428        } 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.cs

    r3518 r3525  
    1212public class TheDungeonGame : PhysicsGame 
    1313{ 
    14     public const double ROOMWIDTH = 850; 
    15     public const double ROOMHEIGHT = 500; 
    16     public const double ROOMTHICKNESS = 70; 
     14    public const double ROOMTHICKNESS = 60; 
     15    public const double ROOMWIDTH = 800 - ROOMTHICKNESS; 
     16    public const double ROOMHEIGHT = 450; 
     17     
    1718    public static Vector roomSize = new Vector(ROOMWIDTH, ROOMHEIGHT); 
    1819    private Player player; 
     
    2526        Level.Width = ROOMWIDTH * 20; 
    2627        Level.Height = ROOMHEIGHT * 20; 
    27         //   Level.CreateBorders(); 
    28         Camera.ZoomToLevel(); 
    2928 
    3029        generator = new LevelGenerator(this, Level.Size, new Vector(20, 20)); 
    31         generator.generateRandomLevel(10, 15); 
     30        generator.generateRandomLevel(5, 10); 
    3231        generator.buildDungeon(); 
     32        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); 
    3334 
    3435        player = new Player(this, Vector.Zero); 
    35         Add(player, 1); 
    36       //  Camera.Follow(player); 
     36        setupPlayer(); 
    3737 
    3838        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli"); 
    3939        Keyboard.Listen(Key.R, ButtonState.Pressed, regenerateLevel, null); 
     40    } 
     41 
     42    private void setupPlayer() 
     43    { 
     44        player.Position = generator.getRoomAt((int)(generator.CenterRoom.X), (int)(generator.CenterRoom.Y)).Position + new Vector(ROOMWIDTH / 2, -ROOMHEIGHT / 2); 
     45        Add(player, 1); 
    4046    } 
    4147 
     
    6672        } 
    6773 
    68         player.tick(); 
     74        player.Update(time); 
    6975    } 
    7076} 
Note: See TracChangeset for help on using the changeset viewer.