- Timestamp:
- 2014-07-23 15:15:00 (7 years ago)
- Location:
- 2014/30/MikkoI
- Files:
-
- 76 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Camera/Camera.cs
r5581 r5603 20 20 public Matrix getMatrix(Vector2 gridSize, Vector2 mapSize, Vector2 screenSize) 21 21 { 22 viewPortBounds();22 //viewPortBounds(); 23 23 24 24 Vector3 pixelMapSize = new Vector3((gridSize.X * mapSize.X / 2), (gridSize.Y * mapSize.Y / 2), 0); 25 25 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)) * 27 27 Matrix.CreateRotationX(MathHelper.ToRadians(pitch)) * 28 28 Matrix.CreateScale(zoomFactor, zoomFactor, 0) * … … 35 35 //if (yaw < -70) { yaw = -70; } else if (yaw > 70) { yaw = 70; }//rajoita pyörittämistä (-70 - 70) 36 36 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 zoomia37 if (zoomFactor < 0.2f) { zoomFactor = 0.2f; } else if (zoomFactor > 3f) { zoomFactor = 3f; }//rajoittaa zoomia 38 38 } 39 39 } -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Game1.cs
r5582 r5603 73 73 spriteBatch = new SpriteBatch(GraphicsDevice); 74 74 75 allMaps.Add(new Map(new Texture2D(GraphicsDevice, 1, 1), 100, 100));75 allMaps.Add(new Map(new Texture2D(GraphicsDevice, 1, 1), 20, 20)); 76 76 77 77 mapRenderer = new MapRenderer(spriteBatch, allMaps[currentMapIndex], screenSize); … … 80 80 textures.Add("testitile", Content.Load<Texture2D>("Graphics/Test/taso5.1")); 81 81 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")); 88 83 89 84 effect = new BasicEffect(GraphicsDevice); … … 159 154 { 160 155 //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)); 163 158 } 164 159 else if (Keyboard.GetState().IsKeyDown(Keys.S)) 165 160 { 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)); 168 163 } 169 164 170 165 if (Keyboard.GetState().IsKeyDown(Keys.A)) 171 166 { 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)); 174 169 } 175 170 else if (Keyboard.GetState().IsKeyDown(Keys.D)) 176 171 { 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)); 179 174 } 180 175 … … 190 185 GraphicsDevice.Clear(Color.Black); 191 186 192 193 194 187 // TODO: Add your drawing code here 195 188 -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Render/MapRenderer.cs
r5582 r5603 14 14 Map map; 15 15 Vector2 screenSize; 16 Vector3 sunPosition = new Vector3(0, 0, 15); 16 Vector3 baseSunPosition = new Vector3(0, 0, 0); 17 float sunAngle = 24; 17 18 18 19 public MapRenderer(SpriteBatch spriteBatch, Map map, Vector2 screenSize) … … 21 22 this.map = map; 22 23 this.screenSize = screenSize; 24 baseSunPosition = new Vector3(map.Size.X/2, map.Size.Y/2, 160); 23 25 } 24 26 void renderGroundTile(Texture2D texture, int x, int y) 25 27 {//renderöi maata 26 28 //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, 0 f);29 spriteBatch.Draw(texture, new Rectangle(x * 64, y * 64, texture.Width, texture.Height), null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0.01f); 28 30 } 29 31 void renderGroundObject(Texture2D texture, int x, int y, Vector2 size, Matrix matrix) … … 36 38 {//renderöi koko mapin, kutsu ulkopuolelta 37 39 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); 39 55 for (var x = 0; x < map.Size.X; x++) 40 56 { … … 47 63 //varjot testi 48 64 49 sunPosition = new Vector3(-20 + (float)Pikseli.Instance.gameTime.TotalGameTime.TotalSeconds + 1.42f, -20 + (float)Pikseli.Instance.gameTime.TotalGameTime.TotalSeconds, 0);50 51 65 foreach (MapObject obj in map.Objects) 52 66 { … … 57 71 58 72 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); 64 83 //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); 65 84 } … … 69 88 70 89 spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); 90 71 91 foreach (MapObject obj in map.Objects) 72 92 { … … 75 95 renderGroundObject(texture, (int)obj.position.X, (int)obj.position.Y, size, matrix); 76 96 } 97 77 98 spriteBatch.End(); 78 99 } -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/WindowsGame1.csproj.Debug.cachefile
r5581 r5603 1 1 Content\Graphics\Test\taso5.1.xnb 2 2 Content\Graphics\Test\Kuusi.xnb 3 Content\Graphics\Taivas\Aurinko.xnb -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/obj/x86/Debug/ContentPipeline-{97A5BC4F-C40A-4D52-BF03-8923DFD60CA0}.xml
r5582 r5603 19 19 <Output>C:\MyTemp\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Test\Kuusi.xnb</Output> 20 20 <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> 21 30 </Item> 22 31 <BuildSuccessful>true</BuildSuccessful> -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/obj/x86/Debug/WindowsGame1.csproj.FileListAbsolute.txt
r5581 r5603 7 7 C:\MyTemp\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\obj\x86\Debug\WindowsGame1.csprojResolveAssemblyReference.cache 8 8 C:\MyTemp\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Test\Kuusi.xnb 9 C:\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 1 1 Content\Graphics\Test\taso5.1.xnb 2 2 Content\Graphics\Test\Kuusi.xnb 3 Content\Graphics\Taivas\Aurinko.xnb -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1Content/WindowsGame1Content.contentproj
r5581 r5603 44 44 </Compile> 45 45 </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> 46 53 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 47 54 <!-- 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.