PyScene 1.0.5__tar.gz → 1.0.7__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 (25) hide show
  1. {pyscene-1.0.5 → pyscene-1.0.7}/PKG-INFO +3 -1
  2. {pyscene-1.0.5 → pyscene-1.0.7}/README.md +2 -0
  3. {pyscene-1.0.5 → pyscene-1.0.7}/pyproject.toml +1 -1
  4. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/Game.py +12 -13
  5. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/__init__.py +5 -1
  6. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/objs/GameObj.py +3 -1
  7. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/objs/Shapes.py +12 -12
  8. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/objs/Text.py +8 -8
  9. pyscene-1.0.7/src/PyScene/objs/Timer.py +33 -0
  10. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/objs/__init__.py +2 -1
  11. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/objs/animation.py +10 -10
  12. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/utils/Assets.py +8 -4
  13. {pyscene-1.0.5/tests → pyscene-1.0.7}/test.py +11 -2
  14. {pyscene-1.0.5 → pyscene-1.0.7}/.gitignore +0 -0
  15. {pyscene-1.0.5 → pyscene-1.0.7}/LICENSE +0 -0
  16. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/Collisions.py +0 -0
  17. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/Keys.py +0 -0
  18. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/Math.py +0 -0
  19. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/Net.py +0 -0
  20. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/objs/Collision_shapes.py +0 -0
  21. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/utils/Subscreen.py +0 -0
  22. {pyscene-1.0.5 → pyscene-1.0.7}/src/PyScene/utils/__init__.py +0 -0
  23. {pyscene-1.0.5 → pyscene-1.0.7}/tests/flappy_bird.py +0 -0
  24. {pyscene-1.0.5 → pyscene-1.0.7}/tests/pause.png +0 -0
  25. {pyscene-1.0.5 → pyscene-1.0.7}/tests/testColl.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: PyScene
3
- Version: 1.0.5
3
+ Version: 1.0.7
4
4
  Summary: A small example package
5
5
  Project-URL: Homepage, https://github.com/sfertig/PyScene
6
6
  Project-URL: Issues, https://github.com/sfertig/PyScene/issues
@@ -18,3 +18,5 @@ PyScene is a custom python + pygame framework / engine developed to streamline 2
18
18
 
19
19
  Please Note: This engine is still in development and many features, like tilemaps and audio, are a work in progress. It also lack any form of documentation, I ask for patience as docs will be rolled out once the core features are more solidified.
20
20
 
21
+ PyScene is in developement and API's may change offten, a fully stable version should come with v2.0.0, currently on v1.0.7
22
+
@@ -4,3 +4,5 @@ PyScene is a custom python + pygame framework / engine developed to streamline 2
4
4
 
5
5
  Please Note: This engine is still in development and many features, like tilemaps and audio, are a work in progress. It also lack any form of documentation, I ask for patience as docs will be rolled out once the core features are more solidified.
6
6
 
7
+ PyScene is in developement and API's may change offten, a fully stable version should come with v2.0.0, currently on v1.0.7
8
+
@@ -3,7 +3,7 @@ requires = ["hatchling >= 1.26"]
3
3
  build-backend = "hatchling.build"
4
4
  [project]
5
5
  name = "PyScene"
6
- version = "1.0.5"
6
+ version = "1.0.7"
7
7
  authors = [
8
8
  { name="Sam Fertig", email="sfertig007@gmail.com" },
9
9
  ]
@@ -96,7 +96,7 @@ class _game:
96
96
  def __update(self):
97
97
  self.click = False
98
98
  self.dt = self.clock.tick(self.fps)/1000.0
99
- self.events = pygame.event.get()
99
+ self.events = pygame.event.get().copy()
100
100
 
101
101
  for obj in self.dynamic_col: obj.update()
102
102
 
@@ -134,11 +134,11 @@ class _game:
134
134
  if _clear: self.screen.fill(self.bg)
135
135
  #render call
136
136
  if self.active_scene is None:
137
- for obj in self.render_queue: obj.render(self.cam)
137
+ for obj in self.render_queue: obj.render()
138
138
  #render scene
139
139
  else:
140
- self.active_scene.render(self.cam)
141
- self.active_scene._render(self.cam)
140
+ self.active_scene.render()
141
+ self.active_scene._render()
142
142
  if self.show_collisions: self.__render_collisions()
143
143
  #update screen
144
144
  pygame.display.flip()
@@ -179,23 +179,22 @@ class _game:
179
179
  self.queue_del_coll = []
180
180
  self._update_coll = False
181
181
 
182
- def set_scene(self, scene=None):
182
+ def _set_scene(self, scene=None):
183
183
  if self.active_scene is not None: self.active_scene.destroy()
184
184
  self._clear_all_collisions_()
