lordmauve / pgzero

A zero-boilerplate games programming framework for Python 3, based on Pygame.
https://pygame-zero.readthedocs.io/
GNU Lesser General Public License v3.0
530 stars 190 forks source link

Allow actors drawing a shape (instead of an image) #235

Open aoloe opened 3 years ago

aoloe commented 3 years ago

When teaching the first steps with Pygame zero, kids tend to get lost in:

Would it be possible to allow the actors to also use shapes like rectangles and squares?

I'm thinking of something like

paddle = Actor()
paddle.shape = Rect((x, y), (w, h))
paddle.color = r, g, b
# paddle.fill_color = r, g, b

def draw()
    paddle.draw_rect()
    # paddle.draw_filled_rect()
aoloe commented 3 years ago

If there is an interest in this feature, I can work on a formal proposal and possibly produce a pull request.

lordmauve commented 3 years ago

This is a good idea - it's something that is already in Wasabi2D and works well (and is handy).

I'd suggest simply avoiding the Actor class though. We can create a new class like shapes.Rectangle() and expose shapes as a built-in.

aoloe commented 3 years ago

I also thought about creating a new ActorShape class.

Still, I'm rather in favor of adding the feature to the Actor class. Keeping the same class would help the programmer start with a shape and later move to an image.

But I'm ok with other solutions.

If we put everything in the Actor, draw() might automatically draw a shape if one is defined... (also useful for checking the bounding boxes...)...
And do nothing if both the shape and the image are not defined.

yonghuming commented 3 years ago

seems you need Sprite class linke Sprite in ActionScript 3

yonghuming commented 3 years ago

This is a good idea - it's something that is already in Wasabi2D and works well (and is handy).

pgzero is nice for teaching kids, Wasabi2D is powerful, but need more work making it out-of-box and lower floor for newbee.

yonghuming commented 3 years ago

Decorator maybe hard to understand for kids