sverpykit 0.2.13__tar.gz → 0.2.15__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {sverpykit-0.2.13 → sverpykit-0.2.15}/PKG-INFO +1 -1
  2. {sverpykit-0.2.13 → sverpykit-0.2.15}/pyproject.toml +1 -1
  3. sverpykit-0.2.15/sverpykit/Collide/Collide.py +57 -0
  4. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit/Draw/Draw.py +1 -1
  5. sverpykit-0.2.15/sverpykit/Objects/Block.py +28 -0
  6. sverpykit-0.2.15/sverpykit/Objects/Entity.py +117 -0
  7. sverpykit-0.2.15/sverpykit/Shapes/Circle.py +22 -0
  8. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit/Ui/TextBlock.py +4 -0
  9. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit/__init__.py +10 -2
  10. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit/core/Config.py +2 -0
  11. sverpykit-0.2.15/sverpykit/core/FileManager.py +16 -0
  12. sverpykit-0.2.15/sverpykit/core/Json.py +19 -0
  13. sverpykit-0.2.15/sverpykit/core/Objects.py +17 -0
  14. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit/core/Runtime.py +55 -3
  15. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit/core/initialize.py +16 -3
  16. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit.egg-info/PKG-INFO +1 -1
  17. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit.egg-info/SOURCES.txt +5 -0
  18. sverpykit-0.2.13/sverpykit/Collide/Collide.py +0 -13
  19. sverpykit-0.2.13/sverpykit/Objects/Entity.py +0 -68
  20. {sverpykit-0.2.13 → sverpykit-0.2.15}/LICENSE +0 -0
  21. {sverpykit-0.2.13 → sverpykit-0.2.15}/README.md +0 -0
  22. {sverpykit-0.2.13 → sverpykit-0.2.15}/setup.cfg +0 -0
  23. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit/Ui/Button.py +0 -0
  24. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit/Ui/DropDown.py +0 -0
  25. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit/Ui/SearchBar.py +0 -0
  26. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit/Ui/Window.py +0 -0
  27. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit.egg-info/dependency_links.txt +0 -0
  28. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit.egg-info/requires.txt +0 -0
  29. {sverpykit-0.2.13 → sverpykit-0.2.15}/sverpykit.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sverpykit
3
- Version: 0.2.13
3
+ Version: 0.2.15
4
4
  Summary: A wrapper for pygame.
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sverpykit"
7
- version = "0.2.13"
7
+ version = "0.2.15"
8
8
  description = "A wrapper for pygame."
9
9
  readme = "README.md"
