{ "info": { "author": "Craig Labenz", "author_email": "craig.labenz@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Natural Language :: English", "Programming Language :: Python", "Topic :: Games/Entertainment" ], "description": "## Okapi\n\n#### What it is\nA library to build grid-based games using Kivy 1.9\n\n\n#### Installation\n\nInstalling packages with Kivy is a joy because you cannot use virtual environments (assuming you use the Kivy package installer). Kivy creates its own unique snowflake environment, then provides a `kivy` command-line utility that heavily modifies your `PYTHONPATH` before ultimately launching the python interpreter. Thus, virtual environments are off the table, as none of their packages can be imported after using `kivy`.\n\n1. [Download the Kivy installer](http://kivy.org/docs/installation/installation.html) and use it to install Kivy.\n2. Next, install `okapi` from PyPI using Kivy's `pip`: `$ kivy -m pip install kivy-okapi`\n\n#### Launching an `Okapi` App\n\nOnce `Okapi` is installed where Kivy is willing to look, you can simply navigate into any game folder and run `kivy main.py` like normal, and all Okapi libraries will be available.\n\n\n## Building a Game with `Okapi`\n\nFor reference, a complete example is provided in the `/examples/rodents_revenge` directory\n\n#### Create an `OkapiApp` class\n\nIn your `main.py` file, provide this bare minimum skeleton:\n\n```py\n# Okapi\nfrom okapi.app import Okapi as OkapiApp\n\n# Local\nfrom game import Game\nfrom screen_manager import ScreenManager\n\n\nclass MyGameApp(OkapiApp):\n\n GAME_CLASS = Game\n SCREEN_MANAGER_CLS = ScreenManager\n PROJECT_PATH = PROJECT_PATH\n\n def get_application_name(self):\n return \"My Game\"\n\nif __name__ == '__main__':\n MyGameApp().run()\n\n```\n\n#### Kivy's `build()` method\n\nThose familiar with Kivy know that the your project's main `App` class is required to define a `build()` function that returns the root widget. For `Okapi`, that root widget is of the `ScreenManager` class. It is this widget's job to swap in and out loading screens, the game screen, menu screens, high score screens, etc.\n\nAn example of overriding the `ScreenManager` class is provided in the Rodent's Revenge game, but here is a bare minimum example:\n\n```py\n# Okapi\nfrom okapi.screen_manager import ScreenManager as OkapiScreenManager\n\n# Local\nfrom welcome_screen import WelcomeScreen\n\nclass ScreenManager(OkapiScreenManager):\n\n def get_welcome_screen(self):\n \"\"\"\n Optional.\n\n If implemented, should return a `Screen` widget that says something\n like \"Hello, welcome to my game!\" and has a click listener. The\n `OkapiScreenManager` will listen for that click and start the game.\n \"\"\"\n return WelcomeScreen()\n\n def get_screen_from_game(self):\n \"\"\"\n Required.\n\n Should do something with `self.game` to get a Screen widget used to start\n and render the game.\n \"\"\"\n return self.game.get_screen()\n\n```\n\n\n#### Listening to Kivy's clock\n\nThe `ScreenManager` is also a clean interface to Kivy's clock module. Your `ScreenManager` keeps track of a `current_screen` attribute,\nand whenever this changes it unregisters any clock listeners from the previous screen and registers the new screen's clock listeners.\n\nTo register clock handlers, define them like so:\n\n```py\n# Okapi\nfrom okapi.screen import Screen\n\n\nclass SomeScreen(Screen):\n\n def every_second(self):\n # Do stuff\n\n def every_other_second(self):\n # Do more stuff\n\n def get_clock_tuple(self):\n # Option 1\n return (self.every_second, 1.0,)\n\n # or Option 2\n return (\n (self.every_second, 1.0,),\n (self.every_other_second, 2.0,),\n )\n```\n\nThe `ScreenManager` class will also drill down and check all top-level children of a screen to see if any have clock listeners.\n\n\n#### Listening to keyboard input\n\nThe `ScreenManager` also listens to all keyboard input and passes it to both `self.game` and whatever is its `current_screen`. To listen for clicks to the \"down arrow\":\n\n```py\n# Okapi\nfrom okapi.screen import Screen\n\n\nclass SomeScreen(Screen):\n\n def on_press_down(self):\n # Do stuff\n\n def on_press_y(self):\n # Do stuff\n\n def on_press_cmd_w(self):\n # Do stuff\n\n def on_press_alt_shift_s(self):\n # Do stuff\n\n```\n\nThe above definitions also apply to your `Game` class.\n\nIf there are > 1 modifier keys pressed (`shift`, `command`, `alt`, etc) they will be alphabetized for consistency.\n\n#### The `Game` class\n\nThe `Game` class is where you put your fun game logic! Define one like so:\n\n\n```py\n# Engine\nfrom okapi.engine.game import Game as OkapiGame\n\n\nclass Game(OkapiGame):\n\n # Used by `OkapiGame` to provide default functionality for\n # `self.get_clock_tuple()`\n # Rodent's Revenge only has to update once per second\n CLOCK_INTERVAL = 1.0\n\n # Default blank ground -- empty walkable space\n BLANK_GROUND_CHARACTER = '.'\n\n # Other special types of ground. Maybe impassable, or maybe\n # containing various actors\n EXTRA_GROUNDS = {\n \"b\": ground.BlockGround,\n \"#\": ground.ImpassableGround,\n }\n\n def clock_update(self, dt):\n # Make the game happen!\n\n def on_press_down(self):\n # Move something down!\n\n```\n\n\n#### Moving actors\n\nThe `OkapiGame` class provides a function called `move_actor`. Let's say you are building a chess app. To move a knight, you would make a call like this:\n\n```py\nself.game.move_actor(self.white_knight_1, 1, 2)\n```\n\nThis will immediately cause a reanimation, showing the white knight having just moved.\n\n\n#### Moving Rules\n\nMoving legality is determined by the target ground's `can_accommodate()` method. By default, this rejects movements into occupied territory. Of course, that rule makes little sense for chess, so for that example you'd want to override that function to accept new pieces at any time, and to remove from the game any piece currently found in that spot.", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/craiglabenz/kivy-okapi/tarball/0.1.1", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/craiglabenz/kivy-okapi", "keywords": "kivy,python,python2,game,games,grid,grid-based", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "kivy-okapi", "package_url": "https://pypi.org/project/kivy-okapi/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/kivy-okapi/", "project_urls": { "Download": "https://github.com/craiglabenz/kivy-okapi/tarball/0.1.1", "Homepage": "https://github.com/craiglabenz/kivy-okapi" }, "release_url": "https://pypi.org/project/kivy-okapi/0.1.1/", "requires_dist": null, "requires_python": null, "summary": "Grid-based game framework built with Kivy 1.9", "version": "0.1.1" }, "last_serial": 1634248, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "4185bfb5a5b5d656323cc2f54ae22a85", "sha256": "403a0afdbd4a6fa749c2a0dada3558b879fff7923c33866f89bb45e9ff89fb28" }, "downloads": -1, "filename": "kivy-okapi-0.1.0.tar.gz", "has_sig": false, "md5_digest": "4185bfb5a5b5d656323cc2f54ae22a85", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12023, "upload_time": "2015-06-30T13:21:18", "url": "https://files.pythonhosted.org/packages/24/de/9b73c304fad95e44342721a58bcbd6049d61d37b1d61230b97a848161a8a/kivy-okapi-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "5d1975b93f705a97f762c01f72fe6ff6", "sha256": "067f7a1655a4b446267ee2dd03195e0c323a6b0a5ba34f7d2e59e368130140bd" }, "downloads": -1, "filename": "kivy-okapi-0.1.1.tar.gz", "has_sig": false, "md5_digest": "5d1975b93f705a97f762c01f72fe6ff6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15846, "upload_time": "2015-07-15T11:49:19", "url": "https://files.pythonhosted.org/packages/41/6d/72b99534e01a6c7b8e46b36994a1a599942cbc374fb82c3c9f3940165fa5/kivy-okapi-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5d1975b93f705a97f762c01f72fe6ff6", "sha256": "067f7a1655a4b446267ee2dd03195e0c323a6b0a5ba34f7d2e59e368130140bd" }, "downloads": -1, "filename": "kivy-okapi-0.1.1.tar.gz", "has_sig": false, "md5_digest": "5d1975b93f705a97f762c01f72fe6ff6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15846, "upload_time": "2015-07-15T11:49:19", "url": "https://files.pythonhosted.org/packages/41/6d/72b99534e01a6c7b8e46b36994a1a599942cbc374fb82c3c9f3940165fa5/kivy-okapi-0.1.1.tar.gz" } ] }