simple2d-3d 0.2.9__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple2d_3d
3
- Version: 0.2.9
3
+ Version: 0.3.0
4
4
  Summary: A lightweight, hardware-accelerated 2D-3D layout and engine.
5
5
  Author: ProdeeptoSundar Roy
6
6
  Project-URL: Homepage, https://github.com/rtumpa099-gif/Simple2D_3D
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "simple2d_3d" # The name users will type: pip install my_engine
7
- version = "0.2.9"
7
+ version = "0.3.0"
8
8
  authors = [
9
9
  { name="ProdeeptoSundar Roy" }
10
10
  ]
@@ -423,12 +423,12 @@ def CreatePlatform2D(scene,map_data,w,h,space,x_offset,y_offset,cast_shadow=True
423
423
  x += 1
424
424
 
425
425
  class Particle:
426
- def __init__(self, x, y):
426
+ def __init__(self, x, y , life=1.0):
427
427
  self.x = x
428
428
  self.y = y
429
429
  self.vx = random.uniform(-2, 2)
430
430
  self.vy = random.uniform(-3, 0)
431
- self.life = 1.0
431
+ self.life = life
432
432
  self.color = (
433
433
  random.randint(200, 255),
434
434
  random.randint(100, 200),
@@ -446,11 +446,10 @@ class ParticleSystem:
446
446
  def __init__(self, renderer):
447
447
  self.particles = []
448
448
  self.cached_textures = {}
449
- self.dst_rect = sdl2.SDL_Rect(0,0,1,1)
450
449
 
451
- def add_explosion(self, x, y, count=30):
450
+ def add_explosion(self, x, y, count=30,life=1.0):
452
451
  for _ in range(count+1):
453
- self.particles.append(Particle(x,y))
452
+ self.particles.append(Particle(x,y,life))
454
453
  def update(self, dt):
455
454
  self.particles = [p for p in self.particles if p.update(dt)]
456
455
 
@@ -458,65 +457,16 @@ class ParticleSystem:
458
457
  for p in self.particles:
459
458
  alpha = max(0, min(255, int(p.life * 255)))
460
459
 
461
- # --- 1. Create a circular texture if it doesn't exist yet ---
462
- if p.size not in self.cached_textures:
463
- diameter = p.size * 2
464
- radius = p.size
465
-
466
- surface = sdl2.SDL_CreateRGBSurface(0, diameter, diameter, 32, 0, 0, 0, 0)
467
- if not surface:
468
- continue
469
-
470
- # We need to manually color pixels to make a smooth circle shape
471
- # Lock the surface so we can write directly to raw pixel memory safely
472
- sdl2.SDL_LockSurface(surface)
473
-
474
- # Convert the raw pixels array pointer to a usable ctypes format
475
- pixels_ptr = ctypes.cast(surface.contents.pixels, ctypes.POINTER(ctypes.c_uint32))
476
- pitch = surface.contents.pitch // 4 # 4 bytes per pixel (32-bit)
477
-
478
- # Get the pixel format mapping for pure white
479
- white_pixel = sdl2.SDL_MapRGBA(surface.contents.format, 255, 255, 255, 255)
480
- transparent_pixel = sdl2.SDL_MapRGBA(surface.contents.format, 0, 0, 0, 0)
481
-
482
- # Loop through every single coordinate inside our square bounding box
483
- for y in range(diameter):
484
- for x in range(diameter):
485
- # Calculate distance from the center of the square using Pythagorean theorem
486
- dx = x - radius
487
- dy = y - radius
488
- if (dx * dx + dy * dy) <= (radius * radius):
489
- # Inside the circle radius? Color it solid white!
490
- pixels_ptr[y * pitch + x] = white_pixel
491
- else:
492
- # Outside the circle? Keep it transparent
493
- pixels_ptr[y * pitch + x] = transparent_pixel
494
-
495
- sdl2.SDL_UnlockSurface(surface)
496
-
497
- # Upload our brand-new round circle template straight to GPU memory
498
- texture = sdl2.SDL_CreateTextureFromSurface(renderer, surface)
499
- sdl2.SDL_FreeSurface(surface)
500
-
501
- if texture:
502
- self.cached_textures[p.size] = texture
503
- else:
504
- continue
460
+ # Set drawing color to match the particle's fade
461
+ sdl2.SDL_SetRenderDrawColor(renderer, p.color[0], p.color[1], p.color[2], alpha)
505
462
 
506
- # --- 2. Pull the texture and apply modifiers ---
507
- tex = self.cached_textures.get(p.size)
508
- if not tex:
509
- continue
510
-
511
- sdl2.SDL_SetTextureColorMod(tex, p.color[0], p.color[1], p.color[2])
512
- sdl2.SDL_SetTextureBlendMode(tex, sdl2.SDL_BLENDMODE_BLEND)
513
- sdl2.SDL_SetTextureAlphaMod(tex, alpha)
514
-
515
- # --- 3. Set the position box ---
516
- self.dst_rect.x = int(p.x - p.size)
517
- self.dst_rect.y = int(p.y - p.size)
518
- self.dst_rect.w = int(p.size * 2)
519
- self.dst_rect.h = int(p.size * 2)
520
-
521
- # --- 4. Render it ---
522
- sdl2.SDL_RenderCopy(renderer, tex, None, ctypes.byref(self.dst_rect))
463
+ cx, cy = int(p.x), int(p.y)
464
+ r = int(p.size)
465
+
466
+ # Draw a smooth structural circle using horizontal scan lines
467
+ # This avoids calculating textures or needing sdl2.sdlgfx!
468
+ for dy in range(-r, r + 1):
469
+ # Calculate the width of the circle at this specific vertical row
470
+ lx = int((r * r - dy * dy) ** 0.5)
471
+ for dx in range(-lx, lx + 1):
472
+ sdl2.SDL_RenderDrawPoint(renderer, cx + dx, cy + dy)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple2d_3d
3
- Version: 0.2.9
3
+ Version: 0.3.0
4
4
  Summary: A lightweight, hardware-accelerated 2D-3D layout and engine.
5
5
  Author: ProdeeptoSundar Roy
6
6
  Project-URL: Homepage, https://github.com/rtumpa099-gif/Simple2D_3D
File without changes
File without changes
File without changes