185
- self.active_scene = self.scenes.get(scene, None)
186
- if self.active_scene: self.active_scene.on_change()
185
+ self.active_scene = scene
186
+ #if self.active_scene: self.active_scene.on_change()
187
187
 
188
188
 
189
189
  class Scene:
190
190
  def __init__(self, name):
191
191
  self.name = name
192
- Game.scenes[name] = self
193
192
  self._objects = []
194
193
  self._render_queue = []
195
194
  self.queue_creation = []
196
195
  self.queue_del = []
197
- Game.scenes[name] = self.__class__
198
- Game.set_scene(name)
196
+ if name not in Game.scenes: Game.scenes[name] = self.__class__
197
+ Game._set_scene(self)
199
198
 
200
199
  def on_change(self): pass
201
200
 
@@ -204,13 +203,13 @@ class Scene:
204
203
  self.__handle_queue()
205
204
  for obj in self._objects: obj.update()
206
205
 
207
- def render(self, cam): pass #user defined
208
- def _render(self, cam): #built in method
206
+ def render(self): pass #user defined
207
+ def _render(self): #built in method
209
208
  #update render queue based on global objects
210
209
  _length = len(self._objects)+len(Game.objects)
211
210
  if _length != len(self._render_queue): self.__update_render_queue()
212
211
  #render
213
- for obj in self._render_queue: obj.render(cam)
212
+ for obj in self._render_queue: obj.render()
214
213
 
215
214
  def _queue_add(self, obj): self.queue_creation.append(obj)
216
215
  def _queue_remove(self, obj): self.queue_del.append(obj)
@@ -1,6 +1,6 @@
1
1
  #imports
2
2
  "PyScene is a custom python + pygame framework / engine developed to streamline 2d game development."
3
- "Version: 1.0.5"
3
+ "Version: 1.0.7"
4
4
 
5
5
  from .Game import Game, Scene, handle_collision
6
6
  from .Math import *
