Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
teaching python/pygame to children

Horst JENS horstjens

💭
teaching python/pygame to children
View GitHub Profile
View pygame_textmenu.py
# generic menu for pygame. see textMenu.py for a simplier version
import os
import pygame
class MenuItem:
def __init__(self, name="dummy", choices=[], cindex=0, helptext=None, rect=None):
"""
Menu Item. For use inside of a Menu.items list.
@horstjens
horstjens / pygame_platformer.py
Last active Aug 11, 2022
pygame platformer ( data folder not included)
View pygame_platformer.py
#!/usr/bin/env python
"""
pygame platform game
"""
# TODO : avoid climbing in block (when jumping) -> set middle point down near foot points
# TODO: fine-tune bounce on ceiling
import os
#
@horstjens
horstjens / roll.py
Created Jul 19, 2022
d & d random roll
View roll.py
def roll(dice_string="2D6+1"):
"""random generator for d&d values, with re-reoll
examples:
2d6+1 : roll 2 6-sides dice, add 1 to the end result
1D6 : roll 1 6-sided die, if it rolls a 6 it counts as 5 but you can re-roll
(exploding dice, has very low probability of very high number)
2D6-1 : roll 2 6-sided exploding dice, subtract 1 from the end result
"""
if not "D" in dice_string:
View emil1.py
import random
import PySimpleGUI as sg
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import numpy as np
from collections import defaultdict
# with re-roll
def roll(dice_string="2D6+1", details=False):
View breakout.py
import PySimpleGUI as sg
import random
import time
RESOLUTIONS = ["640x400","800x600","1024x800", "1024x960","1200x1024"]
WIDTH, HEIGHT = 800,600
MIN_TILES = 10
MAX_TILES = 200
HELPTEXT = """catch the ball
User cursor keys to move left - right"""
View catch_me.py
import PySimpleGUI as sg
import random
import time
RESOLUTIONS = ["100x100", "200x200", "320x200", "400x400", "600x600", "640x400","800x600","1024x800", "1024x960","1280x1024"]
WIDTH, HEIGHT = 400,400
MIN_TILES = 10
MAX_TILES = 50
TX = 40
TY = 40
View daedalus.py
import PySimpleGUI as sg
import random
import time
RESOLUTIONS = ["640x400","800x600","1024x800", "1024x960","1200x1024"]
WIDTH, HEIGHT = 800,600
MIN_TILES = 10
MAX_TILES = 200
HELPTEXT = """Escape from the labyrinth. Reach the yellow goal.
You are the green rect.
@horstjens
horstjens / game_of_life.py
Last active Jun 27, 2022
Conway's Game of Life with Python and PySimpleGUI
View game_of_life.py
import PySimpleGUI as sg
import random
import time
#from matplotlib.colors import hex2color
RESOLUTIONS = ["100x100", "200x200", "320x200", "400x400", "600x600", "640x400","800x600","1024x800", "1024x960","1280x1024"]
WIDTH, HEIGHT = 400,400
MIN_TILES = 10
MAX_TILES = 50
TX = 40
@horstjens
horstjens / paint.py
Last active Jun 21, 2022
pysimplegui paint
View paint.py
import PySimpleGUI as sg
import random
import time
#from matplotlib.colors import hex2color
RESOLUTIONS = ["100x100", "200x200", "320x200", "400x400", "600x600", "640x400","800x600","1024x800", "1024x960","1280x1024"]
WIDTH, HEIGHT = 400,400
MIN_TILES = 10
MAX_TILES = 50
TX = 40
View draft3.py
import PySimpleGUI as sg
import random
import time
RESOLUTIONS = ["100x100", "200x200", "320x200", "400x400", "600x600", "640x400","800x600","1024x800", "1024x960","1280x1024"]
WIDTH, HEIGHT = 400,400
MIN_TILES = 10
MAX_TILES = 50
TX = 40
TY = 40