simple2d-3d 0.2.1__tar.gz → 0.2.2__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,3 +1,7 @@
1
+ Part of this module contains code adapted from python3d
2
+ Copyright (c) 2024 remontmodema830
3
+ Licensed under the MIT License
4
+
1
5
  Copyright (c) 2026 ProdeeptoSundar Roy
2
6
 
3
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple2d_3d
3
- Version: 0.2.1
3
+ Version: 0.2.2
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.1"
7
+ version = "0.2.2"
8
8
  authors = [
9
9
  { name="ProdeeptoSundar Roy" }
10
10
  ]
@@ -3,11 +3,11 @@ try:
3
3
  import sdl2
4
4
  except Exception as err:
5
5
  print("Error : " , err)
6
- #raise ImportError("PySDL2 is needed for this library.") from err
6
+ raise ImportError("PySDL2 is needed for this library.") from err
7
7
 
8
8
  from .setup import Init as init , CleanUp as clean_up , ClearScreen as clear_screen , LoadTextureBMP as loadtexturebmp
9
- from .render import Camera , Vector3 , Rect , Line , Circle , Scene , Scene2D , Raycaster2D , BreakObject2D as break_object_2d , CreatePlatform2D as create_platform_2d , CreatePlatform as create_platform , Project2D as project_2d, DrawFilledFace as draw_filled_face, Cube
9
+ from .render import Camera , Vector3 , Rect , Line , Circle , Scene , Scene2D , Raycaster2D , BreakObject2D as break_object_2d , CreatePlatform2D as create_platform_2d , CreatePlatform as create_platform , Project2D as project_2d, DrawFilledFace as draw_filled_face, Cube , Particle , ParticleSystem
10
10
  from .gui import Button , UI
11
11
  from . import colors
12
12
  __all__ = [
13
- "init" , "clean_up" , "Camera" , "Vector3" , "Rect" , "Circle" , "Line" , "Scene" , "Scene2D" , "Raycaster2D" , "break_object_2d" , "create_platform_2d" , "create_platform" , "project_2d" , "draw_filled_face" , "Cube" , "clear_screen" , "loadtexturebmp" , "Button" , "UI" ,"colors"]
13
+ "init" , "clean_up" , "Camera" , "Vector3" , "Rect" , "Circle" , "Line" , "Scene" , "Scene2D" , "Raycaster2D" , "break_object_2d" , "create_platform_2d" , "create_platform" , "project_2d" , "draw_filled_face" , "Cube" , "Particle" , "ParticleSystem" , "clear_screen" , "loadtexturebmp" , "Button" , "UI" ,"colors"]
@@ -1,4 +1,4 @@
1
- import math , sdl2 , ctypes
1
+ import math , sdl2 , ctypes , random
2
2
  from .colors import *
3
3
  class Camera:
4
4
  def __init__(self,x,y,z,yaw,pitch):
@@ -420,4 +420,64 @@ def CreatePlatform2D(scene,map_data,w,h,space,x_offset,y_offset,cast_shadow=True
420
420
  scene.add(new_rect)
421
421
  x += 1
422
422
  else:
423
- x += 1
423
+ x += 1
424
+
425
+ class Particle:
426
+ def __init__(self, x, y):
427
+ self.x = x
428
+ self.y = y
429
+ self.vx = random.uniform(-2, 2)
430
+ self.vy = random.uniform(-3, 0)
431
+ self.life = 1.0
432
+ self.color = (
433
+ random.randint(200, 255),
434
+ random.randint(100, 200),
435
+ random.randint(50, 100)
436
+ )
437
+ self.size = random.randint(2, 6)
438
+
439
+ def update(self, dt):
440
+ self.x += self.vx * dt
441
+ self.y += self.vy * dt
442
+ self.life -= 0.02 * dt
443
+ return self.life > 0
444
+
445
+ class ParticleSystem:
446
+ def __init__(self, renderer):
447
+ self.particles = []
448
+ self.cached_textures = {}
449
+
450
+ def add_explosion(self, x, y, count=30):
451
+ for _ in range(count+1):
452
+ self.particles.append(Particle(x,y))
453
+ def update(self, dt):
454
+ self.particles = [p for p in self.particles if p.update(dt)]
455
+ def draw(self, renderer):
456
+ for p in self.particles:
457
+ alpha = max(0, min(255, int(p.life * 255)))
458
+
459
+ # --- 1. Only create the texture if it doesn't exist yet ---
460
+ if p.size not in self.cached_textures:
461
+ diameter = p.size * 2
462
+ surface = SDL_CreateRGBSurface(0, diameter, diameter, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000)
463
+ SDL_FillRect(surface, None, SDL_MapRGBA(surface.contents.format, 255, 255, 255, 255))
464
+ texture = SDL_CreateTextureFromSurface(renderer, surface)
465
+ SDL_FreeSurface(surface)
466
+ self.cached_textures[p.size] = texture
467
+
468
+ # --- 2. Pull the texture and apply modifiers (Must run for ALL particles!) ---
469
+ tex = self.cached_textures[p.size]
470
+ SDL_SetTextureColorMod(tex, p.color[0], p.color[1], p.color[2])
471
+ SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND)
472
+ SDL_SetTextureAlphaMod(tex, alpha)
473
+
474
+ # --- 3. Set the position box (Must run for ALL particles!) ---
475
+ dst_rect = SDL_Rect(
476
+ int(p.x - p.size),
477
+ int(p.y - p.size),
478
+ p.size * 2,
479
+ p.size * 2
480
+ )
481
+
482
+ # --- 4. Render it (Must be INSIDE the for loop!) ---
483
+ SDL_RenderCopy(renderer, tex, None, dst_rect)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple2d_3d
3
- Version: 0.2.1
3
+ Version: 0.2.2
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