
Transcription
Lecture4:GD50SuperMarioColton [email protected] J. [email protected].
Topics Tile Maps2D AnimationProcedural Level GenerationPlatformer PhysicsBasic AIPowerups
Butfirst,ademo!
OurGoal
Tilemaps Level is comprised of many small tiles that give theappearance of some larger whole.Tiles often have an ID of some kind to differentiate theirappearance or behavior.
tiles0“StaticTiles”
tiles1“ScrollingTiles”
tiles1,ImportantFunctions love.graphics.translate(x, y) Shifts the coordinate system by x, y; useful for simulatingcamera behavior.
character0“TheStationaryHero”
character1“TheMovingHero”
character2“TheTrackedHero”
character3“TheAnimatedHero”
Animations Animations can be achieved by simply displaying a series offrames from a sprite sheet one after the other, akin to a flipbook.
character4“TheJumpingHero”
Procedural LevelGenerationPlatformer levels can be procedurally generated like anythingelseThese levels can be easily generated per column rather thanper row, given things like gaps, though there are multipleways to do itMost easily, tiles can foundationally be generated and act asthe condition upon which GameObjects and Entities aregenerated
level0“FlatLevels”
level1“PillaredLevels”
level2“ChasmedLevels”
Tile CollisionAABB can be useful for detecting entities, but we can takeadvantage of our static coordinate system and 2D tile arrayand just calculate whether the pixels in the direction we’retraveling are solid, saving us computing time.See TileMap:pointToTile(x, y) !Can just directly check tiles on the map once coordinates areconverted by dividing them by TILE SIZENotably better than having to iterate over all tiles to checkAABB in terms of performance, with some inflexibilities (tilescan’t move around, for example)
TileCollision(up)Tested only when in the PlayerJumpingState !
TileCollision(down)Tested only when in the PlayerFallingState !
Tile Collision(left/right)Tested in PlayerJumpingState , PlayerFallingState , and PlayerMovingState !
Entities Can contain states just like the game, with their ownStateMachine; states can affect input handling (for theplayer) or decision-making (like the Snail)Some engines may adopt an Entity-Component System (or ECS),where everything is an Entity and Entities are simplycontainers of Components, and Components ultimately drivebehavior (Unity revolves around an ECS)Collision can just be done entity-to-entity using AABBcollision detectionRepresent the living things in our distro (Snail and Player),but could represent most anything; arbitrary
Game ObjectsSeparate from the tiles in our map, for things that maybedon’t align perfectly with it (maybe they have differentwidths/heights or their positions are offset by a differentamount than TILE SIZE)Can be tested for collision by AABBOften just containers of traits and functionsCould be represented via Entities, but aren’t in this distro
Powerups Effectively a GameObject that changes some “status” or traitof the playerAn invincible star may flip an “invincible” flag on the playerand begin an “invincibleDuration” timerA mushroom to grow the player may trigger a “huge” flag on theplayer that alters their x, y, width, and height and thenscales their sprite
Assignment4 Ensure the player always starts above solid land. Create random keys and locks (same color) that spawn ineach level; when the player gets the key, they can unlockthe lock, which should spawn the goal flag. When the player touches the goal flag (which should beplaced in the level toward the right end), they shouldproceed to the next level, which should get longer thanthe one before it horizontally.
Next Time.Top-Down d n
Seeyounexttime!
Lecture 4: Super Mario Bros. Colton Ogden [email protected] David J. Malan [email protected] Tile Maps 2D Animation Procedural Level Generation Platformer Physics Basic AI Power