summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-03-16 22:05:05 +0200
committerViljami Ilola <+@hix.fi>2024-03-16 22:05:05 +0200
commit4050057c34c67130cf5f1d202ca85cb81985f968 (patch)
tree93dfd6b3eaa4e8cb153266326724afb07d141dcf
parent2fd254af8613dba6bbd7bd9f52514229a5287d21 (diff)
make it installable
-rw-r--r--.gitignore4
-rw-r--r--README.md (renamed from README.txt)0
-rw-r--r--pyproject.toml7
-rw-r--r--src/sliceitoff/__init__.py0
-rw-r--r--src/sliceitoff/__main__.py49
-rw-r--r--src/sliceitoff/images/images.py13
-rw-r--r--src/sliceitoff/main.py49
7 files changed, 73 insertions, 49 deletions
diff --git a/.gitignore b/.gitignore
index 9ad0382..d2c4f2a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,9 @@
# Caches
__pycache__
+.coverage
+
+# builds
+dist/
# Editor backups
*~
diff --git a/README.txt b/README.md
index 45f56f1..45f56f1 100644
--- a/README.txt
+++ b/README.md
diff --git a/pyproject.toml b/pyproject.toml
index f6ab331..179995a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -21,12 +21,15 @@ requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
-miinaharava = 'sliceitoff.main:main'
+sliceitoff = 'sliceitoff.main:main'
[tool.pytest.ini_options]
pythonpath = [ "src/sliceitoff" ]
-
[tool.pylint.main]
recursive = true
source-roots = ["src/sliceitoff"]
+extension-pkg-whitelist = ["pygame"]
+
+[tool.pylint."messages control"]
+disable = [ "c-extension-no-member" ]
diff --git a/src/sliceitoff/__init__.py b/src/sliceitoff/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/src/sliceitoff/__init__.py
+++ /dev/null
diff --git a/src/sliceitoff/__main__.py b/src/sliceitoff/__main__.py
new file mode 100644
index 0000000..347d78e
--- /dev/null
+++ b/src/sliceitoff/__main__.py
@@ -0,0 +1,49 @@
+""" Slice It Off! - Game where you slice the area where enemies reside to
+ the minimum
+"""
+
+from time import sleep
+from pathlib import Path
+
+import pygame
+
+from display import Display
+from status import Status
+from player import Player
+from field import Field
+from enemies import Enemies
+from images import Images
+from game import Game
+
+
+def sliceitoff():
+ """ The game - It all starts here """
+ pygame.init()
+
+ display = Display()
+ Images.load_images( Path(__file__).parent.resolve() )
+
+ status = Status()
+ field = Field()
+ enemies = Enemies(field = field, level = 2)
+ player = Player(field = field, enemies = enemies)
+ game = Game(player = player)
+
+ clock = pygame.time.Clock()
+
+ for _ in range(6000):
+ if game.step():
+ break
+ display.update(
+ [
+ status.get_sprites(),
+ field.get_sprites(),
+ enemies.get_sprites(),
+ player.get_sprites()
+ ])
+ clock.tick(60)
+
+ sleep(2)
+ pygame.quit()
+
+sliceitoff()
diff --git a/src/sliceitoff/images/images.py b/src/sliceitoff/images/images.py
index 999d92b..07a8bcd 100644
--- a/src/sliceitoff/images/images.py
+++ b/src/sliceitoff/images/images.py
@@ -9,12 +9,13 @@ class Images:
surfaces = {}
@staticmethod
- def reload_images():
+ def reload_images(base_path):
__class__.surfaces = {}
- with open("assets/images.lst") as image_list_file:
- for line in image_list_file:
+ filename_imagelist = os.path.join(base_path, "assets", "images.lst")
+ with open( filename_imagelist ) as imagelist_file:
+ for line in imagelist_file:
name, *path = line.strip().split()
- filename = os.path.join(*path)
+ filename = os.path.join(base_path, *path)
if DEBUG:
print(f"Loading images {name = }, {filename = }")
image = pygame.image.load(filename)
@@ -24,8 +25,8 @@ class Images:
return True
@staticmethod
- def load_images():
+ def load_images(base_path):
if __class__.surfaces:
return False
- return __class__.reload_images()
+ return __class__.reload_images(base_path)
\ No newline at end of file
diff --git a/src/sliceitoff/main.py b/src/sliceitoff/main.py
index 529fcaa..58cc617 100644
--- a/src/sliceitoff/main.py
+++ b/src/sliceitoff/main.py
@@ -1,44 +1,11 @@
-import pygame
-
-from time import sleep
-
-from display import Display
-from status import Status
-from player import Player
-from field import Field
-from enemies import Enemies
-from images import Images
-from game import Game
-
+""" main.py """
+from runpy import run_path
+from pathlib import Path
def main():
- pygame.init()
-
- display = Display()
- Images.load_images()
-
- status = Status()
- field = Field()
- enemies = Enemies(field = field, level = 2)
- player = Player(field = field, enemies = enemies)
- game = Game(player=player)
-
- clock = pygame.time.Clock()
-
- for _ in range(6000):
- if game.step():
- break
- display.update(
- [
- status.get_sprites(),
- field.get_sprites(),
- enemies.get_sprites(),
- player.get_sprites()
- ])
- clock.tick(60)
-
-
- sleep(2)
- pygame.quit()
+ """ Let's start the app as current path being base """
+ my_path = Path(__file__).parent.resolve()
+ run_path(f"{my_path}", run_name="sliceitoff")
-main()
+if __name__ == "__main__":
+ main()