Giter Club home page Giter Club logo

pygame-objects's Introduction

PyGame Objects

Want a sample on how to work with this framework? Check out the docs in the wiki, particularly the Walkthrough

The most awesome framework for PyGame you will ever encounter! Build Status Coverage Status

But it's not there yet. Right now, it's just a simple abstraction for some commmon code patterns I find while using PyGame.

Built on: see .travis.yml as well as requirements.txt. Needs Python 3.7+ as this relies on language features only available from there.

Development

Aside from .travis.yml, the Dockerfile is provided for development. The Dockerfile takes an argument userid which should be a user id outside the container that has access to /tmp/.X11-unix. If you are in a graphical desktop environment, it would suffice to pass the $UID environment variable like so,

docker build -t pygame-objects --build-arg userid=$UID .

You can also pull the image via

docker run skytreader/pygame-objects:latest

At this point, you only have the image. To develop and run games with it, you should use the provided duckrunner script. It takes the package path to the script that invokes your game loop. For example, to run the included snake game, call duckrunner demo.snake.game.

Current Status

Right now, I'm working on adding extra game-making functionalities; stuff that will maybe come useful if you do an RPG, platformer, arcade, etc., type of game. I'm also working on adding new native drawing functionalities.

File Organization

components houses the main framework. sample_sprites contains the sprites I used for the test and demo files. tests contains, well, tests.

Since I tried to follow PEP 328, it may not be that straightforward to run the tests. For convenience, navigate to the runscripts directory, pick the test (as directories) you would like to run, and execute the runscripts from there.

The tests were written after every feature I finished. The tests are a mix of demos and unit tests. Every now and then, I also write some mini-games to compile demonstrations of some feature I'm working on.

Git Organization

Documentation is at the wiki. My todo list I made as issues. I am currently working to make the documentation comprehensive (no more peeking at the framework code!). However, something I was not able to forsee is that, the documentation for Milestone 1 and for the code at the repo head has been mixed at the wiki. Fortunately, they are not yet that different from each other and when and where they differ, it is easy to note. In the near future, I plan to include markdown files of the docs along with the code.

License

All code in master (except when noted) are licensed under MIT.

All sprites under sample_sprites/tiles are licensed under a Creative Commons Attribution-ShareAlike 4.0 license.

pygame-objects's People

Contributors

skytreader avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pygame-objects's Issues

Move to pytest

Nose is, AFAIK, unmaintained plus there's some mysterious behavior in Travis CI that I hope will be remedied by this.

Flaky test_incr_different_keys

======================================================================
FAIL: test_incr_different_keys (tests.snake.ai_tests.WindowedCountTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/chad/kode/PyGame-Objects/tests/snake/ai_tests.py", line 36, in test_incr_different_keys
    self.assertEquals(half - 1, self.windowed_count.counts["spam"])
AssertionError: 3 != 4

----------------------------------------------------------------------

Alternative debug mode display

Instead of having additional window space when debug mode is active, just make use of what window space the game is already using. Just use the bottom/upper n pixel rows of the window to display debug logs. Throw an exception if window size is too small. The text should, of course, overlay on the game.

This makes #16 pointless unless I add in more config values for this.

Code clean-up

Remove unnecessary hash bang lines. Only runnable files should have them (But what if we use it to indicate the expected Python version for the file?)

Fix hash bang lines declaration (#! usr/bin/env python to #! /usr/bin/env python).

Change tabs to spaces.

Use **kwargs for notifying subscribers

Right now, Publisher.notify_subscribers and Subscriber.notify expect a dictionary for arg_bundle. I think it is more Pythonic to use **kwargs instead.

Find a way to specify/bump version numbers

Would've used SemVer but it feels too formal and constrained for something that is under heavy development.

Also, as of this time of writing (and earlier, by a few weeks), the code/demos in release "Milestone1" is no longer compatible with the framework.

GameLoopEvents should no longer need the config in its constructor

It already takes in a GameScreen which, in turn, already takes a GameConfig. The original purpose of taking in the GameConfig can be filled from there.

Furthermore, this opens up to confusing behavior if GameScreen and GameLoopEvents are given different GameConfig instances.

Docker environment segfaults on Ubuntu 20.04.1 LTS

Building from branch logging-dockerenv-fix:

cestioco@nb-hwygy33:PyGame-Objects$ ./duckrunner demo.snake.game
2020-08-28 09:45:06,633 WARNING Can't open a file handler. Logs won't be written to file.
No protocol specified
No protocol specified
No protocol specified
Fatal Python error: (pygame parachute) Segmentation Fault
pygame init
Aborted (core dumped)

Maybe we have to update base image. Or Python/Pygame.

Use decorators for Gameconfig

Might tie in with #6 but, instead of explicitly invoking notify_subscribers everytime a config changes, why not just provide a decorator for it?

Improve Documentation

Keep making games and improve documentation as it goes. Not gonna close until I'm satisfied!

Factory Pattern

Check out Factory Pattern --- might be usable for instantiating Views.

Code Organization

Where to put handler functions?

Most sensible place seems to be in GameLoopEvents. However, handler functions are actually attached inside GameLoop.

Either way, this requires users to interface method calls in Sprites, Images, Models, etc. to handle events. That is tedious.

Determine self-collisions

And while you're at it, define proper endgame conditions too. Collisions determine a defeat conditions but what determines a victory condition?

Can't run games via Docker with newer Ubuntu versions

Distro: Ubuntu 20.04.1 LTS

Sample log:

$ ./duckrunner demo.snake.game
2020-08-31 12:44:56,413 WARNING Can't open a file handler. Logs won't be written to file.
No protocol specified
No protocol specified
No protocol specified
No protocol specified
Traceback (most recent call last):
  File "/app/components/core.py", line 166, in go
    self.loop_events.loop_setup()
  File "/app/components/core.py", line 517, in loop_setup
    self.configurable_setup()
  File "/app/components/core.py", line 501, in configurable_setup
    window = self.invoke_window(self.game_screen.screen_dimensions)
  File "/app/components/core.py", line 473, in invoke_window
    self.__window = pygame.display.set_mode(window_size)
pygame.error: No available video device
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
pygame init

In general, running via GUIs via Docker seems different now.

Make Image Observable

Make Image observable since it is just an encapsulation of the common functionalities of images in a game.

From here, we can make Sprite classes observe Image instances.

Drawable access to screen or GameConfig

Drawable objects should be able to know how big the allotted screen is. In fact, I think all objects should be able to do just that. So that they can scale their actions depending on the size of the screen.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.