Changeset 5607


Ignore:
Timestamp:
2014-07-23 21:30:08 (5 years ago)
Author:
mijoilmo
Message:

muutoksia skriptiin sekä kursori

Location:
2014/30/MikkoI/WindowsGame1
Files:
15 added
18 edited

Legend:

Unmodified
Added
Removed
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Camera/Camera.cs

    r5605 r5607  
    1111    { 
    1212        public Vector2 offset = Vector2.Zero; 
     13        public Vector2 size; 
    1314        public float zoomFactor = 1; 
    1415        public float pitch = -45; 
    1516        public float yaw = 0; 
    16         public Camera() 
     17        public Camera(Vector2 size) 
    1718        { 
    18  
     19            this.size = size; 
    1920        } 
    20         public Matrix getMatrix(Vector2 gridSize, Vector2 mapSize, Vector2 screenSize) 
     21        public Matrix getMatrix(Vector2 gridSize, Vector2 mapSize) 
    2122        { 
    2223            viewPortBounds(); 
     
    2728                Matrix.CreateRotationX(MathHelper.ToRadians(pitch)) * 
    2829                Matrix.CreateScale(zoomFactor, zoomFactor, 0) * 
    29                 Matrix.CreateTranslation(new Vector3(screenSize.X / 2, screenSize.Y / 2, 0)); 
     30                Matrix.CreateTranslation(new Vector3(size.X / 2, size.Y / 2, 0)); 
    3031        } 
    3132        void viewPortBounds() 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Game1.cs

    r5605 r5607  
    2424        MouseState previousMouseState; 
    2525        Vector2 mapSize = new Vector2(40, 40); 
     26        public Vector2 mousePos = new Vector2(0, 0); 
    2627        public Random random; 
    2728        Camera camera; 
     
    4445            graphics.PreferredBackBufferWidth = (int)screenSize.X; 
    4546            graphics.PreferredBackBufferHeight = (int)screenSize.Y; 
     47 
    4648            //graphics.IsFullScreen = true; 
    4749            //contentManager = new ContentManager(); 
     
    6062            // TODO: Add your initialization logic here 
    6163            random = new Random(); 
    62             camera = new Camera(); 
     64            camera = new Camera(screenSize); 
    6365            base.Initialize(); 
    6466        } 
     
    6870        /// all of your content. 
    6971        /// </summary> 
    70         protected override void LoadContent() 
    71         { 
    72             // Create a new SpriteBatch, which can be used to draw textures. 
    73             spriteBatch = new SpriteBatch(GraphicsDevice); 
    74  
    75             allMaps.Add(new Map(new Texture2D(GraphicsDevice, 1, 1), 20, 20)); 
    76  
    77             mapRenderer = new MapRenderer(spriteBatch, allMaps[currentMapIndex], screenSize); 
    78  
     72        void LoadTextures() 
     73        { 
    7974            /*LOAD ALL TEXTURES*/ 
    8075            textures.Add("testitile", Content.Load<Texture2D>("Graphics/Test/taso5.1")); 
     76            textures.Add("test/select", Content.Load<Texture2D>("Graphics/Test/Select")); 
    8177 
    8278            //KÄYTETTÄVÄT PUUT 
     
    9086            textures.Add("taivas/tähdet", Content.Load<Texture2D>("Graphics/Taivas/Tähdet")); 
    9187 
     88            //OLENNOT 
     89            textures.Add("olennot/ukko", Content.Load<Texture2D>("Graphics/Olennot/Ukko")); 
     90 
     91            //GUI 
     92            textures.Add("gui/cursor", Content.Load<Texture2D>("Graphics/Gui/Cursor")); 
     93        } 
     94        protected override void LoadContent() 
     95        { 
     96            // Create a new SpriteBatch, which can be used to draw textures. 
     97            spriteBatch = new SpriteBatch(GraphicsDevice); 
     98 
     99            allMaps.Add(new Map(new Texture2D(GraphicsDevice, 1, 1), 20, 20)); 
     100 
     101            mapRenderer = new MapRenderer(spriteBatch, allMaps[currentMapIndex], camera); 
     102 
     103            LoadTextures(); 
     104 
    92105            effect = new BasicEffect(GraphicsDevice); 
    93106 
     
    130143                camera.zoomFactor /= 1.2f; 
    131144            } 
     145 
     146            mousePos = new Vector2(currentMouseState.X,currentMouseState.Y); 
     147             
    132148            previousMouseState = currentMouseState; 
    133149 
     
    195211            // TODO: Add your drawing code here 
    196212 
    197             mapRenderer.RenderMap(camera); 
     213            mapRenderer.RenderMap(); 
    198214 
    199215            base.Draw(gameTime); 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Map/Map.cs

    r5605 r5607  
    1818        public Tile[,] Tiles; 
    1919        public List<MapObject> Objects = new List<MapObject>(); 
     20        public List<Unit> Units = new List<Unit>(); 
    2021        Texture2D texture; 
    2122        uint[] colorMap; 
     
    6162                } 
    6263            } 
    63  
    64  
     64            Objects.Add(new Unit("ukko", 1, 0)); 
    6565        } 
    6666    } 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Map/MapObject.cs

    r5581 r5607  
    1212        public string textureId; 
    1313        public Vector2 position; 
    14         public MapObject(string textureId, float x, float y) 
     14        public MapObject(string textureId, float x, float y, bool animated = false) 
    1515        { 
    1616            this.textureId = textureId; 
    1717            this.position = new Vector2(x, y); 
     18            if (animated) 
     19            { 
     20                 
     21            } 
    1822        } 
    1923    } 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Render/MapRenderer.cs

    r5605 r5607  
    1313        SpriteBatch spriteBatch; 
    1414        Map map; 
    15         Vector2 screenSize; 
    1615        Vector3 baseSunPosition = new Vector3(0, 0, 0); 
     16        Camera camera; 
     17        Matrix matrix; 
     18        MapRendererBase r; 
     19 
    1720        float sunAngle = 24; 
     21        Vector3 sunPosition = Vector3.Zero; 
    1822 
    19         public MapRenderer(SpriteBatch spriteBatch, Map map, Vector2 screenSize) 
     23        public MapRenderer(SpriteBatch spriteBatch, Map map, Camera camera) 
    2024        { 
    2125            this.spriteBatch = spriteBatch; 
    2226            this.map = map; 
    23             this.screenSize = screenSize; 
    24             baseSunPosition = new Vector3(map.Size.X / 2, map.Size.Y / 2, 40); 
    25         } 
    26         void renderGroundTile(Texture2D texture, int x, int y) 
    27         {//renderöi maata 
    28             //maatilen koko on 64x64. 
    29             spriteBatch.Draw(texture, new Rectangle(x * 64, y * 64, texture.Width, texture.Height), null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0.01f); 
    30         } 
    31         void renderGroundObject(Texture2D texture, int x, int y, Vector2 size, Matrix matrix) 
    32         {//renderöi maassa olevan asian (ei liiku) 
    33             Vector2 paikka = Vector2.Transform(new Vector2((x + 0.5f) * 64, (y + 0.5f) * 64), matrix) - new Vector2(size.X / 2, size.Y); 
    34             spriteBatch.Draw(texture, new Rectangle((int)paikka.X, (int)paikka.Y, (int)size.X, (int)size.Y), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, (paikka.Y + size.Y) / (screenSize.Y + size.Y)); 
     27            this.baseSunPosition = new Vector3(map.Size.X / 2, map.Size.Y / 2, 40);//alusta auringon pyörityksen joint-piste 
     28            this.camera = camera; 
     29            this.r = new MapRendererBase(spriteBatch); 
    3530        } 
    3631 
    37         void renderDistantSprite(Texture2D texture, Vector3 position, Vector2 size, Matrix matrix) 
    38         {//Renderöi kaukaisia juttuja kuten auringon ja tähdet 
    39             Vector3 calcPosition = Vector3.Transform(position * 64.0f, matrix); 
    40             spriteBatch.Draw(texture, new Rectangle((int)(calcPosition.X), (int)(calcPosition.Y), (int)size.X, (int)size.Y), null, Color.White, 0f, new Vector2(texture.Width / 2, texture.Height / 2), SpriteEffects.None, 1f); 
    41         } 
    42         void renderBackground(Texture2D texture, Vector2 size) 
    43         { 
    44             spriteBatch.Draw(texture, new Rectangle(0, 0, (int)size.X, (int)size.Y), Color.White); 
    45         } 
     32        void renderGroundObjects() { 
     33            //renderöi kaikki maassa olevat dynaamiset objektit, eli puut, olennot ym. 
     34            spriteBatch.Begin(SpriteSortMode.FrontToBack, null, null, null, null, null, matrix); 
    4635 
    47         public void RenderMap(Camera camera) 
    48         {//renderöi koko mapin, kutsu ulkopuolelta 
    49             Matrix matrix = camera.getMatrix(new Vector2(64, 64), map.Size, screenSize);//mapin tilen koko 64x64 
    50  
    51             sunAngle += 1 / 3000.0f;//auringon pyörimisnopeus 
    52  
    53             Vector3 sunPosition = baseSunPosition + new Vector3((float)Math.Sin(sunAngle), (float)Math.Cos(sunAngle), 0) * 100; 
    54  
    55             spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); 
    56             Vector3 fixedSun = sunPosition; 
    57             fixedSun.Z *= -1.0f; 
    58             fixedSun.Z += 22;//alaspäin että näkyy pelissä 
    59  
    60             Texture2D sunTexture = Pikseli.Instance.textures["taivas/aurinko"]; 
    61             Texture2D starBackground = Pikseli.Instance.textures["taivas/tähdet"]; 
    62  
    63             renderDistantSprite(sunTexture, fixedSun, new Vector2(sunTexture.Width * camera.zoomFactor * 5, sunTexture.Height * camera.zoomFactor * 5), matrix); 
    64             renderBackground(starBackground, new Vector2(starBackground.Width, starBackground.Height)); 
    65  
    66             spriteBatch.End(); 
    67  
    68             spriteBatch.Begin(SpriteSortMode.FrontToBack, null, null, null, null, null, matrix); 
    69             for (var x = 0; x < map.Size.X; x++) 
    70             { 
    71                 for (var y = 0; y < map.Size.Y; y++) 
    72                 { 
    73                     renderGroundTile(Pikseli.Instance.textures[map.Tiles[x, y].textureId], x, y); 
    74                 } 
    75             } 
    76  
    77             //varjot testi 
    78  
     36            //VARJOJEN RENDERÖINTI 
    7937            foreach (MapObject obj in map.Objects) 
    8038            { 
     
    8745                float shadowAngle = (float)(Math.Atan2(erotus.Y, erotus.X) - Math.PI / 2.0); 
    8846 
    89                 var suunta = sunPosition - new Vector3(obj.position.X, obj.position.Y, 0f); 
    90                 suunta.Normalize(); 
     47                var shadowDirection = sunPosition - new Vector3(obj.position.X, obj.position.Y, 0f); 
     48                shadowDirection.Normalize(); 
    9149 
    92                 double dot = Vector3.Dot(Vector3.UnitZ, suunta); 
     50                double dot = Vector3.Dot(Vector3.UnitZ, shadowDirection); 
    9351 
    9452                spriteBatch.Draw(texture, new Rectangle((int)((obj.position.X + 0.5) * 64), (int)((obj.position.Y + 0.5) * 64), texture.Width, (int)((1.0 / dot) * texture.Height - texture.Height)), null, new Color(0f, 0f, 0f, 0.5f), shadowAngle, new Vector2(texture.Width / 2, texture.Height), SpriteEffects.None, 0.5f); 
    95                 //spriteBatch.Draw(obj.texture, new Rectangle((int)(obj.position.X + 0.5) * 64, (int)(obj.position.Y + 0.5) * 64, (int)obj.texture.Width, (int)obj.texture.Height), null, Color.Gray, MathHelper.ToRadians(30), new Vector2(obj.texture.Width / 2, obj.texture.Height), SpriteEffects.None, 0f); 
    9653            } 
     54 
    9755            spriteBatch.End(); 
    98  
    99  
    10056 
    10157            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); 
    10258 
     59            //OBJEKTIEN RENDERÖINTI 
    10360            foreach (MapObject obj in map.Objects) 
    10461            { 
    10562                Texture2D texture = Pikseli.Instance.textures[obj.textureId]; 
    10663                Vector2 size = new Vector2(texture.Width, texture.Height) * camera.zoomFactor;//ditto 
    107                 renderGroundObject(texture, (int)obj.position.X, (int)obj.position.Y, size, matrix); 
     64                r.renderGroundObject(texture, (int)obj.position.X, (int)obj.position.Y, size, matrix, camera); 
    10865            } 
    10966 
    11067            spriteBatch.End(); 
    11168        } 
     69 
     70        void renderSky() { 
     71            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); 
     72 
     73            sunAngle += 1 / 3000.0f;//auringon pyörimisnopeus 
     74 
     75            sunPosition = baseSunPosition + new Vector3((float)Math.Sin(sunAngle), (float)Math.Cos(sunAngle), 0) * 100; 
     76 
     77            Vector3 fixedSun = sunPosition; 
     78            fixedSun.Z *= -1.0f; 
     79            fixedSun.Z += 22;//alaspäin että näkyy pelissä 
     80 
     81            Texture2D sunTexture = Pikseli.Instance.textures["taivas/aurinko"]; 
     82            Texture2D starBackground = Pikseli.Instance.textures["taivas/tähdet"]; 
     83 
     84            r.renderDistantSprite(sunTexture, fixedSun, new Vector2(sunTexture.Width * camera.zoomFactor * 5, sunTexture.Height * camera.zoomFactor * 5), matrix); 
     85            r.renderBackground(starBackground, new Vector2(starBackground.Width, starBackground.Height)); 
     86 
     87            spriteBatch.End(); 
     88        } 
     89 
     90        public void RenderMap() 
     91        {//renderöi koko mapin, kutsu ulkopuolelta 
     92            matrix = camera.getMatrix(new Vector2(64, 64), map.Size);//mapin tilen koko 64x64 
     93 
     94            renderSky(); 
     95 
     96            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, matrix); 
     97            for (var x = 0; x < map.Size.X; x++) 
     98            { 
     99                for (var y = 0; y < map.Size.Y; y++) 
     100                { 
     101                    r.renderGroundTile(Pikseli.Instance.textures[map.Tiles[x, y].textureId], x, y); 
     102                } 
     103            } 
     104 
     105            r.renderGroundTile(Pikseli.Instance.textures["test/select"], 0, 0); 
     106            spriteBatch.End(); 
     107 
     108            renderGroundObjects(); 
     109 
     110            spriteBatch.Begin(); 
     111            spriteBatch.Draw(Pikseli.Instance.textures["gui/cursor"],Pikseli.Instance.mousePos,Color.White); 
     112            spriteBatch.End(); 
     113        } 
    112114    } 
    113115} 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/WindowsGame1.csproj

    r5581 r5607  
    7777    <Compile Include="Map\MapObject.cs" /> 
    7878    <Compile Include="Map\Tile.cs" /> 
     79    <Compile Include="Map\Unit.cs" /> 
    7980    <Compile Include="Properties\AssemblyInfo.cs" /> 
    8081    <Compile Include="Program.cs" /> 
    8182    <Compile Include="Game1.cs" /> 
    8283    <Compile Include="Render\MapRenderer.cs" /> 
     84    <Compile Include="Render\MapRendererBase.cs" /> 
    8385  </ItemGroup> 
    8486  <ItemGroup> 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/WindowsGame1.csproj.Debug.cachefile

    r5605 r5607  
    77Content\Graphics\Puut\Ohut.xnb 
    88Content\Graphics\Taivas\TÀhdet.xnb 
     9Content\Graphics\Olennot\char_ref.xnb 
     10Content\Graphics\Olennot\Ukko.xnb 
     11Content\Graphics\Gui\cursor.xnb 
     12Content\Graphics\Test\select.xnb 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/obj/x86/Debug/WindowsGame1.csproj.FileListAbsolute.txt

    r5605 r5607  
    2222D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Puut\Ohut.xnb 
    2323D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Taivas\TÀhdet.xnb 
     24D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Olennot\char_ref.xnb 
     25D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Olennot\Ukko.xnb 
     26D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Gui\cursor.xnb 
     27D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Test\select.xnb 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/obj/x86/Debug/cachefile-{97A5BC4F-C40A-4D52-BF03-8923DFD60CA0}-targetpath.txt

    r5605 r5607  
    77Content\Graphics\Puut\Ohut.xnb 
    88Content\Graphics\Taivas\TÀhdet.xnb 
     9Content\Graphics\Olennot\char_ref.xnb 
     10Content\Graphics\Olennot\Ukko.xnb 
     11Content\Graphics\Gui\cursor.xnb 
     12Content\Graphics\Test\select.xnb 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1Content/WindowsGame1Content.contentproj

    r5605 r5607  
    8080    </Compile> 
    8181  </ItemGroup> 
     82  <ItemGroup> 
     83    <Compile Include="Graphics\Olennot\char_ref.png"> 
     84      <Name>char_ref</Name> 
     85      <Importer>TextureImporter</Importer> 
     86      <Processor>TextureProcessor</Processor> 
     87    </Compile> 
     88    <Compile Include="Graphics\Olennot\Ukko.png"> 
     89      <Name>Ukko</Name> 
     90      <Importer>TextureImporter</Importer> 
     91      <Processor>TextureProcessor</Processor> 
     92    </Compile> 
     93  </ItemGroup> 
     94  <ItemGroup> 
     95    <Compile Include="Graphics\Gui\cursor.png"> 
     96      <Name>cursor</Name> 
     97      <Importer>TextureImporter</Importer> 
     98      <Processor>TextureProcessor</Processor> 
     99    </Compile> 
     100  </ItemGroup> 
     101  <ItemGroup> 
     102    <Compile Include="Graphics\Test\select.png"> 
     103      <Name>select</Name> 
     104      <Importer>TextureImporter</Importer> 
     105      <Processor>TextureProcessor</Processor> 
     106    </Compile> 
     107  </ItemGroup> 
    82108  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    83109  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1Content/obj/x86/Debug/ContentPipeline.xml

    r5605 r5607  
    7474      <Time>2014-07-23T17:10:10.9320052+03:00</Time> 
    7575    </Item> 
     76    <Item> 
     77      <Source>Graphics\Olennot\char_ref.png</Source> 
     78      <Name>Graphics\Olennot\char_ref</Name> 
     79      <Importer>TextureImporter</Importer> 
     80      <Processor>TextureProcessor</Processor> 
     81      <Options>None</Options> 
     82      <Output>D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Olennot\char_ref.xnb</Output> 
     83      <Time>2014-07-23T20:09:58.2358767+03:00</Time> 
     84    </Item> 
     85    <Item> 
     86      <Source>Graphics\Olennot\Ukko.png</Source> 
     87      <Name>Graphics\Olennot\Ukko</Name> 
     88      <Importer>TextureImporter</Importer> 
     89      <Processor>TextureProcessor</Processor> 
     90      <Options>None</Options> 
     91      <Output>D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Olennot\Ukko.xnb</Output> 
     92      <Time>2014-07-23T21:04:24.3825583+03:00</Time> 
     93    </Item> 
     94    <Item> 
     95      <Source>Graphics\Gui\cursor.png</Source> 
     96      <Name>Graphics\Gui\cursor</Name> 
     97      <Importer>TextureImporter</Importer> 
     98      <Processor>TextureProcessor</Processor> 
     99      <Options>None</Options> 
     100      <Output>D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Gui\cursor.xnb</Output> 
     101      <Time>2014-07-23T21:14:48.5922647+03:00</Time> 
     102    </Item> 
     103    <Item> 
     104      <Source>Graphics\Test\select.png</Source> 
     105      <Name>Graphics\Test\select</Name> 
     106      <Importer>TextureImporter</Importer> 
     107      <Processor>TextureProcessor</Processor> 
     108      <Options>None</Options> 
     109      <Output>D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Test\select.xnb</Output> 
     110      <Time>2014-07-23T21:26:29.5801296+03:00</Time> 
     111    </Item> 
    76112    <BuildSuccessful>true</BuildSuccessful> 
    77113    <Settings> 
Note: See TracChangeset for help on using the changeset viewer.