cobrapad 0.2.2__tar.gz → 0.2.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cobrapad
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: A beginner-friendly 2D game engine built on top of pygame
5
5
  Author: knyaz
6
6
  License: MIT
@@ -26,7 +26,7 @@ Cobrapad is a fast and easy-to-use 2D game library built on top of Pygame. It is
26
26
  - Add images and backgrounds easily
27
27
  - Display text on screen
28
28
  - Create clickable buttons
29
- - Animate objects with `moves()` and `movesTo()`
29
+ - Animate objects with `moves()` and `movesBy()`
30
30
  - Show and hide objects
31
31
  - Detect mouse clicks anywhere on screen
32
32
  - Delay actions with a timer using `stop()`
@@ -15,7 +15,7 @@ Cobrapad is a fast and easy-to-use 2D game library built on top of Pygame. It is
15
15
  - Add images and backgrounds easily
16
16
  - Display text on screen
17
17
  - Create clickable buttons
18
- - Animate objects with `moves()` and `movesTo()`
18
+ - Animate objects with `moves()` and `movesBy()`
19
19
  - Show and hide objects
20
20
  - Detect mouse clicks anywhere on screen
21
21
  - Delay actions with a timer using `stop()`
@@ -62,4 +62,4 @@ Join our Discord server to learn Cobrapad, ask questions, and share your project
62
62
 
63
63
 
64
64
  ## License
65
- MIT License Copyright (c) 2026 Knyaz
65
+ MIT License Copyright (c) 2026 Knyaz
@@ -7,6 +7,8 @@ import sys
7
7
 
8
8
 
9
9
 
10
+
11
+
10
12
  screenX = 0
11
13
  screenY = 0
12
14
 
@@ -112,18 +114,25 @@ class KareNesnesi:
112
114
  self._moves_aktif = False
113
115
 
114
116
  def moves(self, y=0, x=0, speed=1):
117
+ self._movesby_aktif = False
115
118
  self._moves_y = y
116
119
  self._moves_x = x
117
120
  self._moves_speed = speed
118
121
  self._moves_aktif = True
119
122
 
120
- def movesTo(self, y=0, x=0, speed=1):
121
- self._movesto_y = y
122
- self._movesto_x = x
123
- self._movesto_speed = speed
124
- self._movesto_hedef_x = self.x + x
125
- self._movesto_hedef_y = self.y + y
126
- self._movesto_aktif = True
123
+ def movesBy(self, y=0, x=0, speed=1):
124
+ self._moves_aktif = False
125
+ self._movesby_hedef_x = self.x + x
126
+ self._movesby_hedef_y = self.y + y
127
+ mesafe = (x**2 + y**2) ** 0.5
128
+ if mesafe == 0:
129
+ self._movesby_speed_x = 0
130
+ self._movesby_speed_y = 0
131
+ else:
132
+ self._movesby_speed_x = speed * (x / mesafe)
133
+ self._movesby_speed_y = speed * (y / mesafe)
134
+ self._movesby_aktif = True
135
+
127
136
 
128
137
 
129
138
  class DaireNesnesi:
@@ -137,37 +146,74 @@ class DaireNesnesi:
137
146
  self._moves_aktif = False
138
147
 
139
148
  def moves(self, y=0, x=0, speed=1):
149
+ self._movesby_aktif = False
140
150
  self._moves_y = y
141
151
  self._moves_x = x
142
152
  self._moves_speed = speed
143
153
  self._moves_aktif = True
144
154
 
145
- def movesTo(self, y=0, x=0, speed=1):
146
- self._movesto_y = y
147
- self._movesto_x = x
148
- self._movesto_speed = speed
149
- self._movesto_hedef_x = self.x + x
150
- self._movesto_hedef_y = self.y + y
151
- self._movesto_aktif = True
155
+ def movesBy(self, y=0, x=0, speed=1):
156
+ self._moves_aktif = False
157
+ self._movesby_hedef_x = self.x + x
158
+ self._movesby_hedef_y = self.y + y
159
+ mesafe = (x**2 + y**2) ** 0.5
160
+ if mesafe == 0:
161
+ self._movesby_speed_x = 0
162
+ self._movesby_speed_y = 0
163
+ else:
164
+ self._movesby_speed_x = speed * (x / mesafe)
165
+ self._movesby_speed_y = speed * (y / mesafe)
166
+ self._movesby_aktif = True
167
+
152
168
 
153
169
 
154
170
 
155
171
  class YaziNesnesi:
156
172
  def __init__(self, yazi, x, y, w, renk, tip):
157
- self.yazi = str(yazi)
173
+ self.tip = "yazi"
174
+ self._yazi = str(yazi)
158
175
  self.x = x
159
176
  self.y = y
160
177
  self.w = w
161
178
  self.renk = renk
162
- self.tip = tip
163
179
  self.visible = True
164
-
165
180
 
166
181
  try:
167
182
  self.font_objesi = pygame.font.SysFont(tip, w)
168
183
  except Exception:
169
184
  self.font_objesi = pygame.font.Font(None, w)
170
-
185
+
186
+ self.surface = self.font_objesi.render(self._yazi, True, self.renk)
187
+
188
+
189
+ @property
190
+ def yazi(self):
191
+ return self._yazi
192
+
193
+ @yazi.setter
194
+ def yazi(self, yeni_yazi):
195
+ if self._yazi != str(yeni_yazi):
196
+ self._yazi = str(yeni_yazi)
197
+ self.surface = self.font_objesi.render(self._yazi, True, self.renk)
198
+ def moves(self, y=0, x=0, speed=1):
199
+ self._movesby_aktif = False
200
+ self._moves_y = y
201
+ self._moves_x = x
202
+ self._moves_speed = speed
203
+ self._moves_aktif = True
204
+
205
+ def movesBy(self, y=0, x=0, speed=1):
206
+ self._moves_aktif = False
207
+ self._movesby_hedef_x = self.x + x
208
+ self._movesby_hedef_y = self.y + y
209
+ mesafe = (x**2 + y**2) ** 0.5
210
+ if mesafe == 0:
211
+ self._movesby_speed_x = 0
212
+ self._movesby_speed_y = 0
213
+ else:
214
+ self._movesby_speed_x = speed * (x / mesafe)
215
+ self._movesby_speed_y = speed * (y / mesafe)
216
+ self._movesby_aktif = True
171
217
  class OvalNesnesi:
172
218
  def __init__(self, x, y, w, h, renk):
173
219
  self.tip = "oval"
@@ -183,18 +229,24 @@ class OvalNesnesi:
183
229
  self._moves_aktif = False
184
230
 
185
231
  def moves(self, y=0, x=0, speed=1):
232
+ self._movesby_aktif = False
186
233
  self._moves_y = y
187
234
  self._moves_x = x
188
235
  self._moves_speed = speed
189
- self._moves_aktif = True
236
+ self._moves_aktif = True
190
237
 
191
- def movesTo(self, y=0, x=0, speed=1):
192
- self._movesto_y = y
193
- self._movesto_x = x
194
- self._movesto_speed = speed
195
- self._movesto_hedef_x = self.x + x
196
- self._movesto_hedef_y = self.y + y
197
- self._movesto_aktif = True
238
+ def movesBy(self, y=0, x=0, speed=1):
239
+ self._moves_aktif = False
240
+ self._movesby_hedef_x = self.x + x
241
+ self._movesby_hedef_y = self.y + y
242
+ mesafe = (x**2 + y**2) ** 0.5
243
+ if mesafe == 0:
244
+ self._movesby_speed_x = 0
245
+ self._movesby_speed_y = 0
246
+ else:
247
+ self._movesby_speed_x = speed * (x / mesafe)
248
+ self._movesby_speed_y = speed * (y / mesafe)
249
+ self._movesby_aktif = True
198
250
 
199
251
  class PolygonNesnesi:
200
252
  def __init__(self, noktalar, kalinrik, renk):
@@ -208,8 +260,10 @@ class PolygonNesnesi:
208
260
  class ResimNesnesi:
209
261
  def __init__(self, ekran_resim):
210
262
  self.ekran_resim = ekran_resim
211
- self.surface = pygame.image.load(ekran_resim).convert()
263
+ orijinal_surface = pygame.image.load(ekran_resim).convert()
264
+ self.surface = pygame.transform.scale(orijinal_surface, (screenX, screenY))
212
265
  self.visible = True
266
+
213
267
 
214
268
 
215
269
 
@@ -225,20 +279,25 @@ class Resim2Nesnesi:
225
279
  self._moves_aktif = False
226
280
 
227
281
  def moves(self, y=0, x=0, speed=1):
282
+ self._movesby_aktif = False
228
283
  self._moves_y = y
229
284
  self._moves_x = x
230
285
  self._moves_speed = speed
231
286
  self._moves_aktif = True
232
287
 
233
- def movesTo(self, y=0, x=0, speed=1):
234
- self._movesto_y = y
235
- self._movesto_x = x
236
- self._movesto_speed = speed
237
- self._movesto_hedef_x = self.x + x
238
- self._movesto_hedef_y = self.y + y
239
- self._movesto_aktif = True
240
-
241
-
288
+ def movesBy(self, y=0, x=0, speed=1):
289
+ self._moves_aktif = False
290
+ self._movesby_hedef_x = self.x + x
291
+ self._movesby_hedef_y = self.y + y
292
+ mesafe = (x**2 + y**2) ** 0.5
293
+ if mesafe == 0:
294
+ self._movesby_speed_x = 0
295
+ self._movesby_speed_y = 0
296
+ else:
297
+ self._movesby_speed_x = speed * (x / mesafe)
298
+ self._movesby_speed_y = speed * (y / mesafe)
299
+ self._movesby_aktif = True
300
+
242
301
 
