Skip to content

Instantly share code, notes, and snippets.

View profexorgeek's full-sized avatar
💻
Setting my status

Justin Johnson profexorgeek

💻
Setting my status
View GitHub Profile
@profexorgeek
profexorgeek / RandomFromList.cs
Created September 21, 2021 16:26
Two extension methods that make it really easy to grab a random element from a list. You will need to update `RandomService.Random` with a global RNG.
public static class CollectionExtensions
{
/// <summary>
/// A Linq-like method for getting a random element from an IEnumerable
/// </summary>
/// <typeparam name="T">The element type</typeparam>
/// <param name="array">The array to fetch an element from</param>
/// <param name="rand">Optional Random instance, if not provided
/// the method will use the RandomService.</param>
namespace Narfox.Utilities
{
public enum EmitterScale
{
Small = 16,
Medium = 64,
Large = 256
}
public class EasyEmitter : Emitter
using FlatRedBall;
using FlatRedBall.Audio;
using FlatRedBall.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using NarfoxGameTools.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
@profexorgeek
profexorgeek / FlatRedBall Generic Factory
Last active June 11, 2019 21:37
Generic factory capable of instantiating and pooling a list of entity objects.
using FlatRedBall.Graphics;
using FlatRedBall.Performance;
using System;
using System.Linq;
namespace MasteroidPE.Factories
{
public class Factory<T> where T : IPoolable, IDestroyable, new()
{
PoolList<T> pool = new PoolList<T>();
@profexorgeek
profexorgeek / textureMapper.html
Last active May 22, 2019 14:02
Single page web application that allows quick and easy mapping of spritesheet textures
<!DOCTYPE html>
<html lang="en">
<head>
<title>Texture Mapping Helper</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>
html, body, div, img {
@profexorgeek
profexorgeek / Masteroid Screenshot Utility for FlatRedBall
Last active November 16, 2018 14:09
This is a raw paste of the screenshot utility I use for debugging purposes in Masteroid. This demonstrates how to render to a buffer (render target) and save that buffer as a png in the FlatRedBall game engine.
using FlatRedBall;
using FlatRedBall.Graphics;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.IO;
using System.Text.RegularExpressions;
namespace Masteroid.Utilities
{
public class ScreenshotUtility
@profexorgeek
profexorgeek / HSLColor.cs
Created September 5, 2018 15:39
This struct represents a Color using the HSL color space. It provides convenient conversions into the XNA/MonoGame RGB Color struct. HSL offers an easier way to work with color artistically by separating color into Hue, Saturation and Luminance.
public struct HSLColor
{
// HSL stands for Hue, Saturation and Luminance. HSL
// color space makes it easier to do calculations
// that operate on these channels
// Helpful color math can be found here:
// https://www.easyrgb.com/en/math.php
/// <summary>
@profexorgeek
profexorgeek / GoogleAnalytics.cs
Created February 13, 2018 21:26
Basic cross-platform Google Analytics implementation.
using System;
using System.Text;
using System.Net;
using System.Collections.Specialized;
using System.Collections.Generic;
#if DESKTOP_GL
using System.Web;
#endif
@profexorgeek
profexorgeek / simple-js-app.js
Created December 22, 2016 22:13
A simple example of how to write JavaScript applications.
<!DOCTYPE html>
<html>
<head>
<title>Modular JavaScript Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
//==========================================================================
// This is an application, we write JavaScript this way so that