Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 23522

Inspired Python: Make your own Tower Defense Game with PyGame

$
0
0

Make your own Tower Defense Game with PyGame

In this course you’ll learn how to write a 2d Tower Defense Game from scratch, using PyGame. Writing a game is easy; but writing one that is maintainable and easy to extend is not. A tower defense game is a perfect place to learn how to write a substantial game that will test your skills as a Python programmer. It is also a perfect template for many other 2d games.

Part of the challenge of writing a game is the many disparate discplines that rear their heads once you move beyond the truly basic. During the course you’ll learn the following skills:

What is a Game Loop?

How do games actually update and display things on the screen in a manner that is maintainable and easy to reason about for the budding game developer?

The Game Loop is a cornerstone of all games, big and small. You’ll learn how to create one, and how it’s used to handle keyboard and mouse input, graphics rendering, updating the physics of entities on the screen, and more.

State Machines and Transitions

Few games have just one screen, and thus one state. Most games have a main menu, a score board, the actual game, and possibly more states that a player interacts with during game play. Understanding how to transition your game’s state between these different concepts is critical to writing a game free of spaghetti code.

You’ll learn about finite-state machines, an important concept in Computer Science, and how it can easily make transform a complex set of confusing requirements into neat and tidy code.

Lazy evaluation, Generators and Iterables

Keeping track of the position of things – and calculating the next position of something, such as a flying bullet – is easily solved with a liberal use of Python’s itertools library and generators.

Master a part of Python that gets short thrift from most developers, as they’re harder to reason about than normal for-loops.

Drawing and manipulating graphics

Learn what a sprite is, how to manipulate it to move, rotate, scale it, and how to do it efficiently and in a manner that is clear and easy to reason about.

Level Editing

You’ll write a complete level editor capable of placing and editing all the entities that make up a tower defense game using a simple UI you will build yourself.

The level editor forms a core part of the game, and includes details on how to write a save and load feature, so you can share your levels with friends.

Path finding and Recursion

Learn about recursion, a powerful programming concept, to find valid paths through a map for the enemies to traverse. You’ll learn about basic graph theory and how Depth-First Search is used to traverse a map and find a route from start to end.

Vector Mathematics

Come to grips with the mathematics required to ensure a bullet travels in a straight line towards a target; that your enemies walk smoothly across the map; and how to do simple text-based animations using simple arithmetic.

You’ll learn about simple vector arithmetic, interpolation, and basic affine transformations (like scaling and rotating).

Object-Oriented Programming (OOP)

Improve your understanding of classes and objects and how to best leverage inheritance, the factory pattern, and Python’s dataclasses to succinctly describe your game world using simple classes.

Animation

Learn how to chain together frames of images into simple animations so the enemies walk across the screen and collapse when they’re struck by exploding projectiles.

Collision Detection

Important stuff: how does the turret know when to fire at an enemy that is in its crosshairs? What about when the bullet strikes an enemy?

Are you ready? Let’s code!



Read More ->

Viewing all articles
Browse latest Browse all 23522

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>