Skip to content

Instantly share code, notes, and snippets.

@pathunstrom
pathunstrom / basic_components
Last active May 23, 2016 04:43
The same test with some abstraction
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)

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 October 21, 2016 05:08
Algorithm I did for freeCodeCamp
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];
}
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:
@pathunstrom
pathunstrom / enemymovement.new.py
Created November 8, 2016 19:38
Enemy movement
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 / coroutine.py
Last active August 23, 2022 17:22
Sample Fizz Buzzes
def fizzbuzz_generator():
value = yield
while True:
rv = ""
if not value % 3:
rv += "Fizz"
if not value % 5:
rv += "Buzz"
value = yield rv or value
@pathunstrom
pathunstrom / basegameobject.py
Created September 7, 2017 13:03
Generalized game object probably the actual thing that needs to be built to do this sort of thing.
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 October 20, 2017 15:32
Organize python code
"""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 November 30, 2017 06:00
Pygame Sounds manually building buffers.
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 December 19, 2017 01:16
Pygame sine waves
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