updated readme and license, fixed crash on non existing default asset folders

This commit is contained in:
ohsqueezy 2022-10-24 21:47:25 -04:00
parent 72866bd11c
commit d01bed4905
5 changed files with 78 additions and 69 deletions

View File

@ -1,17 +1,19 @@
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Copyright (c) 2022 shampoo.ooo <mailbox@shampoo.ooo>
This permission notice shall be included in all copies or substantial portions
of the Software.
This software is provided 'as-is', without any express or implied warranty. In
no event will the authors be held liable for any damages arising from the use of
this software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Permission is granted to anyone to use this software for any purpose, including
commercial applications, and to alter it and redistribute it freely, subject to
the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software in a
product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

49
README
View File

@ -1,49 +0,0 @@
----------------
Pygame Framework
----------------
Classes to facilitate creation of Pygame projects
Example
-------
Save and run to create a project that redraws a square at a random location
every second. This script is also written in the `sample.py` file.
from time import sleep
from random import randint
from pgfw.Game import Game
class SampleGame(Game):
square_width = 30
# instructions in the update method automatically run once every frame
def update(self):
sleep(1)
screen = self.get_screen()
bounds = screen.get_size()
screen.fill((0, 0, 0))
screen.fill((255, 255, 255),
(randint(0, bounds[0]), randint(0, bounds[1]),
self.square_width, self.square_width))
if __name__ == '__main__':
SampleGame().run()
License
-------
MIT License
see LICENSE.txt for details
Business
--------
420@shampoo.ooo

57
README.md Normal file
View File

@ -0,0 +1,57 @@
Pygame Framework
================
PGFW is a game framework that facilitates the creation and development of [Pygame][] projects. It contains a class `Game` which can be inherited and used as a project skeleton. There are also classes for features such as sprites, animations, audio, b-splines, geometry, and screen capture. It is a collection of code used in previous projects with a focus on creating 2D games. Some examples of games using it are [Picture Processing][], [Scrapeboard][], and [Cakefoot][].
Requirements
------------
* Python 3+
* [Pygame][] 1.9+
Start a project
---------------
Clone the repository (or [download][https://git.nugget.fun/nugget/pgfw/archive/main.zip] and unzip it)
git clone https://git.nugget.fun/nugget/spacebox
Save the following script at the root of the repository to create a project that redraws a square at a random location every second. The project can be run with `python3 [SCRIPT]`. Maybe some cats may even like this game. This script is also available in [sample.py][].
from time import sleep
from random import randint
from pgfw.Game import Game
class SampleGame(Game):
square_width = 30
# instructions in the update method automatically run once every frame
def update(self):
sleep(1)
screen = self.get_screen()
bounds = screen.get_size()
screen.fill((0, 0, 0))
screen.fill((255, 255, 255),
(randint(0, bounds[0]), randint(0, bounds[1]),
self.square_width, self.square_width))
if __name__ == '__main__':
SampleGame().run()
To further build this example, the [Pygame API][] and classes in [pgfw/][] could be imported and used directly in the update function.
License
-------
Unrestricted use, under the zlib license, see [LICENSE.txt][LICENSE.txt]
[Pygame]: https://pygame.org
[Pygame API]: https://www.pygame.org/docs
[Picture Processing]: https://ohsqueezy.itch.io/ppu
[Scrapeboard]: https://scrape.nugget.fun
[Cakefoot]: https://ohsqueezy.itch.io/cakefoot
[sample.py]: sample.py
[pgfw/]: pgfw/

View File

@ -114,8 +114,8 @@ class Audio(Animation):
for root in sfx_location:
prefix = ""
root = self.get_resource(root)
print("checking {} for sound effects".format(root))
if root:
print("checking {} for sound effects".format(root))
if os.path.isfile(root):
self.load_sfx_file(root)
else:
@ -166,8 +166,8 @@ class Audio(Animation):
for root in self.get_configuration("audio", "bgm-project-path"):
# look for path in resource folders
root = self.get_resource(root)
if os.path.exists(root):
print("checking {} for background music".format(root))
if root is not None and os.path.exists(root):
print("checking {} for background music files".format(root))
if os.path.isfile(root):
self.set_bgm(root)
else:
@ -181,7 +181,7 @@ class Audio(Animation):
# Next load BGM paths defined in the configuration. If any of these have the same name as
# BGM loaded by the previous code block, they will be overwritten to give the config file
# precedence over automatic BGM detection.
print("checking configuration for background music".format(root))
print("checking configuration for background music definitions".format(root))
for name, bgm_definition in self.get_configuration("bgm").items():
bgm_definition_members = bgm_definition.split(self.CONFIG_SEPARATOR)
path, volume = bgm_definition_members[0], 1.0

View File

@ -70,7 +70,6 @@ class GameChild:
path = join(root, rel_path)
if exists(path):
return normpath(path)
print("warning: couldn't find resource: {0} {1}".format(path_or_section, option))
def is_shared_mode(self):
return self.check_command_line("s")