Skip to content

Instantly share code, notes, and snippets.

View netgfx's full-sized avatar
💻
Working...

Michael Dobekidis netgfx

💻
Working...
View GitHub Profile
@netgfx
netgfx / gist:8887894
Created February 8, 2014 18:24
Check max-min positions
function checkMaxMinPos(a, b, aW, aH, bW, bH, maxX, minX, maxY, minY) {
'use strict';
if (a.left < b.left) {
if (a.left < minX) {
minX = a.left;
}
} else {
if (b.left < minX) {
minX = b.left;
@netgfx
netgfx / gist:8887917
Last active March 21, 2018 10:05
Object collision detection
// jQuery
function doObjectsCollide(a, b) { // a and b are your objects
//console.log(a.offset().top,a.position().top, b.position().top, a.width(),a.height(), b.width(),b.height());
var aTop = a.offset().top;
var aLeft = a.offset().left;
var bTop = b.offset().top;
var bLeft = b.offset().left;
return !(
((aTop + a.height()) < (bTop)) ||
@netgfx
netgfx / gist:9781214
Created March 26, 2014 11:28
English letters in array
var ENGLISH = "abcdefghijklmnopqrstuvwxyz".split(""); // [a,b,c,d,...]
@netgfx
netgfx / gist:77dba7df624446a3add4
Last active August 29, 2015 14:00
KineticJS CoD
function doObjectsCollide(a, b) { // a and b are your objects
return !(
((a.getY() + a.getHeight()) < (b.getY())) ||
(a.getY() > (b.y + b.getHeight())) ||
((a.getX() + a.getWidth()) < b.getX()) ||
(a.getX() > (b.getX() + b.getWidth()))
);
}
// for kinetic version > 5.1
@netgfx
netgfx / gist:371e2fb199aae4572309
Created September 19, 2014 07:14
Random from min-max values
function getRandom(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
@netgfx
netgfx / gist:17c0ba8cb556f667f132
Created April 29, 2015 08:51
Phaser.io animate number
GameState.prototype.animateNumber = function(num, fn, step, speed, endFn) {
var _step = step || 10;
var _speed = speed || 10; // in seconds because this is total
var repeats = Math.ceil(num / _step);
var animSpeed = (_speed / repeats) * 1000; // in ms
var _endFn = endFn || function() {
game.time.events.remove(this);
};
var _timer = game.time.create(true);
_timer.start();
@netgfx
netgfx / gist:00d0a01d5de496a3a34e
Last active January 15, 2016 11:44
Phaser Keyboard Keys
// PHASER KEYBOARD KEYS //
Phaser.Keyboard.A = "A".charCodeAt(0);
Phaser.Keyboard.B = "B".charCodeAt(0);
Phaser.Keyboard.C = "C".charCodeAt(0);
Phaser.Keyboard.D = "D".charCodeAt(0);
Phaser.Keyboard.E = "E".charCodeAt(0);
Phaser.Keyboard.F = "F".charCodeAt(0);
Phaser.Keyboard.G = "G".charCodeAt(0);
Phaser.Keyboard.H = "H".charCodeAt(0);
Phaser.Keyboard.I = "I".charCodeAt(0);
@netgfx
netgfx / gist:f33a49d7e95c42a13873
Created February 8, 2016 12:10 — forked from Katafalkas/gist:eb5e840df1ace981c359
Swift UITableViewCell custom subclass simple Chat Bubble
class Cell: UITableViewCell {
override func drawRect(rect: CGRect) {
var bubbleSpace = CGRectMake(20.0, self.bounds.origin.y, self.bounds.width - 20, self.bounds.height)
let bubblePath1 = UIBezierPath(roundedRect: bubbleSpace, byRoundingCorners: .TopLeft | .TopRight | .BottomRight, cornerRadii: CGSize(width: 20.0, height: 20.0))
let bubblePath = UIBezierPath(roundedRect: bubbleSpace, cornerRadius: 20.0)
UIColor.greenColor().setStroke()
UIColor.greenColor().setFill()
@netgfx
netgfx / CoreGraphics+AspectRatio.swift
Created May 28, 2016 10:21 — forked from jkosoy/CoreGraphics+AspectRatio.swift
Calculating for different device Aspect Ratios, used in Melody Jams
//
// CoreGraphics+AspectRatio.swift
// EmptySpriteKitGame
//
// Created by Jamie Kosoy on 11/6/15.
// Copyright © 2015 Arbitrary. All rights reserved.
//
import UIKit
import Foundation
@netgfx
netgfx / doBackgroundTask.swift
Created June 2, 2016 16:56 — forked from kristopherjohnson/doBackgroundTask.swift
Swift helper function for invoking a function in the background and then handling its result on the main thread
import Foundation
/// Execute a function on a background thread and then handle result
/// in main thread.
func doBackgroundTask<Params, Result>(
params: Params,
backgroundTask: (Params) -> Result,
onComplete: (Result) -> ())
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {