Skip to content

Instantly share code, notes, and snippets.

@Joncom
Joncom / impact-edit-map-util.ts
Last active May 25, 2020 08:23
Helper functions for ImpactJS to double or halve the tilesize of a BackgroundMap (without breaking their appearance)
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 March 3, 2019 08:23
How to download canvas.toDataURL image to disk
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 December 18, 2017 15:58
Converting to and from UTC and Unix time
<?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 July 6, 2016 20:55
Sorting An Array By Multiple Criteria
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 July 6, 2016 18:45
ImpactJS Mixin That Adds Tile-Based Grid Movement to Entities
ig.module('plugins.mixin-grid-movement')
.requires()
.defines(function() {
MixinGridMovement = {
src_tile: null,
dst_tile: null,
grid_move: function(direction, seconds) {
// 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 November 30, 2015 02:58
Manually Set FPS in ImpactJS
// 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 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 },
@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 / 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));