Ignore:
Timestamp:
2012-07-03 13:17:05 (8 years ago)
Author:
dezhidki
Message:

Talletus.

File:
1 edited

Legend:

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

    r3466 r3477  
    1212        public Vector Position { get; set; } 
    1313        public double width, height, thickness; 
    14         private List<IPhysicsObject> roomObjects = new List<IPhysicsObject>(); 
     14        protected List<IPhysicsObject> roomObjects = new List<IPhysicsObject>(); 
    1515        private bool isBuilt = false; 
     16        protected IPhysicsObject[,] insideObjects; 
     17        protected double blockWidth, blockHeight; 
     18        protected double insideWidth, insideHeight; 
     19        protected Vector insidePos; 
     20        protected int bWidth, bHeight; 
    1621        public Game Game { get; set; } 
    1722 
     
    2328            height = size.Y; 
    2429            this.thickness = thickness; 
     30 
     31            insidePos = VecMath.add(pos, new Vector(thickness, -thickness)); 
     32            insideWidth = width - thickness; 
     33            insideHeight = height - thickness; 
     34            blockWidth = insideWidth / 10; 
     35            blockHeight = blockWidth; 
     36            bWidth = (int)(insideWidth / blockWidth); 
     37            bHeight = (int)(insideHeight / blockHeight); 
     38 
     39            insideObjects = new PhysicsObject[bWidth, bHeight]; 
    2540        } 
    2641 
     
    3550                Game.Add(obj); 
    3651            } 
     52 
     53            foreach (IPhysicsObject obj in insideObjects) 
     54            { 
     55                if(obj != null) 
     56                Game.Add(obj); 
     57            } 
     58             
    3759 
    3860            isBuilt = true; 
     
    5072        } 
    5173 
     74        public void addBlock(IPhysicsObject obj, int bx, int by) 
     75        { 
     76            if (bx > bWidth || bx < 0 || by > bHeight || by < 0 || insideObjects[bx,by] != null) throw new Exception("Can't put block to " + bx + " , " + by); 
     77            obj.Left = insidePos.X + (bx * blockWidth); 
     78            obj.Top = insidePos.Y + (by * blockHeight); 
     79            insideObjects[bx, by] = obj; 
     80        } 
     81 
    5282        public void createBorders() 
    5383        { 
    54             PhysicsObject wallTop = createWall(Position, width, thickness); 
     84            PhysicsObject wallTop = createWall(Position, width + thickness, thickness); 
    5585            PhysicsObject wallLeft = createWall(VecMath.sub(Position, new Vector(0, thickness)), thickness, height); 
    56             PhysicsObject wallDown = createWall(VecMath.sub(Position, new Vector(0, height)), width+thickness, thickness); 
    57             PhysicsObject wallRight = createWall(VecMath.add(Position, new Vector(width, 0)), thickness, height); 
     86            PhysicsObject wallDown = createWall(VecMath.sub(Position, new Vector(0, height)), width + thickness, thickness); 
     87            PhysicsObject wallRight = createWall(VecMath.add(Position, new Vector(width, -thickness)), thickness, height-thickness); 
    5888            roomObjects.Add(wallTop); 
    5989            roomObjects.Add(wallLeft); 
     
    70100            return wall; 
    71101        } 
    72       
     102 
     103        public PhysicsObject createBackground() 
     104        { 
     105            PhysicsObject bg = PhysicsObject.CreateStaticObject(insideWidth, insideHeight); 
     106            bg.Left = Position.X + thickness; 
     107            bg.Top = Position.Y - thickness; 
     108            bg.IgnoresCollisionResponse = true; 
     109            bg.Color = Color.Black; 
     110            bg.IgnoresExplosions = true; 
     111            return bg; 
     112        } 
     113 
    73114    } 
    74115 
    75116    class RoomTemplates 
    76117    { 
    77          
     118 
    78119    } 
    79120} 
Note: See TracChangeset for help on using the changeset viewer.