from pygame import display
from pygame.font import Font
from pygame.time import get_ticks, wait

from GameChild import GameChild

class Mainloop(GameChild):

    def __init__(self, parent):
        GameChild.__init__(self, parent)
        self.overflow = 0
        self.frame_count = 1
        self.actual_frame_duration = 0
        self.frames_this_second = 0
        self.last_framerate_display = 0
        self.last_ticks = get_ticks()
        self.stopping = False

    def load_configuration(self):
        config = self.get_configuration("display")
        self.target_frame_duration = config["frame-duration"]
        self.wait_duration = config["wait-duration"]
        self.skip_frames = config["skip-frames"]
        self.show_framerate = config["show-framerate"]
        self.framerate_text_size = config["framerate-text-size"]
        self.framerate_text_color = config["framerate-text-color"]
        self.framerate_text_background = config["framerate-text-background"]
        self.framerate_display_flag = config["framerate-display-flag"]

    def init_framerate_display(self):
        if self.framerate_display_active():
            screen = self.get_screen()
            self.last_framerate_count = 0
            self.framerate_topright = screen.get_rect().topright
            self.display_surface = screen
            self.font = Font(None, self.framerate_text_size)

    def framerate_display_active(self):
        return self.check_command_line(self.framerate_display_flag) or \

    def render_framerate(self):
        text = self.font.render(str(self.last_framerate_count), False,
        rect = text.get_rect()
        rect.topright = self.framerate_topright
        self.framerate_text = text
        self.framerate_text_rect = rect

    def run(self):
        while not self.stopping:
        self.stopping = False

    def advance_frame(self):
        refresh = False
        while self.frame_count > 0:
            refresh = True
            if self.framerate_display_active():
            self.frame_count -= 1
            if not self.skip_frames:
        if refresh:

    def update_frame_duration(self):
        last_ticks = self.last_ticks
        actual_frame_duration = get_ticks() - last_ticks
        last_ticks = get_ticks()
        while actual_frame_duration < self.target_frame_duration:
            actual_frame_duration += get_ticks() - last_ticks
            last_ticks = get_ticks()
        self.actual_frame_duration = actual_frame_duration
        self.last_ticks = last_ticks

    def update_overflow(self):
        self.frame_count = 1
        target_frame_duration = self.target_frame_duration
        overflow = self.overflow
        overflow += self.actual_frame_duration - target_frame_duration
        while overflow > target_frame_duration:
            self.frame_count += 1
            overflow -= target_frame_duration
        overflow = self.overflow

    def update_framerate(self):
        count = self.frames_this_second + 1
        if get_ticks() - self.last_framerate_display > 1000:
            if count != self.last_framerate_count:
                self.last_framerate_count = count
            self.last_framerate_display = get_ticks()
            count = 0
        self.display_surface.blit(self.framerate_text, self.framerate_text_rect)
        self.frames_this_second = count

    def stop(self):
        self.stopping = True
from os import makedirs
from os.path import exists, join
from sys import exc_info
from time import strftime

from pygame import image

from GameChild import *
from Input import *

class ScreenGrabber(GameChild):

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.delegate = self.get_delegate()

    def load_configuration(self):
        config = self.get_configuration("screen-captures")
        self.save_path = config["path"]
        self.file_name_format = config["file-name-format"]
        self.file_extension = config["file-extension"]

    def save_display(self, event):
        if, "capture-screen"):
            directory = self.save_path
                if not exists(directory):
                name = self.build_name()
                path = join(directory, name)
                capture =, path)
                self.print_debug("Saved screen capture to %s" % (path))
                self.print_debug("Couldn't save screen capture to %s, %s" %\
                                 (directory, exc_info()[1]))

    def build_name(self):
        return "{0}.{1}".format(strftime(self.file_name_format),
from math import sin, cos, atan2, radians, sqrt

def get_step(start, end, speed):
    x0, y0 = start
    x1, y1 = end
    angle = atan2(x1 - x0, y1 - y0)
    return speed * sin(angle), speed * cos(angle)

def get_endpoint(start, angle, magnitude):
    """clockwise, 0 is up"""
    x0, y0 = start
    dx, dy = get_delta(angle, magnitude)
    return x0 + dx, y0 + dy

def get_delta(angle, magnitude):
    angle = radians(angle)
    return sin(angle) * magnitude, -cos(angle) * magnitude

def rotate_2d(point, center, angle, translate_angle=True):
    if translate_angle:
        angle = radians(angle)
    x, y = point
    cx, cy = center
    return cos(angle) * (x - cx) - sin(angle) * (y - cy) + cx, \
           sin(angle) * (x - cx) + cos(angle) * (y - cy) + cy

def get_points_on_circle(center, radius, count, offset=0):
    angle_step = 360.0 / count
    points = []
    current_angle = 0
    for _ in xrange(count):
        points.append(get_point_on_circle(center, radius, current_angle + offset))
        current_angle += angle_step
    return points

def get_point_on_circle(center, radius, angle, translate_angle=True):
    if translate_angle:
        angle = radians(angle)
    return center[0] + sin(angle) * radius, center[1] - cos(angle) * radius

def get_range_steps(start, end, count):
    for ii in xrange(count):
        yield start + (end - start) * ii / float(count - 1)

def get_distance(p0, p1):
    return sqrt((p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2)
March 22, 2020

The chicken nugget business starter kit is now available online! Send me any amount of money through Venmo or PayPal, and I will mail you a package which will enable you to start a chicken nugget business of your own, play a video game any time you want, introduce a new character into your Animal Crossing village, and start collecting the chicken nugget trading cards.

The kit includes:

  • jellybean
  • instruction manual
  • limited edition trading card

By following the instructions you'll learn how to cook your own chicken or tofu nugget and be well on your way to financial success. I'm also throwing in one randomly selected card from the limited edition trading card set. Collect them, trade them, and if you get all eighteen and show me your set, I will give you an exclusive video game product.

All orders are processed within a day, so you can have your kit on your doorstep as quickly as possible. Don't sleep on this offer! Click the PayPal button or send a Venmo payment of any amount to @ohsqueezy, and in a matter of days you'll be counting money and playing video games.

PayPal me