- Timestamp:
- 2014-07-23 21:30:08 (9 years ago)
- 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 11 11 { 12 12 public Vector2 offset = Vector2.Zero; 13 public Vector2 size; 13 14 public float zoomFactor = 1; 14 15 public float pitch = -45; 15 16 public float yaw = 0; 16 public Camera( )17 public Camera(Vector2 size) 17 18 { 18 19 this.size = size; 19 20 } 20 public Matrix getMatrix(Vector2 gridSize, Vector2 mapSize , Vector2 screenSize)21 public Matrix getMatrix(Vector2 gridSize, Vector2 mapSize) 21 22 { 22 23 viewPortBounds(); … … 27 28 Matrix.CreateRotationX(MathHelper.ToRadians(pitch)) * 28 29 Matrix.CreateScale(zoomFactor, zoomFactor, 0) * 29 Matrix.CreateTranslation(new Vector3(s creenSize.X / 2, screenSize.Y / 2, 0));30 Matrix.CreateTranslation(new Vector3(size.X / 2, size.Y / 2, 0)); 30 31 } 31 32 void viewPortBounds() -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Game1.cs
r5605 r5607 24 24 MouseState previousMouseState; 25 25 Vector2 mapSize = new Vector2(40, 40); 26 public Vector2 mousePos = new Vector2(0, 0); 26 27 public Random random; 27 28 Camera camera; … … 44 45 graphics.PreferredBackBufferWidth = (int)screenSize.X; 45 46 graphics.PreferredBackBufferHeight = (int)screenSize.Y; 47 46 48 //graphics.IsFullScreen = true; 47 49 //contentManager = new ContentManager(); … … 60 62 // TODO: Add your initialization logic here 61 63 random = new Random(); 62 camera = new Camera( );64 camera = new Camera(screenSize); 63 65 base.Initialize(); 64 66 } … … 68 70 /// all of your content. 69 71 /// </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 { 79 74 /*LOAD ALL TEXTURES*/ 80 75 textures.Add("testitile", Content.Load<Texture2D>("Graphics/Test/taso5.1")); 76 textures.Add("test/select", Content.Load<Texture2D>("Graphics/Test/Select")); 81 77 82 78 //KÄYTETTÄVÄT PUUT … … 90 86 textures.Add("taivas/tähdet", Content.Load<Texture2D>("Graphics/Taivas/Tähdet")); 91 87 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 92 105 effect = new BasicEffect(GraphicsDevice); 93 106 … … 130 143 camera.zoomFactor /= 1.2f; 131 144 } 145 146 mousePos = new Vector2(currentMouseState.X,currentMouseState.Y); 147 132 148 previousMouseState = currentMouseState; 133 149 … … 195 211 // TODO: Add your drawing code here 196 212 197 mapRenderer.RenderMap( camera);213 mapRenderer.RenderMap(); 198 214 199 215 base.Draw(gameTime); -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Map/Map.cs
r5605 r5607 18 18 public Tile[,] Tiles; 19 19 public List<MapObject> Objects = new List<MapObject>(); 20 public List<Unit> Units = new List<Unit>(); 20 21 Texture2D texture; 21 22 uint[] colorMap; … … 61 62 } 62 63 } 63 64 64 Objects.Add(new Unit("ukko", 1, 0)); 65 65 } 66 66 } -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Map/MapObject.cs
r5581 r5607 12 12 public string textureId; 13 13 public Vector2 position; 14 public MapObject(string textureId, float x, float y )14 public MapObject(string textureId, float x, float y, bool animated = false) 15 15 { 16 16 this.textureId = textureId; 17 17 this.position = new Vector2(x, y); 18 if (animated) 19 { 20 21 } 18 22 } 19 23 } -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/Render/MapRenderer.cs
r5605 r5607 13 13 SpriteBatch spriteBatch; 14 14 Map map; 15 Vector2 screenSize;16 15 Vector3 baseSunPosition = new Vector3(0, 0, 0); 16 Camera camera; 17 Matrix matrix; 18 MapRendererBase r; 19 17 20 float sunAngle = 24; 21 Vector3 sunPosition = Vector3.Zero; 18 22 19 public MapRenderer(SpriteBatch spriteBatch, Map map, Vector2 screenSize)23 public MapRenderer(SpriteBatch spriteBatch, Map map, Camera camera) 20 24 { 21 25 this.spriteBatch = spriteBatch; 22 26 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); 35 30 } 36 31 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); 46 35 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 79 37 foreach (MapObject obj in map.Objects) 80 38 { … … 87 45 float shadowAngle = (float)(Math.Atan2(erotus.Y, erotus.X) - Math.PI / 2.0); 88 46 89 var s uunta= sunPosition - new Vector3(obj.position.X, obj.position.Y, 0f);90 s uunta.Normalize();47 var shadowDirection = sunPosition - new Vector3(obj.position.X, obj.position.Y, 0f); 48 shadowDirection.Normalize(); 91 49 92 double dot = Vector3.Dot(Vector3.UnitZ, s uunta);50 double dot = Vector3.Dot(Vector3.UnitZ, shadowDirection); 93 51 94 52 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);96 53 } 54 97 55 spriteBatch.End(); 98 99 100 56 101 57 spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend); 102 58 59 //OBJEKTIEN RENDERÖINTI 103 60 foreach (MapObject obj in map.Objects) 104 61 { 105 62 Texture2D texture = Pikseli.Instance.textures[obj.textureId]; 106 63 Vector2 size = new Vector2(texture.Width, texture.Height) * camera.zoomFactor;//ditto 107 r enderGroundObject(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); 108 65 } 109 66 110 67 spriteBatch.End(); 111 68 } 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 } 112 114 } 113 115 } -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/WindowsGame1.csproj
r5581 r5607 77 77 <Compile Include="Map\MapObject.cs" /> 78 78 <Compile Include="Map\Tile.cs" /> 79 <Compile Include="Map\Unit.cs" /> 79 80 <Compile Include="Properties\AssemblyInfo.cs" /> 80 81 <Compile Include="Program.cs" /> 81 82 <Compile Include="Game1.cs" /> 82 83 <Compile Include="Render\MapRenderer.cs" /> 84 <Compile Include="Render\MapRendererBase.cs" /> 83 85 </ItemGroup> 84 86 <ItemGroup> -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/WindowsGame1.csproj.Debug.cachefile
r5605 r5607 7 7 Content\Graphics\Puut\Ohut.xnb 8 8 Content\Graphics\Taivas\TÀhdet.xnb 9 Content\Graphics\Olennot\char_ref.xnb 10 Content\Graphics\Olennot\Ukko.xnb 11 Content\Graphics\Gui\cursor.xnb 12 Content\Graphics\Test\select.xnb -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1/obj/x86/Debug/WindowsGame1.csproj.FileListAbsolute.txt
r5605 r5607 22 22 D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Puut\Ohut.xnb 23 23 D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Taivas\TÀhdet.xnb 24 D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Olennot\char_ref.xnb 25 D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Olennot\Ukko.xnb 26 D:\Csharp feat jypeli\MikkoI\WindowsGame1\WindowsGame1\WindowsGame1\bin\x86\Debug\Content\Graphics\Gui\cursor.xnb 27 D:\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 7 7 Content\Graphics\Puut\Ohut.xnb 8 8 Content\Graphics\Taivas\TÀhdet.xnb 9 Content\Graphics\Olennot\char_ref.xnb 10 Content\Graphics\Olennot\Ukko.xnb 11 Content\Graphics\Gui\cursor.xnb 12 Content\Graphics\Test\select.xnb -
2014/30/MikkoI/WindowsGame1/WindowsGame1/WindowsGame1Content/WindowsGame1Content.contentproj
r5605 r5607 80 80 </Compile> 81 81 </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> 82 108 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 83 109 <!-- 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 74 74 <Time>2014-07-23T17:10:10.9320052+03:00</Time> 75 75 </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> 76 112 <BuildSuccessful>true</BuildSuccessful> 77 113 <Settings>
Note: See TracChangeset
for help on using the changeset viewer.