Skip to content

Instantly share code, notes, and snippets.

@phrohdoh
phrohdoh / BuildingUtils.Util.cs
Created May 20, 2014 23:23
Requesting help for stashing Plug/PlugActor in BuildingUtil/Util.cs ~11-12
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))
{
// 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)
// 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;
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;
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));
}
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);
};
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;
// 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);
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 August 29, 2015 14:03
LTTP Tile Collision
[Flags]
enum CollisionData
{
None = 0,
TopLeft = 1,
TopRight = 2,
BottomLeft = 4,
BottomRight = 8,
TopHalf = TopLeft | TopRight,
BottomHalf = BottomLeft | BottomRight,