Skip to content

Instantly share code, notes, and snippets.

View drhayes's full-sized avatar
🐱

David Hayes drhayes

🐱
View GitHub Profile
@drhayes
drhayes / ImpactJS.JSON-tmLanguage
Created October 22, 2012 06:32
ImpactJS syntax definition
{ "name": "ImpactJS", "scopeName": "source.js.impact",
"fileTypes": ["js"],
"patterns": [
{
"name": "meta.module.impact",
"begin": "\\b(ig)\\.(module)\\(",
"beginCaptures": {
"1": {
"name": "support.variable.impact.namespace"
},
@drhayes
drhayes / followCamera.js
Created October 28, 2012 22:23
followCamera.js
calculatePlayerStats: function() {
this.player = ig.game.getEntityByName('player');
// Did we actually get a player?
if (this.player) {
// Cache some stats.
this.halfPlayerWidth = this.player.size.x / 2;
this.halfPlayerHeight = this.player.size.y / 2;
this.maxVel = this.player.maxVel;
}
},
@drhayes
drhayes / enableBehaviors.js
Created November 15, 2012 04:43
Part of an ImpactJS library to change how entities act at runtime.
ig.module(
'game.behaviors.enableBehaviors'
)
.requires(
'impact.impact'
)
.defines(function() {
enableBehaviors = function(entityClass) {
entityClass.inject({
@drhayes
drhayes / baseBehavior.js
Created November 15, 2012 04:46
Base class for behaviors.
ig.module(
'game.behaviors.baseBehavior'
)
.requires(
'impact.impact'
)
.defines(function() {
BaseBehavior = ig.Class.extend({
enabled: true,
@drhayes
drhayes / player.js
Created November 15, 2012 04:48
Snippet from the player entity.
update: function() {
this.behave('update');
this.handleAnimation();
this.parent();
},
handleMovementTrace: function(res) {
this.behave('handleMovementTrace', res);
this.parent(res);
},
@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: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: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: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;