Skip to main content

Welcome to Serenity Valley Game

Serenity Valley Game is a demonstration project built with pygame that showcases a collection of custom UI widgets, interactive elements, and utility classes for building 2D games in Python.

Get Started

Set up and run the game in minutes

Explore Widgets

Discover interactive UI components

Learn Utilities

Master 2D vector math and timers

API Reference

Complete API documentation

Key Features

Custom UI Widgets

Pre-built components including Box, MessageBoard, Button, Images, and text entry fields

2D Vector Mathematics

Comprehensive vec2d class with operations, rotations, and geometric utilities

Interactive Elements

Toggle buttons, text entry, and mouse click event handling

Animation System

SimpleAnimation class for sprite-based animations with timers

Moving Objects

Animated rectangles and images with collision detection

Grid-Based Layout

Coordinate conversion system for grid-based game fields

What You’ll Learn

This project demonstrates fundamental pygame concepts:
  • Setting up a game loop with frame limiting
  • Creating reusable UI widget classes
  • Handling user input (keyboard and mouse)
  • Managing game state with pause/resume functionality
  • Drawing and updating sprites and shapes
  • Using timer utilities for periodic callbacks
This project is based on examples from Eli Thegreenplace’s pygame tutorial series.

Quick Example

Here’s a simple example of creating a button widget:
game.py
from widgets import Button
from vec2d import vec2d

# Create a toggle button
toggle_button = Button(
    screen,
    pos=vec2d(250, 250),
    btntype='Toggle',
    imgnames=['images/toggle1.png', 'images/toggle2.png'],
    text="Toggle",
    textcolor=(255, 255, 255)
)

# Draw the button in your game loop
toggle_button.draw()

# Handle mouse clicks
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
    toggle_button.mouse_click_event(event.pos)

Next Steps

Quickstart Guide

Install pygame and run the game

Architecture Overview

Understand the project structure

Build docs developers (and LLMs) love