Stephen Gruppetta Profile picture
Apr 25, 2022 12 tweets 6 min read Read on X
The anatomy of a 2D Python game as seen through pictures and videos…

Let's have a look at the steps needed to create this game: thepythoncodingbook.com/2022/04/24/pyt…

👇🪡🧵

#python #100daysofcode #coding #2DGame

1 of 12
1. Create the window and game background

2 of 12
2. Create the lunar module

3 of 12
3. Set the lunar module to start rotating when you press a key…

…but once it starts, it keeps spinning faster and faster and faster…

4 of 12
4. Add option to stop accelerating the rotation when key is released

5 of 12
5. Add some artistic flare—show the fuel burning from the thrusters when they're turned on.

6 of 12
6. Lunar module needs to translate as well as rotate…

7 of 12
7. The thrusters are not just for rotation. When both are on, the lunar module moves forward…

8 of 12
8. And then, there's gravity to pull the lunar module downwards, towards the lunar surface.

9 of 12
9. Finally, there's a landing pad for the lunar module to land on…

…as long as the position and orientation is within landing tolerances!

10 of 12
Read the step-by-step tutorial on The Python Coding Book blog: thepythoncodingbook.com/2022/04/24/pyt…

11 of 12
I hope you liked this anatomy of a 2D game thread…

Follow me @s_gruppetta_ct for more.

Like/Retweet the first tweet below if you can:

#python #coding

12 of 12

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Stephen Gruppetta

Stephen Gruppetta Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @s_gruppetta_ct

Jun 10
What's the `bytes` data structure? Why do I need it? And what's UTF-8?

Sounds boring… but recently, I came across this topic in my meanderings and found it fascinating

This subject is a bit more computer-science-y
But don't worry, I'll take good care of you

/1
First, let's look at a built-in type you may not have heard of: `bytes`

We'll get to the general meaning of "byte" in computing in a second

But first, let's focus on the data type called `bytes`.

And the best way to explain bytes is to compare it with a string.

/2
Let's create a string and a bytes object

The bytes literal looks very similar to the string one. You add b in front of the quotes

/3 Image
Read 40 tweets
Apr 5, 2023
Object-Oriented Python at the Hogwarts School of Codecraft and Algorithmancy
---
Year 5:
Inheritance
---

The students are growing up! This Year they'll learn about a key property of OOP - how to create a class that inherits from another one

Here's the code so far

/1 Image
We've got four classes:
• Wizard
• House
• Wand
• Spell

Each one has its own attributes — these are data attributes and methods

The classes represent "things" as seen from a human's perspective. Each class contains all the data attributes and methods needed by an object

/2
Now, at Hogwarts School of Codecraft & Algorithmancy there are students & professors

They have different things, such as "subject taught" or "mark exam" for professors and "subjects studied" or "take exam" for students

However, all professors & students are wizards

/3
Read 33 tweets
Apr 3, 2023
Object-Oriented Python at the Hogwarts School of Codecraft and Algorithmancy
---
Year 4:
More interaction between classes
---

Year 3 was a busy year. Here's were we left in Year 3

/1 See year 3 thread for code in ALT text
In earlier Years, we discussed how we should think of the problem from the point of view of the "objects" that make sense to a human describing the problem

In our example so far, we have:
• Wizard
• House
• Wand

An object that belongs to these classes has _attributes_

/2
You've already come across the two types of attributes an object can have

• Data attributes are variables that are connected to the instance of the class. They are also called instance variables

• Methods are functions connected to the instance of the class

/3
Read 20 tweets
Apr 1, 2023
Slightly off-topic from my usual on this account—but a lot of my work is also linked to children's education (coding primarily, but let's think beyond subjects)

I've taken a stab at what "homework" in the near-future could look like, using a GPT-first, cheat-proof approach…

/1 1. Write an outline of your...
It solves reasonably well the problem of "cheating" by incorporating GPT into the process and requiring the whole conversation to be submitted, including first drafts, suggestions by GPT, second drafts, and so on

Teachers can craft the right prompts that all students use

/2
But main point is not that it's cheat-proof but that it leverages the opportunities LLMs provide to improve learning

I collated some ideas & examples of how learning (children, but also adult-learning) could change soon

Consider as work-in-progress

codetoday.co.uk/post/learning-…

/3
Read 4 tweets
Mar 5, 2023
What Python data type would [a multi-storey car park] be?
–––
You drive into a multi-storey car park, find a spot to park, and then you ask yourself: "what data structure would best represent this car park", of course

Let's explore

1/ Model of a multi-storey car...
Let's name the object `car_park` and it contains several levels. I'll also look at `level` which represents one the levels. This will be a different data type

The car park has a fixed number of levels which don't change. Therefore, `car_park` is immutable

2/
You can count the levels – `len(car_park)` exists
You can determine whether `level` is in `car_park`, so `car_park` is a container
You can go through the levels one after the other, so `car_park` is iterable

These three properties make `car_park` a collection, too

3/
Read 15 tweets
Mar 4, 2023
These thought experiments help us focus on real decisions we need to make when choosing what data types to use in programs

It's not just about the data itself but how you're likely to use it

For example, in this restaurant tables scenario, I opted for dictionaries, but…

/1
It depends whether we want to prioritise the use case when the tables are being used during normal service, with diners sitting on them and waiters taking their orders and bringing them food [dictionary is a good choice]…

/2
…or if you want to prioritise the setting up process before the restaurant opens its doors when staff go from one table to the next to clean it and set it up. For this, you could be tempted to use a sequence instead, such as a tuple or list

/3
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(