10
10
  dependencies = [
@@ -0,0 +1,57 @@
1
+ from sverpykit.Shapes import Circle
2
+ import pygame, math
3
+
4
+ class collides:
5
+
6
+ @ staticmethod
7
+ def rect_rect(
8
+ rect1: pygame.Rect,
9
+ rect2: pygame.Rect
10
+ ) -> bool:
11
+ return rect1.colliderect(rect2)
12
+
13
+ @ staticmethod
14
+ def rect_point(
15
+ rect: pygame.Rect,
16
+ point: tuple[int, int]
17
+ ) -> bool:
18
+ return rect.collidepoint(point)
19
+
20
+ @ staticmethod
21
+ def circle_circle(
22
+ circle1: Circle.Circle,
23
+ circle2: Circle.Circle
24
+ ) -> bool:
25
+ """
26
+ :param circle1: The first circle.
27
+ :param circle2: The second circle.
28
+ :return: Returns if the circles collide.
29
+ """
30
+ return math.sqrt(
31
+ math.pow(circle1.center[0] - circle2.center[0], 2) + math.pow(circle1.center[1] - circle2.center[1], 2)
32
+ ) < circle1.diameter/2 + circle2.diameter/2
33
+
34
+ @ staticmethod
35
+ def circle_point(
36
+ circle: Circle.Circle,
37
+ point: tuple[int, int]
38
+ ) -> bool:
39
+ """
40
+ :param circle: The circle.
41
+ :param point: The coordinates of the point.
42
+ :return: Returns if the coordinates are in the circle.
43
+ """
44
+ return math.sqrt(
45
+ math.pow(circle.center[0] - point[0], 2) + math.pow(circle.center[1] - point[1], 2)
46
+ ) < circle.diameter
47
+
48
+ # @ staticmethod
49
+ # def circle_rect(
50
+ # circle: Circle.Circle,
51
+ # rect: pygame.Rect
52
+ # ) -> bool:
53
+ # """
54
+ # :param circle: The circle.
55
+ # :param rect: The rect.
56
+ # :return: Returns if the rectangle collides with the circle.
57
+ # """
@@ -49,7 +49,7 @@ def draw_circle(
49
49
  color: pygame.Color | tuple[int, int, int],
50
50
  center: tuple[int, int],
51
51
  radius: float | int,
52
- width: int,
52
+ width: int = 0,
53
53
  draw_top_left: bool = False,
54
54
  draw_top_right: bool = False,
55
55
  draw_bottom_left: bool = False,
@@ -0,0 +1,28 @@
1
+ import pygame
2
+
3
+ class Platform:
4
+ def __init__(
5
+ self,
6
+ rect: pygame.Rect,
7
+ surface: pygame.Surface,
8
+ display: pygame.Surface,
9
+ resize_surface: bool = True
10
+ ):
11
+ self.rect = rect
12
+ self.surface = pygame.transform.scale(
13
+ surface, (self.rect.w, self.rect.h)
14
+ ) if resize_surface else surface
15
+ self.display = display
16
+
17
+ def draw(self, display: pygame.Surface | None = None):
18
+ display = display if display else self.display
19
+
20
+ display.blit(
21
+ self.surface, self.rect
22
+ )
23
+
24
+ def events(self):
25
+ pass
26
+
27
+ def collides(self, rect: pygame.Rect):
28
+ return self.rect.colliderect(rect)
@@ -0,0 +1,117 @@
1
+ from sverpykit.core import Config, Runtime
2
+ from typing import Callable, Any
3
+ import pygame
4
+
5
+ class Entity:
6
+ def __init__(
7
+ self,
8
+ hitbox: pygame.Rect,
9
+ surface: pygame.Surface,
10
+ events: dict[str, Callable] | None = None,
11
+ statistics: dict[str, Any] | None = None,
12
+ states: dict[str, Any] | None = None
13
+ ):
14
+ events = events if isinstance(events, dict)\
15
+ else {}
16
+ statistics = statistics if isinstance(statistics, dict)\
17
+ else {}
18
+ states = states if isinstance(states, dict)\
19
+ else {}
20
+ self.hitbox = hitbox
21
+ self.surface = surface
22
+
23
+ self.states = {
24
+ "vy": 0,
25
+ "vx": 0,
26
+ "show_hitbox": False
27
+ }
28
+ self.states.update(states)
29
+
30
+ self.stats = {
31
+ "speed": 100,
32
+ "jump_power": 15
33
+ }
34
+ self.stats.update(statistics)
35
+
36
+ self.accepted_events = {
37
+ "key": Entity.key_events,
38
+ "mouse": Entity.mouse_events
39
+ }
40
+ self.accepted_events.update(events)
41
+
42
+ def key_events(self, keys: dict):
43
+ pass
44
+
45
+ def mouse_events(self, button: int, pos: tuple[int, int]):
46
+ pass
47
+
48
+ def draw(self):
49
+ Config.screen.blit(
50
+ self.surface, self.hitbox
51
+ )
52
+ if self.states["show_hitbox"]:
53
+ pygame.draw.rect(
54
+ Config.screen,
55
+ (255, 255, 255),
56
+ self.hitbox,
57
+ width=1
58
+ )
59
+
60
+ def events(self):
61
+ self.hitbox.y += self.states["vy"] * Config.delta_time
62
+ self.check_y_collision()
63
+ self.hitbox.x += self.states["vx"] * Config.delta_time
64
+ self.check_x_collision()
65
+ click = pygame.mouse.get_pressed()
66
+ mp = pygame.mouse.get_pos()
67
+ if any(click):
68
+ self.accepted_events["mouse"](self, click, mp)
69
+ keys = pygame.key.get_pressed()
70
+ if any(keys):
71
+ self.accepted_events["key"](self, keys)
72
+
73
+ def check_x_collision(self) -> None:
74
+ """
75
+ This check should be run after every time you update the x-position of the entity.
76
+ """
77
+
78
+ reset_velocity = False
79
+
80
+ for obj in Runtime.game_objects:
81
+ if not hasattr(obj, "collides"):
82
+ continue
83
+ if not obj.collides(self.hitbox):
84
+ continue
85
+
86
+ if self.states["vx"] > 0:
87
+ self.hitbox.x = obj.rect.x - self.hitbox.w
88
+ reset_velocity = True
89
+ elif self.states["vx"] < 0:
90
+ self.hitbox.x = obj.rect.x + obj.rect.w
91
+ reset_velocity = True
92
+
93
+ if reset_velocity:
94
+ self.states["vx"] = 0
95
+
96
+ def check_y_collision(self) -> None:
97
+ """
98
+ This check should be run after every time you update the y-position of the entity.
99
+ """
100
+
101
+ reset_velocity = False
102
+
103
+ for obj in Runtime.game_objects:
104
+ if not hasattr(obj, "collides"):
105
+ continue
106
+ if not obj.collides(self.hitbox):
107
+ continue
108
+
109
+ if self.states["vy"] > 0:
110
+ self.hitbox.y = obj.rect.y - self.hitbox.h
111
+ reset_velocity = True
112
+ elif self.states["vy"] < 0:
113
+ self.hitbox.y = obj.rect.y + obj.rect.h
114
+ reset_velocity = True
115
+
116
+ if reset_velocity:
117
+ self.states["vy"] = 0
@@ -0,0 +1,22 @@
1
+ import pygame
2
+
3
+ class Circle:
4
+ def __init__(
5
+ self,
6
+ center: tuple[int, int],
7
+ diameter: int
8
+ ):
9
+ self.center = center
10
+ self.diameter = diameter
11
+
12
+ def draw(
13
+ self,
14
+ display: pygame.Surface,
15
+ color: tuple[int, int, int]
16
+ ) -> None:
17
+ pygame.draw.circle(
18
+ surface=display,
19
+ color=color,
20
+ center=self.center,
21
+ radius=self.diameter/2
22
+ )
@@ -120,3 +120,7 @@ class TextBlock:
120
120
  "hyperlink": hyperlink,
121
121
  "newline": newline
122
122
  })
