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.
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/LICENSE +4 -0
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/PKG-INFO +1 -1
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/pyproject.toml +1 -1
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/simple2d_3d/__init__.py +3 -3
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/simple2d_3d/render.py +62 -2
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/simple2d_3d.egg-info/PKG-INFO +1 -1
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/README.md +0 -0
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/setup.cfg +0 -0
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/simple2d_3d/colors.py +0 -0
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/simple2d_3d/gui.py +0 -0
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/simple2d_3d/setup.py +0 -0
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/simple2d_3d.egg-info/SOURCES.txt +0 -0
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/simple2d_3d.egg-info/dependency_links.txt +0 -0
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/simple2d_3d.egg-info/requires.txt +0 -0
- {simple2d_3d-0.2.1 → simple2d_3d-0.2.2}/simple2d_3d.egg-info/top_level.txt +0 -0
|
@@ -3,11 +3,11 @@ try:
|
|
|
3
3
|
import sdl2
|
|
4
4
|
except Exception as err:
|
|
5
5
|
print("Error : " , err)
|
|
6
|
-
|
|
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)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|