This is an even more minimalist version of my minimalist game framework. It uses Python 3 and pygame.
A few decisions have been made to keep things simple:
Getting started with the ultra-minimalist game framework is easy!
import game
to the top of your script.game
module to create your game.All functions and enums listed below are members of the game
module. If you wanted to draw a line, you would call game.draw_line()
from your code.
If you don't already have pygame installed, you can install it by running pip install pygame
on the command line.
import game
import random
IMG_FACE_NORMAL = 'eJxjiObgZBAFAygFAoxghAcwIkvD9AMA4AgFsQßß'
IMG_FACE_HIT = 'eJxjiObgZBAFAygFAoxghAmYgACThukHAND6BPUß'
game.set_title('Bouncing Faces')
class Face:
def __init__(self):
self.x = random.randint(1, 141)
self.y = random.randint(1, 90)
self.vx = random.uniform(-1, 1)
self.vy = random.uniform(-1, 1)
faces = []
for i in range(0, 20):
faces.append(Face())
while True:
# Move the faces:
for face in faces:
if face.x <= 0 or face.x >= 142:
face.vx *= -1
if face.y <= 0 or face.y >= 91:
face.vy *= -1
face.x += face.vx
face.y += face.vy
# Draw the screen:
game.clear_screen(game.Color.GRAY_DARKER)
for face in faces:
# Draw the face, using an alternate sprite if it's overlapping any other face:
sprite = IMG_FACE_NORMAL
for otherFace in faces:
if face != otherFace and game.test_sprites(IMG_FACE_NORMAL, face.x, face.y, IMG_FACE_NORMAL, otherFace.x, otherFace.y):
sprite = IMG_FACE_HIT
break
game.draw_sprite(sprite, face.x, face.y)
# Draw a box around the face when it's hovered, and beep when it's clicked:
if game.test_sprite(sprite, face.x, face.y, game.get_mouse_x(), game.get_mouse_y()):
game.draw_rect(game.Color.WHITE, face.x - 2, face.y - 2, 12, 13, False)
if game.is_mouse_down(game.Button.LEFT):
game.play_sound(game.Instrument.SQUARE, game.Note.C4, 0.2)
# End of frame:
game.wait_for_frame()
def wait_for_frame
()
def wait_for_seconds
(duration: float)
def wait_for_close
()
def wait_for_input
(prompt: str) -> str
def set_title
(title: str)
def clear_screen
(color: Color)
def draw_pixel
(color: Color, x: int, y: int)
def draw_line
(color: Color, x1: int, y1: int, x2: int, y2: int)
def draw_rect
(color: Color, x: int, y: int, width: int, height: int, fill: bool)
def draw_circle
(color: Color, x: int, y: int, radius: int, fill: bool)
def draw_triangle
(color: Color, x1: int, y1: int, x2: int, y2: int, x3: int, y3: int, fill: bool)
def draw_text
(text: str, color: Color, x: int, y: int, alignment: Alignment) -> tuple[int, int]
def draw_sprite
(sprite: str, x: int, y: int)
def test_rect
(x: int, y: int, width: int, height: int, test_x: int, test_y: int) -> bool
def test_circle
(x: int, y: int, radius: int, test_x: int, test_y: int) -> bool
def test_sprite
(sprite: str, x: int, y: int, test_x: int, test_y: int) -> bool
def test_sprites
(sprite1: str, x1: int, y1: int, sprite2: str, x2: int, y2: int) -> bool
def play_sound
(instrument: Instrument, note: Note, duration: float, delay: float = 0.0, volume: float = 1.0)
duration
and delay
are measured in seconds.volume
is from 0 (silent) to 1 (maximum volume).def is_key_down
(key: Key) -> bool
def is_key_held
(key: Key) -> bool
def is_key_up
(key: Key) -> bool
def get_typed_text
() -> str
def get_mouse_x
() -> int
def get_mouse_y
() -> int
def is_mouse_down
(button: Button) -> bool
def is_mouse_held
(button: Button) -> bool
def is_mouse_up
(button: Button) -> bool
def set_cursor_visible
(visible: bool)
class Color
(Enum)
Color.TRANSPARENT
Color.BLACK
Color.GRAY_DARKER
Color.GRAY_DARK
Color.GRAY
Color.GRAY_LIGHT
Color.GRAY_LIGHTER
Color.WHITE
Color.BLUE_DARK
Color.PURPLE_DARK
Color.PINK_DARK
Color.RED_DARK
Color.ORANGE_DARK
Color.YELLOW_DARK
Color.GREEN_DARK
Color.MINT_DARK
Color.BLUE
Color.PURPLE
Color.PINK
Color.RED
Color.ORANGE
Color.YELLOW
Color.GREEN
Color.MINT
Color.BLUE_LIGHT
Color.PURPLE_LIGHT
Color.PINK_LIGHT
Color.RED_LIGHT
Color.ORANGE_LIGHT
Color.YELLOW_LIGHT
Color.GREEN_LIGHT
Color.MINT_LIGHT
class Alignment
(Enum)
Alignment.LEFT
Alignment.CENTER
Alignment.RIGHT
class Instrument
(Enum)
Instrument.SQUARE
Instrument.PULSE
Instrument.TRIANGLE
Instrument.SAWTOOTH
Instrument.NOISE
class Note
(Enum)
Note.C6
Note.B5
Note.ASHARP5
Note.A5
Note.GSHARP5
Note.G5
Note.FSHARP5
Note.F5
Note.E5
Note.DSHARP5
Note.D5
Note.CSHARP5
Note.C5
Note.B4
Note.ASHARP4
Note.A4
Note.GSHARP4
Note.G4
Note.FSHARP4
Note.F4
Note.E4
Note.DSHARP4
Note.D4
Note.CSHARP4
Note.C4
Note.B3
Note.ASHARP3
Note.A3
Note.GSHARP3
Note.G3
Note.FSHARP3
Note.F3
Note.E3
Note.DSHARP3
Note.D3
Note.CSHARP3
Note.C3
Note.B2
Note.ASHARP2
Note.A2
Note.GSHARP2
Note.G2
Note.FSHARP2
Note.F2
Note.E2
Note.DSHARP2
Note.D2
Note.CSHARP2
Note.C2
Note.B1
Note.ASHARP1
Note.A1
Note.GSHARP1
Note.G1
Note.FSHARP1
Note.F1
Note.E1
Note.DSHARP1
Note.D1
Note.CSHARP1
Note.C1
class Key
(Enum)
Key.BACKSPACE
Key.TAB
Key.CLEAR
Key.RETURN
Key.PAUSE
Key.ESCAPE
Key.SPACE
Key.EXCLAIM
Key.QUOTEDBL
Key.HASH
Key.DOLLAR
Key.AMPERSAND
Key.QUOTE
Key.LEFTPAREN
Key.RIGHTPAREN
Key.ASTERISK
Key.PLUS
Key.COMMA
Key.MINUS
Key.PERIOD
Key.SLASH
Key.NR_0
Key.NR_1
Key.NR_2
Key.NR_3
Key.NR_4
Key.NR_5
Key.NR_6
Key.NR_7
Key.NR_8
Key.NR_9
Key.COLON
Key.SEMICOLON
Key.LESS
Key.EQUALS
Key.GREATER
Key.QUESTION
Key.AT
Key.LEFTBRACKET
Key.BACKSLASH
Key.RIGHTBRACKET
Key.CARET
Key.UNDERSCORE
Key.BACKQUOTE
Key.A
Key.B
Key.C
Key.D
Key.E
Key.F
Key.G
Key.H
Key.I
Key.J
Key.K
Key.L
Key.M
Key.N
Key.O
Key.P
Key.Q
Key.R
Key.S
Key.T
Key.U
Key.V
Key.W
Key.X
Key.Y
Key.Z
Key.DELETE
Key.KP_0
Key.KP_1
Key.KP_2
Key.KP_3
Key.KP_4
Key.KP_5
Key.KP_6
Key.KP_7
Key.KP_8
Key.KP_9
Key.KP_PERIOD
Key.KP_DIVIDE
Key.KP_MULTIPLY
Key.KP_MINUS
Key.KP_PLUS
Key.KP_ENTER
Key.KP_EQUALS
Key.UP
Key.DOWN
Key.RIGHT
Key.LEFT
Key.INSERT
Key.HOME
Key.END
Key.PAGEUP
Key.PAGEDOWN
Key.F1
Key.F2
Key.F3
Key.F4
Key.F5
Key.F6
Key.F7
Key.F8
Key.F9
Key.F10
Key.F11
Key.F12
Key.F13
Key.F14
Key.F15
Key.NUMLOCK
Key.CAPSLOCK
Key.SCROLLOCK
Key.RSHIFT
Key.LSHIFT
Key.RCTRL
Key.LCTRL
Key.RALT
Key.LALT
class Button
(Enum)
Button.LEFT
Button.MIDDLE
Button.RIGHT