@@ -26,6 +26,10 @@ __all__ = [
26
26
  "Line",
27
27
  "Text",
28
28
  "Image",
29
+ "Timer",
30
+
31
+ "Animation",
32
+ "AnimationManager",
29
33
 
30
34
  "StaticCollisionRect",
31
35
  "DynamicCollisionRect",
@@ -15,7 +15,9 @@ class GameObj: #this will be the base class of every game obj
15
15
  if not Global: Game._queue_add(self)
16
16
  else: Game.queue_creation.append(self) #if obj is just global anyway
17
17
 
18
+ self._global = Global
19
+
18
20
  def update(self): pass
19
- def render(self, cam): pass
21
+ def render(self): pass
20
22
  def destroy(self): Game._queue_remove(self)
21
23
 
@@ -5,8 +5,8 @@ from ..Game import Game
5
5
  from .GameObj import GameObj
6
6
 
7
7
  class Rect(GameObj):
8
- def __init__(self, x, y, w, h, color, z_index=0, width=0, active=True, visible=True, offset=True):
9
- super().__init__(Vector2D(x, y), z_index, active, visible)
8
+ def __init__(self, x, y, w, h, color, z_index=0, width=0, active=True, visible=True, offset=True, Global=False):
9
+ super().__init__(Vector2D(x, y), z_index, active, visible, Global)
10
10
  self.dim = Vector2D(w, h)
11
11
  self.color = color
12
12
  self.rect = pygame.Rect((x, y), (w, h))
@@ -16,30 +16,30 @@ class Rect(GameObj):
16
16
  def update(self):
17
17
  if self.pos.to_int() != self.rect.topleft: self.rect.topleft = self.pos.to_int()
18
18
 
19
- def render(self, cam):
19
+ def render(self):
20
20
  if not self.visible: return
21
- cam.draw_rect(self.rect, self.color, self.width, self.offset)
21
+ Game.cam.draw_rect(self.rect, self.color, self.width, self.offset)
22
22
 
23
23
  class Circle(GameObj):
24
- def __init__(self, x, y, r, color, z_index=0, width=0, active=True, visible=True, offset=True):
25
- super().__init__(Vector2D(x, y), z_index, active, visible)
24
+ def __init__(self, x, y, r, color, z_index=0, width=0, active=True, visible=True, offset=True, Global=False):
25
+ super().__init__(Vector2D(x, y), z_index, active, visible, Global)
26
26
  self.radius = r
27
27
  self.color = color
28
28
  self.width = width
29
29
  self.offset = offset
30
30
 
31
- def render(self, cam):
31
+ def render(self):
32
32
  if not self.visible: return
33
- cam.draw_circle(self.pos, self.radius, self.color, self.width, self.offset)
33
+ Game.cam.draw_circle(self.pos, self.radius, self.color, self.width, self.offset)
34
34
 
35
35
  class Line(GameObj):
36
- def __init__(self, x1, y1, x2, y2, color, z_index=0, width=1, active=True, visible=True, offset=True):
37
- super().__init__(Vector2D(x1, y1), z_index, active, visible)
36
+ def __init__(self, x1, y1, x2, y2, color, z_index=0, width=1, active=True, visible=True, offset=True, Global=False):
37
+ super().__init__(Vector2D(x1, y1), z_index, active, visible, Global)
38
38
  self.end = Vector2D(x2, y2)
39
39
  self.color = color
40
40
  self.width = width
41
41
  self.offset = offset
42
42
 
43
- def render(self, cam):
43
+ def render(self):
44
44
  if not self.visible: return
45
- cam.draw_line(self.pos, self.end, self.color, self.width, self.offset)
45
+ Game.cam.draw_line(self.pos, self.end, self.color, self.width, self.offset)
@@ -4,8 +4,8 @@ from .GameObj import GameObj
4
4
  import pygame
5
5
 
6
6
  class Text(GameObj):
7
- def __init__(self, font, text, color, pos=Vector2D(0, 0), align="center", z_index=0, active=True, visible=True, offset=True):
8
- super().__init__(pos, z_index, active, visible)
7
+ def __init__(self, font, text, color, pos=Vector2D(0, 0), align="center", z_index=0, active=True, visible=True, offset=True, Global=False):
8
+ super().__init__(pos, z_index, active, visible, Global)
9
9
  self.font = font
10
10
  self.text = text
11
11
  self.color = color
@@ -34,17 +34,17 @@ class Text(GameObj):
34
34
  self.pos = new_pos
35
35
  self.rect = self.surface.get_rect(**{self.align: self.pos})
36
36
 
37
- def render(self, cam):
37
+ def render(self):
38
38
  if not self.visible: return
39
- cam.draw_text(self.surface, self.rect, self.offset)
39
+ Game.cam.draw_text(self.surface, self.rect, self.offset)
40
40
 
41
41
  class Image(GameObj):
42
- def __init__(self, image, pos=Vector2D(0, 0), z_index=0, active=True, visible=True, offset=True):
43
- super().__init__(pos, z_index, active, visible)
42
+ def __init__(self, image, pos=Vector2D(0, 0), z_index=0, active=True, visible=True, offset=True, Global=False):
43
+ super().__init__(pos, z_index, active, visible, Global)
44
44
  self.image = image
45
45
  self.offset = offset
46
46
 
47
- def render(self, cam):
47
+ def render(self):
48
48
  if not self.visible: return
49
- cam.draw_image(self.image, self.pos, self.offset)
49
+ Game.cam.draw_image(self.image, self.pos, self.offset)
50
50
 
@@ -0,0 +1,33 @@
1
+ from .GameObj import GameObj
2
+ from ..Game import Game
3
+ from ..Math import Vector2D
4
+
5
+ class Timer(GameObj):
6
+ def __init__(self, duration, active=True, Global=False):
7
+ super().__init__(Vector2D(0, 0), 0, active, True, Global)
8
+ self.duration = duration
9
+ self.elapsed = 0.0
10
+ self.running = False
11
+ self.start()
12
+
13
+ def start(self):
14
+ self.elapsed = 0
15
+ self.running = True
16
+
17
+ def stop(self):
18
+ self.running = False
19
+
20
+ def get_time(self):
21
+ return self.elapsed
22
+
23
+ def update(self, dt):
24
+ if not self.active: return
25
+ if self.running:
26
+ self.elapsed += dt
27
+ if self.elapsed >= self.duration:
28
+ self.running = False
29
+ return True
30
+ return False
31
+
32
+ def is_done(self):
33
+ return not self.running and self.elapsed >= self.duration
@@ -3,5 +3,6 @@ from .Shapes import *
3
3
  from .Text import *
4
4
  from .animation import *
5
5
  from .Collision_shapes import *
6
+ from .Timer import Timer
6
7
 
7
- __all__ = ["GameObj", "Rect", "Circle", "Line", "Text", "Image", "Animation", "AnimationManager", "StaticCollisionRect", "DynamicCollisionRect"]
8
+ __all__ = ["GameObj", "Rect", "Circle", "Line", "Text", "Image", "Animation", "AnimationManager", "StaticCollisionRect", "DynamicCollisionRect", "Timer"]
@@ -5,8 +5,8 @@ from .GameObj import GameObj
5
5
  from ..Game import Game
6
6
 
7
7
  class Animation(GameObj):
8
- def __init__(self, image, size, fps, loop=True, pos=Vector2D(0, 0), z_index=0, active=True, visible=True, offset=True):
9
- super().__init__(pos, z_index, active, visible)
8
+ def __init__(self, image, size, fps, loop=True, pos=Vector2D(0, 0), z_index=0, active=True, visible=True, offset=True, Global=False):
9
+ super().__init__(pos, z_index, active, visible, Global)
10
10
  self.offset = offset
11
11
  self.image = image
12
12
  self.size = size
@@ -63,18 +63,18 @@ class Animation(GameObj):
63
63
  self.images[i] = pygame.transform.flip(self.images[i], True, False)
64
64
 
65
65
  def copy(self):
66
- return Animation(self.image, self.size, self.fps, self.loop)
67
- def render(self, cam):
66
+ return Animation(self.image, self.size, self.fps, self.loop, self.pos, self.z_index, self.active, self.visible, self.offset, self._global)
67
+ def render(self):
68
68
  if not self.visible: return
69
- cam.draw_image(self.get_image(), self.pos, self.offset)
69
+ Game.cam.draw_image(self.get_image(), self.pos, self.offset)
70
70
 
71
71
  class AnimationManager(GameObj):
72
- def __init__(self, animations: dict[str, Animation], current_anim=None, z_index=0, active=True, visible=True, offset=True):
73
- super().__init__(Vector2D(0, 0), z_index, active, visible)
72
+ def __init__(self, animations: dict[str, Animation], current_anim=None, z_index=0, active=True, visible=True, offset=True, Global=False):
73
+ super().__init__(Vector2D(0, 0), z_index, active, visible, Global)
74
74
  self.animations = animations
75
75
  self.current_anim = current_anim
76
76
 
77
- for anim in self.animations:
77
+ for anim in self.animations.values():
78
78
  anim.destroy() #remove from global or scene calls
79
79
 
80
80
  def new_anim(self, name, anim):
@@ -111,6 +111,6 @@ class AnimationManager(GameObj):
111
111
  return
112
112
  return self.animations[self.current_anim]
113
113
 
114
- def render(self, cam):
114
+ def render(self):
115
115
  if not self.visible: return
116
- self.get_animation().render(cam)
116
+ self.get_animation().render()
@@ -84,13 +84,17 @@ class _assets:
84
84
  def new_font(self, name, path, size):
85
85
  self.fonts[name] = pygame.font.Font(path, size)
86
86
 
87
- def new_animation(self, name, image, size=16, fps=3, loop=True, pos=Vector2D(0, 0), z_index=0, active=True, visible=True, offset=True):
88
- self.animations[name] = Animation(image, size, fps, loop, pos, z_index, active, visible, offset)
89
- def new_anim_nIMG(self, name, size=16, fps=3, path=None, rect=None, scale=1.0, colorKey=(0, 0, 0), sWidth=None, sHeight=None, loop=True, pos=Vector2D(0, 0), z_index=0, active=True, visible=True, offset=True):
87
+ def new_animation(self, name, image, size=16, fps=3, loop=True, rect=None, pos=Vector2D(0, 0), z_index=0, active=True, visible=True, offset=True, Global=False):
88
+ m = image
89
+ if rect is not None:
90
+ m = image.subsurface(rect)
91
+ self.animations[name] = Animation(m, size, fps, loop, pos, z_index, active, visible, offset, Global)
92
+ return self.animations[name]
93
+ def new_anim_nIMG(self, name, size=16, fps=3, path=None, rect=None, scale=1.0, colorKey=(0, 0, 0), sWidth=None, sHeight=None, loop=True, pos=Vector2D(0, 0), z_index=0, active=True, visible=True, offset=True, Global=False):
90
94
  #create image
91
95
  self.new_image(name, path, rect, scale, colorKey, sWidth, sHeight)
92
96
  #create animation
93
- self.new_animation(name, self.images[name], size*scale, fps, loop, pos, z_index, active, visible, offset)
97
+ self.new_animation(name, self.images[name], size*scale, fps, loop, pos, z_index, active, visible, offset, Global)
94
98
 
95
99
  def new_sound(self, name, path):
96
100
  self.sounds[name] = pygame.mixer.Sound(path)
@@ -1,4 +1,4 @@
1
- from src import *
1
+ from src.PyScene import *
2
2
  import pygame
3
3
 
4
4
 
@@ -15,7 +15,16 @@ class player(GameObj):
15
15
  self.pos += (Keys.get_vector(Keys.a, Keys.d, Keys.w, Keys.s, False)*150)*Game.dt
16
16
  self.anim.pos = self.pos #positions stay linked
17
17
 
18
- player()
18
+ class Test(Scene):
19
+ def __init__(self):
20
+ super().__init__("Test")
21
+ player()
22
+
23
+ Test()
24
+
25
+ Game.Tick()
26
+ print(Game.objects)
27
+ print(Game.active_scene._objects)
19
28
 
20
29
  Game.Run()
21
30
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes