Skip to content

Instantly share code, notes, and snippets.

@quantumpotato
quantumpotato / StreamHandler.js
Created September 6, 2011 02:24
Adding, sending and writing messages from a queue on a player(client).
//We store chat messages for the player until they send us their input
//Otherwise the message will get sent and terminal writes it *next to* whatever they are typing!
function StreamHandler() {
this.addMessage = function(player, message) {
player.messages.push(message);
}
this.writeMessage = function(player, cb) {
if (player.messages.length > 0) {
@quantumpotato
quantumpotato / NSNotificationCenter+CHAdditions
Created January 3, 2012 21:55
NSNotification observing with blocks
#import <Foundation/Foundation.h>
@interface NSNotificationCenter (CHAdditions)
+ (void)addObserver:(id)observer forNotificationNamed:(NSString *)notificationName withBlock:(void (^)(NSNotification *note))block;
@end
#import "NSNotificationCenter+CHAdditions.h"
@quantumpotato
quantumpotato / BlockHacking
Created February 17, 2012 17:59
For X in Y with C do {}
#import "BlockHacking.h"
typedef void (^twoObjectBlock)(id a, id b);
typedef void (^XYZBlock)(Class x, NSArray *y, id c, twoObjectBlock b);
XYZBlock arrayDoBlock = ^(Class x, NSArray *y, id c, twoObjectBlock b) {
for (x in y) {
b(c,x);
}
};
@quantumpotato
quantumpotato / gist:3709551
Created September 12, 2012 20:11
Avoiding multiple #import .h when using @Class forward declaration
//QPBattlefield.h
#import "ClonePilotBattlefield.h"
#import "QPBFState.h"
#import "QPBFTitleState.h"
#import "QPBFDrawingState.h"
#import "QPBFInputConstants.h"
@interface QPBattlefield : ClonePilotBattlefield
[self.button1 setImage:[UIImage imageNamed:@"image_up.png"] forState:UIControlStateNormal];
[self.button1 setImage:[UIImage imageNamed:@"image_down.png"] forState:UIControlStateSelected];
@quantumpotato
quantumpotato / gist:49bb52da8eea3ff3e0c6
Created April 18, 2015 15:50
Input Loop in Python
stage = 1
def show_prompt():
if stage == 1:
print "You are between a volcano and a supernova."
print "1 for volcano, 2 for supernova."
def restart_input():
print "Nice try."
input_loop()
loop() {
this.now = Date.now();
var delta = this.now - this.last;
this.last = this.now;
this.dt = this.dt + delta;
if (this.dt < this.rate) {
window.requestAnimationFrame(this.loop.bind(this));
return;
@quantumpotato
quantumpotato / Turbo
Created December 11, 2015 22:12
Turbo
class TurboMover extends Component {
registrationNames() {
return ['velocity'];
}
getValue(name, hash) {
if (name == 'velocity') {
hash.vx = hash.vx * 20; //times speed
hash.vy = hash.vy * 20;
}
@quantumpotato
quantumpotato / gamepad
Created August 24, 2016 01:49
gamepad
loopGamepadInput() {
var pads = navigator.getGamepads();
if (pads) {
for (var i = 0; i < pads.length; i++) {
var gp = pads[i];
if (!gp) {
break;
}
var x = gp.axes[0];
@quantumpotato
quantumpotato / readme.txt
Created December 5, 2022 14:28
My PS+ Game (Puzzlescript Plus Script)
Play this game by pasting the script in https://auroriax.github.io/PuzzleScript/editor.html