Skip to content

Instantly share code, notes, and snippets.

@pathunstrom
pathunstrom / basic_components
Last active May 23, 2016
The same test with some abstraction
View basic_components
import logging
import ppb.engine
from ppb.event import Quit, Tick
from ppb.components.models import GameObject
from ppb.components.controls import Publisher
import ppb.hw as hardware
hardware.choose("pygame")
logging.basicConfig(level=logging.INFO)
View keybase.md

Keybase proof

I hereby claim:

  • I am pathunstrom on github.
  • I am pathunstrom (https://keybase.io/pathunstrom) on keybase.
  • I have a public key whose fingerprint is 8FF9 3F4E C447 55EC 4658 BDCC A57E A7A4 86D2 644F

To claim this, I am signing this object:

@pathunstrom
pathunstrom / converttoroman.js
Last active Oct 21, 2016
Algorithm I did for freeCodeCamp
View converttoroman.js
function convertToRoman(num) {
function addSymbols(carrier, val, symbol) {
var returnString = carrier[0];
var startingValue = carrier[1];
for ( ; startingValue >= val; startingValue -= val) {
returnString += symbol;
}
return [returnString, startingValue];
}
View new.py
def newEnemy(style):
spawn = random.randint(1, SPAWNRATE)
coin = random.randint(0, 10)
if style == "z" and spawn >= zomSpawn:
new_enemy = config.enemies["z"].copy()
new_enemy["sight"] = zomSight
elif style == "s" and spawn >= skelSpawn:
new_enemy = config.enemies["s"].copy()
new_enemy["sight"] = skelSight
else:
View enemymovement.new.py
def enemy_update(enemy, containers):
player = containers["player"]
enemies = containers["enemies"]
attacks = containers["attacks"]
if not enemy['awake']:
shuffle = random.randint(1, 10)
move_object(shuffle, enemy["rect"], enemy["speed"])
@pathunstrom
pathunstrom / basegameobject.py
Created Sep 7, 2017
Generalized game object probably the actual thing that needs to be built to do this sort of thing.
View basegameobject.py
class BaseGameObject(DirtySprite):
group = None
image_path = None
image = None
def __init__(self, scene, position=(0, 0)):
cls = self.__class__
if cls.group is None:
cls.group = cls.__name__
super().__init__(scene.groups[cls.group], scene.groups["render"])
@pathunstrom
pathunstrom / sample.py
Last active Oct 20, 2017
Organize python code
View sample.py
"""Everything should be alphabetical in it's group."""
# Group imports by where they come from
# Standard Lib
import os
# PyPI/third party
import requests
# Local
@pathunstrom
pathunstrom / sounds.py
Created Nov 30, 2017
Pygame Sounds manually building buffers.
View sounds.py
import pygame
from itertools import cycle
import math
RESOLUTION = (800, 800)
BITS = 16
MAX_SAMPLE = 2**(BITS - 1) - 1
LEFT_FREQUENCY = 0
RIGHT_FREQUENCY = 450
@pathunstrom
pathunstrom / sound.py
Created Dec 19, 2017
Pygame sine waves
View sound.py
import pygame
from itertools import cycle
import math
RESOLUTION = (800, 800)
BITS = 16
MAX_SAMPLE = 2**(BITS - 1) - 1
LEFT_FREQUENCY = 0
RIGHT_FREQUENCY = 262
@pathunstrom
pathunstrom / main
Created Dec 30, 2017
Ballistic bullets
View main
import pygame, sys
import math
from ppb_vector import Vector2 as Vector
#Colours
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
BLUE = (217, 231, 249)
GOLD = (255, 255, 0)
PURPLE = (202, 90, 155)