Skip to content

Instantly share code, notes, and snippets.

@Joncom
Joncom / gist:5279870
Last active December 15, 2015 15:09
Comparing two JavaScript methods to see which one is faster.
startTimer = function() {
var start = new Date().getTime();
return start;
};
stopTimer = function(start) {
var end = new Date().getTime();
var time = end - start;
return time;
};
@Joncom
Joncom / gist:5703442
Created June 4, 2013 03:49
ImpactJS Box2D - Get Body Count
getbodyCount = function() {
var count = 0;
for( var body = ig.world.GetBodyList(); body; body = body.m_next ) {
count++;
}
console.log(count);
}
@Joncom
Joncom / gist:5812191
Created June 19, 2013 07:02
Count entities player is touching
var count = 0;
for(var i=0; i<ig.game.entities.length; i++) {
if(ig.game.player.touches(ig.game.entities[i])) {
count++;
}
}
console.log(count);
@Joncom
Joncom / gist:6302577
Created August 22, 2013 02:35
Object.defineProperty Example
test = 1;
obj = { test: null };
Object.defineProperty(obj, 'test', {
get: function() { return test; },
set: function(value) { test = value }
});
@Joncom
Joncom / gist:6401880
Created September 1, 2013 02:16
Pokemon Ruby Map Tile Bits
Hex: 0130
Bin: 0000 0001 0011 00.00
Tile: 001
Attr: 0C
Hex: D405
Bin: 1101 0100 0000 01.01
Tile: 1D4
Attr: 01
@Joncom
Joncom / gist:7002036
Created October 16, 2013 03:03
Pokemon Ruby ROM Animation Research
P = ASM Pointer
S = Steps
F = Speed Factor
B = Speed Bitmask?
Q = Animation Slot
T = Start Tile
A = Tile Amount
I = Is Special Part Flag
H = Has Special Part Flag
R = Rotation Shifted Flag
@Joncom
Joncom / gist:e8e8d18ebe7fe55c3894
Last active September 11, 2021 00:29
Check if two line segments intersect
// Adapted from: http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect/1968345#1968345
function line_intersects(p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y) {
var s1_x, s1_y, s2_x, s2_y;
s1_x = p1_x - p0_x;
s1_y = p1_y - p0_y;
s2_x = p3_x - p2_x;
s2_y = p3_y - p2_y;
var s, t;
@Joncom
Joncom / gist:32c95226c3d6a1c588cd
Created March 19, 2015 21:46
Dump Mitel MiCollab Web Client Messages
jQuery('.chat-session').each(function() {
var session = jQuery($(this));
var other_name = session.find('.name').text();
session.find('.chat-messages').each(function() {
var list = jQuery($(this));
list.find('li').each(function() {
var list_item = jQuery($(this));
@Joncom
Joncom / gist:44db1d01a83f995beb2d
Created July 20, 2015 06:44
ImpactJS + Box2D: Draw world body vertex positions
ig.system.context.save();
ig.system.context.fillStyle = '#A6E22E';
var radius = 3 * ig.system.scale;
for (var body = ig.world.GetBodyList(); body; body = body.GetNext()) {
for (var fixture = body.GetFixtureList(); fixture; fixture = fixture.GetNext()) {
var shape = fixture.GetShape();
if (shape.GetType() == Box2D.Collision.Shapes.b2Shape.e_polygonShape) {
var poly = shape;
poly.GetVertices().forEach(function(vertex) {
var pos = body.GetWorldPoint(vertex.Copy());
@Joncom
Joncom / entity-blinking.js
Created August 28, 2015 16:30
Plugin for ImpactJS that makes entities blink
/*
Usage:
ig.module('game.entities.example')
.requires('impact.entity', 'plugins.entity-blinking')
.defines(function() {
EntityExample = ig.Entity.extend({
size: { x: 32, y: 32 },