**Game Basics**
Vocabulary ==== 1. Game Engine * Software like Unity or UE that helps you build a game 2. Asset * Something created by an artist for the game (character, texture, audio file, ...) 3. Project / Game file * Everything the engine needs for the game 4. Scene / Level 1. Distinct part of game 2. Originally everything for one level, but main menu, player selection, etc. may be created as levels. 5. Game Object / Entity * Things you can place in a scene: characters, objects, sound sources, triggers, etc. 6. Collision box 1. Simple shape around a game object, can trigger an action when these overlap 2. Used for physics, but also triggers, regions, power-ups, etc. 7. Editor 1. Part of engine that allows placing game objects in a scene. 2. Unity and UE have editors, but some game engines do not! Buiding a Prototype ==== 1. Small!!! 2. Focus on critical exploration 1. New gameplay? 2. Artistic style? 3. Unique tech? 3. Leave everything else unfinished 4. Some rapid prototyping strategies 1. Physical (cards, dice, ...) 2. 2D prototype for 3D game 3. Mod existing Game organization ==== 1. Game or level state & code 1. Overall state of the game 2. Sometimes split into multiple (invisible) *manager* objects 2. Game object state & code 1. Each game object keeps track of its own position/velocity/health/ammo/etc. 2. Code to run when created, game start, spawn 3. Code to run each *tick* or *update* (game updates decoupled from frame updates) 4. Code to run on collision 3. Collision volumes 1. Originally for physics, but so much more useful 2. Bounding box, sphere, capsule, other shape 3. Trigger action when bounding shapes overlap 4. Zones, portals, ... 4. Events & Delegates https://gamedevbeginner.com/events-and-delegates-in-unity/ 1. Bits of code to run when something happens 2. Direct single call: Change functions when game state changes 3. Multicast: Inform other entities (often "On...") * OnCollision, OnPlayerDeath, Timed Platformer Microgame ==== 1. Unity version 2021.3 (not newer) 1. New Project 2. All Templates 3. 2D Platformer Microgame 4. Download template 5. Create Project 2. Can then update to newer 1. In Hub: change editor version 2. Launch 3. Allow to convert 4. Save 3. Sprites 1. Look in Character > Sprites, e.g. PlayerRun 2. Click "Open" to open sprite image file 3. Open in Sprite Editor 4. Character > Animations * Player and Enemy transition graphs 5. Environment > Tiles / Sprites 4. Prefabs 1. Blue in scene 2. Especially Enemy, anything changed affects all enemies 5. Tilemap editor 1. Look at Grid & sub-objects 2. Select Foreground, Level, Background, Far Background & turn on and off 3. Note that only Level has a Tilemap Collider component 4. Window > Package Manager; Packages: Unity Registry; 2D or search for Tilemap 5. Window > 2D > Tile Palette 6. Select level 7. Choose brush; pick a tile/tiles in tilemap; paint in level 6. Scripts 1. Timed events 1. Scripts/Core/Simulation.Event.cs 1. Class with tick (when to run) and Execute() 2. Example: Scripts/Gameplay/EnemyDeath.cs 1. Adds EnemyController 2. On Execute, disables some stuff, plays a sound 2. Scripts/Core/Simulation.cs 1. Scripts/Core/HeapQueue.cs = generic heap 2. Schedule sets a time as now+delay, adds to heap 3. Tick 1. If top event should already have happened, execute it 2. Loop until no events or only future events left 2. GameController 1. Ticks Simulation object 2. Has a PlatformerObject (Camera, Player, Spawn Point, control params) 3. Token Controller 1. Find all tokens (on Awake, not every frame!) 2. Tick token animation 4. MetaGameController 1. UI Canvas for menus (manually enable to show) 2. Handles showing & hiding menu screens 5. Audio source (background audio) 3. Main Camera * Uses Cinemachine: camera is CM vcam1, set to follow Player 4. Player Controller 1. Control & state for player (notice public vs. private) 2. Expensive GetComponent on awake & save 3. Update 1. Button down: check if OK and prepare to jump (look at UpdateJumpState) 2. Look at ComputeVelocity (override from parent) 3. Button up (in Update): *schedule* PlayerStopJump now (boring, but can extend) 4. Death Zone (Scripts > Mechanics > DeathZone.cs) 1. Select zone & click "Edit Collider" to look at death zones 2. When something enters 1. See if it has a PlayerController (= see if it's the player) 2. Schedule immediate PlayerEnteredDeathZone 3. PlayerEnteredDeathZone schedules immediate PlayerDeath 4. PlayerDeath turns off camera, control, plays sound, plays anim, schedules PlayerSpawn in 2 seconds 5. PlayerSpawn teleports to spawn point, resets camera, health, etc., schedules EnablePlayerInput in 2 more seconds 6. EnablePlayerInput turns input back on 5. EnemyController 1. Collision, check for player, schedule immediate PlayerEnemyCollision * PlayerEnemyCollision checks who is higher, damage or death to enemy or player 2. Update: move on path 1. Patrol path has start and end points 2. PatrolPath.Mover gives position bouncing back and forth between start & end 3. Enemy just uses x position of Mover 3. Custom patrol path editor Editor > PatrolPathEditor.cs 1. Be sure to enable Gizmos to view & edit 2. Gets start & end position, zero's out (relative) y 3. Draws as two yellow discs with dotted line in between 6. Tokens: pretty similar to enemies (but w/o mover) Building a game ==== 1. Planning 1. Plan for characters 1. Assets needed 2. Behavior needed 2. Plan for level 1. Assets needed 2. Design 3. Any game state 4. Any environmental behavior 3. Use existing or build your own 1. Engine 2. Template or prior game 3. Tools 2. Start work in parallel 1. Rough out level (grey box / programmer art) 2. Character & environmental stills 3. Character & environmental animation 4. Constant communication and exchange