123
+
124
+ def reset(self):
125
+ self.text = ""
126
+ self.text_surfs = []
@@ -2,14 +2,22 @@
2
2
  import pygame
3
3
  pygame.init()
4
4
  from .core import Config, Runtime
5
- from .core.Runtime import add_layer, add_game_object, start, update as run_frame
5
+ from .core.Runtime import add_layer, add_game_object, start, update as run_frame, load_image
6
6
  from .core.Config import default_exit as quit_game
7
7
  from .core.initialize import set_display, set_frame_method, set_font, set_quit_method, set_tick_method,\
8
- max_rate
8
+ set_src_path, max_rate
9
+
10
+ # File Management
11
+ from .core import Json
12
+ from .core.FileManager import resource_path
13
+
14
+ # Collision
15
+ from .Collide.Collide import collides
9
16
 
10
17
  # Drawing
11
18
  from .Draw.Draw import draw_surface, draw_rect, draw_circle, render_text
12
19
  from .Objects.Entity import Entity
20
+ from .Objects.Block import Platform
13
21
 
14
22
  # Ui parts
15
23
  from .Ui.Button import Button
@@ -1,3 +1,4 @@
1
+ from sverpykit.core import FileManager
1
2
  import pygame, sys
2
3
  from typing import Callable
3
4
 
@@ -32,6 +33,7 @@ tick_function: Callable = tick
32
33
  fonts: dict[str, pygame.font.Font] = {
33
34
  "default": pygame.font.SysFont("arial",32)
34
35
  }
36
+ images: dict[str, pygame.Surface] = {}
35
37
 
36
38
  # Colors
37
39
  background_color: pygame.Color | tuple[int, int, int] = (25, 25, 25)
@@ -0,0 +1,16 @@
1
+ import sys, os, pygame
2
+ from pathlib import Path
3
+
4
+ base_path = Path(__file__).resolve().parent
5
+ def spk_resource_path(relative_path: str) -> str:
6
+ if hasattr(sys, '_MEIPASS'):
7
+ return os.path.join(sys._MEIPASS, f"../{relative_path}")
8
+ return os.path.join(base_path, f"../{relative_path}")
9
+
10
+ src_path = ""
11
+ def resource_path(relative_path: str) -> str:
12
+ if not os.path.exists(src_path):
13
+ raise TypeError(f"Please set the src path before you run this function!")
14
+ if hasattr(sys, '_MEIPASS'):
15
+ return os.path.join(sys._MEIPASS, f"{relative_path}")
16
+ return os.path.join(src_path, f"{relative_path}")
@@ -0,0 +1,19 @@
1
+ import json
2
+
3
+ def read_json(path: str, obj: int | str | None = None) -> dict | list | int | str:
4
+ with open(path, "r") as f:
5
+ data = json.load(f)
6
+ return data.get(obj, data)
7
+
8
+ def write_json(path: str, obj: dict | list) -> None:
9
+ with open(path, "w") as f:
10
+ json.dump(obj, f, indent=4)
11
+
12
+ def update_json(path: str, obj: dict | list) -> None:
13
+ with open(path, "r") as f:
14
+ data: list | dict = json.load(f)
15
+ if not isinstance(obj, type(data)):
16
+ raise ValueError("Object does not have the same type as JSON file!")
17
+ with open(path, "w") as f:
18
+ data.update(obj) if isinstance(data, dict) else data.extend(obj)
19
+ json.dump(data, f, indent=4)
@@ -0,0 +1,17 @@
1
+ import pygame
2
+
3
+ def create_rect(
4
+ x: int | float,
5
+ y: int | float,
6
+ width: int | float,
7
+ height: int | float
8
+ ) -> pygame.Rect:
9
+ """
10
+ This is the same
11
+ :param x: The x position of the rectangle.
12
+ :param y: The y position of the rectangle.
13
+ :param width: The width of the rectangle.
14
+ :param height: The height of the rectangle.
15
+ :return: Returns a pygame rectangle.
16
+ """
17
+ return pygame.Rect(x, y, width, height)
@@ -1,21 +1,73 @@
1
1
  from sverpykit.Ui.Window import Window
