本文整理汇总了C#中Vector2Int32类的典型用法代码示例。如果您正苦于以下问题:C# Vector2Int32类的具体用法?C# Vector2Int32怎么用?C# Vector2Int32使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Vector2Int32类属于命名空间,在下文中一共展示了Vector2Int32类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckDirectionandDraw
private void CheckDirectionandDraw(Vector2Int32 tile)
{
Vector2Int32 p = tile;
Vector2Int32 p2 = tile;
if (_isRightDown)
{
if (_isLeftDown)
p.X = _startPoint.X;
else
p.Y = _startPoint.Y;
DrawLine(p);
_startPoint = p;
}
else if (_isLeftDown)
{
if ((Keyboard.IsKeyUp(Key.LeftShift)) && (Keyboard.IsKeyUp(Key.RightShift)))
{
DrawLine(p);
_startPoint = p;
_endPoint = p;
}
else if ((Keyboard.IsKeyDown(Key.LeftShift)) || (Keyboard.IsKeyDown(Key.RightShift)))
{
DrawLineP2P(p2);
_endPoint = p2;
}
}
}
示例2: DrawLine
public static IEnumerable<Vector2Int32> DrawLine(Vector2Int32 start, Vector2Int32 end)
{
// Distance start and end point
int dx = end.X - start.X;
int dy = end.Y - start.Y;
// Determine slope (absoulte value)
int len = dy >= 0 ? dy : -dy;
int lenx = dx >= 0 ? dx : -dx;
if (lenx > len)
{
len = lenx;
}
// Prevent divison by zero
if (len != 0)
{
// Init steps and start
float incx = dx / (float)len;
float incy = dy / (float)len;
float x = start.X;
float y = start.Y;
// Walk the line!
for (int i = 0; i < len; i++)
{
yield return new Vector2Int32((int)x, (int)y);
x += incx;
y += incy;
}
}
}
示例3: PasteClipboard
private void PasteClipboard(Vector2Int32 anchor)
{
_wvm.Clipboard.PasteBufferIntoWorld(anchor);
_wvm.UpdateRenderRegion(new Rectangle(anchor.X, anchor.Y, _wvm.Clipboard.Buffer.Size.X, _wvm.Clipboard.Buffer.Size.Y));
/* Heathtech */
BlendRules.ResetUVCache(_wvm, anchor.X, anchor.Y, _wvm.Clipboard.Buffer.Size.X, _wvm.Clipboard.Buffer.Size.Y);
}
示例4: FromHwndMouseEventArgs
public static TileMouseState FromHwndMouseEventArgs(HwndMouseEventArgs e, Vector2Int32 tile)
{
return new TileMouseState
{
LeftButton = e.LeftButton,
RightButton = e.RightButton,
MiddleButton = e.MiddleButton,
Location = tile
};
}
示例5: SetRectangle
public void SetRectangle(Vector2Int32 p1, Vector2Int32 p2)
{
int x1 = p1.X < p2.X ? p1.X : p2.X;
int y1 = p1.Y < p2.Y ? p1.Y : p2.Y;
int width = Math.Abs(p2.X - p1.X) + 1;
int height = Math.Abs(p2.Y - p1.Y) + 1;
SelectionArea = new Rectangle(x1, y1, width, height);
IsActive = true;
}
示例6: FillRectangle
public static IEnumerable<Vector2Int32> FillRectangle(Vector2Int32 offset, Vector2Int32 size)
{
for (int y = offset.Y; y < offset.Y + size.Y; y++)
{
for (int x = offset.X; x < offset.X + size.X; x++)
{
yield return new Vector2Int32(x, y);
}
}
}
示例7: FillEllipse
public static IEnumerable<Vector2Int32> FillEllipse(Vector2Int32 offset, Vector2Int32 size)
{
// Calc center and radius
int xr = (size.X - offset.X) >> 1;
int yr = (size.Y - offset.Y) >> 1;
int xc = offset.X + xr;
int yc = offset.Y + yr;
var center = new Vector2Int32(xc, yc);
var radius = new Vector2Int32(xr, yr);
Debug.WriteLine(string.Format("Center: {0}, Radius: {1}", center, radius));
return FillEllipseCentered(center, radius);
}
示例8: DrawLine
private void DrawLine(Vector2Int32 to)
{
foreach (Vector2Int32 pixel in Shape.DrawLineTool(_startPoint, to))
{
if (!_wvm.CurrentWorld.ValidTileLocation(pixel)) continue;
int index = pixel.X + pixel.Y * _wvm.CurrentWorld.TilesWide;
if (!_wvm.CheckTiles[index])
{
_wvm.CheckTiles[index] = true;
if (_wvm.Selection.IsValid(pixel))
{
_wvm.UndoManager.SaveTile(pixel);
_wvm.SetPixel(pixel.X, pixel.Y);
}
}
}
}
示例9: Add
public void Add(Vector2Int32 location, Tile tile)
{
var undoTile = new UndoTile(location, tile);
if (undoTile == null)
{
throw new Exception("Null undo?");
}
lock (UndoSaveLock)
{
UndoTiles.Add(undoTile);
LastTile = undoTile;
}
if (UndoTiles.Count > FlushSize)
{
Flush();
}
}
示例10: Flood
public void Flood(Vector2Int32 pt)
{
int bitmapWidth = _wvm.CurrentWorld.TilesWide;
int bitmapHeight = _wvm.CurrentWorld.TilesHigh;
int x = pt.X;
int y = pt.Y;
_wvm.CheckTiles = new bool[bitmapWidth * bitmapHeight];
var originTile = (Tile)_wvm.CurrentWorld.Tiles[x, y].Clone();
LinearFloodFill(ref x, ref y, ref originTile);
while (_ranges.Count > 0)
{
//**Get Next Range Off the Queue
FloodFillRange range = _ranges.Dequeue();
//**Check Above and Below Each Pixel in the Floodfill Range
int downPxIdx = (bitmapWidth * (range.Y + 1)) + range.StartX;//CoordsToPixelIndex(lFillLoc,y+1);
int upPxIdx = (bitmapWidth * (range.Y - 1)) + range.StartX;//CoordsToPixelIndex(lFillLoc, y - 1);
int upY = range.Y - 1;//so we can pass the y coord by ref
int downY = range.Y + 1;
for (int i = range.StartX; i <= range.EndX; i++)
{
//*Start Fill Upwards
//if we're not above the top of the bitmap and the pixel above this one is within the color tolerance
if (range.Y > 0 && (!_wvm.CheckTiles[upPxIdx]) && CheckTileMatch(ref originTile, ref _wvm.CurrentWorld.Tiles[i, upY]) && _wvm.Selection.IsValid(i, upY))
LinearFloodFill(ref i, ref upY, ref originTile);
//*Start Fill Downwards
//if we're not below the bottom of the bitmap and the pixel below this one is within the color tolerance
if (range.Y < (bitmapHeight - 1) && (!_wvm.CheckTiles[downPxIdx]) && CheckTileMatch(ref originTile, ref _wvm.CurrentWorld.Tiles[i, downY]) && _wvm.Selection.IsValid(i, downY))
LinearFloodFill(ref i, ref downY, ref originTile);
downPxIdx++;
upPxIdx++;
}
if (upY < _minY)
_minY = upY;
if (downY > _maxY)
_maxY = downY;
}
}
示例11: CheckDirectionandDraw
private void CheckDirectionandDraw(Vector2Int32 tile)
{
Vector2Int32 p = tile;
if (_isRightDown)
{
if (_isLeftDown)
p.X = _startPoint.X;
else
p.Y = _startPoint.Y;
DrawLine(p);
_startPoint = p;
}
else if (_isLeftDown)
{
DrawLine(p);
_startPoint = p;
}
}
示例12: AddNpc
private void AddNpc(int npcId)
{
if (CurrentWorld != null && World.NpcNames.ContainsKey(npcId))
{
string name = World.NpcNames[npcId];
if (CurrentWorld.NPCs.All(n => n.SpriteId != npcId))
{
var spawn = new Vector2Int32(CurrentWorld.SpawnX, CurrentWorld.SpawnY);
CurrentWorld.NPCs.Add(new NPC{Home = spawn, IsHomeless = true, DisplayName = name, Name = name, Position= new Vector2(spawn.X * 16, spawn.Y * 16), SpriteId = npcId});
Points.Add(name);
MessageBox.Show(string.Format("{0} added to spawn.", name), "NPC Added");
}
else
{
MessageBox.Show(string.Format("{0} is already on the map.", name), "NPC Exists");
}
}
else
{
MessageBox.Show(string.Format("Choose an NPC. NPC {0} not found.", npcId), "NPC Error");
}
}
示例13: AddNpc
private void AddNpc(NpcName npc)
{
if (CurrentWorld != null)
{
if (!CurrentWorld.NPCs.Any(n => n.Name == npc.Character))
{
var spawn = new Vector2Int32(CurrentWorld.SpawnX, CurrentWorld.SpawnY);
CurrentWorld.NPCs.Add(new NPC{Home = spawn, IsHomeless = true, Name = npc.Character, Position= new Vector2(spawn.X * 16, spawn.Y * 16), SpriteId = npc.Id});
Points.Add(npc.Character);
MessageBox.Show(string.Format("{1} ({0}) added to spawn.", npc.Character, npc.Name), "NPC Added");
}
else
{
MessageBox.Show(string.Format("{1} ({0}) is already on the map.", npc.Character, npc.Name), "NPC Exists");
}
}
}
示例14: FillEllipseCentered
public static IEnumerable<Vector2Int32> FillEllipseCentered(Vector2Int32 center, Vector2Int32 radius)
{
int xr = radius.X;
int yr = radius.Y;
int xc = center.X;
int yc = center.Y;
if (xr >= 1 && yr >= 1)
{
// Init vars
int uy, ly, lx, rx;
int x = xr;
int y = 0;
int xrSqTwo = (xr * xr) << 1;
int yrSqTwo = (yr * yr) << 1;
int xChg = yr * yr * (1 - (xr << 1));
int yChg = xr * xr;
int err = 0;
int xStopping = yrSqTwo * xr;
int yStopping = 0;
// Draw first set of points counter clockwise where tangent line slope > -1.
while (xStopping >= yStopping)
{
// Draw 4 quadrant points at once
uy = yc + y; // Upper half
ly = yc - y; // Lower half
//if (uy < 0) uy = 0; // Clip
//if (uy >= h) uy = h - 1; // ...
//if (ly < 0) ly = 0;
//if (ly >= h) ly = h - 1;
//uh = uy*w; // Upper half
//lh = ly*w; // Lower half
rx = xc + x;
lx = xc - x;
//if (rx < 0) rx = 0; // Clip
//if (rx >= w) rx = w - 1; // ...
//if (lx < 0) lx = 0;
//if (lx >= w) lx = w - 1;
// Draw line
for (int i = lx; i <= rx; i++)
{
yield return new Vector2Int32(i, uy); // Quadrant II to I (Actually two octants)
yield return new Vector2Int32(i, ly); // Quadrant III to IV
}
y++;
yStopping += xrSqTwo;
err += yChg;
yChg += xrSqTwo;
if ((xChg + (err << 1)) > 0)
{
x--;
xStopping -= yrSqTwo;
err += xChg;
xChg += yrSqTwo;
}
}
// ReInit vars
x = 0;
y = yr;
uy = yc + y; // Upper half
ly = yc - y; // Lower half
//if (uy < 0) uy = 0; // Clip
//if (uy >= h) uy = h - 1; // ...
//if (ly < 0) ly = 0;
//if (ly >= h) ly = h - 1;
//uh = uy*w; // Upper half
//lh = ly*w; // Lower half
xChg = yr * yr;
yChg = xr * xr * (1 - (yr << 1));
err = 0;
xStopping = 0;
yStopping = xrSqTwo * yr;
// Draw second set of points clockwise where tangent line slope < -1.
while (xStopping <= yStopping)
{
// Draw 4 quadrant points at once
rx = xc + x;
lx = xc - x;
//if (rx < 0) rx = 0; // Clip
//if (rx >= w) rx = w - 1; // ...
//if (lx < 0) lx = 0;
//if (lx >= w) lx = w - 1;
// Draw line
for (int i = lx; i <= rx; i++)
{
yield return new Vector2Int32(i, uy); // Quadrant II to I (Actually two octants)
yield return new Vector2Int32(i, ly); // Quadrant III to IV
}
x++;
xStopping += yrSqTwo;
err += xChg;
//.........这里部分代码省略.........
示例15: LinearFloodFill
private static void LinearFloodFill(ref Vector2Int32 start, ref Vector2Int32 minBound, ref Vector2Int32 maxBound, Func<Vector2Int32, bool> validation, ref FloodFillRangeQueue ranges, ref HashSet<Vector2Int32> points)
{
//FIND LEFT EDGE OF COLOR AREA
int lFillLoc = start.X; //the location to check/fill on the left
int x = start.X;
int y = start.Y;
points.Add(start);
while (true)
{
points.Add(new Vector2Int32(lFillLoc, y));
// Preform validation for next point
lFillLoc--;
var curPoint = new Vector2Int32(lFillLoc, y);
if (lFillLoc <= minBound.X || !validation(curPoint) || points.Contains(curPoint))
break; //exit loop if we're at edge of bitmap or match area
}
lFillLoc++;
//FIND RIGHT EDGE OF COLOR AREA
int rFillLoc = x; //the location to check/fill on the left
while (true)
{
points.Add(new Vector2Int32(rFillLoc, y));
rFillLoc++;
var curPoint = new Vector2Int32(rFillLoc, y);
if (rFillLoc >= maxBound.X || !validation(curPoint) || points.Contains(curPoint))
break; //exit loop if we're at edge of bitmap or color area
}
rFillLoc--;
var r = new FloodFillRange(lFillLoc, rFillLoc, y);
ranges.Enqueue(ref r);
}