Posts for: #Python

Converting a Game Written in Basic to Python - Part III

In this third part, we have the following objectives:

  • Clean up the classes
  • Multiple planes
  • Multiple shots.
  • Generalize the game objects into a superclass
  • Display a score
  • Assign keys to shoot and play again or exit

In the version of Part II, the classes have a lot of repeated code. By analyzing each of them, we can reach a conclusion about a common behavior regarding how to draw and update the objects. A method to remove the object from the game is also used.

Read more

Converting a Game Written in Basic to Python - Part III

In this third part, we have the following objectives:

  • Clean up the classes
  • Multiple planes
  • Multiple shots.
  • Generalize the game objects into a superclass
  • Display a score
  • Assign keys to shoot and play again or exit

In the version of Part II, the classes have a lot of repeated code. By analyzing each of them, we can reach a conclusion about a common behavior regarding how to draw and update the objects. A method to remove the object from the game is also used.

Read more

Converting a Basic Game to Python - Part II

In this second post, we’re going to improve our game.

Although the new version runs in Python, it still looks like an old 80s game. The first thing to fix is the animation. Since we’re using a 280 by 192 point coordinate system to simulate Apple coordinates, we multiply each coordinate by 4 when drawing. To make it look similar to the original Apple, I reduced the number of frames to 8 per second. That’s why the animation looks so jerky! To get it running at 60 frames, we need to multiply the velocities by the ratio between the old and new frame numbers: 8/60. The new version defines some constants for this:

Read more

Converting a Basic Game to Python - Part II

In this second post, we’re going to improve our game.

Although the new version runs in Python, it still looks like an old 80s game. The first thing to fix is the animation. Since we’re using a 280 by 192 point coordinate system to simulate Apple coordinates, we multiply each coordinate by 4 when drawing. To make it look similar to the original Apple, I reduced the number of frames to 8 per second. That’s why the animation looks so jerky! To get it running at 60 frames, we need to multiply the velocities by the ratio between the old and new frame numbers: 8/60. The new version defines some constants for this:

Read more

Converting a Game Written in Basic to Python - Part I

The nostalgia of 80s computers is something I have never stopped feeling. As a child, I was fortunate to use several 8-bit computers, such as the ZX-81, ZX-Spectrum, Apple II, and MSX, or rather, their national clones (TK-85, TK-90X, TK2000), since Brazil was experiencing the era of the Informatics Market Reserve.

In a time when there was no Internet, we spent our time typing programs. A series of books on game programming was published by the Lutécia publishing house in Brazil, but the original American versions were released by Usborne.

Read more

Converting a Game Written in Basic to Python - Part I

The nostalgia of 80s computers is something I have never stopped feeling. As a child, I was fortunate to use several 8-bit computers, such as the ZX-81, ZX-Spectrum, Apple II, and MSX, or rather, their national clones (TK-85, TK-90X, TK2000), since Brazil was experiencing the era of the Informatics Market Reserve.

In a time when there was no Internet, we spent our time typing programs. A series of books on game programming was published by the Lutécia publishing house in Brazil, but the original American versions were released by Usborne.

Read more

Server Chat with WebSockets and asyncio

It’s time to write about a more complete project. I’ll show you the websockets module for Python 3.4, which works very well with asyncio. To avoid interface problems, I decided to write the chat client in JavaScript. The example client was downloaded here. As usual, examples are very simple and leave us wanting more about what we could really do. Who has already tried writing a chat in JavaScript knows that WebSockets are a hand on the wheel.

Read more

Server Chat with WebSockets and asyncio

It’s time to write about a more complete project. I’ll show you the websockets module for Python 3.4, which works very well with asyncio. To avoid interface problems, I decided to write the chat client in JavaScript. The example client was downloaded here. As usual, examples are very simple and leave us wanting more about what we could really do. Who has already tried writing a chat in JavaScript knows that WebSockets are a hand on the wheel.

Read more

Asyncio - Reading from the Keyboard

Continuing the series on Python 3.4’s asyncio module, we will see how to create a simple text-based game. The goal of the game is to display a maze and let the player move around using the numeric keypad (4 - left, 6 - right, 8 - up, 2 - down, and S for exit). To exercise our old DOS programming muscles with asynchronous programming, we will display the clock on the last line. The final result should look like this image:

Read more

Asyncio - Reading from the Keyboard

Continuing the series on Python 3.4’s asyncio module, we will see how to create a simple text-based game. The goal of the game is to display a maze and let the player move around using the numeric keypad (4 - left, 6 - right, 8 - up, 2 - down, and S for exit). To exercise our old DOS programming muscles with asynchronous programming, we will display the clock on the last line. The final result should look like this image:

Read more