Skip to content

Instantly share code, notes, and snippets.

@Joncom
Joncom / gist:e8e8d18ebe7fe55c3894
Last active Nov 27, 2020
Check if two line segments intersect
View gist:e8e8d18ebe7fe55c3894
// 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:7002036
Created Oct 16, 2013
Pokemon Ruby ROM Animation Research
View gist:7002036
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:6401880
Created Sep 1, 2013
Pokemon Ruby Map Tile Bits
View gist:6401880
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:6302577
Created Aug 22, 2013
Object.defineProperty Example
View gist:6302577
test = 1;
obj = { test: null };
Object.defineProperty(obj, 'test', {
get: function() { return test; },
set: function(value) { test = value }
});
@Joncom
Joncom / gist:5812191
Created Jun 19, 2013
Count entities player is touching
View gist:5812191
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:5703442
Created Jun 4, 2013
ImpactJS Box2D - Get Body Count
View gist:5703442
getbodyCount = function() {
var count = 0;
for( var body = ig.world.GetBodyList(); body; body = body.m_next ) {
count++;
}
console.log(count);
}
@Joncom
Joncom / gist:5279870
Last active Dec 15, 2015
Comparing two JavaScript methods to see which one is faster.
View gist:5279870
startTimer = function() {
var start = new Date().getTime();
return start;
};
stopTimer = function(start) {
var end = new Date().getTime();
var time = end - start;
return time;
};
You can’t perform that action at this time.