243
302
 
244
303
 
@@ -337,6 +396,8 @@ class AddManager:
337
396
  raise ValueError("Cobrapad Error: You must call setup() before using add.background()")
338
397
  else:
339
398
  pass
399
+ if pencere is None:
400
+ raise RuntimeError("Cobrapad Error: You must call open_screen() before add.background()!")
340
401
  nesne3 = ResimNesnesi(ekran_resim)
341
402
  resim_kutusu.append(nesne3)
342
403
  return nesne3
@@ -414,6 +475,26 @@ def stop(nesne, durduma_suresi, sonra):
414
475
  kutularin_listesi.append(nesne)
415
476
  return kutularin_listesi
416
477
 
478
+
479
+ def _hareket_uygula(nesne):
480
+ if hasattr(nesne, '_moves_aktif') and nesne._moves_aktif:
481
+ nesne.x += nesne._moves_x * nesne._moves_speed
482
+ nesne.y += nesne._moves_y * nesne._moves_speed
483
+
484
+ if hasattr(nesne, '_movesby_aktif') and nesne._movesby_aktif:
485
+ if abs(nesne.x - nesne._movesby_hedef_x) <= abs(nesne._movesby_speed_x):
486
+ nesne.x = nesne._movesby_hedef_x
487
+ else:
488
+ nesne.x += nesne._movesby_speed_x
489
+
490
+ if abs(nesne.y - nesne._movesby_hedef_y) <= abs(nesne._movesby_speed_y):
491
+ nesne.y = nesne._movesby_hedef_y
492
+ else:
493
+ nesne.y += nesne._movesby_speed_y
494
+
495
+ if nesne.x == nesne._movesby_hedef_x and nesne.y == nesne._movesby_hedef_y:
496
+ nesne._movesby_aktif = False
497
+
417
498
  def run(callback=None):
418
499
  global pencere, arka_plan_rengi, saat, cizim_listesi, kutular, kutu_hazirmi2
419
500
 
@@ -439,6 +520,9 @@ def run(callback=None):
439
520
  fonksiyon2(olay.pos)
440
521
  if olay.button == 1:
441
522
  for nesne6 in button_kutusu:
523
+ if hasattr(nesne6, 'visible') and not nesne6.visible:
524
+ continue
525
+
442
526
  if hasattr(nesne6, 'tip'):
443
527
  if nesne6.tip == "kare" or nesne6.tip == "oval":
444
528
  rect = pygame.Rect(nesne6.x, nesne6.y, nesne6.w, nesne6.h)
@@ -447,7 +531,11 @@ def run(callback=None):
447
531
  elif nesne6.tip == "daire":
448
532
  dx = olay.pos[0] - nesne6.x
449
533
  dy = olay.pos[1] - nesne6.y
450
- if (dx**2 + dy**2) <= nesne6.yaricap**2:
534
+ if (dx ** 2 + dy ** 2) <= nesne6.yaricap ** 2:
535
+ nesne6._onclick()
536
+ elif nesne6.tip == "yazi":
537
+ rect = pygame.Rect(nesne6.x, nesne6.y, nesne6.surface.get_width(), nesne6.surface.get_height())
538
+ if rect.collidepoint(olay.pos):
451
539
  nesne6._onclick()
452
540
  else:
453
541
  rect = pygame.Rect(nesne6.x, nesne6.y, nesne6.surface.get_width(), nesne6.surface.get_height())
@@ -460,6 +548,10 @@ def run(callback=None):
460
548
  if pencere:
461
549
  pencere.fill(arka_plan_rengi)
462
550
 
551
+ for nesne3 in resim_kutusu:
552
+ if nesne3.visible:
553
+ pencere.blit(nesne3.surface, (0, 0))
554
+
463
555
  for nesne in cizim_listesi:
464
556
  if nesne.visible:
465
557
  if nesne.tip == "kare":
@@ -470,40 +562,18 @@ def run(callback=None):
470
562
  pygame.draw.ellipse(pencere, nesne.renk, (nesne.x, nesne.y, nesne.w, nesne.h))
471
563
  elif nesne.tip == "polygon":
472
564
  pygame.draw.polygon(pencere, nesne.renk, nesne.noktalar, nesne.kalinrik)
