blueprint

package module
v0.0.2-early-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2025 License: MIT Imports: 6 Imported by: 17

README

Blueprint

Blueprint is a foundation package for the Bappa Framework, providing common components, interfaces, and utilities for game development.

Overview

Blueprint serves as the base layer of the Bappa Framework, defining standard component types and interfaces that other packages in the framework build upon. It establishes shared patterns and data structures used throughout the ecosystem.

Features

  • Core Interfaces: Defines essential interfaces like Scene and CoreSystem
  • Common Components: Provides standardized component definitions across multiple domains
  • Vector Mathematics: Complete 2D vector implementation with comprehensive operations
  • Predefined Queries: Ready-to-use queries for common component combinations
  • Background Utilities: Tools for creating static and parallax backgrounds
  • Shape Factory: Various shape creation functions for collision geometry

Installation

go get github.com/TheBitDrifter/blueprint

Component Subpackages

Blueprint organizes components by domain:

  • blueprint/client: Visual and audio components

    • SpriteBundle: Sprites with animation support
    • SoundBundle: Audio resources
    • ParallaxBackground: Multi-layered scrolling backgrounds
  • blueprint/input: User interaction components

    • InputBuffer: Collection and management of user inputs
    • StampedInput: Inputs with timing and position information
  • blueprint/motion: Physics components

    • Dynamics: Physical properties for movement and forces
  • blueprint/spatial: Positioning and geometry components

    • Position, Rotation, Scale: Basic spatial properties
    • Shape: Collision geometry with various factory methods
    • Direction: Directional orientation
  • blueprint/vector: 2D vector mathematics

    • Two: Vector with extensive operations (add, subtract, rotate, etc.)
    • Vector interfaces for flexible implementation

Quick Start

Using Predefined Queries
// Create a cursor for entities with position components
cursor := scene.NewCursor(blueprint.Queries.Position)

// Process matching entities
for range cursor.Next() {
    pos := blueprintspatial.Components.Position.GetFromCursor(cursor)
    // Process entity...
}
Creating Backgrounds
// Create a parallax background with multiple layers
builder := blueprint.NewParallaxBackgroundBuilder(storage)
builder.AddLayer("backgrounds/mountains.png", 0.2, 0.0) // Slow-moving background
builder.AddLayer("backgrounds/clouds.png", 0.5, 0.1)    // Mid-speed layer
builder.WithOffset(vector.Two{X: 0, Y: 20})             // Optional offset
builder.Build()

// Create a static background
blueprint.CreateStillBackground(storage, "backgrounds/scene.png")
Creating and Using Shapes
// Create a rectangle
rect := blueprintspatial.NewRectangle(50, 30)

// Create a ramp
ramp := blueprintspatial.NewSingleRamp(100, 40, true) // ascending left-to-right

// Create a platform
platform := blueprintspatial.NewTrapezoidPlatform(80, 20, 0.7) // 0.7 = bottom width ratio

License

MIT License - see the LICENSE file for details.

Documentation

Overview

Package blueprint provides common components and interfaces for the Bappa Framework, a game development system based on an entity-component-system (ECS) architecture.

Blueprint serves as the foundation layer of the Bappa Framework, defining standard component types and interfaces that other packages in the framework build upon. It establishes common patterns and data structures used throughout the ecosystem.

Core Concepts

Blueprint defines these key elements:

  • Scene: A minimal interface for accessing entities and systems
  • CoreSystem: Interface for systems that operate on scenes
  • Common component types across various domains
  • Predefined queries for frequently used component combinations

Subpackages

Blueprint organizes components by domain into several subpackages:

  • blueprint/client: Visual and audio components (sprites, animations, sounds)
  • blueprint/input: User interaction components (input buffers)
  • blueprint/motion: Physical movement components (dynamics)
  • blueprint/spatial: Positioning and geometry components (position, rotation, shapes)
  • blueprint/vector: 2D vector mathematics utilities

Working with Queries

The package provides predefined queries for common component combinations:

// Access entities with position components
cursor := scene.NewCursor(blueprint.Queries.Position)

// Access entities with dynamics components
cursor = scene.NewCursor(blueprint.Queries.Dynamics)

// Access entities with sprite components
cursor = scene.NewCursor(blueprint.Queries.SpriteBundle)

Background Utilities

The package includes functions for creating backgrounds and parallax effects:

// Create a parallax background with multiple layers
builder := blueprint.NewParallaxBackgroundBuilder(storage)
builder.AddLayer("backgrounds/mountains.png", 0.2, 0.0)
builder.AddLayer("backgrounds/clouds.png", 0.5, 0.1)
builder.Build()

// Create a static background
blueprint.CreateStillBackground(storage, "backgrounds/scene.png")

Index

Constants

This section is empty.

Variables

View Source
var Queries defaultQueries = defaultQueries{}

Functions

func CreateStillBackground

func CreateStillBackground(sto warehouse.Storage, spritePath string, pos ...vector.Two) error

CreateStillBackground is a utility function for creating a non-parallax (static) background Optional position parameters can be provided to offset the background

Types

type CoreSystem

type CoreSystem interface {
	Run(scene Scene, deltaTime float64) error
}

type ParallaxBackgroundBuilder

type ParallaxBackgroundBuilder struct {
	// contains filtered or unexported fields
}

ParallaxBackgroundBuilder provides a fluent API for creating parallax backgrounds

func NewParallaxBackgroundBuilder

func NewParallaxBackgroundBuilder(sto warehouse.Storage) *ParallaxBackgroundBuilder

NewParallaxBackgroundBuilder creates a new builder for parallax backgrounds

func (*ParallaxBackgroundBuilder) AddLayer

func (b *ParallaxBackgroundBuilder) AddLayer(spritePath string, speedX, speedY float64) *ParallaxBackgroundBuilder

AddLayer adds a new layer to the parallax background

func (*ParallaxBackgroundBuilder) Build

func (b *ParallaxBackgroundBuilder) Build() error

Build generates all layers and creates the parallax background

func (*ParallaxBackgroundBuilder) WithDisableLooping

func (b *ParallaxBackgroundBuilder) WithDisableLooping(disable bool) *ParallaxBackgroundBuilder

WithDisableLooping sets whether background looping should be disabled

func (*ParallaxBackgroundBuilder) WithOffset

WithOffset sets an optional position offset for the entire background

type ParallaxLayer

type ParallaxLayer struct {
	// SpritePath is the path to the sprite resource
	SpritePath string
	// SpeedX is the horizontal parallax speed multiplier
	SpeedX float64
	// SpeedY is the vertical parallax speed multiplier
	SpeedY float64
}

ParallaxLayer defines a single layer in a parallax background

type Plan

type Plan = func(height, width int, storage warehouse.Storage) error

type Scene

type Scene interface {
	NewCursor(warehouse.QueryNode) *warehouse.Cursor
	Height() int
	Width() int
	CurrentTick() int

	Storage() warehouse.Storage
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL