Skip to content

Instantly share code, notes, and snippets.

@drhayes
drhayes / ImpactJS.JSON-tmLanguage
Created Oct 22, 2012
ImpactJS syntax definition
View ImpactJS.JSON-tmLanguage
{ "name": "ImpactJS", "scopeName": "source.js.impact",
"fileTypes": ["js"],
"patterns": [
{
"name": "meta.module.impact",
"begin": "\\b(ig)\\.(module)\\(",
"beginCaptures": {
"1": {
"name": "support.variable.impact.namespace"
},
View 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 Nov 15, 2012
Part of an ImpactJS library to change how entities act at runtime.
View enableBehaviors.js
ig.module(
'game.behaviors.enableBehaviors'
)
.requires(
'impact.impact'
)
.defines(function() {
enableBehaviors = function(entityClass) {
entityClass.inject({
@drhayes
drhayes / baseBehavior.js
Created Nov 15, 2012
Base class for behaviors.
View baseBehavior.js
ig.module(
'game.behaviors.baseBehavior'
)
.requires(
'impact.impact'
)
.defines(function() {
BaseBehavior = ig.Class.extend({
enabled: true,
@drhayes
drhayes / player.js
Created Nov 15, 2012
Snippet from the player entity.
View player.js
update: function() {
this.behave('update');
this.handleAnimation();
this.parent();
},
handleMovementTrace: function(res) {
this.behave('handleMovementTrace', res);
this.parent(res);
},
@drhayes
drhayes / eventChain.js
Created Jan 14, 2013
A function to help arrange sequential events in ImpactJS.
View eventChain.js
/*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 Jan 14, 2013
EventChain: The Basics
View eventChain.js
// 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 Jan 14, 2013
EventChain's then function
View eventChain.js
update.then = function(doThis) {
steps.push(function() {
// Update.
doThis();
// End.
steps.shift();
});
return this;
}
@drhayes
drhayes / eventChain.js
Created Jan 14, 2013
EventChain's wait function
View eventChain.js
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 Jan 14, 2013
EventChain's during function
View eventChain.js
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;