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 / 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: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 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 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++)
@phrohdoh
phrohdoh / Tile.cs
Last active Aug 29, 2015
LTTP Tile Collision
View Tile.cs
[Flags]
enum CollisionData
{
None = 0,
TopLeft = 1,
TopRight = 2,
BottomLeft = 4,
BottomRight = 8,
TopHalf = TopLeft | TopRight,
BottomHalf = BottomLeft | BottomRight,