
Learn to build an alien farm game from scratch in C++ with SDL2, implementing a tiling system, planting and animal life with shadows, water effects, and dynamic placement checks.
Install Visual Studio community edition with the C++ compiler and SDL2, set up a 64-bit project, and import the course code to build your alien farm game.
Set up the basic engine with SDL2 by creating a window and renderer. Load textures, process input, and run a game loop with delta time.
Learners implement a purple checkered grid in a C++ SDL2 game by building a level class with x and y tile counts, and a draw routine uses x+y mod 2.
Add more colors to the tile system by introducing a type structure and a static list, replacing the switch-case with a data-driven color lookup in the draw function.
Develop automatic tile shadows in a top-down 2D alien farm game by comparing surrounding tile heights (water, dirt, purple grass) to render edge and corner shadows using SDL2 textures.
Implement a wet-dry mechanic by updating dirt tiles within a set distance when water tiles are added or removed, using a refresh surrounding function and tile names to drive rendering.
Add and manage plants of types and sizes with shadows, starting small and growing; enable add/remove with mouse and keyboard, and ensure placement on correct tiles via a tile check.
Animate alien farm plants by modulating their draw scale with a cosine-based timer for gentle up-and-down motion. Update the timer every frame to keep the movement lively.
Use a timer growth to control plant size, updated by Countup, with smaller textures during growth and full-size images when it ends, varying growth time from 7.5 to 15 seconds.
Enhance the alien farm by introducing multiple plant types with a type id system, dynamic textures, and variable sizes (two-by-two tiles), and implement overlap checks for placement and removal.
Implement tile-under checks to ensure orange and purple plants require wet dirt, green plants and trees require grass, water is forbidden, and remove any plants when tiles change.
Add and remove animals of various types and sizes with shadows; start small, grow, and move to avoid overlapping plants, animals, and water, using mouse and keyboard.
Model animals as circles and detect overlaps with water and level tiles using point and line-segment checks; add a position ok check and circle-tile overlap logic to ensure safe movement.
Add and manage varied animals that grow, move to random points or rotate, avoid overlaps with plants, animals, and water tiles, and get removed when tiles change.
Overview
You’ll be able to place dirt, water which makes surrounding dirt wet, and different colored grass. Add and remove plants of different types and sizes that have shadows, move up and down, start small and grow, and can only exist on the correct types of tiles. Add and remove animals of different types and sizes that have shadows, start small and grow, move around, and avoid overlapping plants, other animals, and certain tiles like water.
Tiling System
Start by adding a simple purple checkered grid to get the basics setup.
Then it will be improved by adding a tiling system that allows placement of different colored tiles.
Next an algorithm that automatically generates shadows, to give a sense of depth, will be added to the game.
Finally when water tiles are added or removed, the surrounding dirt tiles become wet or dry depending on how far away they are from water.
Plants
Start by setting up simple plants that can be added and removed with the mouse and keyboard.
Then they will be improved so that they look like they’re moving up and down, and start small then grow to their full size.
Next more plants/trees of different sizes will get added to the game, and their shadows improved to be lighter and remove overlap with other images.
Finally an algorithm will be added that checks tile types underneath them. That way they can only get placed on the correct ones, and if tiles are changed to types that they shouldn’t exist on, they get removed.
Animals
Start by setting up simple animals that can be added with the mouse and keyboard, that start small then grow to their full size.
Then they will be improved so that sometimes they either pick random points to move to, or random angles to rotate to.
Next their movement will be improved further so that they avoid overlapping other animals, plants, and tile types that they shouldn’t exist on, for example water.
Finally more overlap checks will be added so that animals can no longer be placed on plants, other animals, or the wrong types of tiles. Also an overlap check so that plants can’t be placed on animals. In addition code will be added so that animals can be remove with the mouse, or if the tiles under them are changed to types they shouldn’t exist on.