GameBox 0.2.0__py3-none-any.whl → 0.3.0__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.
GameBox/__init__.py CHANGED
@@ -5,7 +5,7 @@ GameBox makes it easy to build 2D games with graphics, sound, and UI in just a f
5
5
  """
6
6
 
7
7
 
8
- __version__ = "0.1.3"
8
+ __version__ = "0.3.0"
9
9
  __author__ = "Sam Fertig"
10
10
 
11
11
  #____imports____
@@ -3,6 +3,9 @@ import numpy as np
3
3
 
4
4
  from..helpers._input import Keys
5
5
  from ..basics._net import Global
6
+ from ._collisionDef import _tileCollisionDefs
7
+
8
+ from._editorBrushes import _brushPencil, _collisionsPencil
6
9
 
7
10
  class _tilemapEditor:
8
11
  def __init__(self, tilemap, activation):
@@ -10,92 +13,24 @@ class _tilemapEditor:
10
13
  self.activation = activation
11
14
  self.active = False
12
15
 
13
- self.selectedTile = 1
14
- self.mx, self.my = Keys.mouse_x, Keys.mouse_y
16
+ self.mode = _brushPencil()
15
17
 
16
- self.mode = "paint"
18
+ self.changes = {
19
+ "pencil": Keys.b,
20
+ "collisions": Keys.c
21
+
22
+ }
17
23
 
18
24
  def _update(self):
19
25
  if self.active:
20
- #update mouse pos
21
- self.mx, self.my = Keys.mouse_x, Keys.mouse_y
22
- self.mx += Global.cam.x
23
- self.my += Global.cam.y
24
- self.mx = self.mx // self.tilemap.tileDim[0] * self.tilemap.tileDim[0]
25
- self.my = self.my // self.tilemap.tileDim[1] * self.tilemap.tileDim[1]
26
-
27
- self._mode_()
28
- self.moveSelectionByArrowKeys()
29
- self.ui()
30
-
26
+ self.change_mode()
27
+ #editor stuff
28
+ self.mode.update(self.tilemap)
31
29
  #toggle
32
30
  if Keys.is_pressed(self.activation): self.active = not self.active
33
31
 
34
- def _mode_(self):
35
- x, y = Keys.mouse_x, Keys.mouse_y
36
- if x > self.tilemap.tileset.get_size()[0] * self.tilemap.tilescale / 2 or y > self.tilemap.tileset.get_size()[1] * self.tilemap.tilescale / 2:
37
- self.mode = "paint"
38
- #more parrimeters will be placed as needed
39
- else:
40
- self.mode = "select"
41
-
42
- def ui(self):
43
- tile = self.tilemap.tiles[self.selectedTile]
44
- image = pygame.transform.scale_by(self.tilemap.tileset, self.tilemap.tilescale / 2)
45
- Global.screen.blit(image, (0, 0))
46
- #show outlined sellected tile
47
- x, y = self.tilemap.tilePosInImage[self.selectedTile]
48
- x *= self.tilemap.tilescale / 2
49
- y *= self.tilemap.tilescale / 2
50
- width = self.tilemap.orginDim[0] * self.tilemap.tilescale / 2
51
- height = self.tilemap.orginDim[1] * self.tilemap.tilescale / 2
52
- outline = pygame.Rect(x, y, width, height)
53
- pygame.draw.rect(Global.screen, "white", outline, 2)
54
- #other stuff
55
- if self.mode == "paint":
56
- #show selected tile
57
- #--outline on tileset
58
- #--show beside mouse
59
- x = self.mx
60
- y = self.my
61
-
62
- x -= Global.cam.x
63
- y -= Global.cam.y
64
- Global.screen.blit(tile, (x, y))
65
- if pygame.mouse.get_pressed()[0]:
66
- #check if mouse is on tilemap
67
- x, y = self.mx // self.tilemap.tileDim[0], self.my // self.tilemap.tileDim[1]
68
- if x >= 0 and x < self.tilemap.mapDim[0] and y >= 0 and y < self.tilemap.mapDim[1]:
69
- self.tilemap.map[int(y)][int(x)] = self.selectedTile
70
- if pygame.mouse.get_pressed()[2]:
71
- x, y = self.mx // self.tilemap.tileDim[0], self.my // self.tilemap.tileDim[1]
72
- if x >= 0 and x < self.tilemap.mapDim[0] and y >= 0 and y < self.tilemap.mapDim[1]:
73
- self.tilemap.map[int(y)][int(x)] = 0
74
- elif self.mode == "select":
75
- #paint mouse hovered tile
76
- x, y = Keys.mouse_x, Keys.mouse_y
77
- x = (x // width)
78
- y = (y // height)
79
- outline = pygame.Rect(x * width, y * width, width, height)
80
- pygame.draw.rect(Global.screen, "black", outline, 2)
81
- if pygame.mouse.get_pressed()[0]:
82
- x *= self.tilemap.orginDim[0]
83
- y *= self.tilemap.orginDim[1]
84
- self.selectedTile = self.tilemap.posToTile[(int(x), int(y))]
85
-
86
-
87
- def moveSelectionByArrowKeys(self):
88
- x, y = self.tilemap.tilePosInImage[self.selectedTile]
89
-
90
- width = 16
91
- height = 16
92
-
93
- if Keys.is_pressed(Keys.left): x -= width
94
- if Keys.is_pressed(Keys.right): x += width
95
- if Keys.is_pressed(Keys.up): y -= height
96
- if Keys.is_pressed(Keys.down): y += height
97
-
98
- if (int(x), int(y)) in self.tilemap.posToTile:
99
- self.selectedTile = self.tilemap.posToTile[(int(x), int(y))]
100
-
101
-
32
+ def change_mode(self):
33
+ #key presses
34
+ if Keys.is_pressed(self.changes["pencil"]): self.mode = _brushPencil()
35
+ elif Keys.is_pressed(self.changes["collisions"]): self.mode = _collisionsPencil(self.tilemap)
36
+
@@ -3,6 +3,13 @@ import pygame
3
3
  class _tileCollisionDefs:
4
4
  def __init__(self, tileDim):
5
5
  width, height = tileDim
6
+
7
+
8
+ self.rects = ["full", "none", "halfLeft", "halfRight", "halfTop", "halfBottom", "topRight",
9
+ "topLeft", "bottomRight", "bottomLeft", "dot"]
10
+
11
+ self.num = len(self.rects) + 1
12
+
6
13
  self.full = pygame.Rect(0, 0, width, height)
7
14
 
8
15
  self.halfLeft = pygame.Rect(0, 0, width / 2, height)
@@ -0,0 +1,166 @@
1
+ import pygame
2
+ import numpy as np
3
+
4
+ from ..basics._net import Global
5
+ from ..helpers._input import Keys
6
+ from ._collisionDef import _tileCollisionDefs
7
+
8
+ class _brushPencil():
9
+ def __init__(self):
10
+ self.selectedTile = 1
11
+ self.mode = "paint"
12
+
13
+ def update(self, tilemap):
14
+ #get all mouse calculations
15
+ x, y = Keys.mouse_x, Keys.mouse_y
16
+ x += Global.cam.x
17
+ y += Global.cam.y
18
+ mx = x // tilemap.tileDim[0] * tilemap.tileDim[0]
19
+ my = y // tilemap.tileDim[1] * tilemap.tileDim[1]
20
+
21
+ #get mode
22
+ x, y = Keys.mouse_x, Keys.mouse_y
23
+ if x > tilemap.tileset.get_size()[0] * tilemap.tilescale / 2 or y > tilemap.tileset.get_size()[1] * tilemap.tilescale / 2:
24
+ self.mode = "paint"
25
+ else:
26
+ self.mode = "select"
27
+
28
+ #--show tileset
29
+ tile = tilemap.tiles[self.selectedTile]
30
+ image = pygame.transform.scale_by(tilemap.tileset, tilemap.tilescale / 2)
31
+ Global.screen.blit(image, (0, 0))
32
+ #--show outlined sellected tile
33
+ x, y = tilemap.tilePosInImage[self.selectedTile]
34
+ x *= tilemap.tilescale / 2
35
+ y *= tilemap.tilescale / 2
36
+ width = tilemap.orginDim[0] * tilemap.tilescale / 2
37
+ height = tilemap.orginDim[1] * tilemap.tilescale / 2
38
+ outline = pygame.Rect(x, y, width, height)
39
+ pygame.draw.rect(Global.screen, "white", outline, 2)
40
+ #other stuff
41
+ if self.mode == "paint":
42
+ x = mx
43
+ y = my
44
+
45
+ x -= Global.cam.x
46
+ y -= Global.cam.y
47
+ Global.screen.blit(tile, (x, y))
48
+ #set tile or erase
49
+ if pygame.mouse.get_pressed()[0]:
50
+ #check if mouse is on tilemap
51
+ x, y = mx // tilemap.tileDim[0], my // tilemap.tileDim[1]
52
+ if x >= 0 and x < tilemap.mapDim[0] and y >= 0 and y < tilemap.mapDim[1]:
53
+ tilemap.map[int(y)][int(x)] = self.selectedTile
54
+ elif pygame.mouse.get_pressed()[2]:
55
+ x, y = mx // tilemap.tileDim[0], my // tilemap.tileDim[1]
56
+ if x >= 0 and x < tilemap.mapDim[0] and y >= 0 and y < tilemap.mapDim[1]:
57
+ tilemap.map[int(y)][int(x)] = 0
58
+ elif self.mode == "select":
59
+ #paint mouse hovered tile
60
+ x, y = Keys.mouse_x, Keys.mouse_y
61
+ x = (x // width)
62
+ y = (y // height)
63
+ outline = pygame.Rect(x * width, y * width, width, height)
64
+ pygame.draw.rect(Global.screen, "black", outline, 2)
65
+ if pygame.mouse.get_pressed()[0]:
66
+ x *= tilemap.orginDim[0]
67
+ y *= tilemap.orginDim[1]
68
+ self.selectedTile = tilemap.posToTile[(int(x), int(y))]
69
+
70
+ #move selection by arrow keys
71
+ x, y = tilemap.tilePosInImage[self.selectedTile]
72
+
73
+ width = 16
74
+ height = 16
75
+
76
+ if Keys.is_pressed(Keys.left): x -= width
77
+ if Keys.is_pressed(Keys.right): x += width
78
+ if Keys.is_pressed(Keys.up): y -= height
79
+ if Keys.is_pressed(Keys.down): y += height
80
+
81
+ if (int(x), int(y)) in tilemap.posToTile:
82
+ self.selectedTile = tilemap.posToTile[(int(x), int(y))]
83
+
84
+ class _collisionsPencil():
85
+ def __init__(self, tilemap):
86
+ self.selectedTile = 0
87
+ self.shapes = tilemap.collisionShapes.num
88
+ self.mode = "paint"
89
+ size = tilemap.tilescale / 2
90
+ self.size = tilemap.orginDim[0] * size
91
+ self.coll = _tileCollisionDefs((tilemap.orginDim[0] * size, tilemap.orginDim[1] * size))
92
+
93
+ def update(self, tilemap):
94
+ x, y = Keys.mouse_x, Keys.mouse_y
95
+ #draw tilesets and background
96
+ Global.screen.fill("darkgrey")
97
+ image = pygame.transform.scale_by(tilemap.tileset, tilemap.tilescale / 2)
98
+ Global.screen.blit(image, (0, 0))
99
+ Global.screen.blit(image, (0, image.get_size()[1]+ 10))
100
+ #draw all collision rects on top tileset
101
+ for tile in range(tilemap.tilesetNum - 1):
102
+ tile+=1
103
+ if str(tile) not in tilemap.collisionDict: continue
104
+ rectshape = tilemap.collisionDict[str(tile)]
105
+ rect = getattr(self.coll, rectshape).copy()
106
+ tx, ty = tilemap.tilePosInImage[int(tile)]
107
+ tx = (tx // tilemap.orginDim[0]) * self.size
108
+ ty = (ty // tilemap.orginDim[1]) * self.size
109
+ rect.x += tx
110
+ rect.y += ty
111
+ pygame.draw.rect(Global.screen, "yellow", rect, 5)
112
+ outline = pygame.Rect(tx, ty, self.size, self.size)
113
+ pygame.draw.rect(Global.screen, "gray", outline, 2)
114
+ #change mode
115
+ if y > image.get_size()[1] * 2 + 50: self.mode = "select"
116
+ else: self.mode = "paint"
117
+ #draw collisions tiles at bottom
118
+ tx, ty = 0, image.get_size()[1] * 2 + 50
119
+ for tile in range(self.shapes-1):
120
+ rect = getattr(self.coll, tilemap.collisionShapes.rects[tile]).copy()
121
+ rect.x += tx
122
+ rect.y += ty
123
+ pygame.draw.rect(Global.screen, "yellow", rect, 5)
124
+ outline = pygame.Rect(tx, ty, self.size, self.size)
125
+ pygame.draw.rect(Global.screen, "gray", outline, 2)
126
+ tx += self.size + self.size / 2
127
+ #paint mode
128
+ if self.mode == "paint":
129
+ #draw tile around mouse
130
+ rect = getattr(self.coll, tilemap.collisionShapes.rects[self.selectedTile]).copy()
131
+ rect.x += x - self.size / 2
132
+ rect.y += y - self.size / 2
133
+ pygame.draw.rect(Global.screen, "yellow", rect, 5)
134
+ outline = pygame.Rect(x, y, self.size, self.size)
135
+ outline.center = (Keys.mouse_x, Keys.mouse_y)
136
+ pygame.draw.rect(Global.screen, "gray", outline, 2)
137
+ #paint collisions
138
+ size = tilemap.orginDim[0]
139
+ if pygame.mouse.get_pressed()[0]:
140
+ x = (x - (x % self.size)) // self.size
141
+ y = (y - (y % self.size)) // self.size
142
+ px = x * size
143
+ py = y * size
144
+ if (int(px), int(py)) in tilemap.posToTile:
145
+ tilemap.collisionDict[str(tilemap.posToTile[(int(px), int(py))])] = self.coll.rects[self.selectedTile]
146
+ #erase collisions
147
+ if pygame.mouse.get_pressed()[2]:
148
+ x = (x - (x % self.size)) // self.size
149
+ y = (y - (y % self.size)) // self.size
150
+ px = x * size
151
+ py = y * size
152
+ if (int(px), int(py)) in tilemap.posToTile:
153
+ tilemap.collisionDict[tilemap.posToTile[(int(px), int(py))]] = "none"
154
+
155
+ elif self.mode == "select":
156
+ #get tile at mouse
157
+ x = int(x // (self.size + self.size / 2))
158
+ #draw underline
159
+ underline = pygame.Rect((0, 0), (self.size, 5))
160
+ underline.center = (Keys.mouse_x, ty + self.size+5)
161
+ pygame.draw.rect(Global.screen, "black", underline)
162
+ #select tile
163
+ if pygame.mouse.get_pressed()[0] and x < self.shapes-1 and x >= 0:
164
+ self.selectedTile = int(x)
165
+
166
+
@@ -17,6 +17,8 @@ class TileMap:
17
17
  self.tilescale = tileScale
18
18
  self.orginDim = tileDim
19
19
 
20
+ self.tilesetNum = 0
21
+
20
22
  self.editor = None
21
23
 
22
24
  Global.game.objs.append(self)
@@ -46,10 +48,10 @@ class TileMap:
46
48
  self.tiles[tile_id] = pygame.transform.scale(tile, self.tileDim)
47
49
  self.tilePosInImage[tile_id] = (x, y)
48
50
  self.posToTile[(x, y)] = tile_id
51
+ self.tilesetNum += 1
49
52
  tile_id += 1
50
53
 
51
54
  Global.tilemap.append(self)
52
- print(self.posToTile)
53
55
 
54
56
  def load_map_from_json(self, filePath: str):
55
57
  with open(filePath, "r") as f:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GameBox
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: GameBox is a beginner-friendly Python package built on top of pygame, designed to make 2D game development faster and easier. It provides ready-to-use modules, utilities, and abstractions that let new developers create polished games without needing advanced coding knowledge—while still offering the flexibility for experienced coders to customize and extend.
5
5
  Author-email: Sam Fertig <sfertig007@gmail.com>
6
6
  License-Expression: MIT
@@ -1,4 +1,4 @@
1
- GameBox/__init__.py,sha256=jU3a32yFDiWvSHanU2_xJHNi3Ngcqrvjn190SyKlNwE,727
1
+ GameBox/__init__.py,sha256=uY6ByC6ujfiIjG257S2V75gHN0SWVX-N0MaeQqctlHU,727
2
2
  GameBox/_game.py,sha256=QqfWQRLIiKQ-QjEGQYFLpsjEtPNuhxMqiCnPmXFyq3M,1548
3
3
  GameBox/basics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  GameBox/basics/_net.py,sha256=tZsfUc-rOsbRPxgjzR95gY6vKa8CxM8TJhCBtDnVhtg,766
@@ -10,10 +10,11 @@ GameBox/helpers/_input.py,sha256=97bPxM5dkonRywOhj11lgHVQVicuLAKYi_w8EPM0Af8,196
10
10
  GameBox/player/_player.py,sha256=R0vH1mZhl6RENiQl3Vg4ACF9agR5OP50MenvhgFBYOk,1769
11
11
  GameBox/player/_playerControler.py,sha256=XEb87RFlgLFoXnXqxIS4lpzHN0wywMNCX5y-NIhw0cs,1715
12
12
  GameBox/player/_playerPhysics.py,sha256=XqgEC5FB5mrnlalY3M5TLScw40mSvNAc0AE9g3amEr0,2918
13
- GameBox/tilemap/_Editor.py,sha256=Xed3Q33WEAKyLiTieTWDFeiTMMQm8m7cY2Bv7JzJr0o,4010
14
- GameBox/tilemap/_collisionDef.py,sha256=lZCmSwIsLgxvEB3X30re_izg1DHY83IWp84NcM1cIkM,1393
15
- GameBox/tilemap/_tilemap.py,sha256=fIBaAAu1Rg1iI4xEUk3Xkpe4MllpnkLzNfInj0468cw,3292
16
- gamebox-0.2.0.dist-info/METADATA,sha256=2nL3q0Sg_b_tyg-shYRDrlpNAXJ0MzsZy_5tmWhdKcg,1059
17
- gamebox-0.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
18
- gamebox-0.2.0.dist-info/licenses/LICENSE,sha256=gcuuhKKc5-dwvyvHsXjlC9oM6N5gZ6umYbC8ewW1Yvg,35821
19
- gamebox-0.2.0.dist-info/RECORD,,
13
+ GameBox/tilemap/_Editor.py,sha256=98JcwAvL6JgSG2S-V-527lwpfzbE-A-BbezCI9EfTyI,1027
14
+ GameBox/tilemap/_collisionDef.py,sha256=VxWcfz3nlhyYI_Hemp-LvC6IDC-YN6wIdRaU8AsgipU,1621
15
+ GameBox/tilemap/_editorBrushes.py,sha256=GFfRV0OB3t9sFb37eO3sB8Cmwyd5i_q64q5IjYlkx1k,7247
16
+ GameBox/tilemap/_tilemap.py,sha256=SEQlokpsUO9zQkLMF-j6amx1FqNeD2eM2CRFj3zCnZ8,3330
17
+ gamebox-0.3.0.dist-info/METADATA,sha256=gwV3s_16qJEtjpHlGRTHL9v1M7B02VXU14Rjm_bU1XA,1059
18
+ gamebox-0.3.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
19
+ gamebox-0.3.0.dist-info/licenses/LICENSE,sha256=gcuuhKKc5-dwvyvHsXjlC9oM6N5gZ6umYbC8ewW1Yvg,35821
20
+ gamebox-0.3.0.dist-info/RECORD,,