Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document REPL and warn if unavailable
* Add documentation on the REPL * Add documentation on installing, and installing the REPL * Print a warning if the REPL is not installed * Add a repr for Actor
- Loading branch information
Showing
7 changed files
with
178 additions
and
22 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ User Guide | |
:maxdepth: 2 | ||
|
||
installation | ||
repl | ||
ide-mode | ||
other-libs | ||
changelog | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,89 @@ | ||
Installing Pygame Zero | ||
====================== | ||
|
||
On desktop systems | ||
~~~~~~~~~~~~~~~~~~ | ||
Included with Mu | ||
---------------- | ||
|
||
The `Mu IDE <https://codewith.mu>`_, which is aimed at beginners, includes a | ||
version of Pygame Zero. | ||
|
||
You will need to `switch mode <https://codewith.mu/en/tutorials/1.0/modes>`_ | ||
into Pygame Zero mode to use it. Then type in a program and | ||
`use the Play button <https://codewith.mu/en/tutorials/1.0/pgzero>`_ to run it | ||
with Pygame Zero. | ||
|
||
.. note:: | ||
|
||
The version of Mu included with Pygame Zero may not be the latest version! | ||
You can find which version is installed by running this code in Mu:: | ||
|
||
import pgzero | ||
print(pgzero.__version__) | ||
|
||
|
||
Stand-alone installation | ||
------------------------ | ||
|
||
First of all, you need **Python 3** installed! This is usually installed | ||
already if you are using **Linux** or a **Raspberry Pi**. You can download it | ||
from `python.org <https://www.python.org/>` on other systems. | ||
|
||
|
||
Windows | ||
''''''' | ||
|
||
To install Pygame Zero, use **pip**. At a `command prompt`__, type | ||
|
||
.. __: https://www.lifewire.com/how-to-open-command-prompt-2618089 | ||
|
||
:: | ||
|
||
pip install pgzero | ||
|
||
This will also install Pygame. Pre-compiled Pygame packages are available to pip | ||
for Windows & Linux (32-bit and 64-bit), and for Mac OS (64-bit only). If you | ||
have a different system, you'll need to find a way to install pygame first. Make | ||
sure you are using Python 3 not Python 2. | ||
|
||
On Raspberry Pi | ||
~~~~~~~~~~~~~~~ | ||
Mac | ||
''' | ||
|
||
In a Terminal window, type | ||
|
||
:: | ||
|
||
pip install pgzero | ||
|
||
|
||
Linux | ||
''''' | ||
|
||
In a terminal window, type | ||
|
||
:: | ||
|
||
sudo pip install pgzero | ||
|
||
|
||
Some Linux systems call it ``pip3``; if the above command printed something | ||
like ``sudo: pip: command not found`` then try:: | ||
|
||
sudo pip3 install pgzero | ||
|
||
Sometimes pip is not installed and needs to be installed. If so try this before | ||
running the above commands again:: | ||
|
||
|
||
sudo python3 -m ensurepip | ||
|
||
|
||
.. _install-repl: | ||
|
||
Installing the REPL | ||
------------------- | ||
|
||
:doc:`Pygame Zero's REPL <repl>` is an optional feature. This can be enabled | ||
when installing with ``pip`` by adding ``pgzero[repl]`` to the pip command | ||
line:: | ||
|
||
pip install pgzero[repl] | ||
|
||
If you aren't sure if you have the REPL installed, you can still run this | ||
command (it won't break anything if it is installed!). | ||
|
||
pgzero has been installed by default since the release of Raspbian Jessie in | ||
September 2015! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Using the REPL (Read-Evaluate-Print Loop) | ||
========================================= | ||
|
||
The REPL allows you to interact with a running Pygame Zero game using Python | ||
commands. As you type it will offer suggestions based on variables that exist | ||
in your program. This can be useful for debugging your game or tuning how difficult it is. | ||
|
||
.. image:: _static/repl.png | ||
|
||
REPL is short for a Read-Evaluate-Print Loop; it means: | ||
|
||
1. **Read** a line of code typed by you | ||
2. **Evaluate** the code | ||
3. **Print** the result | ||
4. **Loop** back to step 1! | ||
|
||
This is an *optional feature* that may need to :ref:`be installed | ||
<install-repl>` if it was not originally installed with Pygame Zero. If you try | ||
using the REPL, Pygame Zero will let you know if it is not installed. | ||
|
||
|
||
Running a Pygame Zero program with the REPL | ||
------------------------------------------- | ||
|
||
If you normally run your Pygame Zero program using the terminal, add ``--repl`` | ||
to the command line when running ``pgzrun``. For example, if your game is in | ||
a file called ``mygame.py``, run:: | ||
|
||
pgzrun --repl mygame.py | ||
|
||
|
||
Using the REPL | ||
-------------- | ||
|
||
Python code that you type at the REPL is evaluated as if you had typed it into | ||
your game file. | ||
|
||
For example, if your game file contains the code :: | ||
|
||
alien = Actor('alien', pos=(54, 60)) | ||
|
||
def draw(): | ||
screen.clear() | ||
alien.draw() | ||
|
||
|
||
Then at the REPL you could type ``alien`` to see the alien object:: | ||
|
||
>>> alien | ||
<Actor 'alien' pos=(54, 60)> | ||
|
||
You can set attributes on the ``alien`` object and see it move:: | ||
|
||
>>> alien.x = 90 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters