Skip to content

Instantly share code, notes, and snippets.

@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 / lagCompensation.js
Last active March 15, 2019 03:14
Lag compensation of a player's attack, using a historical stack of quadtrees and "rewinding" relevant entities stored in the quadtrees to the position they were at in the recent past (as decided by the player's ping).There is a SIGNFICANT oddity to this code, which is that quadtrees used for collisions are point quadtrees. Because of this, the i…
// a fat hitbox around the player considered the 'relevant' area for a collision
var hitArea = new AABB({x: player.x, y: player.y}, { x: 54, y : 54})
var actualHitArea = new AABB({x: player.x, y: player.y}, { x: 36, y : 36})
// how behind the player is, in server time
var delay = player.ping + (1000 / player.tickRate)
var tickLength = 1000 / TICKS_PER_SECOND
var ticksAgo = Math.floor(delay / tickLength)
var tickPortion = (delay % tickLength) / tickLength
@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 / 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 / interp-sample.js
Created April 23, 2014 22:43
Entity interpolation
/* Entity Interpolation
this code occurs within the draw loop for an entity
this.x and this.y represent the most recently received server position of
the entity -- though i don't ever intend to use it for drawing
when an update is received (roughly every 50ms in my particular game) this.x and this.y get
pushed into previousState.x and previousState.y
i also continue sloppily onwards to previousPreviousState.x, but I've removed that code
@timetocode
timetocode / Entity.js
Last active February 9, 2017 04:50
An example of extending a prototypical game Entity to have different functionality (via adding functions to the prototype) in its server environment than on the game client.
// a simple game entity having a name and positional data
function Entity(name) {
this.name = name
this.x = 0
this.y = 0
this.speed = 5
}
module.exports = Entity
@timetocode
timetocode / streamData.json
Last active February 12, 2017 20:32
Example twitch stream data for user neuronimo playing awesomenauts 9/24/2014
{
"_links":{
"self":"https://api.twitch.tv/kraken/streams/neuronimo",
"channel":"https://api.twitch.tv/kraken/channels/neuronimo"
},
"stream":{
"_id":11162399536,
"game":"Awesomenauts",
"viewers":2,
"created_at":"2014-09-24T16:31:38Z",
@timetocode
timetocode / twitch-widget.html
Created September 25, 2014 01:25
JavaScript Widget, displays if a twitch.tv user is currently streaming.
<!-- jQuery, delete this line if you already have jQuery on your page -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- the twitch widget, place code in the <HEAD> -->
<script>
var twitchUserName = 'timetocode' // your name goes here
$(document).ready(function() {
$.getJSON("https://api.twitch.tv/kraken/streams/"+twitchUserName+"?callback=?",function(streamData) {
console.log('Stream Data:', streamData) // debug message, shows all available data
if(streamData && streamData.stream) {
@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
{
@timetocode
timetocode / AABB.js
Created May 24, 2015 22:47
Quadtree and AABB gists from nengi
//var BinarySerializer = require('./BinarySerializer')
//var BinaryType = require('./BinaryType')
// axis-aligned bounding box
/* PARAMS: (Point)center, (Point)half */
function AABB(x, y, halfWidth, halfHeight) {
this.initialize(x, y, halfWidth, halfHeight)
}
AABB.pool = []