corebitengine 0.1.0__tar.gz → 0.2.0__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,29 @@
1
+ class Camera2D:
2
+
3
+ def __init__(self):
4
+
5
+ self.x = 0
6
+ self.y = 0
7
+
8
+ self.target = None
9
+
10
+ self.screen_width = 1920
11
+ self.screen_height = 1080
12
+
13
+ def follow(self, target):
14
+ self.target = target
15
+
16
+ def update(self):
17
+
18
+ if self.target is None:
19
+ return
20
+
21
+ self.x = self.target.transform.position.x
22
+ self.y = self.target.transform.position.y
23
+
24
+ def world_to_screen(self, x, y):
25
+
26
+ screen_x = x - self.x + self.screen_width // 2
27
+ screen_y = y - self.y + self.screen_height // 2
28
+
29
+ return screen_x, screen_y
@@ -0,0 +1,63 @@
1
+ class BoxCollider2D:
2
+ def __init__(self, width=None, height=None, is_trigger=False):
3
+
4
+ self.game_object = None
5
+ self.engine = None
6
+
7
+ self.istrigger = is_trigger
8
+ self.enabled = True
9
+
10
+ # Eğer manuel verilmezse GameObject size'ını kullan
11
+ self.width = width
12
+ self.height = height
13
+
14
+ def get_size(self):
15
+
16
+ go = self.game_object
17
+
18
+ if self.width is None:
19
+ self.width = go.transform.size.width
20
+
21
+ if self.height is None:
22
+ self.height = go.transform.size.height
23
+
24
+ return self.width, self.height
25
+
26
+ def check_bound(self):
27
+
28
+ go = self.game_object
29
+ w, h = self.get_size()
30
+
31
+ x = go.transform.position.x
32
+ y = go.transform.position.y
33
+
34
+ return {
35
+ "left": x,
36
+ "right": x + w,
37
+ "top": y,
38
+ "bottom": y + h
39
+ }
40
+
41
+ def check_collisions(self, other):
42
+
43
+ a = self.check_bound()
44
+ b = other.check_bound()
45
+
46
+ return (
47
+ a["left"] < b["right"] and
48
+ a["right"] > b["left"] and
49
+ a["top"] < b["bottom"] and
50
+ a["bottom"] > b["top"]
51
+ )
52
+
53
+ def get_overlap(self, other):
54
+
55
+ a = self.check_bound()
56
+ b = other.check_bound()
57
+
58
+ left = a["right"] - b["left"]
59
+ right = b["right"] - a["left"]
60
+ top = a["bottom"] - b["top"]
61
+ bottom = b["bottom"] - a["top"]
62
+
63
+ return left, right, top, bottom
@@ -0,0 +1,217 @@
1
+ import pygame
2
+ import time
3
+ from .CameraSystem import Camera2D
4
+ from .ColliderSystem import BoxCollider2D
5
+ from .rigidbody2D import Rigidbody2D
6
+
7
+
8
+ class GameLoop():
9
+ def __init__(self):
10
+ self.game_objects = []
11
+ self.camera = Camera2D()
12
+ self.isrun = False
13
+
14
+ # 🔥 collision tracking (Unity OnEnter/Exit için)
15
+ self.active_collisions = set()
16
+
17
+ # -------------------------
18
+ # ADD OBJECT
19
+ # -------------------------
20
+ def add_obj(self, obj):
21
+ obj.engine = self
22
+
23
+ for c in obj.components:
24
+ c.game_object = obj
25
+ c.engine = self
26
+
27
+ self.game_objects.append(obj)
28
+
29
+ # -------------------------
30
+ # EVENT CALLER
31
+ # -------------------------
32
+ def call(self, obj, func, other):
33
+ for c in obj.components:
34
+ if hasattr(c, func):
35
+ getattr(c, func)(other)
36
+
37
+ # -------------------------
38
+ # COLLISION SYSTEM
39
+ # -------------------------
40
+ def check_collisions(self):
41
+
42
+ objects = self.game_objects
43
+ new_collisions = set()
44
+
45
+ for i in range(len(objects)):
46
+ for j in range(i + 1, len(objects)):
47
+
48
+ a = objects[i]
49
+ b = objects[j]
50
+
51
+ colA = a.get_component(BoxCollider2D)
52
+ colB = b.get_component(BoxCollider2D)
53
+
54
+ if not colA or not colB:
55
+ continue
56
+
57
+ if not colA.check_collisions(colB):
58
+ continue
59
+
60
+ if not colA.enabled or not colB.enabled:
61
+ continue
62
+
63
+ pair = (id(a), id(b))
64
+ new_collisions.add(pair)
65
+
66
+ rb = a.get_component(Rigidbody2D)
67
+
68
+ overlap_left, overlap_right, overlap_top, overlap_bottom = \
69
+ colA.get_overlap(colB)
70
+
71
+ min_x = min(overlap_left, overlap_right)
72
+ min_y = min(overlap_top, overlap_bottom)
73
+
74
+ # -------------------------
75
+ # HORIZONTAL COLLISION
76
+ # -------------------------
77
+ if min_x < min_y:
78
+
79
+ if overlap_left < overlap_right:
80
+ a.transform.position.x -= overlap_left
81
+ else:
82
+ a.transform.position.x += overlap_right
83
+
84
+ if rb:
85
+ rb.velocity.x = 0
86
+
87
+ # -------------------------
88
+ # VERTICAL COLLISION
89
+ # -------------------------
90
+ else:
91
+
92
+ # TOP (ground landing)
93
+ if overlap_top < overlap_bottom:
94
+
95
+ a.transform.position.y -= overlap_top
96
+
97
+ if rb:
98
+ if rb.velocity.y > 0:
99
+ rb.velocity.y = 0
100
+
101
+
102
+ else:
103
+
104
+ a.transform.position.y += overlap_bottom
105
+
106
+ if rb:
107
+ if rb.velocity.y < 0:
108
+ rb.velocity.y = 0
109
+
110
+ # -------------------------
111
+ # TRIGGERS
112
+ # -------------------------
113
+ if colA.istrigger or colB.istrigger:
114
+ self.call(a, "OnTriggerEnter", b)
115
+ self.call(b, "OnTriggerEnter", a)
116
+ self.call(a, "OnTriggerStay", b)
117
+ self.call(b, "OnTriggerStay", a)
118
+ continue
119
+
120
+ # -------------------------
121
+ # COLLISION EVENTS
122
+ # -------------------------
123
+ if pair not in self.active_collisions:
124
+ self.call(a, "OnCollisionEnter", b)
125
+ self.call(b, "OnCollisionEnter", a)
126
+
127
+ self.call(a, "OnCollisionStay", b)
128
+ self.call(b, "OnCollisionStay", a)
129
+
130
+ # -------------------------
131
+ # EXIT EVENTS
132
+ # -------------------------
133
+ for pair in self.active_collisions:
134
+ if pair not in new_collisions:
135
+
136
+ a_id, b_id = pair
137
+ a = next((o for o in objects if id(o) == a_id), None)
138
+ b = next((o for o in objects if id(o) == b_id), None)
139
+
140
+ if a and b:
141
+ self.call(a, "OnCollisionExit", b)
142
+ self.call(b, "OnCollisionExit", a)
143
+
144
+ self.active_collisions = new_collisions
145
+
146
+ # -------------------------
147
+ # MAIN LOOP
148
+ # -------------------------
149
+ def run(self, debug=False):
150
+
151
+ pygame.init()
152
+ self.isrun = True
153
+
154
+ last_time = time.time()
155
+
156
+ screen = pygame.display.set_mode((1920, 1080)) if debug else pygame.display.set_mode((0, 0), pygame.NOFRAME)
157
+
158
+ for obj in self.game_objects:
159
+ obj.start()
160
+
161
+ while self.isrun:
162
+
163
+ now_time = time.time()
164
+ dt = now_time - last_time
165
+ last_time = now_time
166
+
167
+ for event in pygame.event.get():
168
+ if event.type == pygame.QUIT:
169
+ self.isrun = False
170
+
171
+ keys = pygame.key.get_pressed()
172
+
173
+ if keys[pygame.K_ESCAPE]:
174
+ self.isrun = False
175
+
176
+ # -------------------------
177
+ # SAVE LAST POSITION
178
+ # -------------------------
179
+ for obj in self.game_objects:
180
+ obj.last_position = (
181
+ obj.transform.position.x,
182
+ obj.transform.position.y
183
+ )
184
+
185
+ # -------------------------
186
+ # UPDATE
187
+ # -------------------------
188
+ for obj in self.game_objects:
189
+ obj.update(dt)
190
+
191
+ # -------------------------
192
+ # COLLISION
193
+ # -------------------------
194
+ self.check_collisions()
195
+
196
+ # -------------------------
197
+ # DRAW
198
+ # -------------------------
199
+ screen.fill((0, 0, 0))
200
+
201
+ for obj in self.game_objects:
202
+ obj.draw(screen, self.camera)
203
+
204
+ pygame.display.flip()
205
+
206
+ self.camera.update()
207
+
208
+ pygame.quit()
209
+
210
+ # -------------------------
211
+ # FIND SYSTEM
212
+ # -------------------------
213
+ def find(self, name):
214
+ for obj in self.game_objects:
215
+ if obj.name == name:
216
+ return obj
217
+ return None
@@ -0,0 +1,240 @@
1
+ import pygame
2
+
3
+ # =========================
4
+ # TRANSFORM
5
+ # =========================
6
+
7
+ class Position:
8
+ def __init__(self):
9
+ self.x = 0
10
+ self.y = 0
11
+
12
+
13
+ class Size:
14
+ def __init__(self):
15
+ self.width = 100
16
+ self.height = 100
17
+
18
+
19
+ class Rotation:
20
+ def __init__(self):
21
+ self.rotation = 0
22
+
23
+
24
+ class Transform:
25
+ def __init__(self):
26
+ self.position = Position()
27
+ self.size = Size()
28
+ self.rotation = Rotation()
29
+
30
+
31
+ # =========================
32
+ # GAME OBJECT
33
+ # =========================
34
+
35
+ class GameObject:
36
+
37
+ def __init__(self, name):
38
+ self.name = name
39
+ self.visible = True
40
+ self.engine = None
41
+
42
+ self.transform = Transform()
43
+ self.components = []
44
+
45
+ def add_component(self, component):
46
+ component.game_object = self
47
+ self.components.append(component)
48
+
49
+ if self.engine:
50
+ component.engine = self.engine
51
+
52
+ def get_component(self, component_type):
53
+
54
+ for c in self.components:
55
+
56
+ if isinstance(c, component_type):
57
+ return c
58
+
59
+ return None
60
+
61
+ def start(self):
62
+ for c in self.components:
63
+ if hasattr(c, "start"):
64
+ c.start()
65
+
66
+ def update(self, dt):
67
+ for c in self.components:
68
+ if hasattr(c, "update"):
69
+ c.update(dt)
70
+
71
+ def draw(self, screen, camera):
72
+
73
+ if not self.visible:
74
+ return
75
+
76
+ for c in self.components:
77
+ if hasattr(c, "draw"):
78
+ c.draw(screen, camera)
79
+
80
+ def get_component(self, component_type):
81
+
82
+ for c in self.components:
83
+
84
+ if isinstance(c, component_type):
85
+ return c
86
+
87
+ return None
88
+
89
+
90
+ # =========================
91
+ # SPRITE RENDERER
92
+ # =========================
93
+
94
+ class SpriteRenderer2D:
95
+
96
+ def __init__(self, image):
97
+
98
+ self.image_path = image
99
+ self.image = None
100
+
101
+ def start(self):
102
+
103
+ self.image = pygame.image.load(
104
+ self.image_path
105
+ ).convert_alpha()
106
+
107
+ def draw(self, screen, camera):
108
+
109
+ if not hasattr(self, "game_object"):
110
+ return
111
+
112
+ if self.image is None:
113
+ return
114
+
115
+ go = self.game_object
116
+
117
+ # CAMERA OFFSET
118
+ x, y = camera.world_to_screen(
119
+ go.transform.position.x,
120
+ go.transform.position.y
121
+ )
122
+
123
+ scaled_image = pygame.transform.scale(
124
+ self.image,
125
+ (
126
+ int(go.transform.size.width),
127
+ int(go.transform.size.height)
128
+ )
129
+ )
130
+
131
+ screen.blit(
132
+ scaled_image,
133
+ (x, y)
134
+ )
135
+
136
+
137
+ # =========================
138
+ # RECT RENDERER
139
+ # =========================
140
+
141
+ class RectRenderer2D:
142
+
143
+ def __init__(self, width=100, height=100, color=(255,0,0)):
144
+
145
+ self.width = width
146
+ self.height = height
147
+ self.color = color
148
+
149
+ def draw(self, screen, camera):
150
+
151
+ go = self.game_object
152
+
153
+ # CAMERA OFFSET
154
+ x, y = camera.world_to_screen(
155
+ go.transform.position.x,
156
+ go.transform.position.y
157
+ )
158
+
159
+ pygame.draw.rect(
160
+ screen,
161
+ self.color,
162
+ (
163
+ x,
164
+ y,
165
+ self.width,
166
+ self.height
167
+ )
168
+ )
169
+
170
+
171
+ # =========================
172
+ # CIRCLE RENDERER
173
+ # =========================
174
+
175
+ class CircleRenderer2D:
176
+
177
+ def __init__(self, radius=50, color=(0,255,0)):
178
+
179
+ self.radius = radius
180
+ self.color = color
181
+
182
+ def draw(self, screen, camera):
183
+
184
+ go = self.game_object
185
+
186
+ # CAMERA OFFSET
187
+ x, y = camera.world_to_screen(
188
+ go.transform.position.x,
189
+ go.transform.position.y
190
+ )
191
+
192
+ pygame.draw.circle(
193
+ screen,
194
+ self.color,
195
+ (
196
+ int(x),
197
+ int(y)
198
+ ),
199
+ self.radius
200
+ )
201
+
202
+
203
+ # =========================
204
+ # LINE RENDERER
205
+ # =========================
206
+
207
+ class LineRenderer2D:
208
+
209
+ def __init__(self, x2, y2, color=(255,255,255), width=2):
210
+
211
+ self.x2 = x2
212
+ self.y2 = y2
213
+ self.color = color
214
+ self.width = width
215
+
216
+ def draw(self, screen, camera):
217
+
218
+ go = self.game_object
219
+
220
+ # START POSITION
221
+ x1, y1 = camera.world_to_screen(
222
+ go.transform.position.x,
223
+ go.transform.position.y
224
+ )
225
+
226
+ # END POSITION
227
+ x2, y2 = camera.world_to_screen(
228
+ self.x2,
229
+ self.y2
230
+ )
231
+
232
+ pygame.draw.line(
233
+ screen,
234
+ self.color,
235
+ (x1, y1),
236
+ (x2, y2),
237
+ self.width
238
+ )
239
+
240
+ ########Coliders############
@@ -0,0 +1,170 @@
1
+ import pygame
2
+ import sys
3
+ from Lib.GameObjectSystem import GameObject
4
+
5
+ class Template:
6
+ def start(self):pass
7
+
8
+
9
+
10
+ def update(self,dt):pass
11
+
12
+
13
+ def __init__(self,):pass
14
+
15
+
16
+
17
+ class Input:
18
+ # =========================
19
+ # LETTER KEYS
20
+ # =========================
21
+ K_a = pygame.K_a
22
+ K_b = pygame.K_b
23
+ K_c = pygame.K_c
24
+ K_d = pygame.K_d
25
+ K_e = pygame.K_e
26
+ K_f = pygame.K_f
27
+ K_g = pygame.K_g
28
+ K_h = pygame.K_h
29
+ K_i = pygame.K_i
30
+ K_j = pygame.K_j
31
+ K_k = pygame.K_k
32
+ K_l = pygame.K_l
33
+ K_m = pygame.K_m
34
+ K_n = pygame.K_n
35
+ K_o = pygame.K_o
36
+ K_p = pygame.K_p
37
+ K_q = pygame.K_q
38
+ K_r = pygame.K_r
39
+ K_s = pygame.K_s
40
+ K_t = pygame.K_t
41
+ K_u = pygame.K_u
42
+ K_v = pygame.K_v
43
+ K_w = pygame.K_w
44
+ K_x = pygame.K_x
45
+ K_y = pygame.K_y
46
+ K_z = pygame.K_z
47
+
48
+ # =========================
49
+ # NUMBER KEYS
50
+ # =========================
51
+ K_0 = pygame.K_0
52
+ K_1 = pygame.K_1
53
+ K_2 = pygame.K_2
54
+ K_3 = pygame.K_3
55
+ K_4 = pygame.K_4
56
+ K_5 = pygame.K_5
57
+ K_6 = pygame.K_6
58
+ K_7 = pygame.K_7
59
+ K_8 = pygame.K_8
60
+ K_9 = pygame.K_9
61
+
62
+ # =========================
63
+ # FUNCTION KEYS
64
+ # =========================
65
+ K_F1 = pygame.K_F1
66
+ K_F2 = pygame.K_F2
67
+ K_F3 = pygame.K_F3
68
+ K_F4 = pygame.K_F4
69
+ K_F5 = pygame.K_F5
70
+ K_F6 = pygame.K_F6
71
+ K_F7 = pygame.K_F7
72
+ K_F8 = pygame.K_F8
73
+ K_F9 = pygame.K_F9
74
+ K_F10 = pygame.K_F10
75
+ K_F11 = pygame.K_F11
76
+ K_F12 = pygame.K_F12
77
+
78
+ # =========================
79
+ # ARROW KEYS
80
+ # =========================
81
+ K_UP = pygame.K_UP
82
+ K_DOWN = pygame.K_DOWN
83
+ K_LEFT = pygame.K_LEFT
84
+ K_RIGHT = pygame.K_RIGHT
85
+
86
+ # =========================
87
+ # SPECIAL KEYS
88
+ # =========================
89
+ K_SPACE = pygame.K_SPACE
90
+ K_ESCAPE = pygame.K_ESCAPE
91
+ K_RETURN = pygame.K_RETURN
92
+ K_BACKSPACE = pygame.K_BACKSPACE
93
+ K_TAB = pygame.K_TAB
94
+ K_LSHIFT = pygame.K_LSHIFT
95
+ K_RSHIFT = pygame.K_RSHIFT
96
+ K_LCTRL = pygame.K_LCTRL
97
+ K_RCTRL = pygame.K_RCTRL
98
+ K_LALT = pygame.K_LALT
99
+ K_RALT = pygame.K_RALT
100
+ K_CAPSLOCK = pygame.K_CAPSLOCK
101
+
102
+ # =========================
103
+ # SYMBOL KEYS
104
+ # =========================
105
+ K_MINUS = pygame.K_MINUS
106
+ K_EQUALS = pygame.K_EQUALS
107
+ K_LEFTBRACKET = pygame.K_LEFTBRACKET
108
+ K_RIGHTBRACKET = pygame.K_RIGHTBRACKET
109
+ K_SEMICOLON = pygame.K_SEMICOLON
110
+ K_QUOTE = pygame.K_QUOTE
111
+ K_COMMA = pygame.K_COMMA
112
+ K_PERIOD = pygame.K_PERIOD
113
+ K_SLASH = pygame.K_SLASH
114
+ K_BACKSLASH = pygame.K_BACKSLASH
115
+
116
+ # =========================
117
+ # MOUSE BUTTONS
118
+ # =========================
119
+ MOUSE_LEFT = 0
120
+ MOUSE_MIDDLE = 1
121
+ MOUSE_RIGHT = 2
122
+
123
+
124
+
125
+ def GetAxıs(self, axis, delta_time):
126
+
127
+ keys = pygame.key.get_pressed()
128
+
129
+ if not hasattr(self, "game_object"):
130
+ return
131
+
132
+ go = self.game_object
133
+
134
+ if axis == "Horizontal":
135
+
136
+ if keys[pygame.K_a]:
137
+ go.transform.position.x -= self.speed * delta_time
138
+
139
+ if keys[pygame.K_d]:
140
+ go.transform.position.x += self.speed * delta_time
141
+
142
+ if axis == "Vertical":
143
+
144
+ if keys[pygame.K_w]:
145
+ go.transform.position.y -= self.speed * delta_time
146
+
147
+ if keys[pygame.K_s]:
148
+ go.transform.position.y += self.speed * delta_time
149
+
150
+ @staticmethod
151
+ def GetMouse(button):
152
+ mouse = pygame.mouse.get_pressed()
153
+ return mouse[button]
154
+
155
+ @staticmethod
156
+ def MousePosition():
157
+ return pygame.mouse.get_pos()
158
+
159
+ #Input Already Command
160
+ @staticmethod
161
+ def GetKey(key):
162
+ keys = pygame.key.get_pressed()
163
+ return keys[key]
164
+
165
+ def Exit_Game(self,exit_comman = pygame.K_ESCAPE):
166
+ keys = pygame.key.get_pressed()
167
+ if keys[exit_comman]:
168
+ pygame.quit()
169
+ sys.exit()
170
+
@@ -0,0 +1,26 @@
1
+ class Vector2:
2
+ def __init__(self,x=0,y=0):
3
+ self.x = x
4
+ self.y = y
5
+
6
+
7
+
8
+
9
+ class Rigidbody2D:
10
+ def __init__(self):
11
+ self.velocity = Vector2()
12
+ self.gravity = 900
13
+ self.usegravity = True
14
+
15
+ def update(self,dt):
16
+
17
+ if not hasattr(self, "game_object"):
18
+ return
19
+
20
+ go =self.game_object
21
+
22
+ if self.usegravity:
23
+ self.velocity.y += self.gravity * dt
24
+
25
+ go.transform.position.x += self.velocity.x *dt
26
+ go.transform.position.y += self.velocity.y *dt
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: corebitengine
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Kendi oyun motoru sistemlerim için kütüphane
5
5
  Requires-Python: >=3.7
