py3dbuilder 0.1.0a1__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.
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: py3dbuilder
3
+ Version: 0.1.0a1
4
+ Summary: Simple 3D Builder for creating 2D and 3D games in Python.
5
+ Author: Victor Zou
6
+ License: MIT
7
+ Keywords: game,pygame,3d,builder,engine,Victor Zou,vzpy,python
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: pygame
11
+
12
+ # py3dbuilder
13
+
14
+ Simple 3D Builder for creating 2D and 3D games in Python.
15
+
16
+ ## Quick Start
17
+
18
+ See `quickstart.py` in the project root directory.
19
+
20
+ ## Version
21
+
22
+ Current version: `0.1.0a1` (Alpha 1)
23
+
24
+ ## Features
25
+
26
+ - Screen
27
+ - Scene
28
+ - Surface
29
+ - Vec2
30
+ - Vec3
31
+
32
+ ## Links
33
+
34
+ - [PyPI](https://pypi.org/project/py3dbuilder/)
35
+ - [PyPI Stats](https://pypistats.org/packages/py3dbuilder)
36
+
37
+ ## License
38
+
39
+ MIT License
@@ -0,0 +1,28 @@
1
+ # py3dbuilder
2
+
3
+ Simple 3D Builder for creating 2D and 3D games in Python.
4
+
5
+ ## Quick Start
6
+
7
+ See `quickstart.py` in the project root directory.
8
+
9
+ ## Version
10
+
11
+ Current version: `0.1.0a1` (Alpha 1)
12
+
13
+ ## Features
14
+
15
+ - Screen
16
+ - Scene
17
+ - Surface
18
+ - Vec2
19
+ - Vec3
20
+
21
+ ## Links
22
+
23
+ - [PyPI](https://pypi.org/project/py3dbuilder/)
24
+ - [PyPI Stats](https://pypistats.org/packages/py3dbuilder)
25
+
26
+ ## License
27
+
28
+ MIT License
@@ -0,0 +1,42 @@
1
+ """Build 3D Games."""
2
+ from . import geometry
3
+ from . import math
4
+ import pygame as _pyg
5
+ BlitAbleObject=geometry.Surface
6
+ from . import scene
7
+ from .scene import Scene
8
+
9
+ _scr=None
10
+ def _set_scr(screen:"Screen"):
11
+ global _scr
12
+ _scr=screen
13
+ class Screen:
14
+ def __init__(self,size:geometry.Size2|math.Vec2|tuple[int,int]):
15
+ self.size=size
16
+ self.width,self.height=size
17
+ self._screen=_pyg.display.set_mode(tuple(size))
18
+ _set_scr(self)
19
+ self.last_scene=None
20
+ def show(self,scene:Scene):
21
+ scene.is_main_scene=True
22
+ scene.clear()
23
+ scene.set_newtitle(scene.title)
24
+ if self.last_scene is not None:
25
+ self.last_scene.is_main_scene=False
26
+ self.last_scene=scene
27
+ def blit(self,object:BlitAbleObject,pos:math.Vec2|geometry.Point2|None=None):
28
+ if pos is None:
29
+ pos=object.pos
30
+ self._screen.blit(object._obj,tuple(pos))
31
+ def fill(self,color:tuple[int,int,int]):
32
+ self._screen.fill(color)
33
+ def quitted():
34
+ for event in _pyg.event.get():
35
+ if event.type==_pyg.QUIT:
36
+ return True
37
+ return False
38
+ def quit():
39
+ _pyg.display.quit()
40
+ _pyg.quit()
41
+ def update():
42
+ _pyg.display.update()
@@ -0,0 +1,86 @@
1
+ from .math import Vec2 as _V2, Vec3 as _V3
2
+ from typing import Literal as _Lit
3
+ class Point2(_V2):pass
4
+ class Size2(_V2):pass
5
+ class Point3(_V3):pass
6
+ class Size3(_V3):pass
7
+ DEFAULT_POS=Point2(0,0)
8
+ class Surface:
9
+ def __init__(self,size:Size2|_V2|tuple[int,int],pos:Point2|_V2|tuple[int,int]=DEFAULT_POS):
10
+ self._width,self._height=size
11
+ self.size=Point2(*size)
12
+ self.sizet=(size.x,size.y) if not isinstance(size,tuple) else size
13
+ self._x,self._y=pos
14
+ self.pos=Point2(*pos)
15
+ self.post=(pos.x,pos.y) if not isinstance(pos,tuple) else pos
16
+ from pygame import Surface
17
+ self._obj=Surface(size)
18
+ @property
19
+ def width(self):
20
+ return self._width
21
+ @width.setter
22
+ def width(self,newwidth):
23
+ self._width=newwidth
24
+ self.size.x=newwidth
25
+ self.sizet=(self.size.x,self.size.y)
26
+ @property
27
+ def height(self):
28
+ return self._width
29
+ @height.setter
30
+ def height(self,newheight):
31
+ self._height=newheight
32
+ self.size.y=newheight
33
+ self.sizet=(self.size.x,self.size.y)
34
+ @property
35
+ def x(self):
36
+ return self._x
37
+ @x.setter
38
+ def x(self,newx):
39
+ self._x=newx
40
+ self.pos.x=newx
41
+ self.post=(self.pos.x,self.pos.y)
42
+ @property
43
+ def y(self):
44
+ return self._y
45
+ @y.setter
46
+ def y(self,newy):
47
+ self._y=newy
48
+ self.pos.y=newy
49
+ self.post=(self.pos.x,self.pos.y)
50
+ @property
51
+ def area(self):
52
+ return self.width*self.height
53
+ def __repr__(self):
54
+ return f"Surface(size={self.sizet},pos={self.post})"
55
+
56
+ def get_whxyscrface(w:int,h:int,x:int,y:int):
57
+ return Surface(Size2(w,h),Point2(x,y))
58
+ def get_cornerssurface(lefttop: Point2 | _V2, rightbottom: Point2 | _V2):
59
+ size = abs(rightbottom - lefttop)
60
+ pos = (lefttop + rightbottom) / 2
61
+ return Surface(size, pos)
62
+ def get_joinedsurface(surf1:Surface,surf2:Surface,addway:_Lit["horizontal","vertical"]="horizontal",alignway:_Lit["align_longer","align_shorter","align_average"]="align_average",new_pos:_V2|Point2=DEFAULT_POS):
63
+ wsum=surf1.width+surf2.width
64
+ hsum=surf1.height+surf2.height
65
+ if addway=="horizontal":
66
+ if alignway=="align_average":
67
+ height=round(hsum/2)
68
+ elif alignway=="align_longer":
69
+ height=surf1.height if surf1.height>surf2.height else surf2.height
70
+ elif alignway=="align_shorter":
71
+ height=surf1.height if surf1.height<surf2.height else surf2.height
72
+ else:
73
+ raise TypeError("Invalid key")
74
+ return Surface(Size2(wsum,height),new_pos)
75
+ elif addway=="vertical":
76
+ if alignway=="align_average":
77
+ width=round(wsum/2)
78
+ elif alignway=="align_longer":
79
+ width=surf1.width if surf1.width>surf2.width else surf2.width
80
+ elif alignway=="align_shorter":
81
+ width=surf1.width if surf1.width<surf2.width else surf2.width
82
+ else:
83
+ raise TypeError("Invalid key")
84
+ return Surface(Size2(width,hsum),new_pos)
85
+ else:
86
+ raise TypeError("Invalid add key")
@@ -0,0 +1,65 @@
1
+ import math as _math
2
+ from typing import Literal as _Lit
3
+ from warnings import warn as _warn
4
+ X=0
5
+ Y=1
6
+ Z=2
7
+ class Vec2:
8
+ """A two-index vector."""
9
+ def __init__(self, x:int, y:int, *, readonly:bool=False):
10
+ self.__x=x
11
+ self.__y=y
12
+ self.__lck=readonly
13
+ @property
14
+ def x(self):
15
+ return self.__x
16
+ @x.setter
17
+ def x(self,x:int):
18
+ if not self.__lck:
19
+ self.__x=x
20
+ else:
21
+ _warn("Cannot revise a readonly vector",UserWarning)
22
+ @property
23
+ def y(self):
24
+ return self.__y
25
+ @y.setter
26
+ def y(self,y:int):
27
+ if not self.__lck:
28
+ self.__y=y
29
+ else:
30
+ _warn("Cannot revise a readonly vector",UserWarning)
31
+ def get(self,coord:int):
32
+ """
33
+ Get the X or Y coordinate of this vector. **coord** is coordinate type.
34
+
35
+ Example:
36
+ >>> from py3dbuilder.math import *
37
+ >>> vector = Vec2(66, 99)
38
+ >>> print(
39
+ ... vector.get(X),
40
+ ... vector.get(Y),
41
+ ... vector.get(0),
42
+ ... vector.get(1)
43
+ ... )
44
+ 66 99 66 99
45
+
46
+ If you want easier, use **vect[coord]** to get.
47
+ """
48
+ return (self.x,self.y)[coord]
49
+ def __add__(self,other:"Vec2"):
50
+ return Vec2(self.x+other.x,self.y+other.y)
51
+ def __sub__(self,other:"Vec2"):
52
+ return Vec2(self.x-other.x,self.y-other.y)
53
+ def __getitem__(self,coord:int):
54
+ """
55
+ Get the X or Y coordinate of this vector.
56
+
57
+ More about it, see **Vec2.get** .
58
+ """
59
+ return self.get(coord)
60
+ def __iter__(self):
61
+ yield self.x
62
+ yield self.y
63
+ class Vec3:
64
+ def __init__(self, x:int, y:int, z:int):
65
+ pass
@@ -0,0 +1,35 @@
1
+ from . import BlitAbleObject
2
+ from . import _pyg
3
+ from .geometry import Point2 as _P2
4
+ from .math import Vec2 as _V2
5
+ class Scene:
6
+ def __init__(self,color:tuple[int,int,int],title:str):
7
+ from . import _scr
8
+ from . import _set_scr
9
+ if _scr is None:
10
+ from . import Screen
11
+ self.screen=Screen((640,640))
12
+ _set_scr(self.screen)
13
+ else:
14
+ self.screen=_scr
15
+ self.bgcolor=color
16
+ self.title=title
17
+ self.is_main_scene=False
18
+ def set_newcolor(self,newcolor:tuple[int,int,int]):
19
+ self.bgcolor=newcolor
20
+ if self.is_main_scene:
21
+ self.screen._screen.fill(newcolor)
22
+ def set_newtitle(self,newtitle:str):
23
+ self.title=newtitle
24
+ if self.is_main_scene:
25
+ _pyg.display.set_caption(newtitle)
26
+ def show(self):
27
+ self.screen.show(self)
28
+ def blit(self,object:BlitAbleObject,pos:_P2|_V2):
29
+ if self.is_main_scene:
30
+ self.screen.blit(object,pos)
31
+ def clear(self,bgcolor:tuple[int,int,int]|None=None):
32
+ if self.is_main_scene:
33
+ if bgcolor is None:
34
+ bgcolor=self.bgcolor
35
+ self.set_newcolor(bgcolor)
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: py3dbuilder
3
+ Version: 0.1.0a1
4
+ Summary: Simple 3D Builder for creating 2D and 3D games in Python.
5
+ Author: Victor Zou
6
+ License: MIT
7
+ Keywords: game,pygame,3d,builder,engine,Victor Zou,vzpy,python
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: pygame
11
+
12
+ # py3dbuilder
13
+
14
+ Simple 3D Builder for creating 2D and 3D games in Python.
15
+
16
+ ## Quick Start
17
+
18
+ See `quickstart.py` in the project root directory.
19
+
20
+ ## Version
21
+
22
+ Current version: `0.1.0a1` (Alpha 1)
23
+
24
+ ## Features
25
+
26
+ - Screen
27
+ - Scene
28
+ - Surface
29
+ - Vec2
30
+ - Vec3
31
+
32
+ ## Links
33
+
34
+ - [PyPI](https://pypi.org/project/py3dbuilder/)
35
+ - [PyPI Stats](https://pypistats.org/packages/py3dbuilder)
36
+
37
+ ## License
38
+
39
+ MIT License
@@ -0,0 +1,11 @@
1
+ ReadMe.md
2
+ pyproject.toml
3
+ py3dbuilder/__init__.py
4
+ py3dbuilder/geometry.py
5
+ py3dbuilder/math.py
6
+ py3dbuilder/scene.py
7
+ py3dbuilder.egg-info/PKG-INFO
8
+ py3dbuilder.egg-info/SOURCES.txt
9
+ py3dbuilder.egg-info/dependency_links.txt
10
+ py3dbuilder.egg-info/requires.txt
11
+ py3dbuilder.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ dist
2
+ py3dbuilder
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+ [project]
5
+ name = "py3dbuilder"
6
+ version = "0.1.0a1"
7
+ authors = [
8
+ { name="Victor Zou" }
9
+ ]
10
+ description = "Simple 3D Builder for creating 2D and 3D games in Python."
11
+ readme = "ReadMe.md"
12
+ requires-python = ">=3.10"
13
+
14
+ dependencies = [
15
+ "pygame"
16
+ ]
17
+ license = {text = "MIT"}
18
+ keywords = [
19
+ "game",
20
+ "pygame",
21
+ "3d",
22
+ "builder",
23
+ "engine",
24
+ "Victor Zou",
25
+ "vzpy",
26
+ "python"
27
+ ]
28
+ [tool.setuptools.packages.find]
29
+ where = ["."]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+