Search Header Logo
Lesson 9 : Game Design Python 101

Lesson 9 : Game Design Python 101

Assessment

Presentation

Computers

9th Grade

Practice Problem

Easy

Created by

Maria Cruz Farooqi

Used 3+ times

FREE Resource

16 Slides • 22 Questions

1

Learning Target:​
I can create a sprite to represent the player, apply coding concepts to clone, loop through a list, and more, in order to program a basic game with just a couple of sprites, one of which is controlled by keyboard input.

media
media

2

media
media
media

3

media

4

Dropdown

What Is a Sprite?

Most games have ​
that perform actions on the screen.

We call these characters sprites. Sprites can move around the screen and ​
. A sprite might include the player character, coins for the player to collect, and ​
for the player to avoid. Or they can be decorations, like the ​
of the game.Let's look at how we can create and clone sprites with the Turtle module.

5

Dropdown

Question image

Creating a Sprite with Turtle

When working with Python's Turtle module, you can use a ​
. In your Asteroids game, for example, the ship and the rocks were all sprites represented ​
So you can just ​
using ​
as we've done before.

6

Dropdown

Question image

Setting a Sprite's Initial Values

You can set the sprite's ​
so that it looks and behaves exactly as you want.

Often you'll want to use the ​
commands so that the sprite doesn't leave a trail and moves as fast as possible, ​

7

Dropdown

Question image

Clone the Prototype

Once you've created one sprite and set its initial values in a way that you like, you can ​
of the sprite by ​
In this way, your original sprite acts like ​


Any clones of the original will​
In the example we create a prototype called sprite, then make two clones of it called actor1 and actor2 using the ​
method.

8

media
media
media
media
media

9

I copied the code on the lesson sheet. Then modified it to clone turtles.
Then I assigned two different colors. Success! "Check Code" says I was successful.

Teacher's Answer:

media
media

10

Multiple Choice

What is a sprite?

1

A sprite is a graphical representation of an object

2

A sprite is a function

3

A sprite is a game

4

A sprite is a string

11

media

12

Dropdown

Question image

What Are Game Loops?

Most games consist of a ​
that are repeated constantly as the game is played.

These steps often include tasks like:

Setting and updating ​
(their location, whether to show or hide each sprite, and so forth)

Checking on important ​
(such as whether the game has been won or lost)

This is called a game loop. Let's see how ​
.

13

Dropdown

A Function That Calls Itself: Game Loop Basics

We can implement a game loop using ​ a ​
. You'll use an update function that sets a timer that calls itself ​
This creates a cycle in which the update( ) function is called ​
, on a regular interval. This process of a function calling itself is a concept called ​
This is the big idea behind the game loop.

You'll need to call the ​
function for the first time to kick off the cycle.

14

Dropdown

Question image
This example shows the code to set up a game loop that updates​
. Click Run to see the output. The background may appear to ​
, but the loop is setting the ​
every second.

15

Dropdown

Question image

Another Game Loop

This example is similar to the previous one, except the ​
now switches the background to a random color ​
.

Press​
and see the background switch color.

16

media

Define an update( ) function and call it to kickstart the loop.


Perform actions with the sprite in the game loop to do something interesting. Need ideas? You might change the pen's color, clone a sprite, or change the shape of a sprite.

Do It Yourself

This code has a sprite, but not much else. Try to write a game loop of your own.

17

Teacher's
Answer:

media
media

18

Multiple Choice

Question image

What is the interval of this game loop?

1

Every 10 seconds

2

Every 1000 seconds

3

Every 1 second

4

It does not loop

19

media

20

More on Lists

To make more advanced games, you'll need to learn more about lists.

media
media
media

21

Dropdown

Question image

Looping

The ​
provides an effective way to loop through every entry ​
in Python. You can provide a list to a "for" loop ​
. Each time the "for" loop runs, the counter variable will be set ​

22

Drag and Drop

Question image

Append

To add more ​
to the list, you can use the ​
method. Check it out:
Drag these tiles and drop them in the correct blank above
items
list.append( )

23

Drag and Drop

Question image

Insert

Another important method is ​
. It lets you insert an entry at any ​
in a list. Any entries at that location or after it will be pushed up one index.
Drag these tiles and drop them in the correct blank above
insert( )
index

24

Drag and Drop

Question image

Pop

Pop( ) ​
at any index on the list. It returns the value at the entry​
.
Drag these tiles and drop them in the correct blank above
removes an entry
it removes

25

Drag and Drop

Question image

In

in is another ​
when you're using lists. It checks if an element is ​
and returns True or ​
.
Drag these tiles and drop them in the correct blank above
useful tool
currently in a list
False

26

media

Let's try out all these new tools in an application. You will be given a randomly generated unsorted list.

Can you use all the list methods you just learned to sort a list of numbers from least to greatest?

Coding Challenge: Sort a List

27

media

Here are the steps:

  • You must loop through each index of the list. For each index:

    • Loop through all earlier indices.

    • If the value at an earlier index is greater than the value at the current index:

      • Pop the value at the current index

      • Insert the popped value into the earlier index

      • Stop looking though the earlier indexes

28

media

Teacher's
Answer

media

29

Multiple Choice

Question image

Select correct answer:

1
2
3
4

30

Multiple Choice

Question image

Select correct answer:

1
2
3
4

31

Multiple Choice

Question image

Select correct answer:

1
2
3
4

32

media

33

Dropdown

Question image

More on Dictionaries

To make more advanced games, you'll also need to know some ​
for manipulating dictionaries.

Keys, Values, Items

The dictionary is a ​
that consists of key-value pairs. You can examine each component of a dictionary separately or as ​
:

34

Dropdown

Question image
The data returned by the values( ), keys( ), and items( ) commands cannot be edited. To change the data in a dictionary, you'll need some different commands.

Looping

You can ​
through a dictionary in ​
ways.

35

media

36

media

​Teacher's
Answer

37

Multiple Choice

Question image

Select correct answer:

1

apple

2

banana

3

cherry

4

Dictionaries require a number as a key

38

Multiple Choice

Question image

Select correct answer:

1
2
3
4

Learning Target:​
I can create a sprite to represent the player, apply coding concepts to clone, loop through a list, and more, in order to program a basic game with just a couple of sprites, one of which is controlled by keyboard input.

media
media

Show answer

Auto Play

Slide 1 / 38

SLIDE