Changeset 3568 for 2012/27


Ignore:
Timestamp:
2012-07-05 10:46:03 (11 years ago)
Author:
dezhidki
Message:

Talletus.

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

Legend:

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

    r3549 r3568  
    44using System.Text; 
    55using Jypeli; 
     6using Jypeli.Assets; 
    67 
    78namespace Entity 
     
    1920        } 
    2021    } 
     22 
     23   public class EntityFly : EntityBase 
     24   { 
     25       public EntityFly(TheDungeonGame game, Vector pos, Vector size, Shape shape) 
     26            : base(game, pos, size, shape) 
     27        { 
     28        } 
     29 
     30       public override void init() 
     31       { 
     32           Brain = new FollowerBrain(game.Player,200); 
     33           Brain.Active = true; 
     34       } 
     35   } 
    2136} 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/LevelGenerator.cs

    r3563 r3568  
    4747        } 
    4848 
     49        public void initDungeon() 
     50        { 
     51            foreach (Room room in roomList) 
     52            { 
     53                room.initRoom(); 
     54            } 
     55        } 
     56 
    4957        public void buildDungeon() 
    5058        { 
    5159            foreach (Room room in roomList) 
    5260            { 
    53                 room.initRoom(); 
    5461                room.buildLevel(); 
    5562            } 
     
    7380                if (room == 0) 
    7481                { 
    75                     lastRoom = new TestRoom(game, VecMath.mul(CenterRoom, new Vector(TheDungeonGame.ROOMWIDTH + TheDungeonGame.ROOMTHICKNESS, -TheDungeonGame.ROOMHEIGHT - TheDungeonGame.ROOMTHICKNESS)), TheDungeonGame.roomSize, TheDungeonGame.ROOMTHICKNESS); 
     82                    lastRoom = new EmptyRoom(game, VecMath.mul(CenterRoom, new Vector(TheDungeonGame.ROOMWIDTH + TheDungeonGame.ROOMTHICKNESS, -TheDungeonGame.ROOMHEIGHT - TheDungeonGame.ROOMTHICKNESS)), TheDungeonGame.roomSize, TheDungeonGame.ROOMTHICKNESS); 
    7683                    placeRoomAt(lastRoom, (int)CenterRoom.X, (int)CenterRoom.Y); 
    7784                    continue; 
     
    113120        { 
    114121            if (getRoomFromDirection(lastRoom, dir) != null) return false; 
    115             currentRoom = new TestRoom(game, VecMath.mul(pos, new Vector(TheDungeonGame.ROOMWIDTH + TheDungeonGame.ROOMTHICKNESS, -TheDungeonGame.ROOMHEIGHT - TheDungeonGame.ROOMTHICKNESS)), TheDungeonGame.roomSize, TheDungeonGame.ROOMTHICKNESS); 
     122            currentRoom = RoomCreator.createRoom(game, VecMath.mul(pos, new Vector(TheDungeonGame.ROOMWIDTH + TheDungeonGame.ROOMTHICKNESS, -TheDungeonGame.ROOMHEIGHT - TheDungeonGame.ROOMTHICKNESS)), TheDungeonGame.roomSize, TheDungeonGame.ROOMTHICKNESS, RandomGen.NextInt(6)+1); 
     123            //currentRoom = new EmptyRoom(game, VecMath.mul(pos, new Vector(TheDungeonGame.ROOMWIDTH + TheDungeonGame.ROOMTHICKNESS, -TheDungeonGame.ROOMHEIGHT - TheDungeonGame.ROOMTHICKNESS)), TheDungeonGame.roomSize, TheDungeonGame.ROOMTHICKNESS); 
    116124            return placeRoomAt(currentRoom, (int)pos.X, (int)pos.Y); 
    117125        } 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Room.cs

    r3563 r3568  
    4949        public abstract void initRoom(); 
    5050 
     51        protected void createLevelDecorations() 
     52        { 
     53            int level = Game.LevelGen.level; 
     54            createBorders(Game.getTopBottomWall(level), Game.getLeftRightWall(level)); 
     55            addDoors(Game.objectTextures[0]); 
     56            roomDecorations.Add(createBackground(Game.getLevelBackground(level))); 
     57        } 
     58 
    5159        public void buildLevel() 
    5260        { 
     
    95103        public void addBlock(IPhysicsObject obj, int bx, int by) 
    96104        { 
    97             if (bx >= bWidth || bx < 0 || by >= bHeight || by < 0 || insideObjects[bx, by] != null) throw new Exception("Can't put block to " + bx + " , " + by); 
     105            if (bx >= bWidth || bx < 0 || by >= bHeight || by < 0) throw new Exception("Can't put block to " + bx + " , " + by); 
    98106            obj.Left = insidePos.X + (bx * blockWidth); 
    99107            obj.Top = insidePos.Y - (by * blockHeight); 
    100108            insideObjects[bx, by] = obj; 
     109        } 
     110 
     111        public void addBlock(IPhysicsObject obj, int bx, int by, Vector offset) 
     112        { 
     113            addBlock(obj, bx, by); 
     114            obj.Position += offset; 
    101115        } 
    102116 
     
    115129            ent.Top = insidePos.Y + (by * blockHeight); 
    116130            insideObjects[bx, by] = ent; 
     131        } 
     132 
     133        public void deleteBlock(int bx, int by) 
     134        { 
     135            insideObjects[bx, by].Destroy(); 
     136            insideObjects[bx, by] = null; 
    117137        } 
    118138 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/RoomTemplates.cs

    r3563 r3568  
    1010namespace Rooms 
    1111{ 
    12     class TestRoom : Room 
     12    class EmptyRoom : Room 
    1313    { 
    14         public TestRoom(TheDungeonGame game, Vector pos, Vector size, double thickness) 
     14        public EmptyRoom(TheDungeonGame game, Vector pos, Vector size, double thickness) 
    1515            : base(game, pos, size, thickness) 
    1616        { 
     
    1919        public override void initRoom() 
    2020        { 
    21             int level = Game.LevelGen.level; 
    22             createBorders(Game.getTopBottomWall(level), Game.getLeftRightWall(level)); 
    23             addDoors(Game.objectTextures[0]); 
    24             roomDecorations.Add(createBackground(Game.getLevelBackground(level))); 
    25             ItemEntity testItem = new ItemEntity(new Items.TestItem(TheDungeonGame.LoadImage("items/testItem"), "Test Item", true)); 
    26             addBlock(testItem, 0, 0); 
    27             //TestEntity entity = new TestEntity(Game, Vector.Zero, new Vector(40, 40), Shape.Rectangle); 
    28             //addEntityAt(entity, 0, 0); 
    29             //RandomMoverBrain brain = new RandomMoverBrain(10000); 
    30             //brain.ChangeMovementSeconds = 0.5; 
    31             //entity.Brain = brain; 
    32             //entity.Brain.Active = true; 
     21            createLevelDecorations(); 
    3322        } 
    3423    } 
    35     
     24 
     25    class RoomType1 : Room 
     26    { 
     27        public RoomType1(TheDungeonGame game, Vector pos, Vector size, double thickness) 
     28            : base(game, pos, size, thickness) 
     29        { 
     30        } 
     31 
     32        public override void initRoom() 
     33        { 
     34            createLevelDecorations(); 
     35 
     36            addBlock(new ObjectRock(blockWidth, blockHeight), 0, 0); 
     37            addBlock(new ObjectRock(blockWidth, blockHeight), bWidth - 1, 0); 
     38            addBlock(new ObjectRock(blockWidth, blockHeight), 0, bHeight - 1, new Vector(0, -50)); 
     39            addBlock(new ObjectRock(blockWidth, blockHeight), bWidth - 1, bHeight - 1, new Vector(0, -50)); 
     40        } 
     41    } 
     42 
     43    class RoomType2 : Room 
     44    { 
     45        public RoomType2(TheDungeonGame game, Vector pos, Vector size, double thickness) 
     46            : base(game, pos, size, thickness) 
     47        { 
     48        } 
     49 
     50        public override void initRoom() 
     51        { 
     52            createLevelDecorations(); 
     53 
     54            for (int i = 0; i < 4; i++) 
     55            { 
     56                addBlock(new ObjectRock(blockWidth, blockHeight), 1, 1 + i, new Vector(0, -50)); 
     57            } 
     58 
     59            for (int i = 0; i < 4; i++) 
     60            { 
     61                addBlock(new ObjectRock(blockWidth, blockHeight), 8, 1 + i, new Vector(0, -50)); 
     62            } 
     63        } 
     64    } 
     65 
     66    class RoomType3 : Room 
     67    { 
     68        public RoomType3(TheDungeonGame game, Vector pos, Vector size, double thickness) 
     69            : base(game, pos, size, thickness) 
     70        { 
     71        } 
     72 
     73        public override void initRoom() 
     74        { 
     75            createLevelDecorations(); 
     76 
     77            for (int i = 0; i < 4; i++) 
     78            { 
     79                addBlock(new ObjectRock(blockWidth, blockHeight), i, 1); 
     80            } 
     81 
     82            for (int i = 0; i < 4; i++) 
     83            { 
     84                addBlock(new ObjectRock(blockWidth, blockHeight), i, 4); 
     85            } 
     86 
     87            for (int i = 0; i < 4; i++) 
     88            { 
     89                addBlock(new ObjectRock(blockWidth, blockHeight), i + 6, 1); 
     90            } 
     91 
     92            for (int i = 0; i < 4; i++) 
     93            { 
     94                addBlock(new ObjectRock(blockWidth, blockHeight), i + 6, 4); 
     95            } 
     96        } 
     97    } 
     98 
     99    class RoomType4 : Room 
     100    { 
     101        public RoomType4(TheDungeonGame game, Vector pos, Vector size, double thickness) 
     102            : base(game, pos, size, thickness) 
     103        { 
     104        } 
     105 
     106        public override void initRoom() 
     107        { 
     108            createLevelDecorations(); 
     109 
     110            for (int y = 1; y < bHeight; y++) 
     111            { 
     112                for (int x = 1; x < bWidth - 1; x++) 
     113                { 
     114                    if (x % 2 != 0 && y % 2 != 0) 
     115                        addBlock(new ObjectRock(blockWidth, blockHeight), x, y, new Vector(40, 0)); 
     116                } 
     117            } 
     118        } 
     119    } 
     120 
     121    class RoomType5 : Room 
     122    { 
     123        public RoomType5(TheDungeonGame game, Vector pos, Vector size, double thickness) 
     124            : base(game, pos, size, thickness) 
     125        { 
     126        } 
     127 
     128        public override void initRoom() 
     129        { 
     130            createLevelDecorations(); 
     131 
     132            for (int y = 0; y < 3; y++) 
     133            { 
     134                for (int x = 0; x < 3; x++) 
     135                { 
     136                    addBlock(new ObjectRock(blockWidth, blockHeight), x + 3, y + 1, new Vector(30, -20)); 
     137                } 
     138            } 
     139 
     140            deleteBlock(bWidth / 2 - 1, bHeight / 2); 
     141        } 
     142    } 
     143 
     144    class RoomType6 : Room 
     145    { 
     146        public RoomType6(TheDungeonGame game, Vector pos, Vector size, double thickness) 
     147            : base(game, pos, size, thickness) 
     148        { 
     149        } 
     150 
     151        public override void initRoom() 
     152        { 
     153            createLevelDecorations(); 
     154 
     155            for (int i = 0; i < 5; i++) 
     156            { 
     157                int bx = RandomGen.NextInt(bWidth); 
     158                int by = RandomGen.NextInt(bHeight); 
     159                addBlock(new ObjectRock(blockWidth, blockHeight), bx, by); 
     160            } 
     161        } 
     162    } 
     163 
     164    class RoomCreator 
     165    { 
     166        public static Room createRoom(TheDungeonGame game, Vector pos, Vector size, double thickness, int room) 
     167        { 
     168            Room result = null; 
     169            if (room == 0) 
     170                result = new EmptyRoom(game, pos, size, thickness); 
     171            else if (room == 1) 
     172                result = new RoomType1(game, pos, size, thickness); 
     173            else if (room == 2) 
     174                result = new RoomType2(game, pos, size, thickness); 
     175            else if (room == 3) 
     176                result = new RoomType3(game, pos, size, thickness); 
     177            else if (room == 4) 
     178                result = new RoomType4(game, pos, size, thickness); 
     179            else if (room == 5) 
     180                result = new RoomType5(game, pos, size, thickness); 
     181            else if (room == 6) 
     182                result = new RoomType6(game, pos, size, thickness); 
     183 
     184            return result; 
     185        } 
     186    } 
    36187} 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.cs

    r3563 r3568  
    4646        generator = new LevelGenerator(this, Level.Size, new Vector(20, 20)); 
    4747        generator.generateRandomLevel(5, 10); 
     48        generator.initDungeon(); 
    4849        generator.buildDungeon(); 
    4950        Room centerRoom = generator.getRoomAt((int)(generator.CenterRoom.X), (int)(generator.CenterRoom.Y)); 
     
    128129        player.Position = generator.getRoomAt(generator.CenterRoom).Position + new Vector(ROOMWIDTH / 2, -ROOMHEIGHT / 2); 
    129130        player.currentRoom = generator.getRoomAt(generator.CenterRoom); 
    130         Add(player, 1); 
     131        Add(player, 2); 
    131132    } 
    132133 
     
    136137        generator = new LevelGenerator(this, Level.Size, new Vector(20, 20)); 
    137138        generator.generateRandomLevel(10, 15); 
     139        generator.initDungeon(); 
    138140        generator.buildDungeon(); 
    139141        player.currentRoom = generator.getRoomAt(generator.CenterRoom); 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.csproj

    r3563 r3568  
    113113  </ItemGroup> 
    114114  <ItemGroup> 
     115    <Compile Include="CollisionGroups.cs" /> 
    115116    <Compile Include="Entity.cs" /> 
    116117    <Compile Include="EntityTemplates.cs" /> 
     
    119120    <Compile Include="ItemEntity.cs" /> 
    120121    <Compile Include="LevelGenerator.cs" /> 
     122    <Compile Include="ObjectRock.cs" /> 
    121123    <Compile Include="Room.cs" /> 
    122124    <Compile Include="Player.cs" /> 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGameContent/TheDungeonGameContent.contentproj

    r3563 r3568  
    9191    </Compile> 
    9292  </ItemGroup> 
     93  <ItemGroup> 
     94    <Compile Include="objects\rock.png"> 
     95      <Name>rock</Name> 
     96      <Importer>TextureImporter</Importer> 
     97      <Processor>TextureProcessor</Processor> 
     98    </Compile> 
     99  </ItemGroup> 
    93100  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    94101  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
Note: See TracChangeset for help on using the changeset viewer.