This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool IsInRangeOf(Actor actorInQuestion, Actor sourceActor, bool use3D = false) | |
{ | |
// convert distance (px -> cells) | |
var distX = (sourceActor.Location.CenterPosition.X - actorInQuestion.Location.CenterPosition.X) / 1024; | |
var distY = (sourceActor.Location.CenterPosition.Y - actorInQuestion.Location.CenterPosition.Y) / 1024; | |
var distZ = (sourceActor.Location.CenterPosition.Z - actorInQuestion.Location.CenterPosition.Z) / 1024; | |
// convert Info.Range (px -> cells) | |
var range = (Info.Range * 1024); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, CPos topLeft, Actor toIgnore) | |
{ | |
if (building.AllowInvalidPlacement) | |
return true; | |
var existing = world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(topLeft); | |
var toPlace = Rules.Info[name.ToLowerInvariant()]; | |
if (CanPlacePlug(existing, toPlace, topLeft)) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1) | |
GetIndexer(this List<Form> list) | |
{ | |
var ifi = new List<IFormIndexer>(); | |
foreach (var item in list) | |
ifi.Add(item as IFormIndexer); | |
} | |
// or 2) | |
GetIndexer(this List<Form> list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sourcePngs is a ListBox with property Items (ListItemCollection) | |
// A custom list of strings in the end (custom to eto, not to me) | |
var pngs = sourcePngs.Items; | |
var temp = new string[pngs.Count]; | |
for (var i = 0; i < temp.Length; i++) | |
temp[i] = pngs[i].Text; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var image = new Bitmap(100, 100, PixelFormat.Format24bppRgb); | |
using (var graphics = new Graphics(image)) | |
{ | |
graphics.DrawRectangle(Colors.Red, 15, 15, 50, 50); | |
} | |
using (var locked = image.Lock()) unsafe | |
{ | |
int *value = (int*)locked.Data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var image = new Bitmap(100, 100, PixelFormat.Format24bppRgb); | |
using (var locked = image.Lock()) unsafe | |
{ | |
for (var x = 0; x < image.Width; x++) | |
for (var y = 0; y < image.Height; y++) | |
if (y == image.Height / 3) | |
image.SetPixel(x, y, Color.FromArgb(70, 0, 0)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using Microsoft.Xna.Framework; | |
using Microsoft.Xna.Framework.Graphics; | |
namespace PrototypeRPG.Traits | |
{ | |
public class World | |
{ | |
public const int TickTimestep = 40; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// World.cs | |
public Rectangle GetSourceRectangle(Texture2D tileset, int tileIndex, int tileSize) | |
{ | |
var borderSize = 1; | |
var paddedTileSize = tileSize + borderSize; | |
var tilesPerRow = tileset.Width / paddedTileSize; | |
var x = paddedTileSize * (tileIndex % tilesPerRow); | |
var y = paddedTileSize * (tileIndex / tilesPerRow); | |
return new Rectangle(x, y, tileSize, tileSize); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void LoadTilesFromFile(string filename) | |
{ | |
var fullText = File.ReadAllLines(filename); | |
var output = new int[fullText.Length][]; | |
foreach (var fullLine in fullText) | |
{ | |
var lineAsIntArray = fullLine.ToIntArray(','); | |
for (var intIndex = 0; intIndex < lineAsIntArray.Length; intIndex++) |
OlderNewer