Skip to content

Instantly share code, notes, and snippets.

@timetocode
timetocode / Program.cs
Last active August 29, 2015 14:08
An example of procedurally generating a cloudy pattern out of hand typed octaves of simplex noise. There may be an error in here, I can't quite remember if this is what the end image should look like or not. I feel like the darks should be darker and the lights lighter, but either way this is the general idea. The traditional approach is to writ…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimplexNoise;
using System.Drawing;
namespace SimplexExample
{
function compareNumbers(a, b) {
return a - b
}
function arrayDiffs(a, b) {
a.sort(compareNumbers)
b.sort(compareNumbers)
//console.log('A', a)
//console.log('B', b)
@timetocode
timetocode / GameComponent.js
Last active November 11, 2015 03:02
nengi.GameObject and nengi.GameComponent - prototype of component based design
function GameComponent(gameObject, config) {
this.gameObject = gameObject
this.position = gameObject.position
this.initialize()
if (config) {
this.configure(config)
}
@timetocode
timetocode / developer-console.coffee
Created April 10, 2013 01:13
add console-like functionality to an html input, while staying decoupled follows a node.js module.exports style, so something like browserify is required before this console can be used as client-side javascript
# developer console
inputEle = null # the console's Prompt (an html input)
dispEle = null # the console's output (a div, span, etc)
submitAction = null # function to run on the input
enabled = false
exports.enable = () ->
# ensures html elements have been specified
# ensures that the console is not already active
if inputEle && dispEle && !enabled
@timetocode
timetocode / Twitch.tv is channel live api query
Last active December 31, 2015 14:09
Query Twitch.tv to see if a channel is streaming! Assumes a div of id = 'streaming' to put the results, and a couple css classes to style the results.
<script type="text/javascript">
$(document).ready(function() {
// your twitch channel name
var twitchName = 'yourchannelname'
// an element on your page to put the widget into
var elementSelector = '#streaming'
// HTML to display while waiting for data
@timetocode
timetocode / Existence-spec.js
Last active April 6, 2016 01:20
Example tests via jasmine.js
var Existence = require('../Existence')
describe('Existence', function() {
var existence = null
beforeEach(function() {
existence = new Existence()
})
it('can add/getById entities', function() {
@timetocode
timetocode / Projectile-spec.js
Created June 13, 2016 02:50
Example of the in-progress development of a projectile system paired with unit tests.
var Projectile = require('../Projectile')
var Vector2 = require('../../../nengi/Vector2')
var Map = require('../../map/Map')
var WallType = require('../../map/WallType')
describe('Projectile', function() {
var projectile = null
var mockClient = null
var mockTarget = null
var mockWeapon = null
@timetocode
timetocode / body code
Last active October 24, 2016 00:30
A script to display if a certain channel is currently live on Twitch.tv. To use this script on your website, paste all of the code from the "head code" into the <head></head> tag of webpage. Then paste the one line from "body code" wherever the widget should appear.
<div id='streaming'></div>
@timetocode
timetocode / Client.js
Last active February 9, 2017 04:44
Example of using nengi.js. NOTE: the clientside rendering code is is skipped, and this example primarily highlights where your game code could use nengi.. the serverside game logic is more revealing (and messy)
var nengi = require('../../nengi')
var EDictionary = require('../../nengi/external/EDictionary')
var protocols = require('../protocols')
// Graphics code
var Squid = require('./entity/Squid')
var Fish = require('./entity/Fish')
var Shark = require('./entity/Shark')
var Ink = require('./effect/Ink')
var Blood = require('./effect/Blood')
@timetocode
timetocode / GameScene.js
Created November 15, 2016 20:34
Scene management, loading assets, beginning a game loop
var Client = require('../Client')
function GameScene() {
this.client = new Client()
}
GameScene.prototype.enterScene = function() {
console.log('GameScene entered')
this.client.connect()
}