Skip to content

Instantly share code, notes, and snippets.

Avatar
🤔
I may be slow to respond.

taryn phrohdoh

🤔
I may be slow to respond.
View GitHub Profile
@phrohdoh
phrohdoh / bool IsInRangeOf.cs
Created Jan 9, 2014
A function written before realizing OpenRA has FindActorsInCircle.
View bool IsInRangeOf.cs
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);
@phrohdoh
phrohdoh / BuildingUtils.Util.cs
Created May 20, 2014
Requesting help for stashing Plug/PlugActor in BuildingUtil/Util.cs ~11-12
View BuildingUtils.Util.cs
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))
{
View GetIndexer.cs
// 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)
View ThereHasToBeABetterWay.cs
// 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;
View gist:156ff55fbf99ee6b5c1c
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;
View gist:d3b0fd5f803e3275b8ec
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));
}
View InButtonClick.cs
var drawable = DrawableArea(image);
drawable.Invalidate();
Drawable DrawableArea(Bitmap image)
{
var ret = new Drawable();
ret.Paint += (sender, e) =>
{
e.Graphics.DrawImage(image, ret.Location.X, ret.Location.Y);
};
View World.cs
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;
View SuchTileRender.cs
// 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);
View LoadTilesFromFile.cs
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++)