Skip to content

Instantly share code, notes, and snippets.

@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:e12b70cec53df547de59
Created Nov 30, 2015
Manually Set FPS in ImpactJS
View gist:e12b70cec53df547de59
// This is how to manually set the frames per second in ImpactJS.
setTimeout(function() {
var fps = 60;
ig.system.stopRunLoop();
window.setInterval( ig.system.run.bind(ig.system), 1000/fps );
}, 0);
@Joncom
Joncom / entity-blinking.js
Created Aug 28, 2015
Plugin for ImpactJS that makes entities blink
View entity-blinking.js
/*
Usage:
ig.module('game.entities.example')
.requires('impact.entity', 'plugins.entity-blinking')
.defines(function() {
EntityExample = ig.Entity.extend({
size: { x: 32, y: 32 },
@Joncom
Joncom / gist:44db1d01a83f995beb2d
Created Jul 20, 2015
ImpactJS + Box2D: Draw world body vertex positions
View gist:44db1d01a83f995beb2d
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 / gist:32c95226c3d6a1c588cd
Created Mar 19, 2015
Dump Mitel MiCollab Web Client Messages
View gist:32c95226c3d6a1c588cd
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));
You can’t perform that action at this time.