- Pyxel Overview: Pyxel is a retrogaming framework built with Rust, exposing a Python API. It's used in this book chapter to create games.
- Books for Learning Python: Mentioned are No Starch Press' "Python for Kids" (second edition) and O'Reilly's "Learning Python" (sixth edition). It's emphasized that learning development requires reading proper books rather than relying on Youtube videos or copy-pasting tutorials.
Demo: The demo involves a bat in a dark cave. With the mouse, the player can control the bat's flight.
- Assets: There are two 16x16px sprite images of the bat - one with wings up and one with wings down.
Code:
- The
Bat
class wraps the bat's functionality. It has attributes likex
,y
,frame
, and methods likeswap_wings
anddraw
. The
App
class initializes the game, loads assets, and contains the main loop withupdate
anddraw
methods. In different versions of the code:- In the first version, the bat flaps its wings every 10 frames and can be quit by hitting the Q key.
- In the second version, clicking the left mouse button moves the bat to the cursor position, and if the button is held, the bat follows the mouse.
- In the third version, the bat flies towards the click position using math (Euclidean distance and trigonometry) to compute the path. Vectors and steps use real numbers, and screen positions use natural numbers, causing rounding issues. The vector is adjusted to use the center of the sprite.
- The
- Beyond: Encouraged to own the code, make changes, add behaviors like randomness in flight or an additional standby sprite, and add sounds. The source code of the bat is hosted on Github.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。