Show More
Commit Description:
Add rudimentary dropdown for menu button.
Commit Description:
Add rudimentary dropdown for menu button.
Show/Diff file:
Action:
isometric-park-fna/Tile.cs
244 lines | 10.4 KiB | text/x-csharp | CSharpLexer
Early working version (including all dependencies, lol).
r0 using System;
Small fixes.
r596 using System.Diagnostics;
Add code for drawing outlines of an arbitrary set of squares.
r154 using System.Collections.Generic;
using System.Linq;
Early working version (including all dependencies, lol).
r0
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace isometricparkfna
{
Add Edge drawing functions (from last night).
r153
public struct Edge {
Fix style.
r462 public Vector2 Start;
public Vector2 End;
Add code for drawing outlines of an arbitrary set of squares.
r154
Fix style.
r462 public static bool operator == (Edge left, Edge right) {
return (left.Start == right.Start && left.End == right.End) ||
(left.Start == right.End && left.End == right.Start);
}
Add code for drawing outlines of an arbitrary set of squares.
r154
Fix style.
r462 public static bool operator != (Edge left, Edge right) {
return !(left == right);
}
Add code for drawing outlines of an arbitrary set of squares.
r154
Fix style.
r462 public override bool Equals(Object other) {
return ((other != null)
&& this.GetType().Equals(other.GetType())
&& this == (Edge)other); //we just confirmed the types match so this is okay
}
Address some warnings.
r155
Fix style.
r462 public override int GetHashCode() {
return (Start, End).GetHashCode();
}
Add Edge drawing functions (from last night).
r153
}
Early working version (including all dependencies, lol).
r0 public class Tile
{
//blatantly stolen from XNA resources.com
static public int TileWidth = 64;
static public int TileHeight = 64;
Remove some dead code.
r124 // static public int TileStepX = 64;
// static public int TileStepY = 16;
//static public int OddRowXOffset = 32;
Early working version (including all dependencies, lol).
r0
Switch to drawing from top middle rather than upper-right corner.
r12 static public int TileSpriteWidth = 64;
static public int TileSpriteHeight = 32;
Early working version (including all dependencies, lol).
r0 static public Texture2D TileSetTexture;
Move cursor rendering out of FNAGame to separate Renderer.
r564 public const float DEPTH = 0.79f;
Add option to shade squares.
r206
Early working version (including all dependencies, lol).
r0 public Tile()
{
Add option to shade squares.
r206
Early working version (including all dependencies, lol).
r0 }
Add option to shade squares.
r206
Early working version (including all dependencies, lol).
r0 static public Rectangle GetSourceRectangle(int tileIndex)
{
int tileY = tileIndex / (TileSetTexture.Width / TileWidth);
int tileX = tileIndex % (TileSetTexture.Width / TileWidth);
return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight);
}
Add rudimentary tree drawing.
r2 static public Rectangle GetExtendedSourceRectangle(int tileIndex, int height)
{
int tileY = tileIndex / (TileSetTexture.Width / TileWidth);
int tileX = tileIndex % (TileSetTexture.Width / TileWidth);
return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight*height);
}
Add option to shade squares.
r206
Move Outline methods.
r67 static public void OutlineSquare(SpriteBatch batch, float x, float y, Color color)
{
Tile.OutlineSquare(batch, x, y, color, 1);
}
static public void OutlineSquare(SpriteBatch batch, float x, float y, Color color, int size)
{
Vector2 adjust2 = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved
//Upper right
//float x = this.mouseGrid.X;
//float y = this.mouseGrid.Y;
Line.drawLine(batch,
Fix style.
r462 new Vector2(((x - y) * Tile.TileSpriteWidth / 2), (x + y) * Tile.TileSpriteHeight / 2) + adjust2,
//new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight),
new Vector2(((x - y + size) * Tile.TileSpriteWidth / 2), (x + y + size) * Tile.TileSpriteHeight / 2) + adjust2,
Add basic sound.
r578 color, 0.77f);
Move Outline methods.
r67
//Bottom right
Line.drawLine(batch,
Fix style.
r462 new Vector2(((x + size - y) * Tile.TileSpriteWidth / 2), (x + size + y) * Tile.TileSpriteHeight / 2) + adjust2,
//new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight),
new Vector2(((x + size - (y + size)) * Tile.TileSpriteWidth / 2), (x + size + (y + size)) * Tile.TileSpriteHeight / 2) + adjust2,
Add basic sound.
r578 color, 0.77f);
Move Outline methods.
r67 //Bottom left
Line.drawLine(batch,
Fix style.
r462 new Vector2(((x - (y + size)) * Tile.TileSpriteWidth / 2), (x + y + size) * Tile.TileSpriteHeight / 2) + adjust2,
//new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight),
new Vector2(((x + size - (y + size)) * Tile.TileSpriteWidth / 2), (x + size + (y + size)) * Tile.TileSpriteHeight / 2) + adjust2,
Add basic sound.
r578 color, 0.77f);
Move Outline methods.
r67 //Upper left
Line.drawLine(batch,
Fix style.
r462 new Vector2(((x - y) * Tile.TileSpriteWidth / 2), (x + y) * Tile.TileSpriteHeight / 2) + adjust2,
//new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight),
new Vector2(((x - (y + size)) * Tile.TileSpriteWidth / 2), (x + (y + size)) * Tile.TileSpriteHeight / 2) + adjust2,
Add basic sound.
r578 color, 0.77f);
Move Outline methods.
r67 }
Factor out some of the tile drawing code.
r68
Add Edge drawing functions (from last night).
r153 static public void OutlineSquare2(SpriteBatch batch, float x, float y, Color color, int size)
{
Vector2 adjust2 = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved
//Upper right
//float x = this.mouseGrid.X;
//float y = this.mouseGrid.Y;
Fix style.
r462 //
int size_less_one = size - 1;
Add Edge drawing functions (from last night).
r153
Line.drawLine(batch,
Fix style.
r462 new Vector2(((x - y) * Tile.TileSpriteWidth / 2), (x + y) * Tile.TileSpriteHeight / 2) + adjust2,
//new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight),
new Vector2(((x - y + size_less_one) * Tile.TileSpriteWidth / 2), (x + y + size_less_one) * Tile.TileSpriteHeight / 2) + adjust2,
Move cursor rendering out of FNAGame to separate Renderer.
r564 color, Tile.DEPTH);
Add Edge drawing functions (from last night).
r153
//Bottom right
Line.drawLine(batch,
Fix style.
r462 new Vector2(((x + size - y) * Tile.TileSpriteWidth / 2), (x + size_less_one + y) * Tile.TileSpriteHeight / 2) + adjust2,
//new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight),
new Vector2(((x + size - (y + size)) * Tile.TileSpriteWidth / 2), (x + size_less_one + (y + size_less_one)) * Tile.TileSpriteHeight / 2) + adjust2,
Move cursor rendering out of FNAGame to separate Renderer.
r564 color, Tile.DEPTH);
Add Edge drawing functions (from last night).
r153 //Bottom left
Line.drawLine(batch,
Fix style.
r462 new Vector2(((x - (y + size)) * Tile.TileSpriteWidth / 2), (x + y + size) * Tile.TileSpriteHeight / 2) + adjust2,
//new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight),
new Vector2(((x + size - (y + size)) * Tile.TileSpriteWidth / 2), (x + size + (y + size)) * Tile.TileSpriteHeight / 2) + adjust2,
Move cursor rendering out of FNAGame to separate Renderer.
r564 color, Tile.DEPTH);
Add Edge drawing functions (from last night).
r153 //Upper left
Line.drawLine(batch,
Fix style.
r462 new Vector2(((x - y) * Tile.TileSpriteWidth / 2), (x + y) * Tile.TileSpriteHeight / 2) + adjust2,
//new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight),
new Vector2(((x - (y + size)) * Tile.TileSpriteWidth / 2), (x + (y + size)) * Tile.TileSpriteHeight / 2) + adjust2,
Move cursor rendering out of FNAGame to separate Renderer.
r564 color, Tile.DEPTH);
Add Edge drawing functions (from last night).
r153 }
Fix style.
r462 public static void drawOutline(SpriteBatch batch, Color color) {
Vector2[] squares = {new Vector2(15, 1), new Vector2(15,2)};
Add Edge drawing functions (from last night).
r153
Fix style.
r462 foreach (Vector2 square in squares) {
}
}
Add Edge drawing functions (from last night).
r153
Fix style.
r462 public static void drawEdge(SpriteBatch batch, Edge edge, Color color) {
Add Edge drawing functions (from last night).
r153
Fix style.
r462 //x = edge.Start.X
//y = edge.Start.y
//y + size = edge.End.y
//x + size = edge.End.x
Add Edge drawing functions (from last night).
r153
Vector2 adjust2 = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved
Line.drawLine(batch,
Fix style.
r462 new Vector2(((edge.Start.X - edge.Start.Y) * Tile.TileSpriteWidth / 2), (edge.Start.X + edge.Start.Y) * Tile.TileSpriteHeight / 2) + adjust2,
//new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight),
new Vector2(((edge.End.X - edge.End.Y) * Tile.TileSpriteWidth / 2), (edge.End.X + edge.End.Y) * Tile.TileSpriteHeight / 2) + adjust2,
color, 0.80f); //Just behind the default
}
Add Edge drawing functions (from last night).
r153
Fix style.
r462 public static void drawEdges(SpriteBatch batch, Edge[] edges, Color color) {
foreach (Edge edge in edges) {
drawEdge(batch, edge, color);
}
}
Add Edge drawing functions (from last night).
r153
Fix style.
r462 public static void DrawOutlinedSquares(SpriteBatch batch, Vector2[] squares, Color color) {
List<Edge> edges = new List<Edge>();
Add code for drawing outlines of an arbitrary set of squares.
r154
Fix style.
r462 foreach (Vector2 square in squares) {
//upper right
edges.Add(new Edge {Start=square, End=square + new Vector2(1, 0)});
//lower right
edges.Add(new Edge {Start=square + new Vector2(1, 0), End=square + new Vector2(1, 1)});
//lower left
edges.Add(new Edge {Start=square + new Vector2(0, 1), End=square + new Vector2(1, 1)});
//upper left
edges.Add(new Edge {Start=square, End=square + new Vector2(0, 1)});
}
Add code for drawing outlines of an arbitrary set of squares.
r154
Small fixes.
r596 //Seems to be v. slow
Fix style.
r462 edges = edges.GroupBy(x => x).Where(grp => grp.Count() == 1).Select(grp => grp.Key).ToList<Edge>();
Add code for drawing outlines of an arbitrary set of squares.
r154
Fix style.
r462 drawEdges(batch, edges.ToArray(), color);
}
Add code for drawing outlines of an arbitrary set of squares.
r154
Add missing file.
r569 public static void drawTileAt(SpriteBatch batch, int x, int y, int tileIndex, int height, float depth) {
drawTileAt(batch, x, y, tileIndex, height, depth, Color.White);
}
Add Edge drawing functions (from last night).
r153
Add missing file.
r569
public static void drawTileAt(SpriteBatch batch, int x, int y, int tileIndex, int height, float depth, Color color)
{
//new Color(100, 100, 100, 100)
Factor out some of the tile drawing code.
r68
Fix style.
r462 int height_adjust = 0;
Factor out some of the tile drawing code.
r68
Fix style.
r462 if (height > 1) //not sure why this is necessary :/
{
height_adjust = height;
}
Factor out some of the tile drawing code.
r68
Fix style.
r462 int adjustedx = x - height_adjust;
int adjustedy = y - height_adjust;
Factor out some of the tile drawing code.
r68
Fix style.
r462 int screenx = (adjustedx - adjustedy) * Tile.TileSpriteWidth / 2;
int screeny = (adjustedx + adjustedy) * Tile.TileSpriteHeight / 2;
Factor out some of the tile drawing code.
r68
Fix style.
r462 // if (this.cull(x, y))
// {
batch.Draw(
Factor out some of the tile drawing code.
r68 Tile.TileSetTexture,
Fix style.
r462 new Rectangle(
screenx,
screeny,
Tile.TileWidth, Tile.TileHeight * height),
Factor out some of the tile drawing code.
r68 Tile.GetExtendedSourceRectangle(tileIndex, height),
Add missing file.
r569 color,
Fix style.
r462 0.0f,
Vector2.Zero,
SpriteEffects.None,
depth);
// }
Factor out some of the tile drawing code.
r68
Fix style.
r462 }
Factor out some of the tile drawing code.
r68
Early working version (including all dependencies, lol).
r0 }
}