473
- if hasattr(nesne, '_moves_aktif') and nesne._moves_aktif:
474
- nesne.x += nesne._moves_x * nesne._moves_speed
475
- nesne.y += nesne._moves_y * nesne._moves_speed
476
- if hasattr(nesne, '_movesto_aktif') and nesne._movesto_aktif:
477
- if abs(nesne.x - nesne._movesto_hedef_x) > nesne._movesto_speed:
478
- nesne.x += nesne._movesto_speed if nesne.x < nesne._movesto_hedef_x else -nesne._movesto_speed
479
- if abs(nesne.y - nesne._movesto_hedef_y) > nesne._movesto_speed:
480
- nesne.y += nesne._movesto_speed if nesne.y < nesne._movesto_hedef_y else -nesne._movesto_speed
481
- if abs(nesne.x - nesne._movesto_hedef_x) <= nesne._movesto_speed and abs(nesne.y - nesne._movesto_hedef_y) <= nesne._movesto_speed:
482
- nesne._movesto_aktif = False
483
565
 
484
- for nesne2 in kutular:
485
- if nesne2.visible:
486
- yazi_resmi = nesne2.font_objesi.render(nesne2.yazi, True, nesne2.renk)
487
- pencere.blit(yazi_resmi, (nesne2.x, nesne2.y))
488
-
489
- for nesne3 in resim_kutusu:
490
- if nesne3.visible:
491
- arka_plan = pygame.transform.scale(nesne3.surface, (screenX, screenY))
492
- pencere.blit(arka_plan, (0, 0))
566
+ _hareket_uygula(nesne)
493
567
 
494
568
  for karakter in resim_kutusu2:
495
569
  if karakter.visible:
496
570
  pencere.blit(karakter.surface, (karakter.x, karakter.y))
497
- if hasattr(karakter, '_moves_aktif') and karakter._moves_aktif:
498
- karakter.x += karakter._moves_x * karakter._moves_speed
499
- karakter.y += karakter._moves_y * karakter._moves_speed
500
- if hasattr(karakter, '_movesto_aktif') and karakter._movesto_aktif:
501
- if abs(karakter.x - karakter._movesto_hedef_x) > karakter._movesto_speed:
502
- karakter.x += karakter._movesto_speed if karakter.x < karakter._movesto_hedef_x else -karakter._movesto_speed
503
- if abs(karakter.y - karakter._movesto_hedef_y) > karakter._movesto_speed:
504
- karakter.y += karakter._movesto_speed if karakter.y < karakter._movesto_hedef_y else -karakter._movesto_speed
505
- if abs(karakter.x - karakter._movesto_hedef_x) <= karakter._movesto_speed and abs(karakter.y - karakter._movesto_hedef_y) <= karakter._movesto_speed:
506
- karakter._movesto_aktif = False
571
+ _hareket_uygula(karakter)
572
+
573
+ for nesne2 in kutular:
574
+ if nesne2.visible:
575
+ pencere.blit(nesne2.surface, (nesne2.x, nesne2.y))
576
+ _hareket_uygula(nesne2)
507
577
 
508
578
  for nesne5 in list(kutularin_listesi):
509
579
  if hasattr(nesne5, '_stop_baslangic'):
@@ -511,13 +581,17 @@ def run(callback=None):
511
581
  nesne5._stop_sonra()
512
582
  del nesne5._stop_baslangic
513
583
  kutularin_listesi.remove(nesne5)
584
+
514
585
  pygame.display.flip()
515
586
 
516
587
  if saat:
517
588
  saat.tick(60)
518
589
 
590
+
519
591
  screen = ScreenManager()
520
592
  draw = DrawManager()
521
593
  display = DisplayManager()
522
594
  add = AddManager()
523
595
 
596
+
597
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cobrapad
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: A beginner-friendly 2D game engine built on top of pygame
5
5
  Author: knyaz
6
6
  License: MIT
@@ -26,7 +26,7 @@ Cobrapad is a fast and easy-to-use 2D game library built on top of Pygame. It is
26
26
  - Add images and backgrounds easily
27
27
  - Display text on screen
28
28
  - Create clickable buttons
29
- - Animate objects with `moves()` and `movesTo()`
29
+ - Animate objects with `moves()` and `movesBy()`
30
30
  - Show and hide objects
31
31
  - Detect mouse clicks anywhere on screen
32
32
  - Delay actions with a timer using `stop()`
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cobrapad"
7
- version = "0.2.2"
7
+ version = "0.2.4"
8
8
  authors = [
9
9
  {name = "knyaz"}
10
10
  ]
@@ -20,3 +20,5 @@ where = ["."]
20
20
 
21
21
  [project.urls]
22
22
  Homepage = "https://github.com/lorkas-052"
23
+
24
+
File without changes
File without changes