Show More
Commit Description:
Add water tiles.
Commit Description:
Add water tiles.
References:
File last commit:
Show/Diff file:
Action:
isometric-park-fna/Line.cs
80 lines | 2.4 KiB | text/x-csharp | CSharpLexer
80 lines | 2.4 KiB | text/x-csharp | CSharpLexer
r0 | using System; | |||
using Microsoft.Xna.Framework; | ||||
using Microsoft.Xna.Framework.Graphics; | ||||
namespace isometricparkfna | ||||
{ | ||||
public class Line | ||||
{ | ||||
public static Texture2D PixelTexture; | ||||
public Line() | ||||
{ | ||||
} | ||||
public static void drawLine(SpriteBatch batch, Vector2 start, Vector2 stop, Color color) | ||||
{ | ||||
r2 | drawLine(batch, start, stop, color, 0, 1); | |||
r1 | } | |||
r2 | public static void drawLine(SpriteBatch batch, Vector2 start, Vector2 stop, Color color, float depth) | |||
{ | ||||
drawLine(batch, start, stop, color, depth, 1); | ||||
} | ||||
public static void drawLine(SpriteBatch batch, Vector2 start, Vector2 stop, Color color, float depth, int width) | ||||
r1 | { | |||
r0 | Vector2 line = stop - start; | |||
float angle = (float)Math.Atan2((double)line.Y, (double) line.X); | ||||
r1 | Rectangle rect = new Rectangle((int)start.X, (int)start.Y, (int)Math.Round(line.Length()), width); | |||
r2 | batch.Draw(Line.PixelTexture, rect, null, color, angle, new Vector2(0,0), SpriteEffects.None, depth); | |||
r0 | ||||
} | ||||
public static void initialize(GraphicsDevice graphics) | ||||
{ | ||||
SpriteBatch spriteBatch = new SpriteBatch(graphics); | ||||
Line.PixelTexture = new Texture2D(graphics, 1, 1); | ||||
Line.PixelTexture.SetData<Color> (new Color[] { Color.White}); | ||||
} | ||||
r8 | ||||
public static Vector2 departurePoint(Vector2 start, Vector2 stop, float width, float height) | ||||
{ | ||||
r224 | if (MathUtils.BetweenExclusive(stop.X, 0, width ) && MathUtils.BetweenExclusive(stop.Y, 0, height)) { | |||
r8 | return stop; | |||
} | ||||
float slope = (start.Y - stop.Y) / (start.X - stop.X); | ||||
float intercept = (start.Y - (slope * start.X)); | ||||
r462 | if (stop.X < 0) { | |||
r8 | float newY = slope * 0 + intercept; | |||
return new Vector2(0, newY); | ||||
} | ||||
else if (stop.Y < 0) | ||||
{ | ||||
float newX = intercept / slope; | ||||
return new Vector2(newX, 0); | ||||
} | ||||
r462 | ||||
r8 | else if (stop.Y > height) | |||
{ | ||||
float newX = (intercept + height) / slope; | ||||
return new Vector2(newX, height); | ||||
} | ||||
else if (stop.X > width) | ||||
{ | ||||
float newY = slope * width + intercept; | ||||
return new Vector2(width, newY); | ||||
} | ||||
return stop;//TODO | ||||
} | ||||
r0 | } | |||
} | ||||