Skip to content

Commit

Permalink
Snuffbox template
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidVenom committed Dec 5, 2014
1 parent cdf4989 commit 8b753b9
Show file tree
Hide file tree
Showing 18 changed files with 624 additions and 0 deletions.
Binary file added fmod64.dll
Binary file not shown.
Binary file added fonts/arial.ttf
Binary file not shown.
Binary file added fonts/arial.ttfb
Binary file not shown.
Binary file added fonts/arial.ttfi
Binary file not shown.
Binary file added fonts/arial.ttfz
Binary file not shown.
30 changes: 30 additions & 0 deletions js/test_state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var TestState = function()
{
this.name = "Test";
this._camera = Camera.new("orthographic");

this.initialise = function()
{

}

this.update = function(dt)
{

}

this.draw = function(dt)
{
Game.render(this._camera);
}

this.reload = function(path)
{

}

this.destroy = function()
{

}
}
44 changes: 44 additions & 0 deletions js/utility/broadcaster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @class Broadcaster
* @brief Broadcasts events over the game
* @author Daniël Konings
*/
var Broadcaster = {
_events: [],
_listeners: [],

/// Registers a listener
register: function(obj,evt,func)
{
if (this._events[evt] === undefined)
{
this._events[evt] = [];
this._listeners[evt] = [];
}

this._events[evt].push(func);
this._listeners[evt].push(obj);
},

/// Broadcasts an event
broadcast: function(evt,params)
{
if (this._events[evt] !== undefined)
{
for (var i = 0; i < this._events[evt].length; ++i)
{
var func = this._events[evt][i];
var obj = this._listeners[evt][i];

obj.func = func;
obj.func(params);
}
}
},

clear: function()
{
this._events = [];
this._listeners = [];
}
}
66 changes: 66 additions & 0 deletions js/utility/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/// The global object, should not be accessed from anything other than helper functions
var _GLOBAL_ = this;

/// Basic class inheritance
function extend(classA, classB)
{
for (var b in classB)
{
if (b == "__quad")
{
continue;
}
classA[b] = classB[b];
}
}

/**
* @class Enum
* @brief An enumerator class
* @author Daniël Konings
*/
var Enum = function(name, enumerations)
{
this._name = name;
for (var i = 0; i < enumerations.length; ++i)
{
this[enumerations[i]] = i;
}
}

/// Changes the toString of the Enum class
Enum.prototype.toString = function()
{
return (this._name);
}

/// Creates an enumerator
function enumerator(name, enumerations)
{
_GLOBAL_[name] = new Enum(name,enumerations);
}

/// Draws a rectangle
function DrawRectangle(x1, y1, x2, y2, z, r, g, b, rr, gg, bb)
{
if (x1 === undefined || y1 === undefined || x2 === undefined || y2 === undefined)
{
Log.error("Cannot draw a rectangle, not all required parameters were set! (x1, y1, x2, y2)");
return;
}

var zz = z === undefined ? 1 : z;

var r1 = r === undefined ? 1 : r;
var g1 = g === undefined ? 1 : g;
var b1 = b === undefined ? 1 : b;

var r2 = rr === undefined ? r1 : rr;
var g2 = gg === undefined ? g1 : gg;
var b2 = bb === undefined ? b1 : bb;

Line.draw(x1, y1, zz, r1, g1, b1, x2, y1, zz, r2, g2, b2);
Line.draw(x2, y1, zz, r1, g1, b1, x2, y2, zz, r2, g2, b2);
Line.draw(x1, y2, zz, r1, g1, b1, x2, y2, zz, r2, g2, b2);
Line.draw(x1, y1, zz, r1, g1, b1, x1, y2, zz, r2, g2, b2);
}
60 changes: 60 additions & 0 deletions js/utility/math_extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Easing functions from: http://www.timotheegroleau.com/Flash/experiments/easing_function_generator.htm

/// Lerps from one value to another
Math.lerp = function(a, b, ratio)
{
return a + (b-a) * ratio;
}

/// Eases elastic out
Math.easeOutElastic = function(t, b, c, d)
{
var ts=(t/=d)*t;
var tc=ts*t;
return b+c*(33*tc*ts + -106*ts*ts + 126*tc + -67*ts + 15*t);
}

/// Eases quadratic in
Math.easeInQuadratic = function(t, b, c, d)
{
t /= d;
return b+c*(t*t);
}

/// Eases quadratic in
Math.easeOutQuadratic = function(t, b, c, d)
{
t /= d;
return b - c*(t*(t-2));
}

/// Converts an easing function to an interpolation
Math.easeToInterpolation = function(a, b, e)
{
return a * (1-e) + b * e;
}

/// Returns the distance between 2 points
Math.distance = function(x1,y1,x2,y2)
{
var dx = x2 - x1;
var dy = y2 - y1;

return Math.sqrt(dx*dx + dy*dy);
}

/// Returns a number within a range
Math.randomRange = function(a,b)
{
return a + (b-a)*Math.random();
}

/// Returns a shake on x and y coordinates
Math.shake = function(magnitude,timer)
{
var random = {x: Math.randomRange(-1,1), y: Math.randomRange(-1,1) }
random.x *= magnitude;
random.y *= magnitude;

return {x: (1-timer) * random.x, y: (1-timer) * random.y }
}
123 changes: 123 additions & 0 deletions js/utility/sprite_animation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
var SpriteAnimation = function(element, frames)
{
this._frames = frames;
this._element = element;
this._playing = false;
this._timer = 1;
this._speed = 1;
this._currentFrame = 0;
this._loop = false;
this._wasPlaying = false;

this._callbacks = {
started: function(){},
ended: function(){}
}

this.start = function()
{
this._playing = true;
}

this.stop = function()
{
this._playing = false;
this._wasPlaying = false;
this._currentFrame = 0;
}

this.pause = function()
{
this._playing = false;
}

this.isPlaying = function()
{
return this._playing;
}

this.setSpeed = function(speed)
{
this._speed = speed;
}

this.setFrame = function(frame)
{
this._currentFrame = frame;
}

this.setToFrame = function(index)
{
var frame = this._frames[index];

var textureMetrics = this._element.textureMetrics();

var width = frame.width / textureMetrics.width;
var height = frame.height / textureMetrics.height;

var offsetX = frame.x / textureMetrics.width;
var offsetY = frame.y / textureMetrics.height;

if (frame.event !== undefined)
{
frame.event();
}

this._element.setUniform("float4", "AnimationMetrics", offsetX, offsetY, width, height);
this._element.setSize(frame.width, frame.height);
}

this.setLoop = function(loop)
{
this._loop = loop;
}

this.on = function(type, func)
{
this._callbacks[type] = func;
}

this.update = function(dt)
{
if (this._playing == false)
{
return;
}
else
{
if (this._wasPlaying == false)
{
this._callbacks["started"]();
this.setToFrame(0);
this._wasPlaying = true;
}
}

if (this._timer < 1)
{
this._timer += dt*this._speed;
}
else
{
this.setToFrame(this._currentFrame);
this._timer = 0;
++this._currentFrame;

if (this._currentFrame >= this._frames.length)
{
this._callbacks["ended"]();

if (this._loop == true)
{
this._currentFrame = 0;
this._callbacks["started"]();
}
else
{
this.stop();
return;
}
}
}
}
}
Loading

0 comments on commit 8b753b9

Please sign in to comment.