Changeset 5603 for 2014


Ignore:
Timestamp:
2014-07-23 15:15:00 (5 years ago)
Author:
mijoilmo
Message:
 
Location:
2014/30/MikkoI
Files:
76 added
13 edited

Legend:

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

    r5581 r5603  
    2020        public Matrix getMatrix(Vector2 gridSize, Vector2 mapSize, Vector2 screenSize) 
    2121        { 
    22             viewPortBounds(); 
     22            //viewPortBounds(); 
    2323 
    2424            Vector3 pixelMapSize = new Vector3((gridSize.X * mapSize.X / 2), (gridSize.Y * mapSize.Y / 2), 0); 
    2525            return Matrix.CreateTranslation(new Vector3(-pixelMapSize.X + offset.X, -pixelMapSize.Y + offset.Y, 0)) * 
    26                 Matrix.CreateRotationZ(MathHelper.ToRadians(45 + yaw)) * 
     26                Matrix.CreateRotationZ(MathHelper.ToRadians(yaw)) * 
    2727                Matrix.CreateRotationX(MathHelper.ToRadians(pitch)) * 
    2828                Matrix.CreateScale(zoomFactor, zoomFactor, 0) * 
     
    3535            //if (yaw < -70) { yaw = -70; } else if (yaw > 70) { yaw = 70; }//rajoita pyörittämistä (-70 - 70) 
    3636            if (pitch < -88) { pitch = -88; } else if (pitch > -45) { pitch = -45; }//rajoittaa ylös-alas-liikettä 
    37             if (zoomFactor < 0.4f) { zoomFactor = 0.4f; } else if (zoomFactor > 3f) { zoomFactor = 3f; }//rajoittaa zoomia 
     37            if (zoomFactor < 0.2f) { zoomFactor = 0.2f; } else if (zoomFactor > 3f) { zoomFactor = 3f; }//rajoittaa zoomia 
    3838        } 
    3939    } 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Game1.cs

    r5582 r5603  
    7373            spriteBatch = new SpriteBatch(GraphicsDevice); 
    7474 
    75             allMaps.Add(new Map(new Texture2D(GraphicsDevice, 1, 1), 100, 100)); 
     75            allMaps.Add(new Map(new Texture2D(GraphicsDevice, 1, 1), 20, 20)); 
    7676 
    7777            mapRenderer = new MapRenderer(spriteBatch, allMaps[currentMapIndex], screenSize); 
     
    8080            textures.Add("testitile", Content.Load<Texture2D>("Graphics/Test/taso5.1")); 
    8181            textures.Add("testipuu", Content.Load<Texture2D>("Graphics/Test/kuusi")); 
    82  
    83  
    84              
    85  
    86  
    87  
     82            textures.Add("aurinko", Content.Load<Texture2D>("Graphics/Taivas/Aurinko")); 
    8883 
    8984            effect = new BasicEffect(GraphicsDevice); 
     
    159154            { 
    160155                //lisätään molempia koska tämä muokkaa translaatiota 
    161                 camera.offset.X += scrollSpeed / camera.zoomFactor; 
    162                 camera.offset.Y += scrollSpeed / camera.zoomFactor; 
     156                camera.offset.X += (scrollSpeed / camera.zoomFactor) * (float)Math.Sin(MathHelper.ToRadians(camera.yaw)); 
     157                camera.offset.Y += (scrollSpeed / camera.zoomFactor) * (float)Math.Cos(MathHelper.ToRadians(camera.yaw)); 
    163158            } 
    164159            else if (Keyboard.GetState().IsKeyDown(Keys.S)) 
    165160            { 
    166                 camera.offset.Y -= scrollSpeed / camera.zoomFactor; 
    167                 camera.offset.X -= scrollSpeed / camera.zoomFactor; 
     161                camera.offset.X -= (scrollSpeed / camera.zoomFactor) * (float)Math.Sin(MathHelper.ToRadians(camera.yaw)); 
     162                camera.offset.Y -= (scrollSpeed / camera.zoomFactor) * (float)Math.Cos(MathHelper.ToRadians(camera.yaw)); 
    168163            } 
    169164 
    170165            if (Keyboard.GetState().IsKeyDown(Keys.A)) 
    171166            { 
    172                 camera.offset.X += scrollSpeed / camera.zoomFactor; 
    173                 camera.offset.Y -= scrollSpeed / camera.zoomFactor; 
     167                camera.offset.X += (scrollSpeed / camera.zoomFactor) * (float)Math.Cos(MathHelper.ToRadians(camera.yaw)); 
     168                camera.offset.Y -= (scrollSpeed / camera.zoomFactor) * (float)Math.Sin(MathHelper.ToRadians(camera.yaw)); 
    174169            } 
    175170            else if (Keyboard.GetState().IsKeyDown(Keys.D)) 
    176171            { 
    177                 camera.offset.X -= scrollSpeed / camera.zoomFactor; 
    178                 camera.offset.Y += scrollSpeed / camera.zoomFactor; 
     172                camera.offset.X -= (scrollSpeed / camera.zoomFactor) * (float)Math.Cos(MathHelper.ToRadians(camera.yaw)); 
     173                camera.offset.Y += (scrollSpeed / camera.zoomFactor) * (float)Math.Sin(MathHelper.ToRadians(camera.yaw)); 
    179174            } 
    180175 
     
    190185            GraphicsDevice.Clear(Color.Black); 
    191186 
    192  
    193  
    194187            // TODO: Add your drawing code here 
    195188 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Render/MapRenderer.cs

    r5582 r5603  
    1414        Map map; 
    1515        Vector2 screenSize; 
    16         Vector3 sunPosition = new Vector3(0, 0, 15); 
     16        Vector3 baseSunPosition = new Vector3(0, 0, 0); 
     17        float sunAngle = 24; 
    1718 
    1819        public MapRenderer(SpriteBatch spriteBatch, Map map, Vector2 screenSize) 
     
    2122            this.map = map; 
    2223            this.screenSize = screenSize; 
     24            baseSunPosition = new Vector3(map.Size.X/2, map.Size.Y/2, 160); 
    2325        } 
    2426        void renderGroundTile(Texture2D texture, int x, int y) 
    2527        {//renderöi maata 
    2628            //maatilen koko on 64x64. 
    27             spriteBatch.Draw(texture, new Rectangle(x * 64, y * 64, texture.Width, texture.Height), null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0f); 
     29            spriteBatch.Draw(texture, new Rectangle(x * 64, y * 64, texture.Width, texture.Height), null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0.01f); 
    2830        } 
    2931        void renderGroundObject(Texture2D texture, int x, int y, Vector2 size, Matrix matrix) 
     
    3638        {//renderöi koko mapin, kutsu ulkopuolelta 
    3739            Matrix matrix = camera.getMatrix(new Vector2(64, 64), map.Size, screenSize);//mapin tilen koko 64x64 
    38             spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, matrix); 
     40 
     41            sunAngle += 1/3000.0f;//auringon pyörimisnopeus 
     42 
     43            Vector3 sunPosition = baseSunPosition + new Vector3((float)Math.Sin(sunAngle), (float)Math.Cos(sunAngle), 0) * 400; 
     44 
     45            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); 
     46            Vector3 fixedSun = sunPosition; 
     47            fixedSun.Z *= -1.0f; 
     48            fixedSun.Z += 162;//alaspäin että näkyy pelissä 
     49            Vector3 sun = Vector3.Transform(fixedSun * 64.0f, matrix); 
     50            Texture2D sunTexture = Pikseli.Instance.textures["aurinko"]; 
     51            spriteBatch.Draw(sunTexture, new Rectangle((int)(sun.X), (int)(sun.Y), sunTexture.Width, (int)(sunTexture.Height)), null, new Color(1f, 1f, 0f, 1f), 0f, new Vector2(sunTexture.Width / 2, sunTexture.Height / 2), SpriteEffects.None, 0f); 
     52            spriteBatch.End(); 
     53 
     54            spriteBatch.Begin(SpriteSortMode.FrontToBack, null, null, null, null, null, matrix); 
    3955            for (var x = 0; x < map.Size.X; x++) 
    4056            { 
     
    4763            //varjot testi 
    4864 
    49             sunPosition = new Vector3(-20 + (float)Pikseli.Instance.gameTime.TotalGameTime.TotalSeconds + 1.42f, -20 + (float)Pikseli.Instance.gameTime.TotalGameTime.TotalSeconds, 0); 
    50  
    5165            foreach (MapObject obj in map.Objects) 
    5266            { 
     
    5771 
    5872 
    59                 float shadowAngle = (float)(Math.Atan2(erotus.Y, erotus.X) - Math.PI / 2); 
    60                 double shadowOffsetX = Math.Cos(shadowAngle + Math.PI / 2) * 5, 
    61                     shadowOffsetY = Math.Sin(shadowAngle + Math.PI / 2) * 5; 
    62                      
    63                 spriteBatch.Draw(texture, new Rectangle((int)((obj.position.X + 0.5) * 64), (int)((obj.position.Y + 0.5) * 64), texture.Width, texture.Height), null, new Color(0f, 0f, 0f, 0.5f), shadowAngle, new Vector2(texture.Width / 2, texture.Height), SpriteEffects.None, 0f); 
     73                float shadowAngle = (float)(Math.Atan2(erotus.Y, erotus.X) - Math.PI / 2.0); 
     74 
     75                var suunta = sunPosition - new Vector3(obj.position.X, obj.position.Y, 0f); 
     76                suunta.Normalize(); 
     77 
     78                double dot = Vector3.Dot(Vector3.UnitZ, suunta); 
     79                double testi = 1.0 / dot; 
     80                double shadowHeight = (28000.0 / sunPosition.Z); 
     81 
     82                spriteBatch.Draw(texture, new Rectangle((int)((obj.position.X + 0.5) * 64), (int)((obj.position.Y + 0.5) * 64), texture.Width, (int)(testi * texture.Height - texture.Height)), null, new Color(0f, 0f, 0f, 0.5f), shadowAngle, new Vector2(texture.Width / 2, texture.Height), SpriteEffects.None, 0.5f); 
    6483                //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); 
    6584            } 
     
    6988 
    7089            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); 
     90 
    7191            foreach (MapObject obj in map.Objects) 
    7292            { 
     
    7595                renderGroundObject(texture, (int)obj.position.X, (int)obj.position.Y, size, matrix); 
    7696            } 
     97 
    7798            spriteBatch.End(); 
    7899        } 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/WindowsGame1.csproj.Debug.cachefile

    r5581 r5603  
    11Content\Graphics\Test\taso5.1.xnb 
    22Content\Graphics\Test\Kuusi.xnb 
     3Content\Graphics\Taivas\Aurinko.xnb 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/obj/x86/Debug/ContentPipeline-{97A5BC4F-C40A-4D52-BF03-8923DFD60CA0}.xml

    r5582 r5603  
    1919      <Output>C:\MyTemp\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Test\Kuusi.xnb</Output> 
    2020      <Time>2014-07-23T12:43:51.363918+03:00</Time> 
     21    </Item> 
     22    <Item> 
     23      <Source>Graphics\Taivas\Aurinko.png</Source> 
     24      <Name>Graphics\Taivas\Aurinko</Name> 
     25      <Importer>TextureImporter</Importer> 
     26      <Processor>TextureProcessor</Processor> 
     27      <Options>None</Options> 
     28      <Output>C:\MyTemp\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Taivas\Aurinko.xnb</Output> 
     29      <Time>2014-07-23T14:23:58.810918+03:00</Time> 
    2130    </Item> 
    2231    <BuildSuccessful>true</BuildSuccessful> 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/obj/x86/Debug/WindowsGame1.csproj.FileListAbsolute.txt

    r5581 r5603  
    77C:\MyTemp\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\obj\x86\Debug\WindowsGame1.csprojResolveAssemblyReference.cache 
    88C:\MyTemp\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Test\Kuusi.xnb 
     9C:\MyTemp\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Taivas\Aurinko.xnb 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/obj/x86/Debug/cachefile-{97A5BC4F-C40A-4D52-BF03-8923DFD60CA0}-targetpath.txt

    r5581 r5603  
    11Content\Graphics\Test\taso5.1.xnb 
    22Content\Graphics\Test\Kuusi.xnb 
     3Content\Graphics\Taivas\Aurinko.xnb 
  • 2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1Content/WindowsGame1Content.contentproj

    r5581 r5603  
    4444    </Compile> 
    4545  </ItemGroup> 
     46  <ItemGroup> 
     47    <Compile Include="Graphics\Taivas\Aurinko.png"> 
     48      <Name>Aurinko</Name> 
     49      <Importer>TextureImporter</Importer> 
     50      <Processor>TextureProcessor</Processor> 
     51    </Compile> 
     52  </ItemGroup> 
    4653  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    4754  <!--  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.