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 / impact-edit-map-util.ts
Last active May 25, 2020
Helper functions for ImpactJS to double or halve the tilesize of a BackgroundMap (without breaking their appearance)
View impact-edit-map-util.ts
export function halveTilesize( layer: Layer, tileset: Image ) {
if( layer.tilesize % 2 !== 0 || (layer.name !== 'collision' && !tileset.loaded) ) {
return false;
}
const oldTileWidth = tileset.width / layer.tilesize;
const newTileWidth = (tileset.width / layer.tilesize) * 2;
const newData = [];
for( let y = 0; y < layer.height; y++ ) {
newData[y * 2] = [];
@Joncom
Joncom / gist:bc7170c0767550eeeebcb77a97c0b362
Created Mar 3, 2019
How to download canvas.toDataURL image to disk
View gist:bc7170c0767550eeeebcb77a97c0b362
var link = document.createElement('a');
link.href = Main.backbuffer.g2canvas.canvas.canvas.toDataURL();
link.download = 'coolimage.jpg';
document.body.appendChild(link);
link.click();
@Joncom
Joncom / timestamp.php
Created Dec 18, 2017
Converting to and from UTC and Unix time
View timestamp.php
<?php
// Convert UTC time string to Unix time interger.
$timestamp = strtotime ( '2014-12-29 12:30:21+0000' );
// Convert Unix time integer back to UTC time string.
echo gmdate(DateTime::ISO8601, $timestamp);
@Joncom
Joncom / gist:59856f30f351510a656b3ffbf5ec633f
Created Jul 6, 2016
Sorting An Array By Multiple Criteria
View gist:59856f30f351510a656b3ffbf5ec633f
ig.game.backgroundMaps.sort(function(a,b) {
var o1 = (a.repeat ? 0 : 1);
var o2 = (b.repeat ? 0 : 1);
var p1 = (a.foreground ? 1 : 0);
var p2 = (b.foreground ? 1 : 0);
if(o1 === o2) {
return (p1 < p2) ? -1 : (p1 > p2) ? 1 : 0;
} else {
return (o1 < o2) ? -1 : 1;
}
@Joncom
Joncom / mixin-grid-movement.js
Last active Jul 6, 2016
ImpactJS Mixin That Adds Tile-Based Grid Movement to Entities
View mixin-grid-movement.js
ig.module('plugins.mixin-grid-movement')
.requires()
.defines(function() {
MixinGridMovement = {
src_tile: null,
dst_tile: null,
grid_move: function(direction, seconds) {
View pixelated-circle-tilesheet-generator.js
// The purpose of this program is to "pre-render" pixel
// perfect circles, so that they can be drawn from an image
// instead of using something like an arc function. The
// output image is a tilesheet that can be used in 2D pixel
// art style games.
// Originally I ran into an issue with common algorthithms
// (such as the midpoint circle algorithm) only supporting
// an increase in diameter of 2 pixels at a time. I wanted
// to capture single pixel size increases (thus doubling
@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 }
});
You can’t perform that action at this time.