Changeset 3563 for 2012


Ignore:
Timestamp:
2012-07-05 00:14:09 (7 years ago)
Author:
dezhidki
Message:

Added some textures
Added basic ingame Gui
Added ability to hold and use items
Camera movement is now totaly fixed and working properly
Added ability to easily add and manage textures
Minor fixes on some stuff

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  
    2121       public abstract void init(); 
    2222 
    23         public EntityBase setMaxHealth(int health) 
     23        public void setMaxHealth(int health) 
    2424        { 
    2525            maxHealth = health; 
    26             return this; 
    27         } 
    28  
    29         public EntityBase setBrains(Brain brain) 
    30         { 
    31             Brain = brain; 
    32             return this; 
    3326        } 
    3427 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/LevelGenerator.cs

    r3539 r3563  
    1515        private Room[,] rooms; 
    1616        private List<Room> roomList = new List<Room>(); 
     17        public int level = 1; 
    1718 
    1819        public LevelGenerator(TheDungeonGame game, Vector size, Vector roomamount) 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Player.cs

    r3562 r3563  
    77using MathHelper; 
    88using Rooms; 
     9using Jypeli.Assets; 
     10using Items; 
    911 
    1012namespace Entity 
    1113{ 
    12     class Player : PhysicsObject 
     14    public class Player : PhysicsObject 
    1315    { 
    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; 
    1618       // private PhysicsObject head; 
    1719        public Vector movementVector = Vector.Zero; 
     
    2123        private TheDungeonGame game; 
    2224        public Room currentRoom; 
     25        public IntMeter playerHealth = new IntMeter(5, 0, 30); 
     26        private Item itemInInventory; 
    2327 
    24         public Player(TheDungeonGame game, Vector pos) 
     28        public Player(TheDungeonGame game, Vector pos, Image texture) 
    2529            : base(playerWidth, playerHeight) 
    2630        { 
     
    2933            CanRotate = false; 
    3034            setupKeys(); 
     35            Image = texture; 
     36            itemInInventory = new TestItem(TheDungeonGame.LoadImage("items/testItem"), "Test Item", false); 
    3137        } 
    3238 
     
    4248            keyboard.Listen(Key.S, ButtonState.Released, removeMovement, null, new Vector(0, -speed)); 
    4349            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); 
    4475        } 
    4576 
     
    75106        } 
    76107 
     108        public void handleItemPickup(IPhysicsObject player, IPhysicsObject item) 
     109        { 
     110            ItemEntity itemEnt =  (ItemEntity)item; 
     111            itemEnt.bindedItem.onPickup(this); 
     112            item.Destroy(); 
     113        } 
     114 
    77115        public override void Update(Time time) 
    78116        { 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/Room.cs

    r3562 r3563  
    1414        public Vector Position; 
    1515        public double width, height, thickness; 
     16        protected List<IPhysicsObject> roomDecorations = new List<IPhysicsObject>(); 
    1617        protected List<IPhysicsObject> roomObjects = new List<IPhysicsObject>(); 
    1718        private bool isBuilt = false; 
     
    5051        public void buildLevel() 
    5152        { 
    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            } 
    5359 
    5460            foreach (IPhysicsObject obj in roomObjects) 
    5561            { 
    56                 Game.Add(obj); 
     62                Game.Add(obj, 1); 
    5763            } 
    5864 
     
    6066            { 
    6167                if (obj != null) 
    62                     Game.Add(obj); 
     68                    Game.Add(obj, 1); 
    6369            } 
    6470 
     
    6975        public void destroyLevel() 
    7076        { 
    71             if (roomObjects.Count == 0) throw new Exception("Cannot destory empty room!"); 
     77            if (roomDecorations.Count == 0) throw new Exception("Cannot destory empty room!"); 
    7278            if (!isBuilt) throw new Exception("Cannot destroy unbuilt room!"); 
    7379 
     80            foreach (IPhysicsObject obj in roomDecorations) 
     81            { 
     82                obj.Destroy(); 
     83            } 
    7484            foreach (IPhysicsObject obj in roomObjects) 
    7585            { 
     
    103113            EntityAmount++; 
    104114            ent.Left = insidePos.X + (bx * blockWidth); 
    105             ent.Top = insidePos.Y * (by * blockHeight); 
     115            ent.Top = insidePos.Y + (by * blockHeight); 
    106116            insideObjects[bx, by] = ent; 
    107117        } 
     
    109119 
    110120        // En vitsinyt käyttää enempää aikaa tämän parantamiseksi. Helppo ja toimiva 
    111         public void addDoors() 
     121        public void addDoors(Image doorTexture) 
    112122        { 
    113123            for (int i = 0; i < 4; i++) 
     
    123133                    door = PhysicsObject.CreateStaticObject(thickness, thickness); 
    124134                    door.Position = Position + new Vector((width + thickness) / 2, -thickness / 2); 
     135                    door.Image = doorTexture; 
    125136                    door.Tag = RoomDirection.North; 
    126137                } 
     
    130141                        door = PhysicsObject.CreateStaticObject(thickness, thickness); 
    131142                        door.Position = Position + new Vector(width + thickness / 2, -(height + thickness) / 2); 
     143                        door.Image = doorTexture; 
     144                        door.Angle = Angle.FromDegrees(270); 
    132145                        door.Tag = RoomDirection.East; 
    133146                    } 
     
    137150                            door = PhysicsObject.CreateStaticObject(thickness, thickness); 
    138151                            door.Position = Position + new Vector((thickness + width) / 2, -height - thickness / 2); 
     152                            door.Image = Image.Flip(doorTexture); 
    139153                            door.Tag = RoomDirection.South; 
    140154                        } 
     
    144158                                door = PhysicsObject.CreateStaticObject(thickness, thickness); 
    145159                                door.Position = Position + new Vector(thickness / 2, -height / 2 - thickness / 2); 
     160                                door.Image = doorTexture; 
     161                                door.Angle = Angle.FromDegrees(90); 
    146162                                door.Tag = RoomDirection.West; 
    147163                            } 
     
    171187        } 
    172188 
    173         public void createBorders() 
     189        public void createBorders(Image topBottom, Image leftRight) 
    174190        { 
    175191            PhysicsObject wallTop = createWall(Position, width + thickness, thickness); 
    176192            wallTop.Color = Color.Blue; 
     193            wallTop.Image = topBottom; 
    177194            PhysicsObject wallLeft = createWall(VecMath.sub(Position, new Vector(0, thickness)), thickness, height); 
    178195            wallLeft.Color = Color.Red; 
     196            wallLeft.Image = leftRight; 
    179197            PhysicsObject wallDown = createWall(VecMath.sub(Position, new Vector(0, height)), width + thickness, thickness); 
    180198            wallDown.Color = Color.Black; 
     199           if(topBottom != null) wallDown.Image = Image.Flip(topBottom); 
    181200            PhysicsObject wallRight = createWall(VecMath.add(Position, new Vector(width, -thickness)), thickness, height - thickness); 
    182201            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); 
    187207        } 
    188208 
     
    196216        } 
    197217 
    198         public PhysicsObject createBackground() 
     218        public PhysicsObject createBackground(Image background) 
    199219        { 
    200220            PhysicsObject bg = PhysicsObject.CreateStaticObject(insideWidth, insideHeight); 
     
    202222            bg.Top = Position.Y - thickness; 
    203223            bg.IgnoresCollisionResponse = true; 
     224            bg.Image = background; 
    204225            bg.Color = Color.Green; 
    205226            bg.IgnoresExplosions = true; 
    206227            return bg; 
    207228        } 
    208  
    209229    } 
    210230 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/RoomTemplates.cs

    r3549 r3563  
    44using System.Text; 
    55using Jypeli; 
     6using Jypeli.Assets; 
    67using MathHelper; 
    78using Entity; 
     
    1819        public override void initRoom() 
    1920        { 
    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; 
    2433        } 
    2534    } 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.cs

    r3562 r3563  
    99using Entity; 
    1010using Rooms; 
     11using Gui; 
    1112 
    1213public class TheDungeonGame : PhysicsGame 
     
    1819    public static Vector roomSize = new Vector(ROOMWIDTH, ROOMHEIGHT); 
    1920    private Player player; 
     21    public Player Player { get { return player; } } 
    2022    private LevelGenerator generator; 
    2123    public LevelGenerator LevelGen { get { return generator; } } 
     
    2325    private Vector cameraPosMission, cameraVelocity, newPos, currentPos; 
    2426    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; 
    2534 
    2635    public override void Begin() 
     
    3039        Level.Width = ROOMWIDTH * 20; 
    3140        Level.Height = ROOMHEIGHT * 20; 
     41        setupLevelTextures(1); 
     42        setupObjectTextures(); 
     43         
     44         
    3245 
    3346        generator = new LevelGenerator(this, Level.Size, new Vector(20, 20)); 
     
    3649        Room centerRoom = generator.getRoomAt((int)(generator.CenterRoom.X), (int)(generator.CenterRoom.Y)); 
    3750        Camera.Position = centerRoom.Position + new Vector(ROOMWIDTH / 2 + ROOMTHICKNESS / 2, -ROOMHEIGHT / 2 + ROOMTHICKNESS / 4); 
     51        //Camera.ZoomToLevel(); 
    3852 
    39         player = new Player(this, Vector.Zero); 
     53        player = new Player(this, Vector.Zero, playerPic); 
    4054        setupPlayer(); 
    4155        AddCollisionHandler(player, player.performCollision); 
     56        AddCollisionHandler(player, "Item", player.handleItemPickup); 
     57 
     58 
     59        gui = new InGameGui(this); 
     60        Add(gui); 
    4261 
    4362        Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Lopeta peli"); 
    4463        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]; 
    4595    } 
    4696 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGame/TheDungeonGame.csproj

    r3547 r3563  
    115115    <Compile Include="Entity.cs" /> 
    116116    <Compile Include="EntityTemplates.cs" /> 
     117    <Compile Include="InGameGui.cs" /> 
     118    <Compile Include="Item.cs" /> 
     119    <Compile Include="ItemEntity.cs" /> 
    117120    <Compile Include="LevelGenerator.cs" /> 
    118121    <Compile Include="Room.cs" /> 
     
    121124    <Compile Include="Ohjelma.cs" /> 
    122125    <Compile Include="RoomTemplates.cs" /> 
     126    <Compile Include="TestItem.cs" /> 
    123127    <Compile Include="TheDungeonGame.cs" /> 
    124128    <Compile Include="Properties\AssemblyInfo.cs" /> 
  • 2012/27/DenisZ/TheDungeonGame/TheDungeonGame/TheDungeonGameContent/TheDungeonGameContent.contentproj

    r3446 r3563  
    4444    <Reference Include="TextFileContentExtension" /> 
    4545  </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> 
    4693  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    4794  <!--  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.