Skip to content

Instantly share code, notes, and snippets.

# Game Project Assignment comment in progress by Julia Luu
import math
import simplegui
# constants
#-------------------------#
CANVAS_WIDTH = 1000
CANVAS_HEIGHT = 550
class BoundedFloat(object):
def __init__(self, value, minimum, maximum):
assert minimum <= maximum
self._val = value
self.minimum = minimum
self.maximum = maximum
@property
def val(self):
return self._val
import pygame as pg
class Square(object):
def __init__(self, center_point, size):
self.image = pg.Surface(size)
self.image.fill(pg.Color("dodgerblue"))
self.rect = self.image.get_rect(center=center_point)
self.pos = self.rect.center
self.x_velocity = 0
import pygame
import sys
from pygame.locals import *
def move(x, y, direction, matrix):
steps = [0, 0]
vx = directs[direction][0]
vy = directs[direction][1]
try:
import pygame
import sys
from pygame.locals import *
data = []
matrix = []
with open("data.txt") as file:
for line in file:
data.append(line)
import sys
from random import choice, randint
import pygame as pg
COLORS = ["springgreen", "goldenrod"]
class Square(pg.sprite.DirtySprite):
"""
from itertools import cycle
import string
import pygame as pg
import prepare, tools
#To avoid instantiating unnecessary Font objects,
#Fonts are stored in this dict. When creating a Label or
#Button object, this dict is checked first to see if the
#font already exists in LOADED_FONTS.
@iminurnamez
iminurnamez / state_engine.py
Last active June 12, 2024 15:49
Simple state engine example
#This code is licensed as CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0/legalcode).
import sys
import pygame as pg
class Game(object):
"""
A single instance of this class is responsible for
managing which individual game state is active
@iminurnamez
iminurnamez / main.py
Last active August 29, 2015 14:25
2 line hack
import sys
import random
import pygame as pg
# Importing prepare initializes the display.
import prepare
import actors
class App(object):
import pygame as pg
def color_swap(source_image, swap_map):
"""
Creates a new Surface from the source_image with some or all colors
swapped for new colors. Colors are swapped according to the
color pairs in the swap_map dict. The keys and values in swap_map
can be RGB tuples or pygame color-names. For each key in swap_map,
all pixels of that color will be replaced by the color that key maps to.