6
6
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: corebitengine
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Kendi oyun motoru sistemlerim için kütüphane
5
5
  Requires-Python: >=3.7
6
6
  Description-Content-Type: text/markdown
@@ -0,0 +1,12 @@
1
+ pyproject.toml
2
+ CoreBitEngine/CameraSystem.py
3
+ CoreBitEngine/ColliderSystem.py
4
+ CoreBitEngine/Engine.py
5
+ CoreBitEngine/GameObjectSystem.py
6
+ CoreBitEngine/TempLine.py
7
+ CoreBitEngine/rigidbody2D.py
8
+ corebitengine.egg-info/PKG-INFO
9
+ corebitengine.egg-info/SOURCES.txt
10
+ corebitengine.egg-info/dependency_links.txt
11
+ corebitengine.egg-info/requires.txt
12
+ corebitengine.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ CoreBitEngine
@@ -4,13 +4,14 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "corebitengine"
7
- version = "0.1.0"
7
+ version = "0.2.0" # Versiyonu 0.1.1 yapıyoruz ki güncelleme algılansın
8
8
  description = "Kendi oyun motoru sistemlerim için kütüphane"
9
- readme = "README.md" # İsteğe bağlı: Proje açıklaması için bir markdown dosyası
9
+ readme = "README.md"
10
10
  requires-python = ">=3.7"
11
11
  dependencies = [
12
12
  "pygame"
13
13
  ]
14
14
 
15
- [tool.setuptools.packages.find]
16
- where = ["CoreBitEngine"] # Kodların hangi klasörde aranacağını belirtir
15
+ # En temiz ve hatasız paket bulma yöntemi budur:
16
+ [tool.setuptools]
17
+ packages = ["CoreBitEngine"]
@@ -1,6 +0,0 @@
1
- pyproject.toml
2
- CoreBitEngine/corebitengine.egg-info/PKG-INFO
3
- CoreBitEngine/corebitengine.egg-info/SOURCES.txt
4
- CoreBitEngine/corebitengine.egg-info/dependency_links.txt
5
- CoreBitEngine/corebitengine.egg-info/requires.txt
6
- CoreBitEngine/corebitengine.egg-info/top_level.txt
File without changes