Skip to content

Conversation

@Mambouna
Copy link

Fixes #235

This PR introduces classmethods to Actor to create actors from simple filled shapes with a given color.

Available functions:

  • Actor.Square(side, color)
  • Actor.Rectangle(width, height, color)
  • Actor.Circle(diameter, color)
  • Actor.Ellipse(width, height, color)
  • Actor.Triangle(width, height, color)

All keyword assignments as well as anchor and starting position as positional arguments remain available when using these functions, for example player = Actor.Square(15, "blue", (40, 25))

The actors are completely normal actors, the shapes are created as image surfaces and saved in the image cache so that creating many actors with the same shape, dimensions and color does not increase cost. This way, users can begin to implement features that rely on Actor functionality without having image files yet. Once they have an image file they want, as long as it has the same dimensions, they can swap to it simply by changing Actor.Shape(dimensions, color) to Actor(image_string).

I am still thinking about whether Square and Circle should be removed, since the same results can easily be achieved via Rectangle and Ellipse. I am leaning towards doing so to lower the number of functions that are available, making it easier for beginners to keep an overview. I would like feedback on that before we merge anything though.

Documentation and tests have been added.

Mambouna added 5 commits July 25, 2025 13:18
- Added the following constructors, which create a new image in
  `loaders.images` with an associated name that exactly matches the
  content and then creates an Actor from it.
    - `Actor.square(sides, color)`
    - `Actor.rectangle(width, height, color)`
    - `Actor.circle(diameter, color)`
    - `Actor.ellipse(width, height, color)`
    - `Actor.triangle(width, height, color)`
- Any arguments after the image name in the normal Actor construction
  can also be added to these and will be passed on.
- Afterwards, these are perfectly normal Actors with all normal
  functionality.
- Returns early from the image creation function if the same image
  had already been created.
- Added documentation and code comments.
- Removed an unnecessary line in the triangle contructor.
@Mambouna Mambouna changed the title Actor from rect Actors from simple shapes Sep 19, 2025
@Mambouna
Copy link
Author

Project dead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow actors drawing a shape (instead of an image)

1 participant