2
2
  from sverpykit.Ui.TextBlock import TextBlock
3
3
  from sverpykit.core import Config
4
- import pygame
4
+ import pygame, sys, os
5
+ from pathlib import Path
5
6
 
6
7
  ui_layers = []
7
8
  game_objects = []
8
9
 
10
+ def load_image(
11
+ path: str,
12
+ name: str
13
+ ) -> pygame.Surface:
14
+ """
15
+ :param path: The path to your file (Be sure this is a full path!).
16
+ :param name: The name that the image gets stored to.
17
+ :return: Returns the image, but also saves it in sverpykit's cache.
18
+ """
19
+ img = pygame.image.load(path)
20
+ Config.images[name] = img
21
+ return img
22
+
23
+ def resize_image(
24
+ name: str,
25
+ width: int | float,
26
+ height: int | float,
27
+ save: bool = True
28
+ ) -> pygame.Surface:
29
+ """
30
+ :param name: This is the same name as where you loaded the image.
31
+ :param width: The width of the resized surface.
32
+ :param height: The height of the resized surface.
33
+ :param save: Decides if the image will be cached with or without changes.
34
+ :return: Returns the resized image.
35
+ """
36
+ img = pygame.transform.scale(Config.images[name], (width, height))
37
+ if save:
38
+ Config.images[name] = img
39
+ return img
40
+
41
+ def rotate_image(
42
+ name: str,
43
+ rotation: float | int,
44
+ save: bool = False
45
+ ) -> pygame.Surface:
46
+ """
47
+ :param name: This is the same name as where you loaded the image.
48
+ :param rotation: The rotation of the new image in degrees.
49
+ :param save: Decides if the image will be cached with or without changes.
50
+ :return: Returns the rotated image.
51
+ """
52
+ img = pygame.transform.rotate(
53
+ Config.images[name],
54
+ rotation
55
+ )
56
+ if save:
57
+ Config.images[name] = img
58
+ return img
59
+
9
60
  def add_layer(
10
61
  layer_type: str,
11
62
  rectangle: pygame.Rect,
12
63
  components: list,
13
- color: tuple[int, int, int] = (150, 150, 150)
64
+ color: tuple[int, int, int] = (150, 150, 150),
65
+ **kwargs
14
66
  ) -> Window:
15
67
  """
16
68
  :return: Returns nothing.
17
69
  """
18
- w = Window(ui_layers, rectangle, components, color)
70
+ w = Window(ui_layers, rectangle, components, color, **kwargs)
19
71
  for component in w.components:
20
72
  if isinstance(component, TextBlock):
21
73
  component.owner = w
@@ -1,6 +1,7 @@
1
- from sverpykit.core import Config, Runtime
1
+ from sverpykit.core import Config, Runtime, FileManager
2
2
  from typing import Callable, Optional
3
- import pygame
3
+ import pygame, os
4
+ from pathlib import Path
4
5
 
5
6
  # Automatic initialization
6
7
  pygame.key.set_repeat(500, 50)
@@ -12,7 +13,8 @@ def set_display(
12
13
  flags: int = 0,
13
14
  depth: int = 0,
14
15
  display: int = 0,
15
- vsync: int = 0
16
+ vsync: int = 0,
17
+ title: str = "Pygame Window"
16
18
  ) -> pygame.Surface:
