Changeset 3563
- Timestamp:
- 2012-07-05 00:14:09 (9 years ago)
- Location:
- 2012/27/DenisZ/TheDungeonGame
- Files:
-
- 21 added
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Entity.cs
r3549 r3563 21 21 public abstract void init(); 22 22 23 public EntityBasesetMaxHealth(int health)23 public void setMaxHealth(int health) 24 24 { 25 25 maxHealth = health; 26 return this;27 }28 29 public EntityBase setBrains(Brain brain)30 {31 Brain = brain;32 return this;33 26 } 34 27 -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/LevelGenerator.cs
r3539 r3563 15 15 private Room[,] rooms; 16 16 private List<Room> roomList = new List<Room>(); 17 public int level = 1; 17 18 18 19 public LevelGenerator(TheDungeonGame game, Vector size, Vector roomamount) -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Player.cs
r3562 r3563 7 7 using MathHelper; 8 8 using Rooms; 9 using Jypeli.Assets; 10 using Items; 9 11 10 12 namespace Entity 11 13 { 12 class Player : PhysicsObject14 public class Player : PhysicsObject 13 15 { 14 public const double playerWidth = 75;15 public const double playerHeight = 75;16 public const double playerWidth = 120/3; 17 public const double playerHeight = 180/3; 16 18 // private PhysicsObject head; 17 19 public Vector movementVector = Vector.Zero; … … 21 23 private TheDungeonGame game; 22 24 public Room currentRoom; 25 public IntMeter playerHealth = new IntMeter(5, 0, 30); 26 private Item itemInInventory; 23 27 24 public Player(TheDungeonGame game, Vector pos )28 public Player(TheDungeonGame game, Vector pos, Image texture) 25 29 : base(playerWidth, playerHeight) 26 30 { … … 29 33 CanRotate = false; 30 34 setupKeys(); 35 Image = texture; 36 itemInInventory = new TestItem(TheDungeonGame.LoadImage("items/testItem"), "Test Item", false); 31 37 } 32 38 … … 42 48 keyboard.Listen(Key.S, ButtonState.Released, removeMovement, null, new Vector(0, -speed)); 43 49 keyboard.Listen(Key.D, ButtonState.Released, removeMovement, null, new Vector(speed, 0)); 50 keyboard.Listen(Key.Space, ButtonState.Pressed, useItemInInventory, "Use Item"); 51 } 52 53 private void useItemInInventory() 54 { 55 if (itemInInventory == null) return; 56 itemInInventory.useItem(game); 57 updateGuiImage(); 58 } 59 60 public Item ItemInInventory 61 { 62 get 63 { 64 return itemInInventory; 65 } 66 set 67 { 68 itemInInventory = value; 69 } 70 } 71 72 public void updateGuiImage() 73 { 74 game.gui.setInventoryImage(itemInInventory); 44 75 } 45 76 … … 75 106 } 76 107 108 public void handleItemPickup(IPhysicsObject player, IPhysicsObject item) 109 { 110 ItemEntity itemEnt = (ItemEntity)item; 111 itemEnt.bindedItem.onPickup(this); 112 item.Destroy(); 113 } 114 77 115 public override void Update(Time time) 78 116 { -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Room.cs
r3562 r3563 14 14 public Vector Position; 15 15 public double width, height, thickness; 16 protected List<IPhysicsObject> roomDecorations = new List<IPhysicsObject>(); 16 17 protected List<IPhysicsObject> roomObjects = new List<IPhysicsObject>(); 17 18 private bool isBuilt = false; … … 50 51 public void buildLevel() 51 52 { 52 if (roomObjects.Count == 0) throw new Exception("Cannot build empty room!"); 53 if (roomDecorations.Count == 0 && roomObjects.Count == 0) throw new Exception("Cannot build empty room!"); 54 55 foreach (IPhysicsObject obj in roomDecorations) 56 { 57 Game.Add(obj); 58 } 53 59 54 60 foreach (IPhysicsObject obj in roomObjects) 55 61 { 56 Game.Add(obj );62 Game.Add(obj, 1); 57 63 } 58 64 … … 60 66 { 61 67 if (obj != null) 62 Game.Add(obj );68 Game.Add(obj, 1); 63 69 } 64 70 … … 69 75 public void destroyLevel() 70 76 { 71 if (room Objects.Count == 0) throw new Exception("Cannot destory empty room!");77 if (roomDecorations.Count == 0) throw new Exception("Cannot destory empty room!"); 72 78 if (!isBuilt) throw new Exception("Cannot destroy unbuilt room!"); 73 79 80 foreach (IPhysicsObject obj in roomDecorations) 81 { 82 obj.Destroy(); 83 } 74 84 foreach (IPhysicsObject obj in roomObjects) 75 85 { … … 103 113 EntityAmount++; 104 114 ent.Left = insidePos.X + (bx * blockWidth); 105 ent.Top = insidePos.Y *(by * blockHeight);115 ent.Top = insidePos.Y + (by * blockHeight); 106 116 insideObjects[bx, by] = ent; 107 117 } … … 109 119 110 120 // En vitsinyt käyttää enempää aikaa tämän parantamiseksi. Helppo ja toimiva 111 public void addDoors( )121 public void addDoors(Image doorTexture) 112 122 { 113 123 for (int i = 0; i < 4; i++) … … 123 133 door = PhysicsObject.CreateStaticObject(thickness, thickness); 124 134 door.Position = Position + new Vector((width + thickness) / 2, -thickness / 2); 135 door.Image = doorTexture; 125 136 door.Tag = RoomDirection.North; 126 137 } … … 130 141 door = PhysicsObject.CreateStaticObject(thickness, thickness); 131 142 door.Position = Position + new Vector(width + thickness / 2, -(height + thickness) / 2); 143 door.Image = doorTexture; 144 door.Angle = Angle.FromDegrees(270); 132 145 door.Tag = RoomDirection.East; 133 146 } … … 137 150 door = PhysicsObject.CreateStaticObject(thickness, thickness); 138 151 door.Position = Position + new Vector((thickness + width) / 2, -height - thickness / 2); 152 door.Image = Image.Flip(doorTexture); 139 153 door.Tag = RoomDirection.South; 140 154 } … … 144 158 door = PhysicsObject.CreateStaticObject(thickness, thickness); 145 159 door.Position = Position + new Vector(thickness / 2, -height / 2 - thickness / 2); 160 door.Image = doorTexture; 161 door.Angle = Angle.FromDegrees(90); 146 162 door.Tag = RoomDirection.West; 147 163 } … … 171 187 } 172 188 173 public void createBorders( )189 public void createBorders(Image topBottom, Image leftRight) 174 190 { 175 191 PhysicsObject wallTop = createWall(Position, width + thickness, thickness); 176 192 wallTop.Color = Color.Blue; 193 wallTop.Image = topBottom; 177 194 PhysicsObject wallLeft = createWall(VecMath.sub(Position, new Vector(0, thickness)), thickness, height); 178 195 wallLeft.Color = Color.Red; 196 wallLeft.Image = leftRight; 179 197 PhysicsObject wallDown = createWall(VecMath.sub(Position, new Vector(0, height)), width + thickness, thickness); 180 198 wallDown.Color = Color.Black; 199 if(topBottom != null) wallDown.Image = Image.Flip(topBottom); 181 200 PhysicsObject wallRight = createWall(VecMath.add(Position, new Vector(width, -thickness)), thickness, height - thickness); 182 201 wallRight.Color = Color.Orange; 183 roomObjects.Add(wallTop); 184 roomObjects.Add(wallLeft); 185 roomObjects.Add(wallDown); 186 roomObjects.Add(wallRight); 202 if(leftRight != null) wallRight.Image = Image.Mirror(leftRight); 203 roomDecorations.Add(wallTop); 204 roomDecorations.Add(wallLeft); 205 roomDecorations.Add(wallDown); 206 roomDecorations.Add(wallRight); 187 207 } 188 208 … … 196 216 } 197 217 198 public PhysicsObject createBackground( )218 public PhysicsObject createBackground(Image background) 199 219 { 200 220 PhysicsObject bg = PhysicsObject.CreateStaticObject(insideWidth, insideHeight); … … 202 222 bg.Top = Position.Y - thickness; 203 223 bg.IgnoresCollisionResponse = true; 224 bg.Image = background; 204 225 bg.Color = Color.Green; 205 226 bg.IgnoresExplosions = true; 206 227 return bg; 207 228 } 208 209 229 } 210 230 -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/RoomTemplates.cs
r3549 r3563 4 4 using System.Text; 5 5 using Jypeli; 6 using Jypeli.Assets; 6 7 using MathHelper; 7 8 using Entity; … … 18 19 public override void initRoom() 19 20 { 20 createBorders(); 21 addDoors(); 22 roomObjects.Add(createBackground()); 23 TestEntity entity = new TestEntity(Game, Vector.Zero, new Vector(40, 40), Shape.Rectangle); 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; 24 33 } 25 34 } -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.cs
r3562 r3563 9 9 using Entity; 10 10 using Rooms; 11 using Gui; 11 12 12 13 public class TheDungeonGame : PhysicsGame … … 18 19 public static Vector roomSize = new Vector(ROOMWIDTH, ROOMHEIGHT); 19 20 private Player player; 21 public Player Player { get { return player; } } 20 22 private LevelGenerator generator; 21 23 public LevelGenerator LevelGen { get { return generator; } } … … 23 25 private Vector cameraPosMission, cameraVelocity, newPos, currentPos; 24 26 private bool moveCamera = false; 27 28 public Image playerPic = LoadImage("player"); 29 public List<Image> levelTopBottoms = new List<Image>(); 30 public List<Image> levelLeftRights = new List<Image>(); 31 public List<Image> levelBackGrounds = new List<Image>(); 32 public List<Image> objectTextures = new List<Image>(); 33 public InGameGui gui; 25 34 26 35 public override void Begin() … … 30 39 Level.Width = ROOMWIDTH * 20; 31 40 Level.Height = ROOMHEIGHT * 20; 41 setupLevelTextures(1); 42 setupObjectTextures(); 43 44 32 45 33 46 generator = new LevelGenerator(this, Level.Size, new Vector(20, 20)); … … 36 49 Room centerRoom = generator.getRoomAt((int)(generator.CenterRoom.X), (int)(generator.CenterRoom.Y)); 37 50 Camera.Position = centerRoom.Position + new Vector(ROOMWIDTH / 2 + ROOMTHICKNESS / 2, -ROOMHEIGHT / 2 + ROOMTHICKNESS / 4); 51 //Camera.ZoomToLevel(); 38 52 39 player = new Player(this, Vector.Zero );53 player = new Player(this, Vector.Zero, playerPic); 40 54 setupPlayer(); 41 55 AddCollisionHandler(player, player.performCollision); 56 AddCollisionHandler(player, "Item", player.handleItemPickup); 57 58 59 gui = new InGameGui(this); 60 Add(gui); 42 61 43 62 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli"); 44 63 Keyboard.Listen(Key.R, ButtonState.Pressed, regenerateLevel, null); 64 } 65 66 private void setupLevelTextures(int levels) 67 { 68 for (int i = 1; i <= levels; i++) 69 { 70 levelTopBottoms.Add(LoadImage("level"+i+"/topBottom")); 71 levelLeftRights.Add(LoadImage("level"+i+"/leftRight")); 72 levelBackGrounds.Add(LoadImage("level"+i+"/levelBackground")); 73 } 74 } 75 76 private void setupObjectTextures() 77 { 78 objectTextures.Add(LoadImage("objects/door_closed")); 79 //objectTextures.Add(LoadImage("objects/door_open")); 80 } 81 82 public Image getLeftRightWall(int level) 83 { 84 return levelLeftRights[level - 1]; 85 } 86 87 public Image getTopBottomWall(int level) 88 { 89 return levelTopBottoms[level - 1]; 90 } 91 92 public Image getLevelBackground(int level) 93 { 94 return levelBackGrounds[level - 1]; 45 95 } 46 96 -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.csproj
r3547 r3563 115 115 <Compile Include="Entity.cs" /> 116 116 <Compile Include="EntityTemplates.cs" /> 117 <Compile Include="InGameGui.cs" /> 118 <Compile Include="Item.cs" /> 119 <Compile Include="ItemEntity.cs" /> 117 120 <Compile Include="LevelGenerator.cs" /> 118 121 <Compile Include="Room.cs" /> … … 121 124 <Compile Include="Ohjelma.cs" /> 122 125 <Compile Include="RoomTemplates.cs" /> 126 <Compile Include="TestItem.cs" /> 123 127 <Compile Include="TheDungeonGame.cs" /> 124 128 <Compile Include="Properties\AssemblyInfo.cs" /> -
2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGameContent/TheDungeonGameContent.contentproj
r3446 r3563 44 44 <Reference Include="TextFileContentExtension" /> 45 45 </ItemGroup> 46 <ItemGroup> 47 <Compile Include="player.png"> 48 <Name>player</Name> 49 <Importer>TextureImporter</Importer> 50 <Processor>TextureProcessor</Processor> 51 </Compile> 52 </ItemGroup> 53 <ItemGroup> 54 <Compile Include="level1\leftRight.png"> 55 <Name>leftRight</Name> 56 <Importer>TextureImporter</Importer> 57 <Processor>TextureProcessor</Processor> 58 </Compile> 59 <Compile Include="level1\topBottom.png"> 60 <Name>topBottom</Name> 61 <Importer>TextureImporter</Importer> 62 <Processor>TextureProcessor</Processor> 63 </Compile> 64 </ItemGroup> 65 <ItemGroup> 66 <Compile Include="level1\levelBackground.png"> 67 <Name>levelBackground</Name> 68 <Importer>TextureImporter</Importer> 69 <Processor>TextureProcessor</Processor> 70 </Compile> 71 </ItemGroup> 72 <ItemGroup> 73 <Compile Include="objects\door_closed.png"> 74 <Name>door_closed</Name> 75 <Importer>TextureImporter</Importer> 76 <Processor>TextureProcessor</Processor> 77 </Compile> 78 </ItemGroup> 79 <ItemGroup> 80 <Compile Include="gui\heart.png"> 81 <Name>heart</Name> 82 <Importer>TextureImporter</Importer> 83 <Processor>TextureProcessor</Processor> 84 </Compile> 85 </ItemGroup> 86 <ItemGroup> 87 <Compile Include="items\testItem.png"> 88 <Name>testItem</Name> 89 <Importer>TextureImporter</Importer> 90 <Processor>TextureProcessor</Processor> 91 </Compile> 92 </ItemGroup> 46 93 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 47 94 <!-- 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.