Skip to content

Instantly share code, notes, and snippets.

@iminurnamez
iminurnamez / gist:10987357
Last active August 29, 2015 13:59 — forked from craig3050/gist:10985630
a few suggestions
#!/usr/bin/python
from random import randint, choice
def return_list(num_to_try,numbers_dictionary):
first = randint(1,6)
list_fig = [int(numbers_dictionary[first])]
called = [first]
import sys
import pygame as pg
class MouseTester(object):
def __init__(self):
self.done = False
self.clock = pg.time.Clock()
self.screen = pg.display.set_mode((800, 800))
self.center_rect = pg.Rect(0, 0, 10, 10)
#!/usr/bin/env python3
import pygame,sys
from pygame.locals import *
from colors import *
from MySprite import *
from MyPlayerObject import *
#Audio - ogg or wav
pygame.init()
@iminurnamez
iminurnamez / angles.py
Last active August 29, 2015 14:06
pygame angle functions
"""A module of funtions dealing with angles in pygame.
All functions (other than project) take lists or tuples
of pygame coordinates as origin, destination
and return the appropriate angle in radians.
"""
from math import pi, cos, sin, atan2, degrees, radians
import pygame as pg
from math import sin, cos, pi, atan2
import pygame as pg
def get_angle(origin, destination):
"""Returns angle in radians from origin to destination.
This is the angle that you would get if the points were
on a cartesian grid. Arguments of (0,0), (1, -1)
return .25pi(45 deg) rather than 1.75pi(315 deg).
"""
x_dist = destination[0] - origin[0]
@iminurnamez
iminurnamez / homing.py
Created October 16, 2014 11:49
Bullets that home in on mouse position
from math import sin, cos, pi, atan2
import pygame as pg
def get_angle(origin, destination):
"""Returns angle in radians from origin to destination.
This is the angle that you would get if the points were
on a cartesian grid. Arguments of (0,0), (1, -1)
return .25pi(45 deg) rather than 1.75pi(315 deg).
"""
x_dist = destination[0] - origin[0]
@iminurnamez
iminurnamez / gist:4e8d505daf423d1f3db4
Last active August 29, 2015 14:08
finding where a ray intersects the edge of a bounding rectangle
import sys
from math import pi, tan
import pygame as pg
from angles import get_angle, project
def get_edge_pos(origin, angle, rect):
"""Returns the intersection of the ray from
origin at angle with the edge of rect. origin
should be a point inside rect."""
@iminurnamez
iminurnamez / pathfinder.py
Last active August 29, 2015 14:14
pathfinding example
"""
Functions for pygame pathfinding.
"""
import pygame as pg
class Cell(object):
def __init__(self, index, cell_size, occupant=None):
self.index = index
self.occupant = occupant
import itertools as it
import pygame as pg
#IMAGE LOADING
#a list of all image names
image_names = ["EnemyMoverRed", "EnemyMoverBlue", "BossMoverRed"]
#Make a dict to hold the images so they're only loaded once.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Sample hueberry
# written in Python
# John Gamble 15/01/2015
import sys, pygame
import phue
import time
from phue import Bridge