Skip to content

Instantly share code, notes, and snippets.

View drhayes's full-sized avatar
🐱

David Hayes drhayes

🐱
View GitHub Profile
@drhayes
drhayes / camera.js
Created November 17, 2015 03:00
Phaser.Camera.js updateTargetTrackSlow
updateTargetTrackSlow() {
// We always have a deadzone. If we don't, that means we haven't set the target yet so
// there's no sense in doing anything in this method yet.
if (!this.deadzone) {
return;
}
this._targetPosition.copyFrom(this.target);
if (this.target.parent) {
this._targetPosition.multiply(this.target.parent.worldTransform.a, this.target.parent.worldTransform.d);
@drhayes
drhayes / eventChain.js
Created January 14, 2013 05:58
A function to help arrange sequential events in ImpactJS.
/*global ig: true */
ig.module(
'game.system.eventChain'
)
.requires(
'impact.impact'
)
.defines(function() {
// Defines a function that can fire sequential events.
@drhayes
drhayes / eventChain.js
Created January 14, 2013 05:59
EventChain: The Basics
// Defines a function that can fire sequential events.
EventChain = function() {
// Make sure we get called with new.
if (this === window) {
return new EventChain();
}
var steps = [];
// Called every frame.
@drhayes
drhayes / eventChain.js
Created January 14, 2013 06:28
EventChain's wait function
update.wait = function(secs) {
var decrement = secs;
steps.push(function() {
// Update.
if (decrement) {
decrement -= ig.system.tick;
}
// End.
if (decrement <= 0) {
steps.shift();
@drhayes
drhayes / eventChain.js
Created January 14, 2013 06:20
EventChain's then function
update.then = function(doThis) {
steps.push(function() {
// Update.
doThis();
// End.
steps.shift();
});
return this;
}
@drhayes
drhayes / eventChain.js
Created January 14, 2013 06:33
EventChain's during function
update.during = function(doThis) {
if (!steps) {
throw new Error('during only works with previous step!');
}
var func = steps[steps.length - 1];
steps[steps.length - 1] = function() {
doThis();
func();
};
return this;
@drhayes
drhayes / eventChain.js
Created January 14, 2013 16:38
EventChain's every method
update.every = function(sec, doThis) {
update.during(
new EventChain()
.wait(sec)
.then(doThis)
.repeat()
);
return this;
};
@drhayes
drhayes / eventChain.js
Created January 15, 2013 05:48
EventChain's last lines
// Returned from this constructor thing.
return update;
};
});
@drhayes
drhayes / eventChain.js
Created January 15, 2013 07:14
EventChain's repeat method
update.repeat = function(times) {
times = times || Infinity;
var originalTimes = times;
var stepsCopy;
steps.push(function() {
times -= 1;
if (times > 0) {
var args = stepsCopy.slice(0);
args.unshift(1, 0);
[].splice.apply(steps, args);
@drhayes
drhayes / gist:4997048
Created February 20, 2013 16:55
Pre-commit hook to remove trailing whitespace on lines you've actually changed
#
# Shamelessly copied from http://blog.yesmeck.com/archives/make-git-automatically-remove-trailing-whitespace-before-committing/
#
# What's distinct about this version, as opposed to several I've seen,
# is that it only fixes the whitespace on lines you've actually changed,
# so avoids making you the blamee of code you didn't change.
# Find files with trailing whitespace
for file in `git diff --check --cached | grep '^[^+-]' | grep -o '^.*[0-9]\+:'` ; do
file_name=`echo ${file} | grep -o '^[^:]\+'`