17
19
  """
18
20
  :param width: Width of the screen
@@ -21,11 +23,22 @@ def set_display(
21
23
  :param depth: How many colors you can use (Most of the time 8-bit is good enough. In which case just leave it blank).
22
24
  :param display: Decides which monitor is used for the window.
23
25
  :param vsync: Caps framerate to the monitor to avoid screen tearing (Screen tearing is just a visual glitch.)
26
+ :param title: What gets displayed in the title bar.
24
27
  :return:
25
28
  """
26
29
  Config.screen = pygame.display.set_mode((width, height), flags, depth, display, vsync)
30
+ pygame.display.set_caption(title)
27
31
  return Config.screen
28
32
 
33
+ def set_src_path(src_path: Path) -> None:
34
+ """
35
+ :param src_path: Use `pathlib.Path(__file__).resolve().parent`.
36
+ :return: Returns nothing.
37
+ """
38
+ if not os.path.exists(src_path):
39
+ print("WARNING: Src-Path does not exist!")
40
+ FileManager.src_path = src_path
41
+
29
42
  def max_rate(
30
43
  fps: int | None = None,
31
44
  tick: int | None = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sverpykit
3
- Version: 0.2.13
3
+ Version: 0.2.15
4
4
  Summary: A wrapper for pygame.
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -9,12 +9,17 @@ sverpykit.egg-info/requires.txt
9
9
  sverpykit.egg-info/top_level.txt
10
10
  sverpykit/Collide/Collide.py
11
11
  sverpykit/Draw/Draw.py
12
+ sverpykit/Objects/Block.py
12
13
  sverpykit/Objects/Entity.py
14
+ sverpykit/Shapes/Circle.py
13
15
  sverpykit/Ui/Button.py
14
16
  sverpykit/Ui/DropDown.py
15
17
  sverpykit/Ui/SearchBar.py
16
18
  sverpykit/Ui/TextBlock.py
17
19
  sverpykit/Ui/Window.py
18
20
  sverpykit/core/Config.py
21
+ sverpykit/core/FileManager.py
22
+ sverpykit/core/Json.py
23
+ sverpykit/core/Objects.py
19
24
  sverpykit/core/Runtime.py
20
25
  sverpykit/core/initialize.py
@@ -1,13 +0,0 @@
1
- import pygame
2
-
3
- def rect_rect(
4
- rect1: pygame.Rect,
5
- rect2: pygame.Rect
6
- ):
7
- return rect1.colliderect(rect2)
8
-
9
- def rect_point(
10
- rect: pygame.Rect,
11
- point: tuple[int, int]
12
- ):
13
- return rect.collidepoint(point)
@@ -1,68 +0,0 @@
1
- from sverpykit.core import Config
2
- from typing import Callable, Any
3
- import pygame
4
-
5
- class Entity:
6
- def __init__(
7
- self,
8
- hitbox: pygame.Rect,
9
- surface: pygame.Surface,
10
- player_events: dict[str, Callable] | None = None,
11
- statistics: dict[str, Any] | None = None,
12
- states: dict[str, Any] | None = None
13
- ):
14
- player_events = player_events if isinstance(player_events, dict)\
15
- else {}
16
- statistics = statistics if isinstance(statistics, dict)\
17
- else {}
18
- states = states if isinstance(states, dict)\
19
- else {}
20
- self.hitbox = hitbox
21
- self.surface = surface
22
-
23
- self.states = {
24
- "vy": 0,
25
- "vx": 0,
26
- "show_hitbox": False
27
- }
28
- self.states.update(states)
29
-
30
- self.stats = {
31
- "speed": 100,
32
- "jump_power": 15
33
- }
34
- self.stats.update(statistics)
35
-
36
- self.accepted_events = {
37
- "key": self.key_events,
38
- "mouse": self.mouse_events
39
- }
40
- self.accepted_events.update(player_events)
41
-
42
- def key_events(self, keys: dict):
43
- pass
44
-
45
- def mouse_events(self, button, pos):
46
- pass
47
-
48
- def draw(self):
49
- Config.screen.blit(
50
- self.surface, self.hitbox
51
- )
52
- if self.states["show_hitbox"]:
53
- pygame.draw.rect(
54
- Config.screen,
55
- (255, 255, 255),
56
- self.hitbox,
57
- width=1
58
- )
59
-
60
- def events(self):
61
- self.hitbox.y -= self.states["vy"] * Config.delta_time
62
- click = pygame.mouse.get_pressed()
63
- mp = pygame.mouse.get_pos()
64
- if any(click):
65
- self.accepted_events["mouse"](click, mp)
66
- keys = pygame.key.get_pressed()
67
- if any(keys):
68
- self.accepted_events["key"](keys)
File without changes
File without changes
File without changes