Game Development Fundamentals: Pygame, Unity, and Graphics
1. Basic Pygame Functions
Pygame is a Python library used to create games.
Common Functions
- pygame.init(): Initializes all Pygame modules
- pygame.display.set_mode((width, height)): Creates the game window
- pygame.display.set_caption(“Title”): Sets window title
- screen.fill(color): Fills screen with a color
- pygame.display.update(): Updates the screen
- pygame.time.Clock(): Controls game speed (FPS)
2. Events (Keyboard & Mouse)
Pygame detects user actions using an event loop.
Key Concepts Summary
- Game Loop: Runs continuously
- Events: Handle input (keyboard/mouse)
- Coordinates: Control object position
- Frame Rate (FPS): Smooth movement
Mouse Events
- pygame.MOUSEBUTTONDOWN: Mouse click
- pygame.MOUSEBUTTONUP: Mouse release
- pygame.MOUSEMOTION: Mouse movement
3. DirectX Fundamentals
DirectX is a collection of APIs by Microsoft used for handling graphics, sound, and input in games. Direct3D is the main part used for 3D graphics rendering.
Device & Context
- Device: Represents the GPU (graphics hardware). Used to create resources like buffers, textures, and shaders. Think: Device = Resource creator.
- Device Context: Used to control rendering operations. Sends commands to GPU (draw calls, set shaders, bind resources). Think: Context = Command executor.
Swap Chain & Page Flipping
A swap chain manages multiple buffers used for displaying images.
- Front Buffer: Currently displayed
- Back Buffer: Where rendering happens
Page Flipping Process
- Render scene to back buffer
- Call Present()
- Back buffer becomes front buffer
- Old front buffer becomes back buffer
This avoids flickering and provides smooth animation.
4. Unity Game Engine
Unity is a popular game engine used to develop 2D, 3D, AR, and VR games.
GameObjects & Components
- GameObject: The basic object in Unity (e.g., Player, Camera, Light). It does nothing by itself.
- Components: Add functionality to GameObjects.
Common Components
- Transform: Position, rotation, scale
- Renderer: Shows object
- Collider: Detects collision
- Rigidbody: Physics
GameObject = container, Components = behavior.
Collision Events
Collision events occur when two objects with colliders interact:
- OnCollisionEnter(): When collision starts
- OnCollisionStay(): While colliding
- OnCollisionExit(): When collision ends
5. Game Engine Overview
A game engine is a software framework used to design and develop video games, providing tools to build games without creating everything from scratch.
Key Functions
- Graphics Rendering: Displays 2D/3D visuals
- Physics Engine: Handles motion, gravity, collisions
- Input Handling: Keyboard, mouse, controller support
- Sound System: Music and sound effects
- Scripting: Controls game logic and behavior
Examples
- Unity: Popular for 2D/3D games
- Unreal Engine: High-quality graphics
- Godot: Free and open-source
6. Homogeneous Coordinate System
A mathematical representation used in computer graphics to handle transformations like translation, rotation, and scaling easily.
Basic Idea
- 2D: (x, y) becomes (x, y, w)
- 3D: (x, y, z) becomes (x, y, z, w)
Conversion to Normal Coordinates
- x = X / w
- y = Y / w
- z = Z / w
7. Types of Vectors
A vector is a quantity that has both magnitude (size) and direction.
- Zero Vector: Zero magnitude, undefined direction.
- Unit Vector: Magnitude 1, represents direction only.
- Position Vector: Position of a point from origin.
- Equal Vectors: Same magnitude and direction.
- Negative Vector: Same magnitude, opposite direction.
- Parallel Vectors: Same or opposite direction.
- Collinear Vectors: Lying on the same line.
- Co-initial Vectors: Same starting point.
8. Game Logic
Game logic refers to the set of rules and instructions that control how a game works and behaves.
Key Elements
- Rules: Win/lose conditions
- Player Actions: Movement, jumping, shooting
- Game State: Score, level, health
- AI Behavior: Controls NPCs
- Collision Handling: Object interaction
