Description:
Add option to shade squares.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -0,0 +1,131 | |||||
|
|
1 | using System; | ||
|
|
2 | using System.Collections.Generic; | ||
|
|
3 | using System.Linq; | ||
|
|
4 | |||
|
|
5 | using Microsoft.Xna.Framework; | ||
|
|
6 | using Microsoft.Xna.Framework.Graphics; | ||
|
|
7 | |||
|
|
8 | namespace isometricparkfna | ||
|
|
9 | { | ||
|
|
10 | |||
|
|
11 | public class Quad | ||
|
|
12 | { | ||
|
|
13 | static public BasicEffect quadEffect; | ||
|
|
14 | static VertexPositionTexture[] vert; | ||
|
|
15 | static short[] ind; | ||
|
|
16 | |||
|
|
17 | public static Texture2D PixelTexture; | ||
|
|
18 | public static Texture2D SolidTexture; | ||
|
|
19 | |||
|
|
20 | |||
|
|
21 | public static void Initialize(GraphicsDevice device, Texture2D texture) | ||
|
|
22 | { | ||
|
|
23 | Quad.quadEffect = new BasicEffect(device); | ||
|
|
24 | Quad.quadEffect.TextureEnabled = true; | ||
|
|
25 | |||
|
|
26 | Quad.vert = new VertexPositionTexture[4]; | ||
|
|
27 | Quad.ind = new short[6]; | ||
|
|
28 | ind[0] = 0; | ||
|
|
29 | ind[1] = 2; | ||
|
|
30 | ind[2] = 1; | ||
|
|
31 | ind[3] = 1; | ||
|
|
32 | ind[4] = 2; | ||
|
|
33 | ind[5] = 3; | ||
|
|
34 | |||
|
|
35 | Quad.PixelTexture = new Texture2D(device, 1, 1); | ||
|
|
36 | Quad.SolidTexture = texture; | ||
|
|
37 | } | ||
|
|
38 | |||
|
|
39 | static public void FillSquare(GraphicsDevice device, int x, int y, Color color, float alpha) | ||
|
|
40 | { | ||
|
|
41 | |||
|
|
42 | // Vector2 adjust2 = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved | ||
|
|
43 | // | ||
|
|
44 | var startX = ((x - y) * Tile.TileSpriteWidth / 2) + (Tile.TileSpriteWidth / 2); | ||
|
|
45 | var startY = (x + y) * Tile.TileSpriteHeight / 2 + (Tile.TileSpriteHeight); | ||
|
|
46 | startX = 0; | ||
|
|
47 | startY = 10; | ||
|
|
48 | // | ||
|
|
49 | // Rectangle rect = new Rectangle(startX, startY, Tile.TileSpriteWidth / 2, (int)(Tile.TileSpriteHeight * 0.75)); | ||
|
|
50 | // batch.Draw(Line.PixelTexture, rect, null, color, 0.785f, new Vector2(0,0), SpriteEffects.None, 0.79f); | ||
|
|
51 | // | ||
|
|
52 | |||
|
|
53 | // vert[0].Position = new Vector3(startX, startY, 0); | ||
|
|
54 | // vert[1].Position = new Vector3(startX+Tile.TileSpriteWidth, startY, 0); | ||
|
|
55 | // vert[2].Position = new Vector3(startX, startY+Tile.TileSpriteHeight, 0); | ||
|
|
56 | // vert[3].Position = new Vector3(startX+Tile.TileSpriteWidth, startY+Tile.TileSpriteHeight, 0); | ||
|
|
57 | vert[0].Position = new Vector3(startX, startY, 0); | ||
|
|
58 | vert[1].Position = new Vector3(startX + 100, startY, 0); | ||
|
|
59 | vert[2].Position = new Vector3(startX, startY + 100, 0); | ||
|
|
60 | vert[3].Position = new Vector3(startX + 100, startY + 100, 0); | ||
|
|
61 | |||
|
|
62 | |||
|
|
63 | |||
|
|
64 | vert[0].TextureCoordinate = new Vector2(0, 0); | ||
|
|
65 | vert[1].TextureCoordinate = new Vector2(1, 0); | ||
|
|
66 | vert[2].TextureCoordinate = new Vector2(0, 1); | ||
|
|
67 | vert[3].TextureCoordinate = new Vector2(1, 1); | ||
|
|
68 | var PixelTexture = new Texture2D(device, 1, 1); | ||
|
|
69 | |||
|
|
70 | PixelTexture.SetData<Color>(new Color[] { color }); | ||
|
|
71 | |||
|
|
72 | quadEffect.Texture = PixelTexture; | ||
|
|
73 | |||
|
|
74 | |||
|
|
75 | foreach (EffectPass effectPass in Quad.quadEffect.CurrentTechnique.Passes) | ||
|
|
76 | { | ||
|
|
77 | effectPass.Apply(); | ||
|
|
78 | device.DrawUserIndexedPrimitives<VertexPositionTexture>( | ||
|
|
79 | PrimitiveType.TriangleList, Quad.vert, 0, Quad.vert.Length, Quad.ind, 0, Quad.ind.Length / 3); | ||
|
|
80 | } | ||
|
|
81 | } | ||
|
|
82 | |||
|
|
83 | public static void FillSquare2(SpriteBatch batch, int x, int y, Color color, float alpha) | ||
|
|
84 | { | ||
|
|
85 | var height = 1; | ||
|
|
86 | var depth = 0.79f; | ||
|
|
87 | |||
|
|
88 | int height_adjust = 0; | ||
|
|
89 | |||
|
|
90 | if (height > 1) //not sure why this is necessary :/ | ||
|
|
91 | { | ||
|
|
92 | height_adjust = height; | ||
|
|
93 | } | ||
|
|
94 | |||
|
|
95 | int adjustedx = x - height_adjust; | ||
|
|
96 | int adjustedy = y - height_adjust; | ||
|
|
97 | |||
|
|
98 | int screenx = (adjustedx - adjustedy) * Tile.TileSpriteWidth / 2; | ||
|
|
99 | int screeny = (adjustedx + adjustedy) * Tile.TileSpriteHeight / 2; | ||
|
|
100 | |||
|
|
101 | PixelTexture.SetData<Color>(new Color[] { color }); | ||
|
|
102 | |||
|
|
103 | // color.A = (byte)(alpha*255.0f); | ||
|
|
104 | color *= alpha; | ||
|
|
105 | |||
|
|
106 | // if (this.cull(x, y)) | ||
|
|
107 | // { | ||
|
|
108 | batch.Draw( | ||
|
|
109 | Quad.SolidTexture, | ||
|
|
110 | new Rectangle( | ||
|
|
111 | screenx, | ||
|
|
112 | screeny, | ||
|
|
113 | Tile.TileWidth, Tile.TileHeight * height), | ||
|
|
114 | // Tile.GetExtendedSourceRectangle(tileIndex, height), | ||
|
|
115 | // new Rectangle(0, 0, 1, 1), | ||
|
|
116 | // null, | ||
|
|
117 | Tile.GetExtendedSourceRectangle(0, height), | ||
|
|
118 | // Color.White, | ||
|
|
119 | color, | ||
|
|
120 | 0.0f, | ||
|
|
121 | Vector2.Zero, | ||
|
|
122 | SpriteEffects.None, | ||
|
|
123 | depth); | ||
|
|
124 | // } | ||
|
|
125 | |||
|
|
126 | } | ||
|
|
127 | |||
|
|
128 | } | ||
|
|
129 | |||
|
|
130 | |||
|
|
131 | } No newline at end of file |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -183,9 +183,12 | |||||
|
183 |
|
183 | ||
|
184 | sound = Content.Load<SoundEffect>("FNASound"); |
|
184 | sound = Content.Load<SoundEffect>("FNASound"); |
|
185 | Tile.TileSetTexture = Content.Load<Texture2D>(@"part4_tileset"); |
|
185 | Tile.TileSetTexture = Content.Load<Texture2D>(@"part4_tileset"); |
|
|
186 | var texture = Content.Load<Texture2D>(@"solid_tileset"); | ||
|
186 |
|
187 | ||
|
187 | Line.initialize(GraphicsDevice); |
|
188 | Line.initialize(GraphicsDevice); |
|
188 |
|
189 | ||
|
|
190 | Quad.Initialize(GraphicsDevice, texture); | ||
|
|
191 | |||
|
189 | //Has to happen before Encompass stuff, because the Encompass machinery around ImGui requires debugWindow's monoFont to be loaded: |
|
192 | //Has to happen before Encompass stuff, because the Encompass machinery around ImGui requires debugWindow's monoFont to be loaded: |
|
190 | this.debugWindow = new DebugWindow(this._imGuiRenderer, GraphicsDevice); |
|
193 | this.debugWindow = new DebugWindow(this._imGuiRenderer, GraphicsDevice); |
|
191 |
|
194 | ||
@@ -693,6 +696,10 | |||||
|
693 | //donut |
|
696 | //donut |
|
694 | Tile.DrawOutlinedSquares(batch, new Vector2[] {new Vector2(19, 1), new Vector2(19, 2), new Vector2(20, 1), new Vector2(21, 1), |
|
697 | Tile.DrawOutlinedSquares(batch, new Vector2[] {new Vector2(19, 1), new Vector2(19, 2), new Vector2(20, 1), new Vector2(21, 1), |
|
695 | new Vector2(21, 2), new Vector2(19, 3), new Vector2(20, 3), new Vector2(21, 3)}, Color.Purple); |
|
698 | new Vector2(21, 2), new Vector2(19, 3), new Vector2(20, 3), new Vector2(21, 3)}, Color.Purple); |
|
|
699 | |||
|
|
700 | Quad.FillSquare2(batch, 7, 4, Color.Orange, 1.0f); | ||
|
|
701 | Quad.FillSquare2(batch, 7, 3, Color.Yellow, 1.0f); | ||
|
|
702 | Quad.FillSquare2(batch, 7, 5, Color.Yellow, .5f); | ||
|
696 | #endif |
|
703 | #endif |
|
697 |
|
704 | ||
|
698 |
|
705 |
@@ -46,10 +46,16 | |||||
|
46 |
|
46 | ||
|
47 | static public Texture2D TileSetTexture; |
|
47 | static public Texture2D TileSetTexture; |
|
48 |
|
48 | ||
|
|
49 | |||
|
|
50 | |||
|
|
51 | |||
|
49 | public Tile() |
|
52 | public Tile() |
|
50 | { |
|
53 | { |
|
|
54 | |||
|
51 | } |
|
55 | } |
|
52 |
|
56 | ||
|
|
57 | |||
|
|
58 | |||
|
53 | static public Rectangle GetSourceRectangle(int tileIndex) |
|
59 | static public Rectangle GetSourceRectangle(int tileIndex) |
|
54 | { |
|
60 | { |
|
55 | int tileY = tileIndex / (TileSetTexture.Width / TileWidth); |
|
61 | int tileY = tileIndex / (TileSetTexture.Width / TileWidth); |
@@ -66,6 +72,8 | |||||
|
66 | return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight*height); |
|
72 | return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight*height); |
|
67 | } |
|
73 | } |
|
68 |
|
74 | ||
|
|
75 | |||
|
|
76 | |||
|
69 | static public void OutlineSquare(SpriteBatch batch, float x, float y, Color color) |
|
77 | static public void OutlineSquare(SpriteBatch batch, float x, float y, Color color) |
|
70 | { |
|
78 | { |
|
71 | Tile.OutlineSquare(batch, x, y, color, 1); |
|
79 | Tile.OutlineSquare(batch, x, y, color, 1); |
@@ -37,6 +37,7 | |||||
|
37 | <Compile Include="Tile.cs" /> |
|
37 | <Compile Include="Tile.cs" /> |
|
38 | <Compile Include="CellMap.cs" /> |
|
38 | <Compile Include="CellMap.cs" /> |
|
39 | <Compile Include="Line.cs" /> |
|
39 | <Compile Include="Line.cs" /> |
|
|
40 | <Compile Include="Quad.cs" /> | ||
|
40 | <Compile Include="Camera.cs" /> |
|
41 | <Compile Include="Camera.cs" /> |
|
41 | <Compile Include="DrawVertDeclaration.cs" /> |
|
42 | <Compile Include="DrawVertDeclaration.cs" /> |
|
42 | <Compile Include="ImGuiRenderer.cs" /> |
|
43 | <Compile Include="ImGuiRenderer.cs" /> |
@@ -89,6 +90,9 | |||||
|
89 | <None Include="Content\part4_tileset.png"> |
|
90 | <None Include="Content\part4_tileset.png"> |
|
90 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|
91 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|
91 | </None> |
|
92 | </None> |
|
|
93 | <None Include="Content\solild_tileset.png"> | ||
|
|
94 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
|
|
95 | </None> | ||
|
92 | <None Include="Content\iosevka-medium.ttf"> |
|
96 | <None Include="Content\iosevka-medium.ttf"> |
|
93 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|
97 | <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
|
94 | </None> |
|
98 | </None> |
You need to be logged in to leave comments.
Login now