GameBox 0.9.2__py3-none-any.whl → 0.10.0.dev1__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/Game.py +68 -0
- GameBox/__init__.py +21 -24
- GameBox/basics/Cammera.py +43 -0
- GameBox/basics/Net.py +28 -0
- GameBox/basics/Shapes.py +80 -0
- GameBox/basics/sound.py +16 -0
- GameBox/basics/ui.py +70 -0
- GameBox/basics/utils.py +2 -1
- GameBox/helpers/{_input.py → Input.py} +8 -3
- GameBox/helpers/_collisions.py +60 -147
- GameBox/player/Player.py +45 -0
- GameBox/player/_playerControler.py +27 -52
- GameBox/player/_playerPhysics.py +27 -76
- GameBox/tilemap/Tilemap.py +46 -0
- {gamebox-0.9.2.dist-info → gamebox-0.10.0.dev1.dist-info}/METADATA +1 -1
- gamebox-0.10.0.dev1.dist-info/RECORD +18 -0
- GameBox/GameLevel_ui/_Animations.py +0 -39
- GameBox/GameLevel_ui/_sprites.py +0 -185
- GameBox/_game.py +0 -81
- GameBox/basics/__init__.py +0 -0
- GameBox/basics/_net.py +0 -36
- GameBox/basics/_shapes.py +0 -44
- GameBox/basics/cammera.py +0 -36
- GameBox/helpers/_Conditions.py +0 -56
- GameBox/player/_player.py +0 -61
- GameBox/player/_playerSprite.py +0 -86
- GameBox/tilemap/_Editor.py +0 -36
- GameBox/tilemap/_collisionDef.py +0 -41
- GameBox/tilemap/_editorBrushes.py +0 -166
- GameBox/tilemap/_tilemap.py +0 -94
- GameBox/ui/_basicUI.py +0 -36
- gamebox-0.9.2.dist-info/RECORD +0 -25
- {gamebox-0.9.2.dist-info → gamebox-0.10.0.dev1.dist-info}/WHEEL +0 -0
- {gamebox-0.9.2.dist-info → gamebox-0.10.0.dev1.dist-info}/licenses/LICENSE +0 -0
GameBox/player/Player.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
|
|
3
|
+
from ..basics.Net import Global
|
|
4
|
+
from ._playerPhysics import playerPhysics
|
|
5
|
+
from ._playerControler import playerController
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Player:
|
|
9
|
+
def __init__(self, pos, dim, color, show=True, layer=3):
|
|
10
|
+
self.pos = pygame.Vector2(pos)
|
|
11
|
+
self.dim = pygame.Vector2(dim)
|
|
12
|
+
self.vel = pygame.Vector2(0, 0)
|
|
13
|
+
self.color = color
|
|
14
|
+
|
|
15
|
+
self.physics = None
|
|
16
|
+
self.move = playerController(self)
|
|
17
|
+
self.show = show
|
|
18
|
+
|
|
19
|
+
self.sampleSize = 5
|
|
20
|
+
self.layer = layer
|
|
21
|
+
|
|
22
|
+
Global.objs[str(layer)].append(self)
|
|
23
|
+
#Global.player = self
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def copy(self):
|
|
27
|
+
p = Player(self.pos, self.dim, self.color, self.show, self.layer)
|
|
28
|
+
p.add_physics(self.physics.speed, self.physics.gravity, self.physics.jumpForce, self.physics.maxV, self.physics.friction)
|
|
29
|
+
return p
|
|
30
|
+
|
|
31
|
+
def add_physics(self, speed: float = 7.0, gravity: float = 5.5, jumpForce: float = 10.0, maxV: tuple = (25, 25), friction: tuple = (0.8, 0.8)):
|
|
32
|
+
self.physics = playerPhysics(self, speed, gravity, jumpForce, pygame.Vector2(maxV), pygame.Vector2(friction))
|
|
33
|
+
|
|
34
|
+
def update(self):
|
|
35
|
+
if self.physics: self.physics.update()
|
|
36
|
+
if self.show: self.draw()
|
|
37
|
+
|
|
38
|
+
#--debug func--
|
|
39
|
+
def draw(self):
|
|
40
|
+
sp = (self.pos - Global.cam.pos) * Global.cam.zoom
|
|
41
|
+
ss = self.dim * Global.cam.zoom
|
|
42
|
+
pygame.draw.rect(Global.screen, self.color, [sp, ss])
|
|
43
|
+
|
|
44
|
+
def set_sample_size(self, size):
|
|
45
|
+
self.sampleSize = size
|
|
@@ -1,54 +1,29 @@
|
|
|
1
1
|
import pygame
|
|
2
|
-
import numpy as np
|
|
3
|
-
|
|
4
|
-
from ..basics._net import Global
|
|
5
|
-
from ..basics.utils import clamp, moveTward, zeroOut
|
|
6
|
-
|
|
7
|
-
class _playerControler:
|
|
8
|
-
def __init__(self, player: object, speed: float = 1.0, gravity: float = 0.0, jump: float = 0.0, maxV: float = 10.0, airRes: float = 0.2):
|
|
9
|
-
self.speed = speed
|
|
10
|
-
self.gravity = gravity
|
|
11
|
-
self.jump = jump
|
|
12
|
-
self.player = player
|
|
13
|
-
self.maxV = maxV
|
|
14
|
-
self.airRes = airRes
|
|
15
|
-
|
|
16
|
-
def update(self):
|
|
17
|
-
self.player.vx = clamp(self.player.vx, -self.maxV, self.maxV)
|
|
18
|
-
#self.player.vy = clamp(self.player.vy, -self.maxV, self.maxV)
|
|
19
|
-
|
|
20
|
-
self.player.vx = moveTward(self.player.vx, 0, self.airRes)
|
|
21
|
-
self.player.vy = moveTward(self.player.vy, 0, self.airRes)
|
|
22
|
-
|
|
23
|
-
self.player.vx = zeroOut(self.player.vx, 0.3)
|
|
24
|
-
self.player.vy = zeroOut(self.player.vy, 0.3)
|
|
25
|
-
|
|
26
|
-
if self.player.gravity and not self.player.onGround: self.player.vy += self.gravity
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def move(self, x, y):
|
|
32
|
-
self.player.vx += x * self.speed
|
|
33
|
-
self.player.vy += y * self.speed
|
|
34
|
-
|
|
35
|
-
def top_down_movement(self):
|
|
36
|
-
keys = pygame.key.get_pressed()
|
|
37
|
-
if keys[pygame.K_a]:
|
|
38
|
-
self.move(-1, 0)
|
|
39
|
-
if keys[pygame.K_d]:
|
|
40
|
-
self.move(1, 0)
|
|
41
|
-
if keys[pygame.K_w]:
|
|
42
|
-
self.move(0, -1)
|
|
43
|
-
if keys[pygame.K_s]:
|
|
44
|
-
self.move(0, 1)
|
|
45
|
-
|
|
46
|
-
def platforming_movement(self):
|
|
47
|
-
keys = pygame.key.get_pressed()
|
|
48
|
-
if keys[pygame.K_a]:
|
|
49
|
-
self.move(-1, 0)
|
|
50
|
-
if keys[pygame.K_d]:
|
|
51
|
-
self.move(1, 0)
|
|
52
|
-
if keys[pygame.K_SPACE] and self.player.onGround:
|
|
53
|
-
self.player.vy = -self.jump
|
|
54
2
|
|
|
3
|
+
from ..helpers.Input import Keys
|
|
4
|
+
|
|
5
|
+
class playerController:
|
|
6
|
+
def __init__(self, player):
|
|
7
|
+
self.p = player
|
|
8
|
+
|
|
9
|
+
def by_WSAD(self, speed):
|
|
10
|
+
if Keys.is_held(Keys.w): self.p.vel.y -= speed
|
|
11
|
+
if Keys.is_held(Keys.s): self.p.vel.y += speed
|
|
12
|
+
if Keys.is_held(Keys.a): self.p.vel.x -= speed
|
|
13
|
+
if Keys.is_held(Keys.d): self.p.vel.x += speed
|
|
14
|
+
|
|
15
|
+
def by_arrows(self, speed):
|
|
16
|
+
if Keys.is_held(Keys.up): self.p.vel.y -= speed
|
|
17
|
+
if Keys.is_held(Keys.down): self.p.vel.y += speed
|
|
18
|
+
if Keys.is_held(Keys.left): self.p.vel.x -= speed
|
|
19
|
+
if Keys.is_held(Keys.right): self.p.vel.x += speed
|
|
20
|
+
|
|
21
|
+
def platformor_by_WSAD(self, speed):
|
|
22
|
+
if Keys.is_pressed(Keys.w): self.p.vel.y -= speed
|
|
23
|
+
if Keys.is_held(Keys.a): self.p.vel.x -= speed
|
|
24
|
+
if Keys.is_held(Keys.d): self.p.vel.x += speed
|
|
25
|
+
|
|
26
|
+
def platformor_by_arrows(self, speed):
|
|
27
|
+
if Keys.is_pressed(Keys.up): self.p.vel.y -= speed
|
|
28
|
+
if Keys.is_held(Keys.left): self.p.vel.x -= speed
|
|
29
|
+
if Keys.is_held(Keys.right): self.p.vel.x += speed
|
GameBox/player/_playerPhysics.py
CHANGED
|
@@ -1,84 +1,35 @@
|
|
|
1
1
|
import pygame
|
|
2
|
-
import numpy as np
|
|
3
2
|
|
|
4
|
-
from ..basics.
|
|
5
|
-
from ..basics.utils import clamp,
|
|
6
|
-
from ..helpers._collisions import CheckCollisions
|
|
3
|
+
from ..basics.Net import Global
|
|
4
|
+
from ..basics.utils import clamp, zeroOut
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
from ..helpers._collisions import CollisionLogic
|
|
7
|
+
|
|
8
|
+
class playerPhysics:
|
|
9
|
+
def __init__(self, player, speed, gravity, jumpForce, maxV, friction):
|
|
10
10
|
self.player = player
|
|
11
|
-
self.rect = pygame.Rect(self.player.x, self.player.y, self.player.dim[0], self.player.dim[1])
|
|
12
|
-
|
|
13
11
|
self.speed = speed
|
|
14
12
|
self.gravity = gravity
|
|
15
|
-
self.
|
|
16
|
-
self.player = player
|
|
13
|
+
self.jumpForce = jumpForce
|
|
17
14
|
self.maxV = maxV
|
|
18
|
-
self.
|
|
19
|
-
|
|
20
|
-
self.canJump = False
|
|
21
|
-
|
|
22
|
-
self.sample = 25
|
|
23
|
-
|
|
24
|
-
self.vx, self.vy = 0, 0
|
|
25
|
-
|
|
15
|
+
self.friction = friction
|
|
16
|
+
|
|
26
17
|
def update(self):
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
self.
|
|
44
|
-
|
|
45
|
-
for collision in Global.collisions:
|
|
46
|
-
if collision.colliderect(rect):
|
|
47
|
-
self.canJump = True
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def move(self, x, y):
|
|
51
|
-
self.vx += x * self.speed
|
|
52
|
-
self.vy += y * self.speed
|
|
53
|
-
|
|
54
|
-
def top_down_movement(self):
|
|
55
|
-
keys = pygame.key.get_pressed()
|
|
56
|
-
if keys[pygame.K_a]:
|
|
57
|
-
self.move(-1, 0)
|
|
58
|
-
if keys[pygame.K_d]:
|
|
59
|
-
self.move(1, 0)
|
|
60
|
-
if keys[pygame.K_w]:
|
|
61
|
-
self.move(0, -1)
|
|
62
|
-
if keys[pygame.K_s]:
|
|
63
|
-
self.move(0, 1)
|
|
64
|
-
#limit velocity
|
|
65
|
-
self.vx = clamp(self.vx, -self.maxV, self.maxV)
|
|
66
|
-
self.vy = clamp(self.vy, -self.maxV, self.maxV)
|
|
67
|
-
self.vx = moveTward(self.vx, 0, self.airRes)
|
|
68
|
-
self.vy = moveTward(self.vy, 0, self.airRes)
|
|
69
|
-
self.vx = zeroOut(self.vx, 0.3)
|
|
70
|
-
self.vy = zeroOut(self.vy, 0.3)
|
|
71
|
-
|
|
72
|
-
def platforming_movement(self):
|
|
73
|
-
keys = pygame.key.get_pressed()
|
|
74
|
-
if keys[pygame.K_a]:
|
|
75
|
-
self.move(-1, 0)
|
|
76
|
-
if keys[pygame.K_d]:
|
|
77
|
-
self.move(1, 0)
|
|
78
|
-
if keys[pygame.K_w] and self.canJump:
|
|
79
|
-
self.vy -= self.jump
|
|
80
|
-
#limit velocity
|
|
81
|
-
self.vx = clamp(self.vx, -self.maxV, self.maxV)
|
|
82
|
-
self.vx = moveTward(self.vx, 0, self.airRes)
|
|
83
|
-
self.vx = zeroOut(self.vx, 0.3)
|
|
84
|
-
if self.player.gravity and not self.onGround: self.vy += self.gravity
|
|
18
|
+
#clamp velocities
|
|
19
|
+
self.player.vel.x = clamp(self.player.vel.x, -self.maxV.x, self.maxV.x)
|
|
20
|
+
self.player.vel.y = clamp(self.player.vel.y, -self.maxV.y, self.maxV.y)
|
|
21
|
+
|
|
22
|
+
#apply gravity
|
|
23
|
+
self.player.vel.y += self.gravity
|
|
24
|
+
|
|
25
|
+
#apply friction
|
|
26
|
+
self.player.vel.x *= self.friction.x
|
|
27
|
+
self.player.vel.y *= self.friction.y
|
|
28
|
+
|
|
29
|
+
#zero out very small velocities to prevent drift
|
|
30
|
+
self.player.vel.x = zeroOut(self.player.vel.x, 0.01)
|
|
31
|
+
self.player.vel.y = zeroOut(self.player.vel.y, 0.01)
|
|
32
|
+
|
|
33
|
+
#update position
|
|
34
|
+
self.player.pos, self.player.vel = CollisionLogic(self.player.vel, self.player.pos, self.player.dim, self.player.sampleSize)
|
|
35
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from ..basics.Net import Global
|
|
5
|
+
from ..basics.ui import load_image
|
|
6
|
+
|
|
7
|
+
class Tilemap:
|
|
8
|
+
def __init__(self, tilesetImage, tileDim, scale, layer=4, show=True):
|
|
9
|
+
self.tilemap = load_image(tilesetImage)
|
|
10
|
+
|
|
11
|
+
self.tileDim = pygame.Vector2(tileDim)
|
|
12
|
+
self.scaleDim = pygame.Vector2(tileDim) * scale
|
|
13
|
+
self.scale = scale
|
|
14
|
+
self.mapDim = mapDim
|
|
15
|
+
|
|
16
|
+
self.fill = fill
|
|
17
|
+
self.layer = layer
|
|
18
|
+
self.show = show
|
|
19
|
+
Global.objs[str(self.layer)].append(self)
|
|
20
|
+
|
|
21
|
+
#load images and create basic tilemap
|
|
22
|
+
self.map = {}
|
|
23
|
+
self.tiles: Dict[int, pygame.Surface] = {}
|
|
24
|
+
self.images: Dict[int, pygame.Surface] = {}
|
|
25
|
+
tile = 1
|
|
26
|
+
#split image into tiles
|
|
27
|
+
for y in range(mapDim[1]):
|
|
28
|
+
for x in range(mapDim[0]):
|
|
29
|
+
try:
|
|
30
|
+
self.images[tile] = self.tilemap.subsurface(pygame.Rect(x * self.tileDim.x, y * self.tileDim.y, self.tileDim.x, self.tileDim.y))
|
|
31
|
+
self.tiles[tile] = pygame.transform.scale_by(self.images[tile], self.scale)
|
|
32
|
+
except:
|
|
33
|
+
pass
|
|
34
|
+
tile += 1
|
|
35
|
+
|
|
36
|
+
def update(self):
|
|
37
|
+
if self.show: self.draw()
|
|
38
|
+
|
|
39
|
+
def draw(self):
|
|
40
|
+
for key in self.map:
|
|
41
|
+
tile = self.map[key]
|
|
42
|
+
image = self.tiles[tile['type']]
|
|
43
|
+
pos = tile['pos']
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: GameBox
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0.dev1
|
|
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
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
GameBox/Game.py,sha256=WpuQh_zyyEaRwCH1LIoPPb1c9ouCdeA__j_L8UiMlLE,2465
|
|
2
|
+
GameBox/__init__.py,sha256=mM7TXJro8t3fmEpeWX8zgJc9THrYufTl9YJv5Q9ydR0,817
|
|
3
|
+
GameBox/basics/Cammera.py,sha256=91uhSOb0S1M_Sm5G4Ryen9bVygvVWENgLYXZ3JUplT0,1284
|
|
4
|
+
GameBox/basics/Net.py,sha256=YNbcIrTOt7NHckWUJIyWor1DVYfOk6KPxMprRbLjYm0,597
|
|
5
|
+
GameBox/basics/Shapes.py,sha256=uFSI7HijdkAhelI7wRP1nWVbsu0CHg9NTj52Oy8ato4,2556
|
|
6
|
+
GameBox/basics/sound.py,sha256=SnkCvp0sNV_EoDA9Ocg4D9Ve3gKMBwgfLm_QxmIY4Vk,453
|
|
7
|
+
GameBox/basics/ui.py,sha256=XozEs_C_RM4mPDPRbq9F3qhQrXzIXf_cLMCa07RMu_c,2289
|
|
8
|
+
GameBox/basics/utils.py,sha256=mVYXumz0s1pvn4H_BEQIOI3C7uq3PsfGAMAMVui2cKU,436
|
|
9
|
+
GameBox/helpers/Input.py,sha256=aTbe_fpM_KXyOR5AYxCHwhiQW1uidh9EpJ0gtRqWyGk,2112
|
|
10
|
+
GameBox/helpers/_collisions.py,sha256=9sCEqqX0J_znk4DKMXdhSLJh8hsZeFLbu2a1Uz5s9NM,2555
|
|
11
|
+
GameBox/player/Player.py,sha256=J-Nn5Rv8KLbA6RE4HXWx40Tf-kCcDa2HHRdN3fmAvV0,1533
|
|
12
|
+
GameBox/player/_playerControler.py,sha256=MNhqYBd10z1y9CQdQeZWbyZZyNcluTGtPCHsYreCqKw,1103
|
|
13
|
+
GameBox/player/_playerPhysics.py,sha256=AebFiV9ue-lIODI6zPI2R9vnEMj2PMvgXS5_cpQgDeI,1236
|
|
14
|
+
GameBox/tilemap/Tilemap.py,sha256=r2aVV0l2idkNC6m_rGGq0w3JyKO8FkU_yyHCYl97BXg,1452
|
|
15
|
+
gamebox-0.10.0.dev1.dist-info/METADATA,sha256=WI3XbRWfD4fgRFRZZxAsaeMFm72nB05EjIWXk3PAs10,1065
|
|
16
|
+
gamebox-0.10.0.dev1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
17
|
+
gamebox-0.10.0.dev1.dist-info/licenses/LICENSE,sha256=gcuuhKKc5-dwvyvHsXjlC9oM6N5gZ6umYbC8ewW1Yvg,35821
|
|
18
|
+
gamebox-0.10.0.dev1.dist-info/RECORD,,
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
import numpy as np
|
|
3
|
-
|
|
4
|
-
from ..basics._net import Global
|
|
5
|
-
|
|
6
|
-
class Animation:
|
|
7
|
-
def __init__(self, image, tileDim, startPos, frames, dur):
|
|
8
|
-
if type(image) == str:
|
|
9
|
-
image = pygame.image.load(image)
|
|
10
|
-
|
|
11
|
-
#others
|
|
12
|
-
self.dur = dur
|
|
13
|
-
self.currentFrame = 0
|
|
14
|
-
self.currentDur = 0
|
|
15
|
-
|
|
16
|
-
#get frames from image
|
|
17
|
-
self.frames = []
|
|
18
|
-
x, y = startPos
|
|
19
|
-
x *= tileDim[0]
|
|
20
|
-
y *= tileDim[1]
|
|
21
|
-
for i in range(frames):
|
|
22
|
-
self.frames.append(image.subsurface(x, y, tileDim[0], tileDim[1]))
|
|
23
|
-
x += tileDim[0]
|
|
24
|
-
if x >= image.get_width():
|
|
25
|
-
x = 0
|
|
26
|
-
y += tileDim[1]
|
|
27
|
-
|
|
28
|
-
def update(self, dt):
|
|
29
|
-
self.currentDur += dt
|
|
30
|
-
if self.currentDur >= self.dur:
|
|
31
|
-
self.currentDur = 0
|
|
32
|
-
self.currentFrame += 1
|
|
33
|
-
if self.currentFrame >= len(self.frames):
|
|
34
|
-
self.currentFrame = 0
|
|
35
|
-
|
|
36
|
-
def getFrame(self):
|
|
37
|
-
return self.frames[self.currentFrame]
|
|
38
|
-
|
|
39
|
-
|
GameBox/GameLevel_ui/_sprites.py
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
import numpy as np
|
|
3
|
-
|
|
4
|
-
from ..basics._net import Global
|
|
5
|
-
from ._Animations import Animation
|
|
6
|
-
|
|
7
|
-
class Sprite_2d:
|
|
8
|
-
def __init__(self, pos: tuple, image, scale: float = 1.0, collision = True, dirrection: int = 1):
|
|
9
|
-
"""
|
|
10
|
-
Initialize a 2D sprite.
|
|
11
|
-
|
|
12
|
-
Args:
|
|
13
|
-
pos: Tuple (x, y) for the sprite position
|
|
14
|
-
image: Either a file path (str) or pygame.Surface object
|
|
15
|
-
scale: Scale factor for the sprite (default: 1.0)
|
|
16
|
-
"""
|
|
17
|
-
#add to game
|
|
18
|
-
Global.game.objs.append(self)
|
|
19
|
-
self.collision = collision
|
|
20
|
-
self.__worldPos__ = True
|
|
21
|
-
self.dir = dirrection
|
|
22
|
-
|
|
23
|
-
self.pos = pos
|
|
24
|
-
if type(image) == str:
|
|
25
|
-
self.image = pygame.image.load(image)
|
|
26
|
-
else:
|
|
27
|
-
self.image = image
|
|
28
|
-
|
|
29
|
-
#scale image
|
|
30
|
-
print(self.image)
|
|
31
|
-
self.image = pygame.transform.scale_by(self.image, scale)
|
|
32
|
-
#flip image
|
|
33
|
-
if self.dir == -1:
|
|
34
|
-
self.image = pygame.transform.flip(self.image, True, False)
|
|
35
|
-
|
|
36
|
-
def update(self):
|
|
37
|
-
#world space
|
|
38
|
-
x, y = self.pos
|
|
39
|
-
if self.__worldPos__:
|
|
40
|
-
x = x - Global.cam.x
|
|
41
|
-
y = y - Global.cam.y
|
|
42
|
-
Global.screen.blit(self.image, (x, y))
|
|
43
|
-
if self.collision:
|
|
44
|
-
rect = self.image.get_rect()
|
|
45
|
-
rect.x = x
|
|
46
|
-
rect.y = y
|
|
47
|
-
Global.collisions.append(rect)
|
|
48
|
-
|
|
49
|
-
def switch_dirrection(self):
|
|
50
|
-
self.image = pygame.transform.flip(self.image, True, False)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def move_by(self, x: int, y: int):
|
|
54
|
-
self.pos = (self.pos[0] + x, self.pos[1] + y)
|
|
55
|
-
|
|
56
|
-
def move_to(self, x: int, y: int):
|
|
57
|
-
self.pos = (x, y)
|
|
58
|
-
|
|
59
|
-
def get_pos(self):
|
|
60
|
-
return self.pos
|
|
61
|
-
|
|
62
|
-
def rescale(self, scale: float):
|
|
63
|
-
self.image = pygame.transform.scale_by(self.image, scale)
|
|
64
|
-
|
|
65
|
-
def __remove__(self):
|
|
66
|
-
Global.game.objs.remove(self)
|
|
67
|
-
|
|
68
|
-
def split_image(image, tileDim, startPos):
|
|
69
|
-
if type(image) == str:
|
|
70
|
-
image = pygame.image.load(image)
|
|
71
|
-
else:
|
|
72
|
-
image = image
|
|
73
|
-
|
|
74
|
-
#return image split
|
|
75
|
-
x = startPos[0] * tileDim[0]
|
|
76
|
-
y = startPos[1] * tileDim[1]
|
|
77
|
-
return image.subsurface((x, y, tileDim[0], tileDim[1]))
|
|
78
|
-
|
|
79
|
-
class Animated_Sprite2D:
|
|
80
|
-
def __init__(self, pos, image, imageDim, tileDim, frames, speed, scale = 1.0, collision = True, dirrection = 1):
|
|
81
|
-
self.animation = Animation(image, tileDim, (0, 0), frames, speed)
|
|
82
|
-
self.collision = collision
|
|
83
|
-
self.dir = dirrection
|
|
84
|
-
self.pos = pos
|
|
85
|
-
|
|
86
|
-
self.scale = scale
|
|
87
|
-
self.image = pygame.transform.scale_by(self.animation.getFrame(), scale)
|
|
88
|
-
if self.dir == -1:
|
|
89
|
-
self.image = pygame.transform.flip(self.image, True, False)
|
|
90
|
-
|
|
91
|
-
self.__worldPos__ = True
|
|
92
|
-
|
|
93
|
-
#add to game
|
|
94
|
-
Global.game.objs.append(self)
|
|
95
|
-
|
|
96
|
-
def update(self):
|
|
97
|
-
self.animation.update(Global.dt)
|
|
98
|
-
self.image = pygame.transform.scale_by(self.animation.getFrame(), self.scale)
|
|
99
|
-
if self.dir == -1:
|
|
100
|
-
self.image = pygame.transform.flip(self.image, True, False)
|
|
101
|
-
|
|
102
|
-
#world space
|
|
103
|
-
x, y = self.pos
|
|
104
|
-
if self.__worldPos__:
|
|
105
|
-
x = x - Global.cam.x
|
|
106
|
-
y = y - Global.cam.y
|
|
107
|
-
Global.screen.blit(self.image, (x, y))
|
|
108
|
-
if self.collision:
|
|
109
|
-
rect = self.image.get_rect()
|
|
110
|
-
rect.x = x
|
|
111
|
-
rect.y = y
|
|
112
|
-
Global.collisions.append(rect)
|
|
113
|
-
|
|
114
|
-
def __remove__(self):
|
|
115
|
-
Global.game.objs.remove(self)
|
|
116
|
-
|
|
117
|
-
def switch_dirrection(self):
|
|
118
|
-
self.image = pygame.transform.flip(self.image, True, False)
|
|
119
|
-
|
|
120
|
-
def move_by(self, x: int, y: int):
|
|
121
|
-
self.pos = (self.pos[0] + x, self.pos[1] + y)
|
|
122
|
-
|
|
123
|
-
def move_to(self, x: int, y: int):
|
|
124
|
-
self.pos = (x, y)
|
|
125
|
-
|
|
126
|
-
def get_pos(self):
|
|
127
|
-
return self.pos
|
|
128
|
-
|
|
129
|
-
def rescale(self, scale: float):
|
|
130
|
-
self.image = pygame.transform.scale_by(self.image, scale)
|
|
131
|
-
|
|
132
|
-
class AnimationPlayer2D:
|
|
133
|
-
def __init__(self, pos, scale):
|
|
134
|
-
self.pos = pos
|
|
135
|
-
self.scale = scale
|
|
136
|
-
self.anims = {}
|
|
137
|
-
self.currentAnim = None
|
|
138
|
-
|
|
139
|
-
self.__worldPos__ = True
|
|
140
|
-
|
|
141
|
-
#add to game
|
|
142
|
-
Global.game.objs.append(self)
|
|
143
|
-
|
|
144
|
-
def update(self):
|
|
145
|
-
if self.currentAnim is not None:
|
|
146
|
-
self.anims[self.currentAnim].update()
|
|
147
|
-
|
|
148
|
-
def add_animation(self, name, image, imageDim, tileDim, frames, speed, scale = 1.0, collision = True, dirrection = 1):
|
|
149
|
-
self.anims[name] = Animated_Sprite2D(self.pos, image, imageDim, tileDim, frames, speed, scale, collision, dirrection)
|
|
150
|
-
self.currentAnim = name
|
|
151
|
-
self.anims[self.currentAnim].__remove__()
|
|
152
|
-
|
|
153
|
-
def remove_animation(self, name: str):
|
|
154
|
-
self.anims[name].__remove__()
|
|
155
|
-
del self.anims[name]
|
|
156
|
-
|
|
157
|
-
def set_worldPos(self, worldPos: bool):
|
|
158
|
-
for anim in self.anims:
|
|
159
|
-
self.anims[anim].__worldPos__ = worldPos
|
|
160
|
-
|
|
161
|
-
def __remove__(self):
|
|
162
|
-
if self in Global.game.objs:
|
|
163
|
-
Global.game.objs.remove(self)\
|
|
164
|
-
|
|
165
|
-
def set_scale(self, scale: float):
|
|
166
|
-
for anim in self.anims:
|
|
167
|
-
self.anims[anim].rescale(scale)
|
|
168
|
-
|
|
169
|
-
def set_animation(self, anim: str):
|
|
170
|
-
self.currentAnim = anim
|
|
171
|
-
|
|
172
|
-
def move_by(self, x: int, y: int):
|
|
173
|
-
self.pos = (self.pos[0] + x, self.pos[1] + y)
|
|
174
|
-
for anim in self.anims:
|
|
175
|
-
self.anims[anim].move_by(x, y)
|
|
176
|
-
|
|
177
|
-
def move_to(self, x: int, y: int):
|
|
178
|
-
self.pos = (x, y)
|
|
179
|
-
for anim in self.anims:
|
|
180
|
-
self.anims[anim].move_to(x, y)
|
|
181
|
-
|
|
182
|
-
def get_pos(self):
|
|
183
|
-
return self.pos
|
|
184
|
-
|
|
185
|
-
|
GameBox/_game.py
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
import numpy as np
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
from .basics._net import Global
|
|
6
|
-
from .player._player import Player
|
|
7
|
-
|
|
8
|
-
class Game:
|
|
9
|
-
def __init__(self, width, height, bg_color, WinTitle="GameBox"):
|
|
10
|
-
"""
|
|
11
|
-
Initialize the Game object.
|
|
12
|
-
|
|
13
|
-
Parameters:
|
|
14
|
-
width (int): The width of the game window.
|
|
15
|
-
height (int): The height of the game window.
|
|
16
|
-
bg_color (tuple): The background color of the game window.
|
|
17
|
-
WinTitle (str): The title of the game window.
|
|
18
|
-
|
|
19
|
-
Returns:
|
|
20
|
-
None
|
|
21
|
-
"""
|
|
22
|
-
Global.screenDim = (width, height)
|
|
23
|
-
Global.screen = pygame.display.set_mode(Global.screenDim)
|
|
24
|
-
pygame.display.set_caption(WinTitle)
|
|
25
|
-
Global.bgColor = bg_color
|
|
26
|
-
Global.clock = pygame.time.Clock()
|
|
27
|
-
Global.game = self
|
|
28
|
-
self.objs = []
|
|
29
|
-
self.ui_objs = []
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def update(self, event: pygame.event,frame_rate=60):
|
|
33
|
-
Global.event = event
|
|
34
|
-
#clear collisions
|
|
35
|
-
Global.collisions.clear()
|
|
36
|
-
|
|
37
|
-
Global.dt = Global.clock.tick(frame_rate) / 1000.0
|
|
38
|
-
Global.screen.fill(Global.bgColor)
|
|
39
|
-
player = None
|
|
40
|
-
for obj in self.objs:
|
|
41
|
-
if type(obj) == Player: player = obj
|
|
42
|
-
else: obj.update()
|
|
43
|
-
if player != None: player.update()
|
|
44
|
-
|
|
45
|
-
#update ui
|
|
46
|
-
for obj in self.ui_objs:
|
|
47
|
-
obj.update()
|
|
48
|
-
|
|
49
|
-
pygame.display.update()
|
|
50
|
-
|
|
51
|
-
def get_screen(self):
|
|
52
|
-
return Global.screen
|
|
53
|
-
|
|
54
|
-
def quit(self):
|
|
55
|
-
#will save files later
|
|
56
|
-
for obj in self.objs:
|
|
57
|
-
if hasattr(obj, "_quit") and callable(obj._quit):
|
|
58
|
-
obj._quit()
|
|
59
|
-
|
|
60
|
-
def _set_debug(self, debug: bool):
|
|
61
|
-
"""
|
|
62
|
-
Set the debug mode for the game. This will show / hide debuging information
|
|
63
|
-
like collisions. Note: This feture is for development and testing purposes only.
|
|
64
|
-
|
|
65
|
-
Parameters:
|
|
66
|
-
debug (bool): The debug mode.
|
|
67
|
-
|
|
68
|
-
Returns:
|
|
69
|
-
None
|
|
70
|
-
"""
|
|
71
|
-
Global._debug = debug
|
|
72
|
-
def _get_debug_state(self):
|
|
73
|
-
"""
|
|
74
|
-
Get the debug mode for the game.
|
|
75
|
-
|
|
76
|
-
Returns:
|
|
77
|
-
bool: The debug mode.
|
|
78
|
-
"""
|
|
79
|
-
return Global._debug
|
|
80
|
-
|
|
81
|
-
|
GameBox/basics/__init__.py
DELETED
|
File without changes
|
GameBox/basics/_net.py
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import pygame
|
|
2
|
-
import numpy as np
|
|
3
|
-
|
|
4
|
-
class _global_:
|
|
5
|
-
def __init__(self):
|
|
6
|
-
#screen info and win data
|
|
7
|
-
self.screen: pygame.Surface = None
|
|
8
|
-
self.dt: float = 0
|
|
9
|
-
self.screenDim: tuple = None
|
|
10
|
-
self.bgColor: tuple = None
|
|
11
|
-
self.clock: pygame.time.Clock = None
|
|
12
|
-
|
|
13
|
-
#basics
|
|
14
|
-
#--game and cam
|
|
15
|
-
self.game: object = None
|
|
16
|
-
self.cam: object = None
|
|
17
|
-
self.event: pygame.event = None
|
|
18
|
-
#-collisions
|
|
19
|
-
self.collisions: list[pygame.Rect] = []
|
|
20
|
-
|
|
21
|
-
self.cond: object = None
|
|
22
|
-
|
|
23
|
-
self._debug: bool = False
|
|
24
|
-
|
|
25
|
-
#objects
|
|
26
|
-
self.player = self._player()
|
|
27
|
-
self.tilemap = []
|
|
28
|
-
|
|
29
|
-
class _player:
|
|
30
|
-
def __init__(self):
|
|
31
|
-
self.pos: tuple = None
|
|
32
|
-
self.player: object = None
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Global = _global_()
|