batframework 1.0.8a1__py3-none-any.whl → 1.0.8a2__py3-none-any.whl
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.
- batFramework/__init__.py +50 -53
- batFramework/action.py +105 -116
- batFramework/actionContainer.py +11 -53
- batFramework/animatedSprite.py +65 -115
- batFramework/audioManager.py +26 -70
- batFramework/camera.py +68 -253
- batFramework/constants.py +54 -16
- batFramework/cutscene.py +25 -34
- batFramework/cutsceneBlocks.py +42 -37
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +7 -9
- batFramework/easing.py +71 -0
- batFramework/entity.py +98 -42
- batFramework/gui/__init__.py +2 -8
- batFramework/gui/button.py +79 -7
- batFramework/gui/constraints.py +204 -0
- batFramework/gui/container.py +31 -155
- batFramework/gui/debugger.py +43 -124
- batFramework/gui/frame.py +19 -0
- batFramework/gui/image.py +17 -41
- batFramework/gui/indicator.py +21 -41
- batFramework/gui/interactiveWidget.py +13 -116
- batFramework/gui/label.py +73 -278
- batFramework/gui/layout.py +61 -148
- batFramework/gui/root.py +37 -102
- batFramework/gui/shape.py +57 -258
- batFramework/gui/toggle.py +46 -97
- batFramework/gui/widget.py +254 -268
- batFramework/manager.py +19 -40
- batFramework/particles.py +77 -0
- batFramework/scene.py +107 -214
- batFramework/sceneManager.py +107 -150
- batFramework/stateMachine.py +0 -1
- batFramework/time.py +57 -117
- batFramework/transition.py +126 -184
- batFramework/transitionManager.py +0 -0
- batFramework/utils.py +161 -34
- batframework-1.0.8a2.dist-info/METADATA +58 -0
- batframework-1.0.8a2.dist-info/RECORD +42 -0
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/WHEEL +1 -1
- batFramework/easingController.py +0 -58
- batFramework/enums.py +0 -104
- batFramework/fontManager.py +0 -65
- batFramework/gui/clickableWidget.py +0 -206
- batFramework/gui/constraints/__init__.py +0 -1
- batFramework/gui/constraints/constraints.py +0 -378
- batFramework/gui/dialogueBox.py +0 -96
- batFramework/gui/draggableWidget.py +0 -38
- batFramework/gui/meter.py +0 -76
- batFramework/gui/radioButton.py +0 -62
- batFramework/gui/slider.py +0 -220
- batFramework/gui/textInput.py +0 -134
- batFramework/object.py +0 -115
- batFramework/particle.py +0 -101
- batFramework/renderGroup.py +0 -62
- batFramework/resourceManager.py +0 -84
- batFramework/scrollingSprite.py +0 -113
- batFramework/sprite.py +0 -45
- batFramework/tileset.py +0 -46
- batframework-1.0.8a1.dist-info/LICENCE +0 -21
- batframework-1.0.8a1.dist-info/METADATA +0 -55
- batframework-1.0.8a1.dist-info/RECORD +0 -56
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/top_level.txt +0 -0
batFramework/transition.py
CHANGED
@@ -1,215 +1,157 @@
|
|
1
|
-
import batFramework as bf
|
2
|
-
from typing import Self
|
3
1
|
import pygame
|
4
|
-
|
5
|
-
"""
|
6
|
-
Both surfaces to transition need to be the same size
|
7
|
-
|
8
|
-
"""
|
9
|
-
|
10
|
-
|
11
|
-
class Transition:
|
12
|
-
def __init__(
|
13
|
-
self, duration: float, easing_function: bf.easing = bf.easing.LINEAR
|
14
|
-
) -> None:
|
15
|
-
"""
|
16
|
-
duration : time in seconds
|
17
|
-
easing function : controls the progression rate
|
18
|
-
"""
|
19
|
-
self.duration: float = duration
|
20
|
-
self.controller = bf.EasingController(
|
21
|
-
easing_function,
|
22
|
-
duration,
|
23
|
-
update_callback=self.update,
|
24
|
-
end_callback=self.end,
|
25
|
-
)
|
26
|
-
self.start_callback = None
|
27
|
-
self.update_callback = None
|
28
|
-
self.end_callback = None
|
29
|
-
self.source: pygame.Surface = None
|
30
|
-
self.dest: pygame.Surface = None
|
31
|
-
|
32
|
-
def __repr__(self) -> str:
|
33
|
-
return f"Transition {self.__class__},{self.duration}"
|
34
|
-
|
35
|
-
def set_start_callback(self, func) -> Self:
|
36
|
-
self.start_callback = func
|
37
|
-
return self
|
38
|
-
|
39
|
-
def set_update_callback(self, func) -> Self:
|
40
|
-
self.update_callback = func
|
41
|
-
return self
|
42
|
-
|
43
|
-
def set_end_callback(self, func) -> Self:
|
44
|
-
self.end_callback = func
|
45
|
-
return self
|
46
|
-
|
47
|
-
def set_source(self, surface: pygame.Surface) -> None:
|
48
|
-
self.source = surface
|
49
|
-
|
50
|
-
def set_dest(self, surface: pygame.Surface) -> None:
|
51
|
-
self.dest = surface
|
52
|
-
|
53
|
-
def start(self):
|
54
|
-
if self.controller.has_started():
|
55
|
-
return
|
56
|
-
if self.duration:
|
57
|
-
self.controller.start()
|
58
|
-
if self.start_callback:
|
59
|
-
self.start_callback()
|
60
|
-
return
|
61
|
-
|
62
|
-
self.controller.start()
|
63
|
-
if self.start_callback:
|
64
|
-
self.start_callback()
|
65
|
-
self.controller.end()
|
66
|
-
self.update(1)
|
67
|
-
self.end()
|
68
|
-
|
69
|
-
def update(self, progression: float) -> None:
|
70
|
-
if self.update_callback:
|
71
|
-
self.update_callback(progression)
|
72
|
-
|
73
|
-
def end(self):
|
74
|
-
self.controller.stop()
|
75
|
-
if self.end_callback:
|
76
|
-
self.end_callback()
|
77
|
-
|
78
|
-
def draw(self, surface: pygame.Surface) -> None:
|
79
|
-
pass
|
80
|
-
|
81
|
-
def skip(self, no_callback: bool = False):
|
82
|
-
self.controller.stop()
|
83
|
-
if self.end_callback and (no_callback == False):
|
84
|
-
self.end_callback()
|
2
|
+
import batFramework as bf
|
85
3
|
|
86
4
|
|
87
|
-
class
|
5
|
+
class BaseTransition:
|
88
6
|
def __init__(
|
89
7
|
self,
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
easing_function: bf.easing = bf.easing.LINEAR,
|
8
|
+
source_surf: pygame.Surface,
|
9
|
+
dest_surf: pygame.Surface,
|
10
|
+
duration=100,
|
11
|
+
**kwargs,
|
95
12
|
) -> None:
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
13
|
+
self.source = source_surf
|
14
|
+
self.dest = dest_surf
|
15
|
+
self.ended = False
|
16
|
+
self.source_scene_name = ""
|
17
|
+
self.dest_scene_name = ""
|
18
|
+
self.duration = duration
|
101
19
|
self.index = 0
|
102
|
-
self.first = Fade(first_duration)
|
103
|
-
self.color = color
|
104
|
-
self.second = Fade(second_duration).set_end_callback(
|
105
|
-
lambda: self.next_step(self.end)
|
106
|
-
)
|
107
|
-
self.timer = bf.Timer(
|
108
|
-
middle_duration, lambda: self.next_step(self.second.start)
|
109
|
-
)
|
110
|
-
self.first.set_end_callback(lambda: self.next_step(self.timer.start))
|
111
|
-
|
112
|
-
def next_step(self, callback=None) -> None:
|
113
|
-
self.index += 1
|
114
|
-
if callback:
|
115
|
-
callback()
|
116
20
|
|
117
|
-
def
|
118
|
-
|
119
|
-
self.first.set_source(surface)
|
21
|
+
def set_scene_index(self,index):
|
22
|
+
self.index = index
|
120
23
|
|
121
|
-
def
|
122
|
-
|
123
|
-
self.second.set_dest(surface)
|
24
|
+
def set_source_name(self, name):
|
25
|
+
self.source_scene_name = name
|
124
26
|
|
125
|
-
def
|
126
|
-
|
127
|
-
self.start_callback()
|
128
|
-
self.color_surf = pygame.Surface(self.source.get_size())
|
129
|
-
self.color_surf.fill(self.color)
|
27
|
+
def set_dest_name(self, name):
|
28
|
+
self.dest_scene_name = name
|
130
29
|
|
131
|
-
|
132
|
-
|
133
|
-
self.first.start()
|
30
|
+
def update(self, dt):
|
31
|
+
pass
|
134
32
|
|
135
33
|
def draw(self, surface):
|
136
|
-
|
137
|
-
self.first.draw(surface)
|
138
|
-
elif self.index == 1:
|
139
|
-
surface.blit(self.color_surf, (0, 0))
|
140
|
-
else:
|
141
|
-
self.second.draw(surface)
|
142
|
-
|
143
|
-
def skip(self, no_callback: bool = False):
|
144
|
-
if (no_callback == False) and self.end_callback:
|
145
|
-
self.end_callback()
|
146
|
-
|
147
|
-
self.first.controller.stop()
|
148
|
-
self.timer.stop()
|
149
|
-
self.second.controller.stop()
|
34
|
+
pass
|
150
35
|
|
36
|
+
def has_ended(self):
|
37
|
+
return False
|
151
38
|
|
152
|
-
|
153
|
-
|
154
|
-
self.dest.set_alpha(255)
|
155
|
-
return super().end()
|
39
|
+
def set_ended(self, val):
|
40
|
+
self.ended = val
|
156
41
|
|
157
|
-
def draw(self, surface):
|
158
|
-
dest_alpha = 255 * self.controller.get_value()
|
159
|
-
self.dest.set_alpha(dest_alpha)
|
160
|
-
surface.blit(self.source, (0, 0))
|
161
|
-
surface.blit(self.dest, (0, 0))
|
162
42
|
|
43
|
+
class FadeColorTransition(BaseTransition):
|
44
|
+
def __init__(
|
45
|
+
self,
|
46
|
+
source_surf,
|
47
|
+
dest_surf,
|
48
|
+
duration=600,
|
49
|
+
color_duration=200,
|
50
|
+
color=bf.color.CLOUD_WHITE,
|
51
|
+
**kwargs,
|
52
|
+
) -> None:
|
53
|
+
super().__init__(source_surf, dest_surf, duration)
|
54
|
+
self.target_time = duration * 2 + color_duration
|
55
|
+
self.color_surf = pygame.Surface((source_surf.get_rect().size)).convert_alpha()
|
56
|
+
self.color_surf.fill(color)
|
57
|
+
self.ease_out = bf.EasingAnimation(
|
58
|
+
easing_function=bf.Easing.EASE_IN,
|
59
|
+
duration=(duration-color_duration)//2,
|
60
|
+
update_callback = lambda x: self.color_surf.set_alpha(int(255 - (255 * x))),
|
61
|
+
end_callback=lambda: self.set_ended(True))
|
62
|
+
|
63
|
+
self.color_timer = bf.Timer(
|
64
|
+
duration=color_duration,
|
65
|
+
end_callback=lambda: self.set_state("out"))
|
66
|
+
self.ease_in = bf.EasingAnimation(
|
67
|
+
easing_function=bf.Easing.EASE_IN,
|
68
|
+
duration=(duration-color_duration)//2,
|
69
|
+
update_callback=lambda x: self.color_surf.set_alpha(int(255 * x)),
|
70
|
+
# update_callback=lambda x: print(x),
|
71
|
+
end_callback=lambda: self.set_state("color"))
|
72
|
+
self.state = None
|
73
|
+
|
74
|
+
self.state = "in"
|
75
|
+
self.ease_in.start()
|
76
|
+
|
77
|
+
def set_state(self, state: str):
|
78
|
+
self.state = state
|
79
|
+
if state == "in":
|
80
|
+
self.ease_in.start()
|
81
|
+
elif state == "color":
|
82
|
+
self.color_timer.start()
|
83
|
+
elif state == "out":
|
84
|
+
self.ease_out.start()
|
85
|
+
|
86
|
+
def has_ended(self):
|
87
|
+
return self.ended
|
88
|
+
|
89
|
+
def set_ended(self, val):
|
90
|
+
super().set_ended(val)
|
163
91
|
|
164
|
-
class GlideRight(Transition):
|
165
92
|
def draw(self, surface):
|
166
|
-
|
167
|
-
|
168
|
-
surface.blit(self.
|
169
|
-
surface.blit(self.dest, (width + source_x, 0))
|
93
|
+
if self.state != "color":
|
94
|
+
surface.blit(self.source if self.state == "in" else self.dest, (0, 0))
|
95
|
+
surface.blit(self.color_surf, (0, 0))
|
170
96
|
|
171
97
|
|
172
|
-
class
|
173
|
-
def
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
surface.blit(self.dest, (source_x - width, 0))
|
98
|
+
class FadeTransition(BaseTransition):
|
99
|
+
def __init__(self, source_surf, dest_surf, duration=500) -> None:
|
100
|
+
super().__init__(source_surf, dest_surf)
|
101
|
+
self.anim = bf.EasingAnimation(None,bf.Easing.EASE_IN_OUT,duration,self.update_surface,lambda : self.set_ended(True))
|
102
|
+
self.anim.start()
|
178
103
|
|
104
|
+
def update_surface(self,progress):
|
105
|
+
self.source.set_alpha(int(255 - (255 * progress)))
|
106
|
+
self.dest.set_alpha(int(255 * progress))
|
179
107
|
|
180
|
-
|
181
|
-
|
182
|
-
super().start()
|
183
|
-
self.circle_surf = self.source.copy()
|
184
|
-
self.circle_surf.set_colorkey((0, 0, 0))
|
185
|
-
self.circle_surf.fill((0, 0, 0))
|
186
|
-
self.surface_width = self.circle_surf.get_width()
|
108
|
+
def has_ended(self):
|
109
|
+
return self.ended
|
187
110
|
|
188
111
|
def draw(self, surface):
|
189
|
-
|
112
|
+
surface.blit(self.source, (0, 0))
|
113
|
+
surface.blit(self.dest, (0, 0))
|
114
|
+
|
190
115
|
|
191
|
-
|
192
|
-
|
193
|
-
|
116
|
+
class SlideTransition(BaseTransition):
|
117
|
+
def __init__(
|
118
|
+
self,
|
119
|
+
source_surf,
|
120
|
+
dest_surf,
|
121
|
+
duration=1000,
|
122
|
+
source_alignment: bf.Alignment = bf.Alignment.BOTTOM,
|
123
|
+
easing: bf.Easing = bf.Easing.EASE_IN_OUT,
|
124
|
+
**kwargs,
|
125
|
+
) -> None:
|
126
|
+
super().__init__(source_surf, dest_surf, duration)
|
127
|
+
self.offset = pygame.Vector2(0, 0)
|
128
|
+
if source_alignment in [bf.Alignment.TOP, bf.Alignment.BOTTOM]:
|
129
|
+
self.offset.y = bf.const.RESOLUTION[1]
|
130
|
+
if source_alignment == bf.Alignment.TOP:
|
131
|
+
self.offset.y *= -1
|
132
|
+
elif source_alignment in [bf.Alignment.LEFT, bf.Alignment.RIGHT]:
|
133
|
+
self.offset.x = bf.const.RESOLUTION[0]
|
134
|
+
if source_alignment == bf.Alignment.LEFT:
|
135
|
+
self.offset.x *= -1
|
136
|
+
else:
|
137
|
+
self.offset.x = -bf.const.RESOLUTION[0]
|
138
|
+
print(
|
139
|
+
f"Unsupported Alignment : {source_alignment.value}, set to default : {bf.Alignment.LEFT.value} "
|
140
|
+
)
|
141
|
+
self.anim = bf.EasingAnimation(
|
142
|
+
easing_function=easing,
|
143
|
+
duration=duration,
|
144
|
+
update_callback =lambda x: self.update_offset(self.offset.lerp((0, 0), x)),
|
145
|
+
end_callback =lambda: self.set_ended(True),
|
194
146
|
)
|
195
|
-
|
196
|
-
mask.to_surface(surface=surface, setsurface=self.dest, unsetsurface=self.source)
|
147
|
+
self.anim.start()
|
197
148
|
|
149
|
+
def update_offset(self, vec):
|
150
|
+
self.offset.update(vec)
|
198
151
|
|
199
|
-
|
200
|
-
|
201
|
-
super().start()
|
202
|
-
self.circle_surf = self.source.copy()
|
203
|
-
self.circle_surf.set_colorkey((0, 0, 0))
|
204
|
-
self.circle_surf.fill((0, 0, 0))
|
205
|
-
self.surface_width = self.circle_surf.get_width()
|
152
|
+
def has_ended(self):
|
153
|
+
return self.ended
|
206
154
|
|
207
155
|
def draw(self, surface):
|
208
|
-
|
209
|
-
|
210
|
-
self.circle_surf.fill((0, 0, 0))
|
211
|
-
pygame.draw.circle(
|
212
|
-
self.circle_surf, "white", self.circle_surf.get_rect().center, radius
|
213
|
-
)
|
214
|
-
mask = pygame.mask.from_surface(self.circle_surf)
|
215
|
-
mask.to_surface(surface=surface, setsurface=self.source, unsetsurface=self.dest)
|
156
|
+
surface.blit(self.source, (0, 0))
|
157
|
+
surface.blit(self.dest, self.offset)
|
File without changes
|
batFramework/utils.py
CHANGED
@@ -3,8 +3,10 @@ from enum import Enum
|
|
3
3
|
import os
|
4
4
|
import batFramework as bf
|
5
5
|
import json
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
MAX_FONT_SIZE = 100
|
8
|
+
MIN_FONT_SIZE = 8
|
9
|
+
|
8
10
|
class Singleton(type):
|
9
11
|
_instances = {}
|
10
12
|
|
@@ -14,44 +16,169 @@ class Singleton(type):
|
|
14
16
|
return cls._instances[cls]
|
15
17
|
|
16
18
|
|
19
|
+
class Direction(Enum):
|
20
|
+
HORIZONTAL = "horizontal"
|
21
|
+
VERTICAL = "vertical"
|
22
|
+
|
23
|
+
|
24
|
+
class Alignment(Enum):
|
25
|
+
LEFT = "left"
|
26
|
+
RIGHT = "right"
|
27
|
+
CENTER = "center"
|
28
|
+
TOP = "top"
|
29
|
+
BOTTOM = "bottom"
|
30
|
+
|
31
|
+
|
32
|
+
class Layout(Enum):
|
33
|
+
FILL = "fill"
|
34
|
+
FIT = "fit"
|
35
|
+
|
36
|
+
|
17
37
|
class Utils:
|
38
|
+
pygame.font.init()
|
39
|
+
FONTS = {}
|
40
|
+
tilesets = {}
|
41
|
+
|
42
|
+
@staticmethod
|
43
|
+
def get_path(path: str):
|
44
|
+
return os.path.join(bf.const.RESOURCE_PATH, path)
|
18
45
|
|
19
46
|
@staticmethod
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
"""
|
28
|
-
if surface is None:
|
47
|
+
def load_json_from_file(path: str) -> dict:
|
48
|
+
try:
|
49
|
+
with open(Utils.get_path(path), "r") as file:
|
50
|
+
data = json.load(file)
|
51
|
+
return data
|
52
|
+
except FileNotFoundError:
|
53
|
+
print(f"File '{path}' not found")
|
29
54
|
return None
|
30
|
-
width, height = surface.get_size()
|
31
|
-
res = {}
|
32
|
-
for iy, y in enumerate(range(0, height, split_size[1])):
|
33
|
-
for ix, x in enumerate(range(0, width, split_size[0])):
|
34
|
-
sub = surface.subsurface((x, y, split_size[0], split_size[1]))
|
35
55
|
|
36
|
-
|
37
|
-
|
56
|
+
@staticmethod
|
57
|
+
def save_json_to_file(path: str, data) -> bool:
|
58
|
+
try:
|
59
|
+
with open(Utils.get_path(path), "w") as file:
|
60
|
+
json.dump(data, file, indent=2)
|
61
|
+
return True
|
62
|
+
except FileNotFoundError:
|
63
|
+
return False
|
64
|
+
|
65
|
+
@staticmethod
|
66
|
+
def init_font(raw_path:str):
|
67
|
+
try :
|
68
|
+
if raw_path is not None:
|
69
|
+
Utils.load_font(raw_path if raw_path else None,None)
|
70
|
+
Utils.load_font(raw_path)
|
71
|
+
except FileNotFoundError:
|
72
|
+
Utils.load_sysfont(raw_path)
|
73
|
+
Utils.load_sysfont(raw_path,None)
|
38
74
|
|
39
|
-
res[(ix, iy)] = sub
|
40
75
|
|
41
|
-
return res
|
42
|
-
|
43
76
|
@staticmethod
|
44
|
-
def
|
45
|
-
if
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
77
|
+
def load_font(path:str,name:str=''):
|
78
|
+
if path is not None: path = Utils.get_path(path) # convert path if given
|
79
|
+
filename = os.path.basename(path).split('.')[0] if path is not None else None # get filename if path is given, else None
|
80
|
+
if name != '' : filename = name # if name is not given, name is the filename
|
81
|
+
Utils.FONTS[filename] = {}
|
82
|
+
# fill the dict
|
83
|
+
for size in range(MIN_FONT_SIZE, MAX_FONT_SIZE, 2):
|
84
|
+
Utils.FONTS[filename][size] = pygame.font.Font(path,size=size)
|
85
|
+
|
86
|
+
def load_sysfont(font_name:str,key:str=''):
|
87
|
+
if key == '' : key = font_name
|
88
|
+
if pygame.font.match_font(font_name) is None:
|
89
|
+
raise FileNotFoundError(f"Requested font '{font_namey}' was not found")
|
90
|
+
Utils.FONTS[font_name] = {}
|
91
|
+
|
92
|
+
for size in range(MIN_FONT_SIZE, MAX_FONT_SIZE, 2):
|
93
|
+
Utils.FONTS[key][size] = pygame.font.SysFont(font_name,size=size)
|
94
|
+
|
95
|
+
|
96
|
+
@staticmethod
|
97
|
+
def get_font(name:str|None=None,text_size:int=12) -> pygame.Font:
|
98
|
+
if not name in Utils.FONTS: return None
|
99
|
+
if not text_size in Utils.FONTS[name]: return None
|
100
|
+
return Utils.FONTS[name][text_size]
|
101
|
+
|
102
|
+
class Tileset:
|
103
|
+
_flip_cache = {} # {"tileset":tileset,"index","flipX","flipY"}
|
104
|
+
|
105
|
+
def __init__(self, surface: pygame.Surface, tilesize) -> None:
|
106
|
+
self.tile_dict = {}
|
107
|
+
self.surface = surface
|
108
|
+
self.tile_size = tilesize
|
109
|
+
self.split_surface(surface)
|
110
|
+
|
111
|
+
def split_surface(self, surface: pygame.Surface):
|
112
|
+
width, height = surface.get_size()
|
113
|
+
num_tiles_x = width // self.tile_size
|
114
|
+
num_tiles_y = height // self.tile_size
|
115
|
+
# Iterate over the tiles vertically and horizontally
|
116
|
+
for y in range(num_tiles_y):
|
117
|
+
for x in range(num_tiles_x):
|
118
|
+
# Calculate the coordinates of the current tile in the tileset
|
119
|
+
tile_x = x * self.tile_size
|
120
|
+
tile_y = y * self.tile_size
|
121
|
+
# Create a subsurface for the current tile
|
122
|
+
tile_surface = surface.subsurface(
|
123
|
+
pygame.Rect(tile_x, tile_y, self.tile_size, self.tile_size)
|
124
|
+
)
|
125
|
+
# Calculate the unique key for the tile (e.g., based on its coordinates)
|
126
|
+
tile_key = (x, y)
|
127
|
+
# Store the subsurface in the dictionary with the corresponding key
|
128
|
+
self.tile_dict[tile_key] = tile_surface
|
129
|
+
# print(self.tile_dict)
|
130
|
+
|
131
|
+
def get_tile(self, x, y, flipX=False, flipY=False) -> pygame.Surface | None:
|
132
|
+
if (x, y) not in self.tile_dict:
|
133
|
+
return None
|
134
|
+
if flipX or flipY:
|
135
|
+
key = f"{x}{y}:{flipX}{flipY}"
|
136
|
+
if not key in self._flip_cache:
|
137
|
+
self._flip_cache[key] = pygame.transform.flip(
|
138
|
+
self.tile_dict[(x, y)], flipX, flipY
|
139
|
+
)
|
140
|
+
return self._flip_cache[key]
|
141
|
+
return self.tile_dict[(x, y)]
|
142
|
+
|
143
|
+
@staticmethod
|
144
|
+
def img_slice(file, cell_width, cell_height, flipX=False) -> list[pygame.Surface]:
|
145
|
+
src = pygame.image.load(
|
146
|
+
os.path.join(bf.const.RESOURCE_PATH, file)
|
147
|
+
).convert_alpha()
|
148
|
+
width, height = src.get_size()
|
149
|
+
res = []
|
150
|
+
for y in range(0, height, cell_height):
|
151
|
+
for x in range(0, width, cell_width):
|
152
|
+
sub = src.subsurface((x, y, cell_width, cell_height))
|
153
|
+
if flipX:
|
154
|
+
sub = pygame.transform.flip(sub, True, False)
|
155
|
+
|
156
|
+
res.append(sub)
|
157
|
+
return res
|
158
|
+
|
159
|
+
def load_tileset(path: str, name: str, tilesize):
|
160
|
+
if name in Utils.tilesets:
|
161
|
+
return Utils.tilesets[name]
|
51
162
|
else:
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
163
|
+
img = pygame.image.load(
|
164
|
+
os.path.join(bf.const.RESOURCE_PATH, path)
|
165
|
+
).convert_alpha()
|
166
|
+
tileset = Utils.Tileset(img, tilesize)
|
167
|
+
Utils.tilesets[name] = tileset
|
168
|
+
return tileset
|
169
|
+
|
170
|
+
@staticmethod
|
171
|
+
def get_tileset(name: str) -> Tileset:
|
172
|
+
if name not in Utils.tilesets:
|
173
|
+
return None
|
174
|
+
return Utils.tilesets[name]
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
def move_points(delta, *points):
|
181
|
+
res = []
|
182
|
+
for point in points:
|
183
|
+
res.append((point[0] + delta[0], point[1] + delta[1]))
|
184
|
+
return res
|
@@ -0,0 +1,58 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: batframework
|
3
|
+
Version: 1.0.8a2
|
4
|
+
Summary: Pygame framework for making games easier.
|
5
|
+
Author-email: Turan Baturay <baturayturan@gmail.com>
|
6
|
+
Project-URL: Homepage, https://github.com/TuranBaturay/batFramework
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
9
|
+
Classifier: Operating System :: OS Independent
|
10
|
+
Requires-Python: >=3.10
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
Requires-Dist: pygame-ce
|
13
|
+
|
14
|
+
# batFramework
|
15
|
+
|
16
|
+
batFramework is a Python game framework built using Pygame, designed to simplify game development by providing entities, scenes, a scene manager, and various utilities.
|
17
|
+
|
18
|
+
## Purpose and Overview
|
19
|
+
The primary objective of batFramework is to streamline game development by utilizing entities and scenes that hold entities. It employs a manager, which inherits from the scene manager, to handle scenes, propagate events, and manage updates and rendering.
|
20
|
+
|
21
|
+
## Installation and Setup
|
22
|
+
To install batFramework, you can use pip:
|
23
|
+
```pip install batFramework```
|
24
|
+
|
25
|
+
|
26
|
+
The only dependency required is pygame-ce.
|
27
|
+
|
28
|
+
## Usage Instructions
|
29
|
+
To create a basic app using batFramework, here's an example:
|
30
|
+
|
31
|
+
```python
|
32
|
+
import batFramework as bf
|
33
|
+
|
34
|
+
# Initialize the framework
|
35
|
+
bf.init((1280, 720), window_title="My Amazing Program")
|
36
|
+
|
37
|
+
# Create a manager and a scene
|
38
|
+
bf.Manager(bf.Scene("main")).run()
|
39
|
+
```
|
40
|
+
In practice, users can inherit bf.Scene to create their own scenes, adding specific behaviors, entities, etc.
|
41
|
+
|
42
|
+
## Features and Functionalities
|
43
|
+
|
44
|
+
- Scene management for organizing game components
|
45
|
+
- Cutscene support to facilitate storytelling sequences
|
46
|
+
- Audio management for music and sound effects with volume control
|
47
|
+
- Entity, sprite, and animated sprite support
|
48
|
+
- Utility modules such as time management and easingAnimation
|
49
|
+
|
50
|
+
Users can leverage these functionalities to build games efficiently using batFramework.
|
51
|
+
|
52
|
+
For more detailed usage and examples, please refer to the documentation or codebase.
|
53
|
+
|
54
|
+
|
55
|
+
# License
|
56
|
+
MIT License
|
57
|
+
|
58
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
batFramework/__init__.py,sha256=MLVXC2ymkO3k8LdCgB6TbahgJfhxk4GKAbmndmEgZS4,2146
|
2
|
+
batFramework/action.py,sha256=Phk6-q2P-XyV2GVlXPpxyje0due4fIrKnhI1_4anfjI,7600
|
3
|
+
batFramework/actionContainer.py,sha256=K9dIgG559ckxzRB3t-lpON4dFTcM2mcKZfsf4bhuJ1k,1092
|
4
|
+
batFramework/animatedSprite.py,sha256=kJPKrTOfkbQu2uYDziIEop1z6-gjBwZxkC1Rxd_vBwE,3992
|
5
|
+
batFramework/audioManager.py,sha256=5UsDPy4zsDO7Va1y1kM4lSpEJXU95o9F01E-Sts3osg,2546
|
6
|
+
batFramework/camera.py,sha256=wt4TyWTgQmQElBVeFI7ONzNI75r0FKtB3KmNH00GeFM,4322
|
7
|
+
batFramework/constants.py,sha256=FSyEYLxdAb3JaXA11sAwZBfAImedASohpFcd_7qnG0I,2075
|
8
|
+
batFramework/cutscene.py,sha256=5aiIQeWGmvHCb-N3vjmwxhE4dCXv3iZRFHiexSNxCXM,3650
|
9
|
+
batFramework/cutsceneBlocks.py,sha256=1gmof0jKJ8SqE-RoErm6n1A0JJ4Ang9Q30xEZnW9NaI,5123
|
10
|
+
batFramework/debugger.py,sha256=gh5kOUmGr4t-BFXA17tImid4nzxUqrhsUhE_JV9srNg,1671
|
11
|
+
batFramework/dynamicEntity.py,sha256=REIqH0jnfX6yUThoQNkQrsG0390TR6C5la1h2MAioYk,665
|
12
|
+
batFramework/easing.py,sha256=vGkk7FDPj27X7NCJXALCEyVKDbpXXebWYtMvxkbhOh0,2217
|
13
|
+
batFramework/entity.py,sha256=Tw4_PIA_sY8fhbj9TjE6wPcDTrZZX_Tj7l8oKquqe8U,3178
|
14
|
+
batFramework/manager.py,sha256=LdiQVyuPQE23jwO4EjR4zqDymxtRmthUJ7VE7RIEDpU,1583
|
15
|
+
batFramework/particles.py,sha256=PX8zSqOS1gyDloGAz3fAlrto51lWMUpBXDIM152EYWc,2172
|
16
|
+
batFramework/scene.py,sha256=KM1e53ZfPvuJoSGQZaEl_IouWRYCbFq0QOYTuXYCr-E,7324
|
17
|
+
batFramework/sceneManager.py,sha256=sFkQbfMuR19M4duvCf0SOxSY7MkMrkmiiKh72-tC1nI,5743
|
18
|
+
batFramework/stateMachine.py,sha256=_er9_dcm6MLmlTjXTVm175eqZ9puaKb31PFmNPRhcSU,1338
|
19
|
+
batFramework/time.py,sha256=iGV9mxUFrdXsvm4fJ1faX-VYNsOH7DX2N_aXsDRHhmM,2403
|
20
|
+
batFramework/transition.py,sha256=wmL1Mgg_xopzeDbEPJyAmllLB2BCRJZtuMOR7Mez480,4873
|
21
|
+
batFramework/transitionManager.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
22
|
+
batFramework/triggerZone.py,sha256=ikOOlJT1KIND0MO2xiilCHuKlb1eQhkCMEhZTi1btsI,586
|
23
|
+
batFramework/utils.py,sha256=EUB3bMldWTYFVZxcJk5_7XAWcEz080P7PT5ZtkO5TAQ,6164
|
24
|
+
batFramework/gui/__init__.py,sha256=azu5HpC8Q9kupythU5GN5blt7K9oH55oXlOeXsIw1Mw,391
|
25
|
+
batFramework/gui/button.py,sha256=05RMQ20P5npgU9QmiT8v6abJhnhjqRgYbpZGaQXr6Bg,2703
|
26
|
+
batFramework/gui/constraints.py,sha256=pUTNwJqI2Tu57l8ZeQXVXg3b5F5t3aR4Us-CD5qXwnM,7544
|
27
|
+
batFramework/gui/container.py,sha256=XAkPZ0BOVXxzxWP5mKDF_MjYPPPAmUBY-J5zIadO0wQ,1480
|
28
|
+
batFramework/gui/debugger.py,sha256=JORHcSYQQCZ0tDzjnNQvDSOOjZVwEQLeqlr8e6xk2RI,1379
|
29
|
+
batFramework/gui/frame.py,sha256=zjHwbQT1fpRuvNgfBGZhMO_GdMEWqExa5dNlN9kUnUM,514
|
30
|
+
batFramework/gui/image.py,sha256=goOcPntsJeTb3LR7avzi4cXfYHwyGb0KXYttbCiE6fA,777
|
31
|
+
batFramework/gui/indicator.py,sha256=OgqDFsi2HCfbSzVjHkHO_shmo4q4ro3wfd0LWSLTJeQ,957
|
32
|
+
batFramework/gui/interactiveWidget.py,sha256=rRElxI1eFkvOeTfTaA6f8kVTOswOD-DFLAJDUCAI_Yk,641
|
33
|
+
batFramework/gui/label.py,sha256=EO1J5zPVe1skHz-KVqXKBZVKug8UVJUCXyHnvdRDuig,3586
|
34
|
+
batFramework/gui/layout.py,sha256=HyVhYTy1AQacALg6XMY5aX5lj7WY__HCCh8sTSBXwgI,3210
|
35
|
+
batFramework/gui/root.py,sha256=mhlu8ohqq8N-8q__ugv_tGRgPv-1jIHXBFezMFZ4mUM,1763
|
36
|
+
batFramework/gui/shape.py,sha256=CYaD0BdCiuGJO_tS2pALfKPlNGaGRNPzvy-Lk08_R8g,2490
|
37
|
+
batFramework/gui/toggle.py,sha256=jAeEyQXA893gDBUmjN7aoGgfsVln5RTODpSFB4LxwTY,2020
|
38
|
+
batFramework/gui/widget.py,sha256=1PkxThmet8nI5rvSDE6-iPtD_DsZkk-OxriZHbBZaFc,10509
|
39
|
+
batframework-1.0.8a2.dist-info/METADATA,sha256=YnyIVG7YvAIqBiqWVbeQ6h4tWUT7VHAHUr_Is1uQyJw,1980
|
40
|
+
batframework-1.0.8a2.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
41
|
+
batframework-1.0.8a2.dist-info/top_level.txt,sha256=vxAKBIk1oparFTxeXGBrgfIO7iq_YR5Fv1JvPVAIwmA,13
|
42
|
+
batframework-1.0.8a2.dist-info/RECORD,,
|