fix: Update test files to use current API patterns

Migrates test suite to current API:
- Frame(x, y, w, h) → Frame(pos=(x, y), size=(w, h))
- Caption("text", x, y) → Caption(pos=(x, y), text="text")
- caption.size → caption.font_size
- Entity(x, y, ...) → Entity((x, y), ...)
- Grid(w, h, ...) → Grid(grid_size=(w, h), ...)
- cell.color → ColorLayer system

Tests now serve as valid API usage examples.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2025-12-29 19:47:48 -05:00
commit 9f481a2e4a
53 changed files with 614 additions and 586 deletions

View file

@ -34,12 +34,15 @@ grid = mcrfpy.Grid(
size=(1024, 768) size=(1024, 768)
) )
# Add color layer for floor pattern
color_layer = grid.add_layer("color", z_index=-1)
# Simple floor pattern # Simple floor pattern
for x in range(100): for x in range(100):
for y in range(100): for y in range(100):
cell = grid.at((x, y)) cell = grid.at(x, y)
cell.tilesprite = 0 cell.tilesprite = 0
cell.color = (40, 40, 40, 255) color_layer.set(x, y, mcrfpy.Color(40, 40, 40, 255))
# Create 50 entities with random positions and velocities # Create 50 entities with random positions and velocities
entities = [] entities = []
@ -47,15 +50,15 @@ ENTITY_COUNT = 50
for i in range(ENTITY_COUNT): for i in range(ENTITY_COUNT):
entity = mcrfpy.Entity( entity = mcrfpy.Entity(
grid_pos=(random.randint(0, 99), random.randint(0, 99)), (random.randint(0, 99), random.randint(0, 99)),
sprite_index=random.randint(10, 20) # Use varied sprites sprite_index=random.randint(10, 20), # Use varied sprites
grid=grid
) )
# Give each entity a random velocity # Give each entity a random velocity (stored as Python attributes)
entity.velocity_x = random.uniform(-0.5, 0.5) entity.velocity_x = random.uniform(-0.5, 0.5)
entity.velocity_y = random.uniform(-0.5, 0.5) entity.velocity_y = random.uniform(-0.5, 0.5)
grid.entities.append(entity)
entities.append(entity) entities.append(entity)
ui.append(grid) ui.append(grid)

View file

@ -282,23 +282,23 @@ def setup_grid_stress():
grid.center = (400, 400) # Center view grid.center = (400, 400) # Center view
ui.append(grid) ui.append(grid)
# Fill with alternating colors # Add color layer and fill with alternating colors
color_layer = grid.add_layer("color", z_index=-1)
for y in range(50): for y in range(50):
for x in range(50): for x in range(50):
cell = grid.at(x, y)
if (x + y) % 2 == 0: if (x + y) % 2 == 0:
cell.color = mcrfpy.Color(60, 60, 80) color_layer.set(x, y, mcrfpy.Color(60, 60, 80))
else: else:
cell.color = mcrfpy.Color(40, 40, 60) color_layer.set(x, y, mcrfpy.Color(40, 40, 60))
# Add 50 entities # Add 50 entities
try: try:
texture = mcrfpy.Texture("assets/kenney_tinydungeon.png", 16, 16) texture = mcrfpy.Texture("assets/kenney_tinydungeon.png", 16, 16)
for i in range(50): for i in range(50):
# Entity takes positional args: (position, texture, sprite_index, grid) # Entity takes tuple position and keyword args
pos = mcrfpy.Vector(random.randint(5, 45), random.randint(5, 45)) pos = (random.randint(5, 45), random.randint(5, 45))
entity = mcrfpy.Entity(pos, texture, random.randint(0, 100), grid) entity = mcrfpy.Entity(pos, texture=texture, sprite_index=random.randint(0, 100), grid=grid)
grid.entities.append(entity) grid.entities.append(entity)
except Exception as e: except Exception as e:
print(f" Note: Could not create entities: {e}") print(f" Note: Could not create entities: {e}")

View file

@ -6,10 +6,14 @@ Uses C++ benchmark logger (start_benchmark/end_benchmark) for accurate timing.
Results written to JSON files for analysis. Results written to JSON files for analysis.
Compares rendering performance between: Compares rendering performance between:
1. Traditional grid.at(x,y).color API (no caching) 1. ColorLayer with per-cell modifications (no caching benefit)
2. New layer system with dirty flag caching 2. ColorLayer with dirty flag caching (static after fill)
3. Various layer configurations 3. Various layer configurations
NOTE: The old grid.at(x,y).color API no longer exists. All color operations
now go through the ColorLayer system. This benchmark compares different
layer usage patterns to measure caching effectiveness.
Usage: Usage:
./mcrogueface --exec tests/benchmarks/layer_performance_test.py ./mcrogueface --exec tests/benchmarks/layer_performance_test.py
# Results in benchmark_*.json files # Results in benchmark_*.json files
@ -94,7 +98,7 @@ def run_next_test():
# ============================================================================ # ============================================================================
def setup_base_layer_static(): def setup_base_layer_static():
"""Traditional grid.at(x,y).color API - no modifications during render.""" """ColorLayer with per-cell set() calls - static after initial fill."""
mcrfpy.createScene("test_base_static") mcrfpy.createScene("test_base_static")
ui = mcrfpy.sceneUI("test_base_static") ui = mcrfpy.sceneUI("test_base_static")
@ -102,17 +106,17 @@ def setup_base_layer_static():
pos=(10, 10), size=(600, 600)) pos=(10, 10), size=(600, 600))
ui.append(grid) ui.append(grid)
# Fill base layer using traditional API # Fill using ColorLayer with per-cell set() calls (baseline)
layer = grid.add_layer("color", z_index=-1)
for y in range(GRID_SIZE): for y in range(GRID_SIZE):
for x in range(GRID_SIZE): for x in range(GRID_SIZE):
cell = grid.at(x, y) layer.set(x, y, mcrfpy.Color((x * 2) % 256, (y * 2) % 256, 128, 255))
cell.color = mcrfpy.Color((x * 2) % 256, (y * 2) % 256, 128, 255)
mcrfpy.setScene("test_base_static") mcrfpy.setScene("test_base_static")
def setup_base_layer_modified(): def setup_base_layer_modified():
"""Traditional API with single cell modified each frame.""" """ColorLayer with single cell modified each frame - tests dirty flag."""
mcrfpy.createScene("test_base_mod") mcrfpy.createScene("test_base_mod")
ui = mcrfpy.sceneUI("test_base_mod") ui = mcrfpy.sceneUI("test_base_mod")
@ -120,19 +124,16 @@ def setup_base_layer_modified():
pos=(10, 10), size=(600, 600)) pos=(10, 10), size=(600, 600))
ui.append(grid) ui.append(grid)
# Fill base layer # Fill using ColorLayer
for y in range(GRID_SIZE): layer = grid.add_layer("color", z_index=-1)
for x in range(GRID_SIZE): layer.fill(mcrfpy.Color(100, 100, 100, 255))
cell = grid.at(x, y)
cell.color = mcrfpy.Color(100, 100, 100, 255)
# Timer to modify one cell per frame # Timer to modify one cell per frame (triggers dirty flag each frame)
mod_counter = [0] mod_counter = [0]
def modify_cell(runtime): def modify_cell(runtime):
x = mod_counter[0] % GRID_SIZE x = mod_counter[0] % GRID_SIZE
y = (mod_counter[0] // GRID_SIZE) % GRID_SIZE y = (mod_counter[0] // GRID_SIZE) % GRID_SIZE
cell = grid.at(x, y) layer.set(x, y, mcrfpy.Color(255, 0, 0, 255))
cell.color = mcrfpy.Color(255, 0, 0, 255)
mod_counter[0] += 1 mod_counter[0] += 1
mcrfpy.setScene("test_base_mod") mcrfpy.setScene("test_base_mod")

View file

@ -19,26 +19,30 @@ END_COLOR = mcrfpy.Color(255, 255, 100) # Yellow for end
# Global state # Global state
grid = None grid = None
color_layer = None
mode = "ASTAR" mode = "ASTAR"
start_pos = (5, 10) start_pos = (5, 10)
end_pos = (27, 10) # Changed from 25 to 27 to avoid the wall end_pos = (27, 10) # Changed from 25 to 27 to avoid the wall
def create_map(): def create_map():
"""Create a map with obstacles to show pathfinding differences""" """Create a map with obstacles to show pathfinding differences"""
global grid global grid, color_layer
mcrfpy.createScene("pathfinding_comparison") mcrfpy.createScene("pathfinding_comparison")
# Create grid # Create grid
grid = mcrfpy.Grid(grid_x=30, grid_y=20) grid = mcrfpy.Grid(grid_x=30, grid_y=20)
grid.fill_color = mcrfpy.Color(0, 0, 0) grid.fill_color = mcrfpy.Color(0, 0, 0)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Initialize all as floor # Initialize all as floor
for y in range(20): for y in range(20):
for x in range(30): for x in range(30):
grid.at(x, y).walkable = True grid.at(x, y).walkable = True
grid.at(x, y).color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
# Create obstacles that make A* and Dijkstra differ # Create obstacles that make A* and Dijkstra differ
obstacles = [ obstacles = [
# Vertical wall with gaps # Vertical wall with gaps
@ -50,15 +54,15 @@ def create_map():
[(x, 10) for x in range(20, 25)], [(x, 10) for x in range(20, 25)],
[(25, y) for y in range(5, 15)], [(25, y) for y in range(5, 15)],
] ]
for obstacle_group in obstacles: for obstacle_group in obstacles:
for x, y in obstacle_group: for x, y in obstacle_group:
grid.at(x, y).walkable = False grid.at(x, y).walkable = False
grid.at(x, y).color = WALL_COLOR color_layer.set(x, y, WALL_COLOR)
# Mark start and end # Mark start and end
grid.at(start_pos[0], start_pos[1]).color = START_COLOR color_layer.set(start_pos[0], start_pos[1], START_COLOR)
grid.at(end_pos[0], end_pos[1]).color = END_COLOR color_layer.set(end_pos[0], end_pos[1], END_COLOR)
def clear_paths(): def clear_paths():
"""Clear path highlighting""" """Clear path highlighting"""
@ -66,34 +70,34 @@ def clear_paths():
for x in range(30): for x in range(30):
cell = grid.at(x, y) cell = grid.at(x, y)
if cell.walkable: if cell.walkable:
cell.color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
# Restore start and end colors # Restore start and end colors
grid.at(start_pos[0], start_pos[1]).color = START_COLOR color_layer.set(start_pos[0], start_pos[1], START_COLOR)
grid.at(end_pos[0], end_pos[1]).color = END_COLOR color_layer.set(end_pos[0], end_pos[1], END_COLOR)
def show_astar(): def show_astar():
"""Show A* path""" """Show A* path"""
clear_paths() clear_paths()
# Compute A* path # Compute A* path
path = grid.compute_astar_path(start_pos[0], start_pos[1], end_pos[0], end_pos[1]) path = grid.compute_astar_path(start_pos[0], start_pos[1], end_pos[0], end_pos[1])
# Color the path # Color the path
for i, (x, y) in enumerate(path): for i, (x, y) in enumerate(path):
if (x, y) != start_pos and (x, y) != end_pos: if (x, y) != start_pos and (x, y) != end_pos:
grid.at(x, y).color = ASTAR_COLOR color_layer.set(x, y, ASTAR_COLOR)
status_text.text = f"A* Path: {len(path)} steps (optimized for single target)" status_text.text = f"A* Path: {len(path)} steps (optimized for single target)"
status_text.fill_color = ASTAR_COLOR status_text.fill_color = ASTAR_COLOR
def show_dijkstra(): def show_dijkstra():
"""Show Dijkstra exploration""" """Show Dijkstra exploration"""
clear_paths() clear_paths()
# Compute Dijkstra from start # Compute Dijkstra from start
grid.compute_dijkstra(start_pos[0], start_pos[1]) grid.compute_dijkstra(start_pos[0], start_pos[1])
# Color cells by distance (showing exploration) # Color cells by distance (showing exploration)
max_dist = 40.0 max_dist = 40.0
for y in range(20): for y in range(20):
@ -103,50 +107,50 @@ def show_dijkstra():
if dist is not None and dist < max_dist: if dist is not None and dist < max_dist:
# Color based on distance # Color based on distance
intensity = int(255 * (1 - dist / max_dist)) intensity = int(255 * (1 - dist / max_dist))
grid.at(x, y).color = mcrfpy.Color(0, intensity // 2, intensity) color_layer.set(x, y, mcrfpy.Color(0, intensity // 2, intensity))
# Get the actual path # Get the actual path
path = grid.get_dijkstra_path(end_pos[0], end_pos[1]) path = grid.get_dijkstra_path(end_pos[0], end_pos[1])
# Highlight the actual path more brightly # Highlight the actual path more brightly
for x, y in path: for x, y in path:
if (x, y) != start_pos and (x, y) != end_pos: if (x, y) != start_pos and (x, y) != end_pos:
grid.at(x, y).color = DIJKSTRA_COLOR color_layer.set(x, y, DIJKSTRA_COLOR)
# Restore start and end # Restore start and end
grid.at(start_pos[0], start_pos[1]).color = START_COLOR color_layer.set(start_pos[0], start_pos[1], START_COLOR)
grid.at(end_pos[0], end_pos[1]).color = END_COLOR color_layer.set(end_pos[0], end_pos[1], END_COLOR)
status_text.text = f"Dijkstra: {len(path)} steps (explores all directions)" status_text.text = f"Dijkstra: {len(path)} steps (explores all directions)"
status_text.fill_color = DIJKSTRA_COLOR status_text.fill_color = DIJKSTRA_COLOR
def show_both(): def show_both():
"""Show both paths overlaid""" """Show both paths overlaid"""
clear_paths() clear_paths()
# Get both paths # Get both paths
astar_path = grid.compute_astar_path(start_pos[0], start_pos[1], end_pos[0], end_pos[1]) astar_path = grid.compute_astar_path(start_pos[0], start_pos[1], end_pos[0], end_pos[1])
grid.compute_dijkstra(start_pos[0], start_pos[1]) grid.compute_dijkstra(start_pos[0], start_pos[1])
dijkstra_path = grid.get_dijkstra_path(end_pos[0], end_pos[1]) dijkstra_path = grid.get_dijkstra_path(end_pos[0], end_pos[1])
print(astar_path, dijkstra_path) print(astar_path, dijkstra_path)
# Color Dijkstra path first (blue) # Color Dijkstra path first (blue)
for x, y in dijkstra_path: for x, y in dijkstra_path:
if (x, y) != start_pos and (x, y) != end_pos: if (x, y) != start_pos and (x, y) != end_pos:
grid.at(x, y).color = DIJKSTRA_COLOR color_layer.set(x, y, DIJKSTRA_COLOR)
# Then A* path (green) - will overwrite shared cells # Then A* path (green) - will overwrite shared cells
for x, y in astar_path: for x, y in astar_path:
if (x, y) != start_pos and (x, y) != end_pos: if (x, y) != start_pos and (x, y) != end_pos:
grid.at(x, y).color = ASTAR_COLOR color_layer.set(x, y, ASTAR_COLOR)
# Mark differences # Mark differences
different_cells = [] different_cells = []
for cell in dijkstra_path: for cell in dijkstra_path:
if cell not in astar_path: if cell not in astar_path:
different_cells.append(cell) different_cells.append(cell)
status_text.text = f"Both paths: A*={len(astar_path)} steps, Dijkstra={len(dijkstra_path)} steps" status_text.text = f"Both paths: A*={len(astar_path)} steps, Dijkstra={len(dijkstra_path)} steps"
if different_cells: if different_cells:
info_text.text = f"Paths differ at {len(different_cells)} cells" info_text.text = f"Paths differ at {len(different_cells)} cells"
@ -202,26 +206,26 @@ grid.size = (600, 400) # 30*20, 20*20
grid.position = (100, 100) grid.position = (100, 100)
# Add title # Add title
title = mcrfpy.Caption("A* vs Dijkstra Pathfinding", 250, 20) title = mcrfpy.Caption(pos=(250, 20), text="A* vs Dijkstra Pathfinding")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
# Add status # Add status
status_text = mcrfpy.Caption("Press A for A*, D for Dijkstra, B for Both", 100, 60) status_text = mcrfpy.Caption(pos=(100, 60), text="Press A for A*, D for Dijkstra, B for Both")
status_text.fill_color = mcrfpy.Color(200, 200, 200) status_text.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(status_text) ui.append(status_text)
# Add info # Add info
info_text = mcrfpy.Caption("", 100, 520) info_text = mcrfpy.Caption(pos=(100, 520), text="")
info_text.fill_color = mcrfpy.Color(200, 200, 200) info_text.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(info_text) ui.append(info_text)
# Add legend # Add legend
legend1 = mcrfpy.Caption("Red=Start, Yellow=End, Green=A*, Blue=Dijkstra", 100, 540) legend1 = mcrfpy.Caption(pos=(100, 540), text="Red=Start, Yellow=End, Green=A*, Blue=Dijkstra")
legend1.fill_color = mcrfpy.Color(150, 150, 150) legend1.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(legend1) ui.append(legend1)
legend2 = mcrfpy.Caption("Dark=Walls, Light=Floor", 100, 560) legend2 = mcrfpy.Caption(pos=(100, 560), text="Dark=Walls, Light=Floor")
legend2.fill_color = mcrfpy.Color(150, 150, 150) legend2.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(legend2) ui.append(legend2)

View file

@ -20,9 +20,8 @@ for y in range(5):
# Create entity # Create entity
print("Creating entity...") print("Creating entity...")
entity = mcrfpy.Entity(2, 2) entity = mcrfpy.Entity((2, 2), grid=grid)
entity.sprite_index = 64 entity.sprite_index = 64
grid.entities.append(entity)
print(f"Entity at ({entity.x}, {entity.y})") print(f"Entity at ({entity.x}, {entity.y})")
# Check gridstate # Check gridstate

View file

@ -20,6 +20,7 @@ NO_PATH_COLOR = mcrfpy.Color(255, 0, 0) # Pure red for unreachable
# Global state # Global state
grid = None grid = None
color_layer = None
entities = [] entities = []
current_combo_index = 0 current_combo_index = 0
all_combinations = [] # All possible pairs all_combinations = [] # All possible pairs
@ -27,14 +28,17 @@ current_path = []
def create_map(): def create_map():
"""Create the map with entities""" """Create the map with entities"""
global grid, entities, all_combinations global grid, color_layer, entities, all_combinations
mcrfpy.createScene("dijkstra_all") mcrfpy.createScene("dijkstra_all")
# Create grid # Create grid
grid = mcrfpy.Grid(grid_x=14, grid_y=10) grid = mcrfpy.Grid(grid_x=14, grid_y=10)
grid.fill_color = mcrfpy.Color(0, 0, 0) grid.fill_color = mcrfpy.Color(0, 0, 0)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Map layout - Entity 1 is intentionally trapped! # Map layout - Entity 1 is intentionally trapped!
map_layout = [ map_layout = [
"..............", # Row 0 "..............", # Row 0
@ -48,29 +52,28 @@ def create_map():
"..W.WWW.......", # Row 8 "..W.WWW.......", # Row 8
"..............", # Row 9 "..............", # Row 9
] ]
# Create the map # Create the map
entity_positions = [] entity_positions = []
for y, row in enumerate(map_layout): for y, row in enumerate(map_layout):
for x, char in enumerate(row): for x, char in enumerate(row):
cell = grid.at(x, y) cell = grid.at(x, y)
if char == 'W': if char == 'W':
cell.walkable = False cell.walkable = False
cell.color = WALL_COLOR color_layer.set(x, y, WALL_COLOR)
else: else:
cell.walkable = True cell.walkable = True
cell.color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
if char == 'E': if char == 'E':
entity_positions.append((x, y)) entity_positions.append((x, y))
# Create entities # Create entities
entities = [] entities = []
for i, (x, y) in enumerate(entity_positions): for i, (x, y) in enumerate(entity_positions):
entity = mcrfpy.Entity(x, y) entity = mcrfpy.Entity((x, y), grid=grid)
entity.sprite_index = 49 + i # '1', '2', '3' entity.sprite_index = 49 + i # '1', '2', '3'
grid.entities.append(entity)
entities.append(entity) entities.append(entity)
print("Map Analysis:") print("Map Analysis:")
@ -90,47 +93,47 @@ def create_map():
def clear_path_colors(): def clear_path_colors():
"""Reset all floor tiles to original color""" """Reset all floor tiles to original color"""
global current_path global current_path
for y in range(grid.grid_y): for y in range(grid.grid_y):
for x in range(grid.grid_x): for x in range(grid.grid_x):
cell = grid.at(x, y) cell = grid.at(x, y)
if cell.walkable: if cell.walkable:
cell.color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
current_path = [] current_path = []
def show_combination(index): def show_combination(index):
"""Show a specific path combination (valid or invalid)""" """Show a specific path combination (valid or invalid)"""
global current_combo_index, current_path global current_combo_index, current_path
current_combo_index = index % len(all_combinations) current_combo_index = index % len(all_combinations)
from_idx, to_idx = all_combinations[current_combo_index] from_idx, to_idx = all_combinations[current_combo_index]
# Clear previous path # Clear previous path
clear_path_colors() clear_path_colors()
# Get entities # Get entities
e_from = entities[from_idx] e_from = entities[from_idx]
e_to = entities[to_idx] e_to = entities[to_idx]
# Calculate path # Calculate path
path = e_from.path_to(int(e_to.x), int(e_to.y)) path = e_from.path_to(int(e_to.x), int(e_to.y))
current_path = path if path else [] current_path = path if path else []
# Always color start and end positions # Always color start and end positions
grid.at(int(e_from.x), int(e_from.y)).color = START_COLOR color_layer.set(int(e_from.x), int(e_from.y), START_COLOR)
grid.at(int(e_to.x), int(e_to.y)).color = NO_PATH_COLOR if not path else END_COLOR color_layer.set(int(e_to.x), int(e_to.y), NO_PATH_COLOR if not path else END_COLOR)
# Color the path if it exists # Color the path if it exists
if path: if path:
# Color intermediate steps # Color intermediate steps
for i, (x, y) in enumerate(path): for i, (x, y) in enumerate(path):
if i > 0 and i < len(path) - 1: if i > 0 and i < len(path) - 1:
grid.at(x, y).color = PATH_COLOR color_layer.set(x, y, PATH_COLOR)
status_text.text = f"Path {current_combo_index + 1}/{len(all_combinations)}: Entity {from_idx+1} → Entity {to_idx+1} = {len(path)} steps" status_text.text = f"Path {current_combo_index + 1}/{len(all_combinations)}: Entity {from_idx+1} → Entity {to_idx+1} = {len(path)} steps"
status_text.fill_color = mcrfpy.Color(100, 255, 100) # Green for valid status_text.fill_color = mcrfpy.Color(100, 255, 100) # Green for valid
# Show path steps # Show path steps
path_display = [] path_display = []
for i, (x, y) in enumerate(path[:5]): for i, (x, y) in enumerate(path[:5]):
@ -142,7 +145,7 @@ def show_combination(index):
status_text.text = f"Path {current_combo_index + 1}/{len(all_combinations)}: Entity {from_idx+1} → Entity {to_idx+1} = NO PATH!" status_text.text = f"Path {current_combo_index + 1}/{len(all_combinations)}: Entity {from_idx+1} → Entity {to_idx+1} = NO PATH!"
status_text.fill_color = mcrfpy.Color(255, 100, 100) # Red for invalid status_text.fill_color = mcrfpy.Color(255, 100, 100) # Red for invalid
path_text.text = "Path: [] (No valid path exists)" path_text.text = "Path: [] (No valid path exists)"
# Update info # Update info
info_text.text = f"From: Entity {from_idx+1} at ({int(e_from.x)}, {int(e_from.y)}) | To: Entity {to_idx+1} at ({int(e_to.x)}, {int(e_to.y)})" info_text.text = f"From: Entity {from_idx+1} at ({int(e_from.x)}, {int(e_from.y)}) | To: Entity {to_idx+1} at ({int(e_to.x)}, {int(e_to.y)})"
@ -183,37 +186,37 @@ grid.size = (560, 400)
grid.position = (120, 100) grid.position = (120, 100)
# Add title # Add title
title = mcrfpy.Caption("Dijkstra - All Paths (Valid & Invalid)", 200, 20) title = mcrfpy.Caption(pos=(200, 20), text="Dijkstra - All Paths (Valid & Invalid)")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
# Add status (will change color based on validity) # Add status (will change color based on validity)
status_text = mcrfpy.Caption("Ready", 120, 60) status_text = mcrfpy.Caption(pos=(120, 60), text="Ready")
status_text.fill_color = mcrfpy.Color(255, 255, 100) status_text.fill_color = mcrfpy.Color(255, 255, 100)
ui.append(status_text) ui.append(status_text)
# Add info # Add info
info_text = mcrfpy.Caption("", 120, 80) info_text = mcrfpy.Caption(pos=(120, 80), text="")
info_text.fill_color = mcrfpy.Color(200, 200, 200) info_text.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(info_text) ui.append(info_text)
# Add path display # Add path display
path_text = mcrfpy.Caption("Path: None", 120, 520) path_text = mcrfpy.Caption(pos=(120, 520), text="Path: None")
path_text.fill_color = mcrfpy.Color(200, 200, 200) path_text.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(path_text) ui.append(path_text)
# Add controls # Add controls
controls = mcrfpy.Caption("SPACE/N=Next, P=Previous, 1-6=Jump to path, Q=Quit", 120, 540) controls = mcrfpy.Caption(pos=(120, 540), text="SPACE/N=Next, P=Previous, 1-6=Jump to path, Q=Quit")
controls.fill_color = mcrfpy.Color(150, 150, 150) controls.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(controls) ui.append(controls)
# Add legend # Add legend
legend = mcrfpy.Caption("Red Start→Blue End (valid) | Red Start→Red End (invalid)", 120, 560) legend = mcrfpy.Caption(pos=(120, 560), text="Red Start→Blue End (valid) | Red Start→Red End (invalid)")
legend.fill_color = mcrfpy.Color(150, 150, 150) legend.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(legend) ui.append(legend)
# Expected results info # Expected results info
expected = mcrfpy.Caption("Entity 1 is trapped: paths 1→2, 1→3, 2→1, 3→1 will fail", 120, 580) expected = mcrfpy.Caption(pos=(120, 580), text="Entity 1 is trapped: paths 1→2, 1→3, 2→1, 3→1 will fail")
expected.fill_color = mcrfpy.Color(255, 150, 150) expected.fill_color = mcrfpy.Color(255, 150, 150)
ui.append(expected) ui.append(expected)

View file

@ -18,6 +18,7 @@ END_COLOR = mcrfpy.Color(100, 100, 255) # Light blue
# Global state # Global state
grid = None grid = None
color_layer = None
entities = [] entities = []
current_path_index = 0 current_path_index = 0
path_combinations = [] path_combinations = []
@ -25,14 +26,17 @@ current_path = []
def create_map(): def create_map():
"""Create the map with entities""" """Create the map with entities"""
global grid, entities global grid, color_layer, entities
mcrfpy.createScene("dijkstra_cycle") mcrfpy.createScene("dijkstra_cycle")
# Create grid # Create grid
grid = mcrfpy.Grid(grid_x=14, grid_y=10) grid = mcrfpy.Grid(grid_x=14, grid_y=10)
grid.fill_color = mcrfpy.Color(0, 0, 0) grid.fill_color = mcrfpy.Color(0, 0, 0)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Map layout # Map layout
map_layout = [ map_layout = [
"..............", # Row 0 "..............", # Row 0
@ -46,29 +50,28 @@ def create_map():
"..W.WWW.......", # Row 8 "..W.WWW.......", # Row 8
"..............", # Row 9 "..............", # Row 9
] ]
# Create the map # Create the map
entity_positions = [] entity_positions = []
for y, row in enumerate(map_layout): for y, row in enumerate(map_layout):
for x, char in enumerate(row): for x, char in enumerate(row):
cell = grid.at(x, y) cell = grid.at(x, y)
if char == 'W': if char == 'W':
cell.walkable = False cell.walkable = False
cell.color = WALL_COLOR color_layer.set(x, y, WALL_COLOR)
else: else:
cell.walkable = True cell.walkable = True
cell.color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
if char == 'E': if char == 'E':
entity_positions.append((x, y)) entity_positions.append((x, y))
# Create entities # Create entities
entities = [] entities = []
for i, (x, y) in enumerate(entity_positions): for i, (x, y) in enumerate(entity_positions):
entity = mcrfpy.Entity(x, y) entity = mcrfpy.Entity((x, y), grid=grid)
entity.sprite_index = 49 + i # '1', '2', '3' entity.sprite_index = 49 + i # '1', '2', '3'
grid.entities.append(entity)
entities.append(entity) entities.append(entity)
print("Entities created:") print("Entities created:")
@ -113,48 +116,48 @@ def create_map():
def clear_path_colors(): def clear_path_colors():
"""Reset all floor tiles to original color""" """Reset all floor tiles to original color"""
global current_path global current_path
for y in range(grid.grid_y): for y in range(grid.grid_y):
for x in range(grid.grid_x): for x in range(grid.grid_x):
cell = grid.at(x, y) cell = grid.at(x, y)
if cell.walkable: if cell.walkable:
cell.color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
current_path = [] current_path = []
def show_path(index): def show_path(index):
"""Show a specific path combination""" """Show a specific path combination"""
global current_path_index, current_path global current_path_index, current_path
if not path_combinations: if not path_combinations:
status_text.text = "No valid paths available (Entity 1 is trapped!)" status_text.text = "No valid paths available (Entity 1 is trapped!)"
return return
current_path_index = index % len(path_combinations) current_path_index = index % len(path_combinations)
from_idx, to_idx, path = path_combinations[current_path_index] from_idx, to_idx, path = path_combinations[current_path_index]
# Clear previous path # Clear previous path
clear_path_colors() clear_path_colors()
# Get entities # Get entities
e_from = entities[from_idx] e_from = entities[from_idx]
e_to = entities[to_idx] e_to = entities[to_idx]
# Color the path # Color the path
current_path = path current_path = path
if path: if path:
# Color start and end # Color start and end
grid.at(int(e_from.x), int(e_from.y)).color = START_COLOR color_layer.set(int(e_from.x), int(e_from.y), START_COLOR)
grid.at(int(e_to.x), int(e_to.y)).color = END_COLOR color_layer.set(int(e_to.x), int(e_to.y), END_COLOR)
# Color intermediate steps # Color intermediate steps
for i, (x, y) in enumerate(path): for i, (x, y) in enumerate(path):
if i > 0 and i < len(path) - 1: if i > 0 and i < len(path) - 1:
grid.at(x, y).color = PATH_COLOR color_layer.set(x, y, PATH_COLOR)
# Update status # Update status
status_text.text = f"Path {current_path_index + 1}/{len(path_combinations)}: Entity {from_idx+1} → Entity {to_idx+1} ({len(path)} steps)" status_text.text = f"Path {current_path_index + 1}/{len(path_combinations)}: Entity {from_idx+1} → Entity {to_idx+1} ({len(path)} steps)"
# Update path display # Update path display
path_display = [] path_display = []
for i, (x, y) in enumerate(path[:5]): # Show first 5 steps for i, (x, y) in enumerate(path[:5]): # Show first 5 steps
@ -194,27 +197,27 @@ grid.size = (560, 400)
grid.position = (120, 100) grid.position = (120, 100)
# Add title # Add title
title = mcrfpy.Caption("Dijkstra Pathfinding - Cycle Paths", 200, 20) title = mcrfpy.Caption(pos=(200, 20), text="Dijkstra Pathfinding - Cycle Paths")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
# Add status # Add status
status_text = mcrfpy.Caption("Press SPACE to cycle paths", 120, 60) status_text = mcrfpy.Caption(pos=(120, 60), text="Press SPACE to cycle paths")
status_text.fill_color = mcrfpy.Color(255, 255, 100) status_text.fill_color = mcrfpy.Color(255, 255, 100)
ui.append(status_text) ui.append(status_text)
# Add path display # Add path display
path_text = mcrfpy.Caption("Path: None", 120, 520) path_text = mcrfpy.Caption(pos=(120, 520), text="Path: None")
path_text.fill_color = mcrfpy.Color(200, 200, 200) path_text.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(path_text) ui.append(path_text)
# Add controls # Add controls
controls = mcrfpy.Caption("SPACE/N=Next, P=Previous, R=Refresh, Q=Quit", 120, 540) controls = mcrfpy.Caption(pos=(120, 540), text="SPACE/N=Next, P=Previous, R=Refresh, Q=Quit")
controls.fill_color = mcrfpy.Color(150, 150, 150) controls.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(controls) ui.append(controls)
# Add legend # Add legend
legend = mcrfpy.Caption("Red=Start, Blue=End, Green=Path, Dark=Wall", 120, 560) legend = mcrfpy.Caption(pos=(120, 560), text="Red=Start, Blue=End, Green=Path, Dark=Wall")
legend.fill_color = mcrfpy.Color(150, 150, 150) legend.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(legend) ui.append(legend)

View file

@ -18,49 +18,52 @@ ENTITY_COLORS = [
# Global state # Global state
grid = None grid = None
color_layer = None
entities = [] entities = []
first_point = None first_point = None
second_point = None second_point = None
def create_simple_map(): def create_simple_map():
"""Create a simple test map""" """Create a simple test map"""
global grid, entities global grid, color_layer, entities
mcrfpy.createScene("dijkstra_debug") mcrfpy.createScene("dijkstra_debug")
# Small grid for easy debugging # Small grid for easy debugging
grid = mcrfpy.Grid(grid_x=10, grid_y=10) grid = mcrfpy.Grid(grid_x=10, grid_y=10)
grid.fill_color = mcrfpy.Color(0, 0, 0) grid.fill_color = mcrfpy.Color(0, 0, 0)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
print("Initializing 10x10 grid...") print("Initializing 10x10 grid...")
# Initialize all as floor # Initialize all as floor
for y in range(10): for y in range(10):
for x in range(10): for x in range(10):
grid.at(x, y).walkable = True grid.at(x, y).walkable = True
grid.at(x, y).transparent = True grid.at(x, y).transparent = True
grid.at(x, y).color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
# Add a simple wall # Add a simple wall
print("Adding walls at:") print("Adding walls at:")
walls = [(5, 2), (5, 3), (5, 4), (5, 5), (5, 6)] walls = [(5, 2), (5, 3), (5, 4), (5, 5), (5, 6)]
for x, y in walls: for x, y in walls:
print(f" Wall at ({x}, {y})") print(f" Wall at ({x}, {y})")
grid.at(x, y).walkable = False grid.at(x, y).walkable = False
grid.at(x, y).color = WALL_COLOR color_layer.set(x, y, WALL_COLOR)
# Create 3 entities # Create 3 entities
entity_positions = [(2, 5), (8, 5), (5, 8)] entity_positions = [(2, 5), (8, 5), (5, 8)]
entities = [] entities = []
print("\nCreating entities at:") print("\nCreating entities at:")
for i, (x, y) in enumerate(entity_positions): for i, (x, y) in enumerate(entity_positions):
print(f" Entity {i+1} at ({x}, {y})") print(f" Entity {i+1} at ({x}, {y})")
entity = mcrfpy.Entity(x, y) entity = mcrfpy.Entity((x, y), grid=grid)
entity.sprite_index = 49 + i # '1', '2', '3' entity.sprite_index = 49 + i # '1', '2', '3'
grid.entities.append(entity)
entities.append(entity) entities.append(entity)
return grid return grid
def test_path_highlighting(): def test_path_highlighting():
@ -88,12 +91,14 @@ def test_path_highlighting():
print(f" Step {i}: ({x}, {y})") print(f" Step {i}: ({x}, {y})")
# Get current color for debugging # Get current color for debugging
cell = grid.at(x, y) cell = grid.at(x, y)
old_color = (cell.color.r, cell.color.g, cell.color.b) old_c = color_layer.at(x, y)
old_color = (old_c.r, old_c.g, old_c.b)
# Set new color # Set new color
cell.color = PATH_COLOR color_layer.set(x, y, PATH_COLOR)
new_color = (cell.color.r, cell.color.g, cell.color.b) new_c = color_layer.at(x, y)
new_color = (new_c.r, new_c.g, new_c.b)
print(f" Color changed from {old_color} to {new_color}") print(f" Color changed from {old_color} to {new_color}")
print(f" Walkable: {cell.walkable}") print(f" Walkable: {cell.walkable}")
@ -111,8 +116,8 @@ def test_path_highlighting():
# Verify colors were set # Verify colors were set
print("\nVerifying cell colors after highlighting:") print("\nVerifying cell colors after highlighting:")
for x, y in path[:3]: # Check first 3 cells for x, y in path[:3]: # Check first 3 cells
cell = grid.at(x, y) c = color_layer.at(x, y)
color = (cell.color.r, cell.color.g, cell.color.b) color = (c.r, c.g, c.b)
expected = (PATH_COLOR.r, PATH_COLOR.g, PATH_COLOR.b) expected = (PATH_COLOR.r, PATH_COLOR.g, PATH_COLOR.b)
match = color == expected match = color == expected
print(f" Cell ({x}, {y}): color={color}, expected={expected}, match={match}") print(f" Cell ({x}, {y}): color={color}, expected={expected}, match={match}")
@ -143,12 +148,12 @@ grid.position = (50, 50)
grid.size = (400, 400) # 10*40 grid.size = (400, 400) # 10*40
# Add title # Add title
title = mcrfpy.Caption("Dijkstra Debug - Press SPACE to retest, Q to quit", 50, 10) title = mcrfpy.Caption(pos=(50, 10), text="Dijkstra Debug - Press SPACE to retest, Q to quit")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
# Add debug info # Add debug info
info = mcrfpy.Caption("Check console for debug output", 50, 470) info = mcrfpy.Caption(pos=(50, 470), text="Check console for debug output")
info.fill_color = mcrfpy.Color(200, 200, 200) info.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(info) ui.append(info)

View file

@ -29,20 +29,24 @@ ENTITY_COLORS = [
# Global state # Global state
grid = None grid = None
color_layer = None
entities = [] entities = []
first_point = None first_point = None
second_point = None second_point = None
def create_map(): def create_map():
"""Create the interactive map with the layout specified by the user""" """Create the interactive map with the layout specified by the user"""
global grid, entities global grid, color_layer, entities
mcrfpy.createScene("dijkstra_interactive") mcrfpy.createScene("dijkstra_interactive")
# Create grid - 14x10 as specified # Create grid - 14x10 as specified
grid = mcrfpy.Grid(grid_x=14, grid_y=10) grid = mcrfpy.Grid(grid_x=14, grid_y=10)
grid.fill_color = mcrfpy.Color(0, 0, 0) grid.fill_color = mcrfpy.Color(0, 0, 0)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Define the map layout from user's specification # Define the map layout from user's specification
# . = floor, W = wall, E = entity position # . = floor, W = wall, E = entity position
map_layout = [ map_layout = [
@ -57,36 +61,35 @@ def create_map():
"..W.WWW.......", # Row 8 "..W.WWW.......", # Row 8
"..............", # Row 9 "..............", # Row 9
] ]
# Create the map # Create the map
entity_positions = [] entity_positions = []
for y, row in enumerate(map_layout): for y, row in enumerate(map_layout):
for x, char in enumerate(row): for x, char in enumerate(row):
cell = grid.at(x, y) cell = grid.at(x, y)
if char == 'W': if char == 'W':
# Wall # Wall
cell.walkable = False cell.walkable = False
cell.transparent = False cell.transparent = False
cell.color = WALL_COLOR color_layer.set(x, y, WALL_COLOR)
else: else:
# Floor # Floor
cell.walkable = True cell.walkable = True
cell.transparent = True cell.transparent = True
cell.color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
if char == 'E': if char == 'E':
# Entity position # Entity position
entity_positions.append((x, y)) entity_positions.append((x, y))
# Create entities at marked positions # Create entities at marked positions
entities = [] entities = []
for i, (x, y) in enumerate(entity_positions): for i, (x, y) in enumerate(entity_positions):
entity = mcrfpy.Entity(x, y) entity = mcrfpy.Entity((x, y), grid=grid)
entity.sprite_index = 49 + i # '1', '2', '3' entity.sprite_index = 49 + i # '1', '2', '3'
grid.entities.append(entity)
entities.append(entity) entities.append(entity)
return grid return grid
def clear_path_highlight(): def clear_path_highlight():
@ -96,37 +99,37 @@ def clear_path_highlight():
for x in range(grid.grid_x): for x in range(grid.grid_x):
cell = grid.at(x, y) cell = grid.at(x, y)
if cell.walkable: if cell.walkable:
cell.color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
def highlight_path(): def highlight_path():
"""Highlight the path between selected entities""" """Highlight the path between selected entities"""
if first_point is None or second_point is None: if first_point is None or second_point is None:
return return
# Clear previous highlighting # Clear previous highlighting
clear_path_highlight() clear_path_highlight()
# Get entities # Get entities
entity1 = entities[first_point] entity1 = entities[first_point]
entity2 = entities[second_point] entity2 = entities[second_point]
# Compute Dijkstra from first entity # Compute Dijkstra from first entity
grid.compute_dijkstra(int(entity1.x), int(entity1.y)) grid.compute_dijkstra(int(entity1.x), int(entity1.y))
# Get path to second entity # Get path to second entity
path = grid.get_dijkstra_path(int(entity2.x), int(entity2.y)) path = grid.get_dijkstra_path(int(entity2.x), int(entity2.y))
if path: if path:
# Highlight the path # Highlight the path
for x, y in path: for x, y in path:
cell = grid.at(x, y) cell = grid.at(x, y)
if cell.walkable: if cell.walkable:
cell.color = PATH_COLOR color_layer.set(x, y, PATH_COLOR)
# Also highlight start and end with entity colors # Also highlight start and end with entity colors
grid.at(int(entity1.x), int(entity1.y)).color = ENTITY_COLORS[first_point] color_layer.set(int(entity1.x), int(entity1.y), ENTITY_COLORS[first_point])
grid.at(int(entity2.x), int(entity2.y)).color = ENTITY_COLORS[second_point] color_layer.set(int(entity2.x), int(entity2.y), ENTITY_COLORS[second_point])
# Update info # Update info
distance = grid.get_dijkstra_distance(int(entity2.x), int(entity2.y)) distance = grid.get_dijkstra_distance(int(entity2.x), int(entity2.y))
info_text.text = f"Path: Entity {first_point+1} to Entity {second_point+1} - {len(path)} steps, {distance:.1f} units" info_text.text = f"Path: Entity {first_point+1} to Entity {second_point+1} - {len(path)} steps, {distance:.1f} units"
@ -199,34 +202,33 @@ grid.size = (560, 400) # 14*40, 10*40
grid.position = (120, 60) grid.position = (120, 60)
# Add title # Add title
title = mcrfpy.Caption("Dijkstra Pathfinding Interactive", 250, 10) title = mcrfpy.Caption(pos=(250, 10), text="Dijkstra Pathfinding Interactive")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
# Add status text # Add status text
status_text = mcrfpy.Caption("Press 1/2/3 for first entity, A/B/C for second", 120, 480) status_text = mcrfpy.Caption(pos=(120, 480), text="Press 1/2/3 for first entity, A/B/C for second")
status_text.fill_color = mcrfpy.Color(255, 255, 255) status_text.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(status_text) ui.append(status_text)
# Add info text # Add info text
info_text = mcrfpy.Caption("Space to clear, Q to quit", 120, 500) info_text = mcrfpy.Caption(pos=(120, 500), text="Space to clear, Q to quit")
info_text.fill_color = mcrfpy.Color(200, 200, 200) info_text.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(info_text) ui.append(info_text)
# Add legend # Add legend
legend1 = mcrfpy.Caption("Entities: 1=Red 2=Green 3=Blue", 120, 540) legend1 = mcrfpy.Caption(pos=(120, 540), text="Entities: 1=Red 2=Green 3=Blue")
legend1.fill_color = mcrfpy.Color(150, 150, 150) legend1.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(legend1) ui.append(legend1)
legend2 = mcrfpy.Caption("Colors: Dark=Wall Light=Floor Cyan=Path", 120, 560) legend2 = mcrfpy.Caption(pos=(120, 560), text="Colors: Dark=Wall Light=Floor Cyan=Path")
legend2.fill_color = mcrfpy.Color(150, 150, 150) legend2.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(legend2) ui.append(legend2)
# Mark entity positions with colored indicators # Mark entity positions with colored indicators
for i, entity in enumerate(entities): for i, entity in enumerate(entities):
marker = mcrfpy.Caption(str(i+1), marker = mcrfpy.Caption(pos=(120 + int(entity.x) * 40 + 15, 60 + int(entity.y) * 40 + 10),
120 + int(entity.x) * 40 + 15, text=str(i+1))
60 + int(entity.y) * 40 + 10)
marker.fill_color = ENTITY_COLORS[i] marker.fill_color = ENTITY_COLORS[i]
marker.outline = 1 marker.outline = 1
marker.outline_color = mcrfpy.Color(0, 0, 0) marker.outline_color = mcrfpy.Color(0, 0, 0)

View file

@ -32,6 +32,7 @@ ENTITY_COLORS = [
# Global state # Global state
grid = None grid = None
color_layer = None
entities = [] entities = []
first_point = None first_point = None
second_point = None second_point = None
@ -43,14 +44,17 @@ original_positions = [] # Store original entity positions
def create_map(): def create_map():
"""Create the interactive map with the layout specified by the user""" """Create the interactive map with the layout specified by the user"""
global grid, entities, original_positions global grid, color_layer, entities, original_positions
mcrfpy.createScene("dijkstra_enhanced") mcrfpy.createScene("dijkstra_enhanced")
# Create grid - 14x10 as specified # Create grid - 14x10 as specified
grid = mcrfpy.Grid(grid_x=14, grid_y=10) grid = mcrfpy.Grid(grid_x=14, grid_y=10)
grid.fill_color = mcrfpy.Color(0, 0, 0) grid.fill_color = mcrfpy.Color(0, 0, 0)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Define the map layout from user's specification # Define the map layout from user's specification
# . = floor, W = wall, E = entity position # . = floor, W = wall, E = entity position
map_layout = [ map_layout = [
@ -65,87 +69,86 @@ def create_map():
"..W.WWW.......", # Row 8 "..W.WWW.......", # Row 8
"..............", # Row 9 "..............", # Row 9
] ]
# Create the map # Create the map
entity_positions = [] entity_positions = []
for y, row in enumerate(map_layout): for y, row in enumerate(map_layout):
for x, char in enumerate(row): for x, char in enumerate(row):
cell = grid.at(x, y) cell = grid.at(x, y)
if char == 'W': if char == 'W':
# Wall # Wall
cell.walkable = False cell.walkable = False
cell.transparent = False cell.transparent = False
cell.color = WALL_COLOR color_layer.set(x, y, WALL_COLOR)
else: else:
# Floor # Floor
cell.walkable = True cell.walkable = True
cell.transparent = True cell.transparent = True
cell.color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
if char == 'E': if char == 'E':
# Entity position # Entity position
entity_positions.append((x, y)) entity_positions.append((x, y))
# Create entities at marked positions # Create entities at marked positions
entities = [] entities = []
original_positions = [] original_positions = []
for i, (x, y) in enumerate(entity_positions): for i, (x, y) in enumerate(entity_positions):
entity = mcrfpy.Entity(x, y) entity = mcrfpy.Entity((x, y), grid=grid)
entity.sprite_index = 49 + i # '1', '2', '3' entity.sprite_index = 49 + i # '1', '2', '3'
grid.entities.append(entity)
entities.append(entity) entities.append(entity)
original_positions.append((x, y)) original_positions.append((x, y))
return grid return grid
def clear_path_highlight(): def clear_path_highlight():
"""Clear any existing path highlighting""" """Clear any existing path highlighting"""
global current_path global current_path
# Reset all floor tiles to original color # Reset all floor tiles to original color
for y in range(grid.grid_y): for y in range(grid.grid_y):
for x in range(grid.grid_x): for x in range(grid.grid_x):
cell = grid.at(x, y) cell = grid.at(x, y)
if cell.walkable: if cell.walkable:
cell.color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
current_path = [] current_path = []
def highlight_path(): def highlight_path():
"""Highlight the path between selected entities using entity.path_to()""" """Highlight the path between selected entities using entity.path_to()"""
global current_path global current_path
if first_point is None or second_point is None: if first_point is None or second_point is None:
return return
# Clear previous highlighting # Clear previous highlighting
clear_path_highlight() clear_path_highlight()
# Get entities # Get entities
entity1 = entities[first_point] entity1 = entities[first_point]
entity2 = entities[second_point] entity2 = entities[second_point]
# Use the new path_to method! # Use the new path_to method!
path = entity1.path_to(int(entity2.x), int(entity2.y)) path = entity1.path_to(int(entity2.x), int(entity2.y))
if path: if path:
current_path = path current_path = path
# Highlight the path # Highlight the path
for i, (x, y) in enumerate(path): for i, (x, y) in enumerate(path):
cell = grid.at(x, y) cell = grid.at(x, y)
if cell.walkable: if cell.walkable:
# Use gradient for path visualization # Use gradient for path visualization
if i < len(path) - 1: if i < len(path) - 1:
cell.color = PATH_COLOR color_layer.set(x, y, PATH_COLOR)
else: else:
cell.color = VISITED_COLOR color_layer.set(x, y, VISITED_COLOR)
# Highlight start and end with entity colors # Highlight start and end with entity colors
grid.at(int(entity1.x), int(entity1.y)).color = ENTITY_COLORS[first_point] color_layer.set(int(entity1.x), int(entity1.y), ENTITY_COLORS[first_point])
grid.at(int(entity2.x), int(entity2.y)).color = ENTITY_COLORS[second_point] color_layer.set(int(entity2.x), int(entity2.y), ENTITY_COLORS[second_point])
# Update info # Update info
info_text.text = f"Path: Entity {first_point+1} to Entity {second_point+1} - {len(path)} steps" info_text.text = f"Path: Entity {first_point+1} to Entity {second_point+1} - {len(path)} steps"
else: else:
@ -291,39 +294,38 @@ grid.size = (560, 400) # 14*40, 10*40
grid.position = (120, 60) grid.position = (120, 60)
# Add title # Add title
title = mcrfpy.Caption("Enhanced Dijkstra Pathfinding", 250, 10) title = mcrfpy.Caption(pos=(250, 10), text="Enhanced Dijkstra Pathfinding")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
# Add status text # Add status text
status_text = mcrfpy.Caption("Press 1/2/3 for first entity, A/B/C for second", 120, 480) status_text = mcrfpy.Caption(pos=(120, 480), text="Press 1/2/3 for first entity, A/B/C for second")
status_text.fill_color = mcrfpy.Color(255, 255, 255) status_text.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(status_text) ui.append(status_text)
# Add info text # Add info text
info_text = mcrfpy.Caption("Space to clear, Q to quit", 120, 500) info_text = mcrfpy.Caption(pos=(120, 500), text="Space to clear, Q to quit")
info_text.fill_color = mcrfpy.Color(200, 200, 200) info_text.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(info_text) ui.append(info_text)
# Add control text # Add control text
control_text = mcrfpy.Caption("Press M to move, P to pause, R to reset", 120, 520) control_text = mcrfpy.Caption(pos=(120, 520), text="Press M to move, P to pause, R to reset")
control_text.fill_color = mcrfpy.Color(150, 200, 150) control_text.fill_color = mcrfpy.Color(150, 200, 150)
ui.append(control_text) ui.append(control_text)
# Add legend # Add legend
legend1 = mcrfpy.Caption("Entities: 1=Red 2=Green 3=Blue", 120, 560) legend1 = mcrfpy.Caption(pos=(120, 560), text="Entities: 1=Red 2=Green 3=Blue")
legend1.fill_color = mcrfpy.Color(150, 150, 150) legend1.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(legend1) ui.append(legend1)
legend2 = mcrfpy.Caption("Colors: Dark=Wall Light=Floor Cyan=Path", 120, 580) legend2 = mcrfpy.Caption(pos=(120, 580), text="Colors: Dark=Wall Light=Floor Cyan=Path")
legend2.fill_color = mcrfpy.Color(150, 150, 150) legend2.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(legend2) ui.append(legend2)
# Mark entity positions with colored indicators # Mark entity positions with colored indicators
for i, entity in enumerate(entities): for i, entity in enumerate(entities):
marker = mcrfpy.Caption(str(i+1), marker = mcrfpy.Caption(pos=(120 + int(entity.x) * 40 + 15, 60 + int(entity.y) * 40 + 10),
120 + int(entity.x) * 40 + 15, text=str(i+1))
60 + int(entity.y) * 40 + 10)
marker.fill_color = ENTITY_COLORS[i] marker.fill_color = ENTITY_COLORS[i]
marker.outline = 1 marker.outline = 1
marker.outline_color = mcrfpy.Color(0, 0, 0) marker.outline_color = mcrfpy.Color(0, 0, 0)

View file

@ -128,12 +128,12 @@ grid.position = (50, 50)
grid.size = (500, 300) grid.size = (500, 300)
# Add title # Add title
title = mcrfpy.Caption("Dijkstra Pathfinding Test", 200, 10) title = mcrfpy.Caption(pos=(200, 10), text="Dijkstra Pathfinding Test")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
# Add legend # Add legend
legend = mcrfpy.Caption("Red=Entity1 Green=Entity2 Blue=Entity3 Cyan=Path 1→3", 50, 360) legend = mcrfpy.Caption(pos=(50, 360), text="Red=Entity1 Green=Entity2 Blue=Entity3 Cyan=Path 1→3")
legend.fill_color = mcrfpy.Color(180, 180, 180) legend.fill_color = mcrfpy.Color(180, 180, 180)
ui.append(legend) ui.append(legend)

View file

@ -19,33 +19,36 @@ mcrfpy.createScene("visibility_demo")
grid = mcrfpy.Grid(grid_x=30, grid_y=20) grid = mcrfpy.Grid(grid_x=30, grid_y=20)
grid.fill_color = mcrfpy.Color(20, 20, 30) # Dark background grid.fill_color = mcrfpy.Color(20, 20, 30) # Dark background
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Initialize grid - all walkable and transparent # Initialize grid - all walkable and transparent
for y in range(20): for y in range(20):
for x in range(30): for x in range(30):
cell = grid.at(x, y) cell = grid.at(x, y)
cell.walkable = True cell.walkable = True
cell.transparent = True cell.transparent = True
cell.color = mcrfpy.Color(100, 100, 120) # Floor color color_layer.set(x, y, mcrfpy.Color(100, 100, 120)) # Floor color
# Create walls # Create walls
walls = [ walls = [
# Central cross # Central cross
[(15, y) for y in range(8, 12)], [(15, y) for y in range(8, 12)],
[(x, 10) for x in range(13, 18)], [(x, 10) for x in range(13, 18)],
# Rooms # Rooms
# Top-left room # Top-left room
[(x, 5) for x in range(2, 8)] + [(8, y) for y in range(2, 6)], [(x, 5) for x in range(2, 8)] + [(8, y) for y in range(2, 6)],
[(2, y) for y in range(2, 6)] + [(x, 2) for x in range(2, 8)], [(2, y) for y in range(2, 6)] + [(x, 2) for x in range(2, 8)],
# Top-right room # Top-right room
[(x, 5) for x in range(22, 28)] + [(22, y) for y in range(2, 6)], [(x, 5) for x in range(22, 28)] + [(22, y) for y in range(2, 6)],
[(28, y) for y in range(2, 6)] + [(x, 2) for x in range(22, 28)], [(28, y) for y in range(2, 6)] + [(x, 2) for x in range(22, 28)],
# Bottom-left room # Bottom-left room
[(x, 15) for x in range(2, 8)] + [(8, y) for y in range(15, 18)], [(x, 15) for x in range(2, 8)] + [(8, y) for y in range(15, 18)],
[(2, y) for y in range(15, 18)] + [(x, 18) for x in range(2, 8)], [(2, y) for y in range(15, 18)] + [(x, 18) for x in range(2, 8)],
# Bottom-right room # Bottom-right room
[(x, 15) for x in range(22, 28)] + [(22, y) for y in range(15, 18)], [(x, 15) for x in range(22, 28)] + [(22, y) for y in range(15, 18)],
[(28, y) for y in range(15, 18)] + [(x, 18) for x in range(22, 28)], [(28, y) for y in range(15, 18)] + [(x, 18) for x in range(22, 28)],
@ -57,12 +60,12 @@ for wall_group in walls:
cell = grid.at(x, y) cell = grid.at(x, y)
cell.walkable = False cell.walkable = False
cell.transparent = False cell.transparent = False
cell.color = mcrfpy.Color(40, 20, 20) # Wall color color_layer.set(x, y, mcrfpy.Color(40, 20, 20)) # Wall color
# Create entities # Create entities
player = mcrfpy.Entity(5, 10, grid=grid) player = mcrfpy.Entity((5, 10), grid=grid)
player.sprite_index = 64 # @ player.sprite_index = 64 # @
enemy = mcrfpy.Entity(25, 10, grid=grid) enemy = mcrfpy.Entity((25, 10), grid=grid)
enemy.sprite_index = 69 # E enemy.sprite_index = 69 # E
# Update initial visibility # Update initial visibility
@ -80,24 +83,24 @@ grid.position = (50, 100)
grid.size = (900, 600) # 30*30, 20*30 grid.size = (900, 600) # 30*30, 20*30
# Title # Title
title = mcrfpy.Caption("Interactive Visibility Demo", 350, 20) title = mcrfpy.Caption(pos=(350, 20), text="Interactive Visibility Demo")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
# Info displays # Info displays
perspective_label = mcrfpy.Caption("Perspective: Omniscient", 50, 50) perspective_label = mcrfpy.Caption(pos=(50, 50), text="Perspective: Omniscient")
perspective_label.fill_color = mcrfpy.Color(200, 200, 200) perspective_label.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(perspective_label) ui.append(perspective_label)
controls = mcrfpy.Caption("WASD: Move player | Arrows: Move enemy | Tab: Cycle perspective | Space: Update visibility | R: Reset", 50, 730) controls = mcrfpy.Caption(pos=(50, 730), text="WASD: Move player | Arrows: Move enemy | Tab: Cycle perspective | Space: Update visibility | R: Reset")
controls.fill_color = mcrfpy.Color(150, 150, 150) controls.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(controls) ui.append(controls)
player_info = mcrfpy.Caption("Player: (5, 10)", 700, 50) player_info = mcrfpy.Caption(pos=(700, 50), text="Player: (5, 10)")
player_info.fill_color = mcrfpy.Color(100, 255, 100) player_info.fill_color = mcrfpy.Color(100, 255, 100)
ui.append(player_info) ui.append(player_info)
enemy_info = mcrfpy.Caption("Enemy: (25, 10)", 700, 70) enemy_info = mcrfpy.Caption(pos=(700, 70), text="Enemy: (25, 10)")
enemy_info.fill_color = mcrfpy.Color(255, 100, 100) enemy_info.fill_color = mcrfpy.Color(255, 100, 100)
ui.append(enemy_info) ui.append(enemy_info)

View file

@ -11,6 +11,9 @@ mcrfpy.createScene("vis_test")
print("Creating grid...") print("Creating grid...")
grid = mcrfpy.Grid(grid_x=10, grid_y=10) grid = mcrfpy.Grid(grid_x=10, grid_y=10)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Initialize grid # Initialize grid
print("Initializing grid...") print("Initializing grid...")
for y in range(10): for y in range(10):
@ -18,11 +21,11 @@ for y in range(10):
cell = grid.at(x, y) cell = grid.at(x, y)
cell.walkable = True cell.walkable = True
cell.transparent = True cell.transparent = True
cell.color = mcrfpy.Color(100, 100, 120) color_layer.set(x, y, mcrfpy.Color(100, 100, 120))
# Create entity # Create entity
print("Creating entity...") print("Creating entity...")
entity = mcrfpy.Entity(5, 5, grid=grid) entity = mcrfpy.Entity((5, 5), grid=grid)
entity.sprite_index = 64 entity.sprite_index = 64
print("Updating visibility...") print("Updating visibility...")

View file

@ -13,8 +13,8 @@ print("Scene created")
grid = mcrfpy.Grid(grid_x=5, grid_y=5) grid = mcrfpy.Grid(grid_x=5, grid_y=5)
print("Grid created") print("Grid created")
# Create entity without appending # Create entity with grid association
entity = mcrfpy.Entity(2, 2, grid=grid) entity = mcrfpy.Entity((2, 2), grid=grid)
print(f"Entity created at ({entity.x}, {entity.y})") print(f"Entity created at ({entity.x}, {entity.y})")
# Check if gridstate is initialized # Check if gridstate is initialized

View file

@ -8,6 +8,10 @@ while small grids use the original flat storage. Verifies that:
2. Large grids work correctly with chunks 2. Large grids work correctly with chunks
3. Cell access (read/write) works for both modes 3. Cell access (read/write) works for both modes
4. Rendering displays correctly for both modes 4. Rendering displays correctly for both modes
NOTE: This test uses ColorLayer for color operations since cell.color
is no longer supported. The chunk system affects internal storage, which
ColorLayer also uses.
""" """
import mcrfpy import mcrfpy
@ -19,22 +23,21 @@ def test_small_grid():
# Small grid should use flat storage # Small grid should use flat storage
grid = mcrfpy.Grid(grid_size=(50, 50), pos=(10, 10), size=(400, 400)) grid = mcrfpy.Grid(grid_size=(50, 50), pos=(10, 10), size=(400, 400))
color_layer = grid.add_layer("color", z_index=-1)
# Set some cells # Set some cells
for y in range(50): for y in range(50):
for x in range(50): for x in range(50):
cell = grid.at(x, y) cell = grid.at(x, y)
cell.color = mcrfpy.Color((x * 5) % 256, (y * 5) % 256, 128, 255) color_layer.set(x, y, mcrfpy.Color((x * 5) % 256, (y * 5) % 256, 128, 255))
cell.tilesprite = -1 cell.tilesprite = -1
# Verify cells # Verify cells
cell = grid.at(25, 25)
expected_r = (25 * 5) % 256 expected_r = (25 * 5) % 256
expected_g = (25 * 5) % 256 expected_g = (25 * 5) % 256
color = cell.color color = color_layer.at(25, 25)
r, g = color[0], color[1] if color.r != expected_r or color.g != expected_g:
if r != expected_r or g != expected_g: print(f"FAIL: Small grid cell color mismatch. Expected ({expected_r}, {expected_g}), got ({color.r}, {color.g})")
print(f"FAIL: Small grid cell color mismatch. Expected ({expected_r}, {expected_g}), got ({r}, {g})")
return False return False
print(" Small grid: PASS") print(" Small grid: PASS")
@ -46,6 +49,7 @@ def test_large_grid():
# Large grid should use chunk storage (100 > 64) # Large grid should use chunk storage (100 > 64)
grid = mcrfpy.Grid(grid_size=(100, 100), pos=(10, 10), size=(400, 400)) grid = mcrfpy.Grid(grid_size=(100, 100), pos=(10, 10), size=(400, 400))
color_layer = grid.add_layer("color", z_index=-1)
# Set cells across multiple chunks # Set cells across multiple chunks
# Chunks are 64x64, so a 100x100 grid has 2x2 = 4 chunks # Chunks are 64x64, so a 100x100 grid has 2x2 = 4 chunks
@ -61,15 +65,14 @@ def test_large_grid():
for x, y in test_points: for x, y in test_points:
cell = grid.at(x, y) cell = grid.at(x, y)
cell.color = mcrfpy.Color(x, y, 100, 255) color_layer.set(x, y, mcrfpy.Color(x, y, 100, 255))
cell.tilesprite = -1 cell.tilesprite = -1
# Verify cells # Verify cells
for x, y in test_points: for x, y in test_points:
cell = grid.at(x, y) color = color_layer.at(x, y)
color = cell.color if color.r != x or color.g != y:
if color[0] != x or color[1] != y: print(f"FAIL: Large grid cell ({x},{y}) color mismatch. Expected ({x}, {y}), got ({color.r}, {color.g})")
print(f"FAIL: Large grid cell ({x},{y}) color mismatch. Expected ({x}, {y}), got ({color[0]}, {color[1]})")
return False return False
print(" Large grid cell access: PASS") print(" Large grid cell access: PASS")
@ -81,6 +84,7 @@ def test_very_large_grid():
# 500x500 = 250,000 cells, should use ~64 chunks (8x8) # 500x500 = 250,000 cells, should use ~64 chunks (8x8)
grid = mcrfpy.Grid(grid_size=(500, 500), pos=(10, 10), size=(400, 400)) grid = mcrfpy.Grid(grid_size=(500, 500), pos=(10, 10), size=(400, 400))
color_layer = grid.add_layer("color", z_index=-1)
# Set some cells at various positions # Set some cells at various positions
test_points = [ test_points = [
@ -94,14 +98,12 @@ def test_very_large_grid():
] ]
for x, y in test_points: for x, y in test_points:
cell = grid.at(x, y) color_layer.set(x, y, mcrfpy.Color(x % 256, y % 256, 200, 255))
cell.color = mcrfpy.Color(x % 256, y % 256, 200, 255)
# Verify # Verify
for x, y in test_points: for x, y in test_points:
cell = grid.at(x, y) color = color_layer.at(x, y)
color = cell.color if color.r != (x % 256) or color.g != (y % 256):
if color[0] != (x % 256) or color[1] != (y % 256):
print(f"FAIL: Very large grid cell ({x},{y}) color mismatch") print(f"FAIL: Very large grid cell ({x},{y}) color mismatch")
return False return False
@ -114,20 +116,20 @@ def test_boundary_case():
# 64x64 should use flat storage (not exceeding threshold) # 64x64 should use flat storage (not exceeding threshold)
grid_64 = mcrfpy.Grid(grid_size=(64, 64), pos=(10, 10), size=(400, 400)) grid_64 = mcrfpy.Grid(grid_size=(64, 64), pos=(10, 10), size=(400, 400))
cell = grid_64.at(63, 63) color_layer_64 = grid_64.add_layer("color", z_index=-1)
cell.color = mcrfpy.Color(255, 0, 0, 255) color_layer_64.set(63, 63, mcrfpy.Color(255, 0, 0, 255))
color = grid_64.at(63, 63).color color = color_layer_64.at(63, 63)
if color[0] != 255: if color.r != 255:
print(f"FAIL: 64x64 grid boundary cell not set correctly, got r={color[0]}") print(f"FAIL: 64x64 grid boundary cell not set correctly, got r={color.r}")
return False return False
# 65x65 should use chunk storage (exceeding threshold) # 65x65 should use chunk storage (exceeding threshold)
grid_65 = mcrfpy.Grid(grid_size=(65, 65), pos=(10, 10), size=(400, 400)) grid_65 = mcrfpy.Grid(grid_size=(65, 65), pos=(10, 10), size=(400, 400))
cell = grid_65.at(64, 64) color_layer_65 = grid_65.add_layer("color", z_index=-1)
cell.color = mcrfpy.Color(0, 255, 0, 255) color_layer_65.set(64, 64, mcrfpy.Color(0, 255, 0, 255))
color = grid_65.at(64, 64).color color = color_layer_65.at(64, 64)
if color[1] != 255: if color.g != 255:
print(f"FAIL: 65x65 grid cell not set correctly, got g={color[1]}") print(f"FAIL: 65x65 grid cell not set correctly, got g={color.g}")
return False return False
print(" Boundary cases: PASS") print(" Boundary cases: PASS")
@ -139,19 +141,18 @@ def test_edge_cases():
# Create 100x100 grid # Create 100x100 grid
grid = mcrfpy.Grid(grid_size=(100, 100), pos=(10, 10), size=(400, 400)) grid = mcrfpy.Grid(grid_size=(100, 100), pos=(10, 10), size=(400, 400))
color_layer = grid.add_layer("color", z_index=-1)
# Test all corners # Test all corners
corners = [(0, 0), (99, 0), (0, 99), (99, 99)] corners = [(0, 0), (99, 0), (0, 99), (99, 99)]
for i, (x, y) in enumerate(corners): for i, (x, y) in enumerate(corners):
cell = grid.at(x, y) color_layer.set(x, y, mcrfpy.Color(i * 60, i * 60, i * 60, 255))
cell.color = mcrfpy.Color(i * 60, i * 60, i * 60, 255)
for i, (x, y) in enumerate(corners): for i, (x, y) in enumerate(corners):
cell = grid.at(x, y)
expected = i * 60 expected = i * 60
color = cell.color color = color_layer.at(x, y)
if color[0] != expected: if color.r != expected:
print(f"FAIL: Corner ({x},{y}) color mismatch, expected {expected}, got {color[0]}") print(f"FAIL: Corner ({x},{y}) color mismatch, expected {expected}, got {color.r}")
return False return False
print(" Edge cases: PASS") print(" Edge cases: PASS")

View file

@ -10,10 +10,10 @@ import sys
# Create a derived Entity class # Create a derived Entity class
class CustomEntity(mcrfpy.Entity): class CustomEntity(mcrfpy.Entity):
def __init__(self, x, y): def __init__(self, pos):
super().__init__(x, y) super().__init__(pos)
self.custom_attribute = "I am custom!" self.custom_attribute = "I am custom!"
def custom_method(self): def custom_method(self):
return "Custom method called" return "Custom method called"
@ -21,11 +21,11 @@ def run_test(runtime):
"""Test that derived entity classes maintain their type in collections""" """Test that derived entity classes maintain their type in collections"""
try: try:
# Create a grid # Create a grid
grid = mcrfpy.Grid(10, 10) grid = mcrfpy.Grid(grid_size=(10, 10))
# Create instances of base and derived entities # Create instances of base and derived entities
base_entity = mcrfpy.Entity(1, 1) base_entity = mcrfpy.Entity((1, 1))
custom_entity = CustomEntity(2, 2) custom_entity = CustomEntity((2, 2))
# Add them to the grid's entity collection # Add them to the grid's entity collection
grid.entities.append(base_entity) grid.entities.append(base_entity)

View file

@ -51,17 +51,17 @@ mcrfpy.setScene("timer_test_scene")
ui = mcrfpy.sceneUI("timer_test_scene") ui = mcrfpy.sceneUI("timer_test_scene")
# Add a bright red frame that should be visible # Add a bright red frame that should be visible
frame = mcrfpy.Frame(100, 100, 400, 300, frame = mcrfpy.Frame(pos=(100, 100), size=(400, 300),
fill_color=mcrfpy.Color(255, 0, 0), # Bright red fill_color=mcrfpy.Color(255, 0, 0), # Bright red
outline_color=mcrfpy.Color(255, 255, 255), # White outline outline_color=mcrfpy.Color(255, 255, 255), # White outline
outline=5.0) outline=5.0)
ui.append(frame) ui.append(frame)
# Add text # Add text
caption = mcrfpy.Caption(mcrfpy.Vector(150, 150), caption = mcrfpy.Caption(pos=(150, 150),
text="TIMER TEST - SHOULD BE VISIBLE", text="TIMER TEST - SHOULD BE VISIBLE",
fill_color=mcrfpy.Color(255, 255, 255)) fill_color=mcrfpy.Color(255, 255, 255))
caption.size = 24 caption.font_size = 24
frame.children.append(caption) frame.children.append(caption)
# Add click handler to demonstrate interaction # Add click handler to demonstrate interaction

View file

@ -1,4 +1,4 @@
import mcrfpy import mcrfpy
e = mcrfpy.Entity(0, 0) e = mcrfpy.Entity((0, 0))
print("Entity attributes:", dir(e)) print("Entity attributes:", dir(e))
print("\nEntity repr:", repr(e)) print("\nEntity repr:", repr(e))

View file

@ -22,7 +22,7 @@ print(f"UI collection type: {type(ui)}")
print(f"Initial UI elements: {len(ui)}") print(f"Initial UI elements: {len(ui)}")
# Add a simple frame # Add a simple frame
frame = mcrfpy.Frame(0, 0, 100, 100, frame = mcrfpy.Frame(pos=(0, 0), size=(100, 100),
fill_color=mcrfpy.Color(255, 255, 255)) fill_color=mcrfpy.Color(255, 255, 255))
ui.append(frame) ui.append(frame)
print(f"After adding frame: {len(ui)} elements") print(f"After adding frame: {len(ui)} elements")

View file

@ -22,14 +22,13 @@ mcrfpy.createScene("grid")
texture = mcrfpy.Texture("assets/kenney_TD_MR_IP.png", 16, 16) texture = mcrfpy.Texture("assets/kenney_TD_MR_IP.png", 16, 16)
# Title # Title
title = mcrfpy.Caption(400, 30, "Grid Example - Dungeon View") title = mcrfpy.Caption(pos=(400, 30), text="Grid Example - Dungeon View")
title.font = mcrfpy.default_font title.font = mcrfpy.default_font
title.font_size = 24 title.font_size = 24
title.font_color = (255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
# Create main grid (20x15 tiles, each 32x32 pixels) # Create main grid (20x15 tiles, each 32x32 pixels)
grid = mcrfpy.Grid(100, 100, 20, 15, texture, 32, 32) grid = mcrfpy.Grid(pos=(100, 100), grid_size=(20, 15), texture=texture, size=(640, 480))
grid.texture = texture
# Define tile types from Crypt of Sokoban # Define tile types from Crypt of Sokoban
FLOOR = 58 # Stone floor FLOOR = 58 # Stone floor
@ -63,36 +62,21 @@ grid.set_tile(12, 8, BOULDER)
# Create some entities on the grid # Create some entities on the grid
# Player entity # Player entity
player = mcrfpy.Entity(5, 7) player = mcrfpy.Entity((5, 7), texture=texture, sprite_index=84, grid=grid) # Player sprite
player.texture = texture
player.sprite_index = 84 # Player sprite
# Enemy entities # Enemy entities
rat1 = mcrfpy.Entity(12, 5) rat1 = mcrfpy.Entity((12, 5), texture=texture, sprite_index=123, grid=grid) # Rat
rat1.texture = texture
rat1.sprite_index = 123 # Rat
rat2 = mcrfpy.Entity(14, 9) rat2 = mcrfpy.Entity((14, 9), texture=texture, sprite_index=123, grid=grid) # Rat
rat2.texture = texture
rat2.sprite_index = 123 # Rat
cyclops = mcrfpy.Entity(10, 10) cyclops = mcrfpy.Entity((10, 10), texture=texture, sprite_index=109, grid=grid) # Cyclops
cyclops.texture = texture
cyclops.sprite_index = 109 # Cyclops
# Add entities to grid
grid.entities.append(player)
grid.entities.append(rat1)
grid.entities.append(rat2)
grid.entities.append(cyclops)
# Create a smaller grid showing tile palette # Create a smaller grid showing tile palette
palette_label = mcrfpy.Caption(100, 600, "Tile Types:") palette_label = mcrfpy.Caption(pos=(100, 600), text="Tile Types:")
palette_label.font = mcrfpy.default_font palette_label.font = mcrfpy.default_font
palette_label.font_color = (255, 255, 255) palette_label.fill_color = mcrfpy.Color(255, 255, 255)
palette = mcrfpy.Grid(250, 580, 7, 1, texture, 32, 32) palette = mcrfpy.Grid(pos=(250, 580), grid_size=(7, 1), texture=texture, size=(224, 32))
palette.texture = texture
palette.set_tile(0, 0, FLOOR) palette.set_tile(0, 0, FLOOR)
palette.set_tile(1, 0, WALL) palette.set_tile(1, 0, WALL)
palette.set_tile(2, 0, DOOR) palette.set_tile(2, 0, DOOR)
@ -104,17 +88,17 @@ palette.set_tile(6, 0, BOULDER)
# Labels for palette # Labels for palette
labels = ["Floor", "Wall", "Door", "Chest", "Button", "Exit", "Boulder"] labels = ["Floor", "Wall", "Door", "Chest", "Button", "Exit", "Boulder"]
for i, label in enumerate(labels): for i, label in enumerate(labels):
l = mcrfpy.Caption(250 + i * 32, 615, label) l = mcrfpy.Caption(pos=(250 + i * 32, 615), text=label)
l.font = mcrfpy.default_font l.font = mcrfpy.default_font
l.font_size = 10 l.font_size = 10
l.font_color = (255, 255, 255) l.fill_color = mcrfpy.Color(255, 255, 255)
mcrfpy.sceneUI("grid").append(l) mcrfpy.sceneUI("grid").append(l)
# Add info caption # Add info caption
info = mcrfpy.Caption(100, 680, "Grid supports tiles and entities. Entities can move independently of the tile grid.") info = mcrfpy.Caption(pos=(100, 680), text="Grid supports tiles and entities. Entities can move independently of the tile grid.")
info.font = mcrfpy.default_font info.font = mcrfpy.default_font
info.font_size = 14 info.font_size = 14
info.font_color = (200, 200, 200) info.fill_color = mcrfpy.Color(200, 200, 200)
# Add all elements to scene # Add all elements to scene
ui = mcrfpy.sceneUI("grid") ui = mcrfpy.sceneUI("grid")

View file

@ -22,20 +22,20 @@ mcrfpy.createScene("sprites")
texture = mcrfpy.Texture("assets/kenney_TD_MR_IP.png", 16, 16) texture = mcrfpy.Texture("assets/kenney_TD_MR_IP.png", 16, 16)
# Title # Title
title = mcrfpy.Caption(400, 30, "Sprite Examples") title = mcrfpy.Caption(pos=(400, 30), text="Sprite Examples")
title.font = mcrfpy.default_font title.font = mcrfpy.default_font
title.font_size = 24 title.font_size = 24
title.font_color = (255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
# Create a frame background # Create a frame background
frame = mcrfpy.Frame(50, 80, 700, 500) frame = mcrfpy.Frame(pos=(50, 80), size=(700, 500))
frame.bgcolor = (64, 64, 128) frame.fill_color = mcrfpy.Color(64, 64, 128)
frame.outline = 2 frame.outline = 2
# Player sprite # Player sprite
player_label = mcrfpy.Caption(100, 120, "Player") player_label = mcrfpy.Caption(pos=(100, 120), text="Player")
player_label.font = mcrfpy.default_font player_label.font = mcrfpy.default_font
player_label.font_color = (255, 255, 255) player_label.fill_color = mcrfpy.Color(255, 255, 255)
player = mcrfpy.Sprite(120, 150) player = mcrfpy.Sprite(120, 150)
player.texture = texture player.texture = texture
@ -43,9 +43,9 @@ player.sprite_index = 84 # Player sprite
player.scale = (3.0, 3.0) player.scale = (3.0, 3.0)
# Enemy sprites # Enemy sprites
enemy_label = mcrfpy.Caption(250, 120, "Enemies") enemy_label = mcrfpy.Caption(pos=(250, 120), text="Enemies")
enemy_label.font = mcrfpy.default_font enemy_label.font = mcrfpy.default_font
enemy_label.font_color = (255, 255, 255) enemy_label.fill_color = mcrfpy.Color(255, 255, 255)
rat = mcrfpy.Sprite(250, 150) rat = mcrfpy.Sprite(250, 150)
rat.texture = texture rat.texture = texture
@ -63,9 +63,9 @@ cyclops.sprite_index = 109 # Cyclops
cyclops.scale = (3.0, 3.0) cyclops.scale = (3.0, 3.0)
# Items row # Items row
items_label = mcrfpy.Caption(100, 250, "Items") items_label = mcrfpy.Caption(pos=(100, 250), text="Items")
items_label.font = mcrfpy.default_font items_label.font = mcrfpy.default_font
items_label.font_color = (255, 255, 255) items_label.fill_color = mcrfpy.Color(255, 255, 255)
# Boulder # Boulder
boulder = mcrfpy.Sprite(100, 280) boulder = mcrfpy.Sprite(100, 280)
@ -92,9 +92,9 @@ button.sprite_index = 250 # Button
button.scale = (3.0, 3.0) button.scale = (3.0, 3.0)
# UI elements row # UI elements row
ui_label = mcrfpy.Caption(100, 380, "UI Elements") ui_label = mcrfpy.Caption(pos=(100, 380), text="UI Elements")
ui_label.font = mcrfpy.default_font ui_label.font = mcrfpy.default_font
ui_label.font_color = (255, 255, 255) ui_label.fill_color = mcrfpy.Color(255, 255, 255)
# Hearts # Hearts
heart_full = mcrfpy.Sprite(100, 410) heart_full = mcrfpy.Sprite(100, 410)
@ -119,9 +119,9 @@ armor.sprite_index = 211 # Armor
armor.scale = (3.0, 3.0) armor.scale = (3.0, 3.0)
# Scale demonstration # Scale demonstration
scale_label = mcrfpy.Caption(500, 120, "Scale Demo") scale_label = mcrfpy.Caption(pos=(500, 120), text="Scale Demo")
scale_label.font = mcrfpy.default_font scale_label.font = mcrfpy.default_font
scale_label.font_color = (255, 255, 255) scale_label.fill_color = mcrfpy.Color(255, 255, 255)
# Same sprite at different scales # Same sprite at different scales
for i, scale in enumerate([1.0, 2.0, 3.0, 4.0]): for i, scale in enumerate([1.0, 2.0, 3.0, 4.0]):

View file

@ -17,42 +17,42 @@ def test_transparency_workaround():
# WORKAROUND: Create a full-window opaque frame as the first element # WORKAROUND: Create a full-window opaque frame as the first element
# This acts as an opaque background since the scene clears with transparent # This acts as an opaque background since the scene clears with transparent
print("Creating full-window opaque background...") print("Creating full-window opaque background...")
background = mcrfpy.Frame(0, 0, 1024, 768, background = mcrfpy.Frame(pos=(0, 0), size=(1024, 768),
fill_color=mcrfpy.Color(50, 50, 50), # Dark gray fill_color=mcrfpy.Color(50, 50, 50), # Dark gray
outline_color=None, outline_color=None,
outline=0.0) outline=0.0)
ui.append(background) ui.append(background)
print("✓ Added opaque background frame") print("✓ Added opaque background frame")
# Now add normal content on top # Now add normal content on top
print("\nAdding test content...") print("\nAdding test content...")
# Red frame # Red frame
frame1 = mcrfpy.Frame(100, 100, 200, 150, frame1 = mcrfpy.Frame(pos=(100, 100), size=(200, 150),
fill_color=mcrfpy.Color(255, 0, 0), fill_color=mcrfpy.Color(255, 0, 0),
outline_color=mcrfpy.Color(255, 255, 255), outline_color=mcrfpy.Color(255, 255, 255),
outline=3.0) outline=3.0)
ui.append(frame1) ui.append(frame1)
# Green frame # Green frame
frame2 = mcrfpy.Frame(350, 100, 200, 150, frame2 = mcrfpy.Frame(pos=(350, 100), size=(200, 150),
fill_color=mcrfpy.Color(0, 255, 0), fill_color=mcrfpy.Color(0, 255, 0),
outline_color=mcrfpy.Color(0, 0, 0), outline_color=mcrfpy.Color(0, 0, 0),
outline=3.0) outline=3.0)
ui.append(frame2) ui.append(frame2)
# Blue frame # Blue frame
frame3 = mcrfpy.Frame(100, 300, 200, 150, frame3 = mcrfpy.Frame(pos=(100, 300), size=(200, 150),
fill_color=mcrfpy.Color(0, 0, 255), fill_color=mcrfpy.Color(0, 0, 255),
outline_color=mcrfpy.Color(255, 255, 0), outline_color=mcrfpy.Color(255, 255, 0),
outline=3.0) outline=3.0)
ui.append(frame3) ui.append(frame3)
# Add text # Add text
caption = mcrfpy.Caption(mcrfpy.Vector(250, 50), caption = mcrfpy.Caption(pos=(250, 50),
text="OPAQUE BACKGROUND TEST", text="OPAQUE BACKGROUND TEST",
fill_color=mcrfpy.Color(255, 255, 255)) fill_color=mcrfpy.Color(255, 255, 255))
caption.size = 32 caption.font_size = 32
ui.append(caption) ui.append(caption)
# Take screenshot # Take screenshot

View file

@ -31,9 +31,9 @@ def take_screenshot(runtime):
mcrfpy.createScene("test") mcrfpy.createScene("test")
# Add a visible element # Add a visible element
caption = mcrfpy.Caption(100, 100, "Screenshot Test") caption = mcrfpy.Caption(pos=(100, 100), text="Screenshot Test")
caption.font = mcrfpy.default_font caption.font = mcrfpy.default_font
caption.font_color = (255, 255, 255) caption.fill_color = mcrfpy.Color(255, 255, 255)
caption.font_size = 24 caption.font_size = 24
mcrfpy.sceneUI("test").append(caption) mcrfpy.sceneUI("test").append(caption)

View file

@ -30,7 +30,7 @@ mcrfpy.setScene("test")
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
# Add visible content - a white frame on default background # Add visible content - a white frame on default background
frame = mcrfpy.Frame(100, 100, 200, 200, frame = mcrfpy.Frame(pos=(100, 100), size=(200, 200),
fill_color=mcrfpy.Color(255, 255, 255)) fill_color=mcrfpy.Color(255, 255, 255))
ui.append(frame) ui.append(frame)

View file

@ -73,6 +73,9 @@ mcrfpy.createScene("chain_test")
grid = mcrfpy.Grid(grid_x=20, grid_y=15) grid = mcrfpy.Grid(grid_x=20, grid_y=15)
grid.fill_color = mcrfpy.Color(20, 20, 30) grid.fill_color = mcrfpy.Color(20, 20, 30)
# Add a color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Simple map # Simple map
for y in range(15): for y in range(15):
for x in range(20): for x in range(20):
@ -80,17 +83,17 @@ for y in range(15):
if x == 0 or x == 19 or y == 0 or y == 14: if x == 0 or x == 19 or y == 0 or y == 14:
cell.walkable = False cell.walkable = False
cell.transparent = False cell.transparent = False
cell.color = mcrfpy.Color(60, 40, 40) color_layer.set(x, y, mcrfpy.Color(60, 40, 40))
else: else:
cell.walkable = True cell.walkable = True
cell.transparent = True cell.transparent = True
cell.color = mcrfpy.Color(100, 100, 120) color_layer.set(x, y, mcrfpy.Color(100, 100, 120))
# Create entities # Create entities
player = mcrfpy.Entity(2, 2, grid=grid) player = mcrfpy.Entity((2, 2), grid=grid)
player.sprite_index = 64 # @ player.sprite_index = 64 # @
enemy = mcrfpy.Entity(17, 12, grid=grid) enemy = mcrfpy.Entity((17, 12), grid=grid)
enemy.sprite_index = 69 # E enemy.sprite_index = 69 # E
# UI setup # UI setup
@ -99,15 +102,15 @@ ui.append(grid)
grid.position = (100, 100) grid.position = (100, 100)
grid.size = (600, 450) grid.size = (600, 450)
title = mcrfpy.Caption("Animation Chaining Test", 300, 20) title = mcrfpy.Caption(pos=(300, 20), text="Animation Chaining Test")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
status = mcrfpy.Caption("Press 1: Animate Player | 2: Animate Enemy | 3: Both | Q: Quit", 100, 50) status = mcrfpy.Caption(pos=(100, 50), text="Press 1: Animate Player | 2: Animate Enemy | 3: Both | Q: Quit")
status.fill_color = mcrfpy.Color(200, 200, 200) status.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(status) ui.append(status)
info = mcrfpy.Caption("Status: Ready", 100, 70) info = mcrfpy.Caption(pos=(100, 70), text="Status: Ready")
info.fill_color = mcrfpy.Color(100, 255, 100) info.fill_color = mcrfpy.Color(100, 255, 100)
ui.append(info) ui.append(info)

View file

@ -63,14 +63,15 @@ mcrfpy.createScene("anim_debug")
# Simple grid # Simple grid
grid = mcrfpy.Grid(grid_x=15, grid_y=10) grid = mcrfpy.Grid(grid_x=15, grid_y=10)
color_layer = grid.add_layer("color", z_index=-1)
for y in range(10): for y in range(10):
for x in range(15): for x in range(15):
cell = grid.at(x, y) cell = grid.at(x, y)
cell.walkable = True cell.walkable = True
cell.color = mcrfpy.Color(100, 100, 120) color_layer.set(x, y, mcrfpy.Color(100, 100, 120))
# Test entity # Test entity
entity = mcrfpy.Entity(5, 5, grid=grid) entity = mcrfpy.Entity((5, 5), grid=grid)
entity.sprite_index = 64 entity.sprite_index = 64
# UI # UI
@ -79,19 +80,19 @@ ui.append(grid)
grid.position = (100, 150) grid.position = (100, 150)
grid.size = (450, 300) grid.size = (450, 300)
title = mcrfpy.Caption("Animation Debug Tool", 250, 20) title = mcrfpy.Caption(pos=(250, 20), text="Animation Debug Tool")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
status = mcrfpy.Caption("Press keys to test animations", 100, 50) status = mcrfpy.Caption(pos=(100, 50), text="Press keys to test animations")
status.fill_color = mcrfpy.Color(200, 200, 200) status.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(status) ui.append(status)
pos_display = mcrfpy.Caption("", 100, 70) pos_display = mcrfpy.Caption(pos=(100, 70), text="")
pos_display.fill_color = mcrfpy.Color(255, 255, 100) pos_display.fill_color = mcrfpy.Color(255, 255, 100)
ui.append(pos_display) ui.append(pos_display)
active_display = mcrfpy.Caption("Active animations: 0", 100, 90) active_display = mcrfpy.Caption(pos=(100, 90), text="Active animations: 0")
active_display.fill_color = mcrfpy.Color(100, 255, 255) active_display.fill_color = mcrfpy.Color(100, 255, 255)
ui.append(active_display) ui.append(active_display)

View file

@ -13,7 +13,7 @@ print("2. Getting UI...")
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
print("3. Creating frame...") print("3. Creating frame...")
frame = mcrfpy.Frame(100, 100, 200, 200) frame = mcrfpy.Frame(pos=(100, 100), size=(200, 200))
ui.append(frame) ui.append(frame)
print("4. Creating Animation object...") print("4. Creating Animation object...")

View file

@ -30,7 +30,7 @@ def test_1_basic_animation():
"""Test that basic animations still work""" """Test that basic animations still work"""
try: try:
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
frame = mcrfpy.Frame(100, 100, 100, 100) frame = mcrfpy.Frame(pos=(100, 100), size=(100, 100))
ui.append(frame) ui.append(frame)
anim = mcrfpy.Animation("x", 200.0, 1000, "linear") anim = mcrfpy.Animation("x", 200.0, 1000, "linear")
@ -49,7 +49,7 @@ def test_2_remove_animated_object():
"""Test removing object with active animation""" """Test removing object with active animation"""
try: try:
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
frame = mcrfpy.Frame(100, 100, 100, 100) frame = mcrfpy.Frame(pos=(100, 100), size=(100, 100))
ui.append(frame) ui.append(frame)
# Start animation # Start animation
@ -73,7 +73,7 @@ def test_3_complete_animation():
"""Test completing animation immediately""" """Test completing animation immediately"""
try: try:
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
frame = mcrfpy.Frame(100, 100, 100, 100) frame = mcrfpy.Frame(pos=(100, 100), size=(100, 100))
ui.append(frame) ui.append(frame)
# Start animation # Start animation
@ -98,7 +98,7 @@ def test_4_multiple_animations_timer():
nonlocal success nonlocal success
try: try:
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
frame = mcrfpy.Frame(200, 200, 100, 100) frame = mcrfpy.Frame(pos=(200, 200), size=(100, 100))
ui.append(frame) ui.append(frame)
# Create multiple animations rapidly (this used to crash) # Create multiple animations rapidly (this used to crash)
@ -129,7 +129,7 @@ def test_5_scene_cleanup():
# Add animated objects to first scene # Add animated objects to first scene
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
for i in range(5): for i in range(5):
frame = mcrfpy.Frame(50 * i, 100, 40, 40) frame = mcrfpy.Frame(pos=(50 * i, 100), size=(40, 40))
ui.append(frame) ui.append(frame)
anim = mcrfpy.Animation("y", 300.0, 2000, "easeOutBounce") anim = mcrfpy.Animation("y", 300.0, 2000, "easeOutBounce")
anim.start(frame) anim.start(frame)
@ -148,9 +148,9 @@ def test_6_animation_after_clear():
"""Test animations after clearing UI""" """Test animations after clearing UI"""
try: try:
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
# Create and animate # Create and animate
frame = mcrfpy.Frame(100, 100, 100, 100) frame = mcrfpy.Frame(pos=(100, 100), size=(100, 100))
ui.append(frame) ui.append(frame)
anim = mcrfpy.Animation("w", 200.0, 1500, "easeInOutCubic") anim = mcrfpy.Animation("w", 200.0, 1500, "easeInOutCubic")
anim.start(frame) anim.start(frame)
@ -207,7 +207,7 @@ mcrfpy.setScene("test")
# Add a background # Add a background
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
bg = mcrfpy.Frame(0, 0, 1024, 768) bg = mcrfpy.Frame(pos=(0, 0), size=(1024, 768))
bg.fill_color = mcrfpy.Color(20, 20, 30) bg.fill_color = mcrfpy.Color(20, 20, 30)
ui.append(bg) ui.append(bg)

View file

@ -42,14 +42,14 @@ mcrfpy.setScene("test")
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
# Add title and subtitle (to preserve during clearing) # Add title and subtitle (to preserve during clearing)
title = mcrfpy.Caption("Test Title", 400, 20) title = mcrfpy.Caption(pos=(400, 20), text="Test Title")
subtitle = mcrfpy.Caption("Test Subtitle", 400, 50) subtitle = mcrfpy.Caption(pos=(400, 50), text="Test Subtitle")
ui.extend([title, subtitle]) ui.extend([title, subtitle])
# Create initial animated objects # Create initial animated objects
print("Creating initial animated objects...") print("Creating initial animated objects...")
for i in range(10): for i in range(10):
f = mcrfpy.Frame(50 + i*30, 100, 25, 25) f = mcrfpy.Frame(pos=(50 + i*30, 100), size=(25, 25))
f.fill_color = mcrfpy.Color(255, 100, 100) f.fill_color = mcrfpy.Color(255, 100, 100)
ui.append(f) ui.append(f)

View file

@ -17,10 +17,15 @@ import sys
def create_test_grid(): def create_test_grid():
"""Create a test grid with obstacles""" """Create a test grid with obstacles"""
mcrfpy.createScene("dijkstra_test") mcrfpy.createScene("dijkstra_test")
# Create grid # Create grid
grid = mcrfpy.Grid(grid_x=20, grid_y=20) grid = mcrfpy.Grid(grid_x=20, grid_y=20)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Store color_layer on grid for access elsewhere
grid._color_layer = color_layer
# Initialize all cells as walkable # Initialize all cells as walkable
for y in range(grid.grid_y): for y in range(grid.grid_y):
for x in range(grid.grid_x): for x in range(grid.grid_x):
@ -28,8 +33,8 @@ def create_test_grid():
cell.walkable = True cell.walkable = True
cell.transparent = True cell.transparent = True
cell.tilesprite = 46 # . period cell.tilesprite = 46 # . period
cell.color = mcrfpy.Color(50, 50, 50) color_layer.set(x, y, mcrfpy.Color(50, 50, 50))
# Create some walls to make pathfinding interesting # Create some walls to make pathfinding interesting
# Vertical wall # Vertical wall
for y in range(5, 15): for y in range(5, 15):
@ -37,8 +42,8 @@ def create_test_grid():
cell.walkable = False cell.walkable = False
cell.transparent = False cell.transparent = False
cell.tilesprite = 219 # Block cell.tilesprite = 219 # Block
cell.color = mcrfpy.Color(100, 100, 100) color_layer.set(10, y, mcrfpy.Color(100, 100, 100))
# Horizontal wall # Horizontal wall
for x in range(5, 15): for x in range(5, 15):
if x != 10: # Leave a gap if x != 10: # Leave a gap
@ -46,8 +51,8 @@ def create_test_grid():
cell.walkable = False cell.walkable = False
cell.transparent = False cell.transparent = False
cell.tilesprite = 219 cell.tilesprite = 219
cell.color = mcrfpy.Color(100, 100, 100) color_layer.set(x, 10, mcrfpy.Color(100, 100, 100))
return grid return grid
def test_basic_dijkstra(): def test_basic_dijkstra():
@ -133,7 +138,7 @@ def test_multi_target_scenario():
# Mark threat position # Mark threat position
cell = grid.at(tx, ty) cell = grid.at(tx, ty)
cell.tilesprite = 84 # T for threat cell.tilesprite = 84 # T for threat
cell.color = mcrfpy.Color(255, 0, 0) grid._color_layer.set(tx, ty, mcrfpy.Color(255, 0, 0))
# Compute Dijkstra from this threat # Compute Dijkstra from this threat
grid.compute_dijkstra(tx, ty) grid.compute_dijkstra(tx, ty)
@ -176,7 +181,7 @@ def test_multi_target_scenario():
# Mark safe position # Mark safe position
cell = grid.at(best_pos[0], best_pos[1]) cell = grid.at(best_pos[0], best_pos[1])
cell.tilesprite = 83 # S for safe cell.tilesprite = 83 # S for safe
cell.color = mcrfpy.Color(0, 255, 0) grid._color_layer.set(best_pos[0], best_pos[1], mcrfpy.Color(0, 255, 0))
def run_test(runtime): def run_test(runtime):
"""Timer callback to run tests after scene loads""" """Timer callback to run tests after scene loads"""
@ -211,7 +216,7 @@ ui = mcrfpy.sceneUI("dijkstra_test")
ui.append(grid) ui.append(grid)
# Add title # Add title
title = mcrfpy.Caption("Dijkstra Pathfinding Test", 10, 10) title = mcrfpy.Caption(pos=(10, 10), text="Dijkstra Pathfinding Test")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)

View file

@ -17,13 +17,16 @@ mcrfpy.createScene("test_anim")
grid = mcrfpy.Grid(grid_x=15, grid_y=15) grid = mcrfpy.Grid(grid_x=15, grid_y=15)
grid.fill_color = mcrfpy.Color(20, 20, 30) grid.fill_color = mcrfpy.Color(20, 20, 30)
# Add a color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Initialize all cells as walkable floors # Initialize all cells as walkable floors
for y in range(15): for y in range(15):
for x in range(15): for x in range(15):
cell = grid.at(x, y) cell = grid.at(x, y)
cell.walkable = True cell.walkable = True
cell.transparent = True cell.transparent = True
cell.color = mcrfpy.Color(100, 100, 120) color_layer.set(x, y, mcrfpy.Color(100, 100, 120))
# Mark the path we'll follow with different color # Mark the path we'll follow with different color
path_cells = [(5,5), (6,5), (7,5), (8,5), (9,5), (10,5), path_cells = [(5,5), (6,5), (7,5), (8,5), (9,5), (10,5),
@ -32,11 +35,10 @@ path_cells = [(5,5), (6,5), (7,5), (8,5), (9,5), (10,5),
(5,9), (5,8), (5,7), (5,6)] (5,9), (5,8), (5,7), (5,6)]
for x, y in path_cells: for x, y in path_cells:
cell = grid.at(x, y) color_layer.set(x, y, mcrfpy.Color(120, 120, 150))
cell.color = mcrfpy.Color(120, 120, 150)
# Create entity at start position # Create entity at start position
entity = mcrfpy.Entity(5, 5, grid=grid) entity = mcrfpy.Entity((5, 5), grid=grid)
entity.sprite_index = 64 # @ entity.sprite_index = 64 # @
# UI setup # UI setup
@ -46,27 +48,27 @@ grid.position = (100, 100)
grid.size = (450, 450) # 15 * 30 pixels per cell grid.size = (450, 450) # 15 * 30 pixels per cell
# Title # Title
title = mcrfpy.Caption("Entity Animation Test - Square Path", 200, 20) title = mcrfpy.Caption(pos=(200, 20), text="Entity Animation Test - Square Path")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
# Status display # Status display
status = mcrfpy.Caption("Press SPACE to start animation | Q to quit", 100, 50) status = mcrfpy.Caption(pos=(100, 50), text="Press SPACE to start animation | Q to quit")
status.fill_color = mcrfpy.Color(200, 200, 200) status.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(status) ui.append(status)
# Position display # Position display
pos_display = mcrfpy.Caption(f"Entity Position: ({entity.x:.2f}, {entity.y:.2f})", 100, 70) pos_display = mcrfpy.Caption(pos=(100, 70), text=f"Entity Position: ({entity.x:.2f}, {entity.y:.2f})")
pos_display.fill_color = mcrfpy.Color(255, 255, 100) pos_display.fill_color = mcrfpy.Color(255, 255, 100)
ui.append(pos_display) ui.append(pos_display)
# Animation info # Animation info
anim_info = mcrfpy.Caption("Animation: Not started", 400, 70) anim_info = mcrfpy.Caption(pos=(400, 70), text="Animation: Not started")
anim_info.fill_color = mcrfpy.Color(100, 255, 255) anim_info.fill_color = mcrfpy.Color(100, 255, 255)
ui.append(anim_info) ui.append(anim_info)
# Debug info # Debug info
debug_info = mcrfpy.Caption("Debug: Waiting...", 100, 570) debug_info = mcrfpy.Caption(pos=(100, 570), text="Debug: Waiting...")
debug_info.fill_color = mcrfpy.Color(150, 150, 150) debug_info.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(debug_info) ui.append(debug_info)

View file

@ -33,16 +33,19 @@ mcrfpy.createScene("fix_demo")
grid = mcrfpy.Grid(grid_x=15, grid_y=10) grid = mcrfpy.Grid(grid_x=15, grid_y=10)
grid.fill_color = mcrfpy.Color(20, 20, 30) grid.fill_color = mcrfpy.Color(20, 20, 30)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Make floor # Make floor
for y in range(10): for y in range(10):
for x in range(15): for x in range(15):
cell = grid.at(x, y) cell = grid.at(x, y)
cell.walkable = True cell.walkable = True
cell.transparent = True cell.transparent = True
cell.color = mcrfpy.Color(100, 100, 120) color_layer.set(x, y, mcrfpy.Color(100, 100, 120))
# Create entity # Create entity
entity = mcrfpy.Entity(2, 2, grid=grid) entity = mcrfpy.Entity((2, 2), grid=grid)
entity.sprite_index = 64 # @ entity.sprite_index = 64 # @
# UI # UI
@ -52,19 +55,19 @@ grid.position = (100, 150)
grid.size = (450, 300) grid.size = (450, 300)
# Info displays # Info displays
title = mcrfpy.Caption("Entity Animation Issue Demo", 250, 20) title = mcrfpy.Caption(pos=(250, 20), text="Entity Animation Issue Demo")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
pos_info = mcrfpy.Caption("", 100, 50) pos_info = mcrfpy.Caption(pos=(100, 50), text="")
pos_info.fill_color = mcrfpy.Color(255, 255, 100) pos_info.fill_color = mcrfpy.Color(255, 255, 100)
ui.append(pos_info) ui.append(pos_info)
sprite_info = mcrfpy.Caption("", 100, 70) sprite_info = mcrfpy.Caption(pos=(100, 70), text="")
sprite_info.fill_color = mcrfpy.Color(255, 100, 100) sprite_info.fill_color = mcrfpy.Color(255, 100, 100)
ui.append(sprite_info) ui.append(sprite_info)
status = mcrfpy.Caption("Press SPACE to animate entity", 100, 100) status = mcrfpy.Caption(pos=(100, 100), text="Press SPACE to animate entity")
status.fill_color = mcrfpy.Color(200, 200, 200) status.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(status) ui.append(status)

View file

@ -22,8 +22,7 @@ for x, y in walls:
grid.at(x, y).walkable = False grid.at(x, y).walkable = False
# Create entity # Create entity
entity = mcrfpy.Entity(2, 2) entity = mcrfpy.Entity((2, 2), grid=grid)
grid.entities.append(entity)
print(f"Entity at: ({entity.x}, {entity.y})") print(f"Entity at: ({entity.x}, {entity.y})")

View file

@ -9,7 +9,7 @@ print("=" * 50)
# Test 1: Entity without grid # Test 1: Entity without grid
print("Test 1: Entity not in grid") print("Test 1: Entity not in grid")
try: try:
entity = mcrfpy.Entity(5, 5) entity = mcrfpy.Entity((5, 5))
path = entity.path_to(8, 8) path = entity.path_to(8, 8)
print(" ✗ Should have failed for entity not in grid") print(" ✗ Should have failed for entity not in grid")
except ValueError as e: except ValueError as e:
@ -31,8 +31,7 @@ for y in range(5):
for x in range(5): for x in range(5):
grid.at(x, 2).walkable = False grid.at(x, 2).walkable = False
entity = mcrfpy.Entity(1, 1) entity = mcrfpy.Entity((1, 1), grid=grid)
grid.entities.append(entity)
try: try:
path = entity.path_to(1, 4) path = entity.path_to(1, 4)

View file

@ -13,32 +13,28 @@ def test_grid_background():
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
# Create a grid with default background # Create a grid with default background
grid = mcrfpy.Grid(20, 15, grid_size=(20, 15)) grid = mcrfpy.Grid(pos=(50, 50), size=(400, 300), grid_size=(20, 15))
grid.x = 50
grid.y = 50
grid.w = 400
grid.h = 300
ui.append(grid) ui.append(grid)
# Add some tiles to see the background better # Add color layer for some tiles to see the background better
color_layer = grid.add_layer("color", z_index=-1)
for x in range(5, 15): for x in range(5, 15):
for y in range(5, 10): for y in range(5, 10):
point = grid.at(x, y) color_layer.set(x, y, mcrfpy.Color(100, 150, 100))
point.color = mcrfpy.Color(100, 150, 100)
# Add UI to show current background color # Add UI to show current background color
info_frame = mcrfpy.Frame(500, 50, 200, 150, info_frame = mcrfpy.Frame(pos=(500, 50), size=(200, 150),
fill_color=mcrfpy.Color(40, 40, 40), fill_color=mcrfpy.Color(40, 40, 40),
outline_color=mcrfpy.Color(200, 200, 200), outline_color=mcrfpy.Color(200, 200, 200),
outline=2) outline=2)
ui.append(info_frame) ui.append(info_frame)
color_caption = mcrfpy.Caption(510, 60, "Background Color:") color_caption = mcrfpy.Caption(pos=(510, 60), text="Background Color:")
color_caption.font_size = 14 color_caption.font_size = 14
color_caption.fill_color = mcrfpy.Color(255, 255, 255) color_caption.fill_color = mcrfpy.Color(255, 255, 255)
info_frame.children.append(color_caption) info_frame.children.append(color_caption)
color_display = mcrfpy.Caption(510, 80, "") color_display = mcrfpy.Caption(pos=(510, 80), text="")
color_display.font_size = 12 color_display.font_size = 12
color_display.fill_color = mcrfpy.Color(200, 200, 200) color_display.fill_color = mcrfpy.Color(200, 200, 200)
info_frame.children.append(color_display) info_frame.children.append(color_display)

View file

@ -11,8 +11,8 @@ ui = mcrfpy.sceneUI("detect_test")
mcrfpy.setScene("detect_test") mcrfpy.setScene("detect_test")
# Create a frame # Create a frame
frame = mcrfpy.Frame(100, 100, 200, 200) frame = mcrfpy.Frame(pos=(100, 100), size=(200, 200))
frame.fill_color = (255, 100, 100, 255) frame.fill_color = mcrfpy.Color(255, 100, 100, 255)
ui.append(frame) ui.append(frame)
def test_mode(runtime): def test_mode(runtime):

View file

@ -10,13 +10,13 @@ ui = mcrfpy.sceneUI("headless_test")
mcrfpy.setScene("headless_test") mcrfpy.setScene("headless_test")
# Create a visible indicator # Create a visible indicator
frame = mcrfpy.Frame(200, 200, 400, 200) frame = mcrfpy.Frame(pos=(200, 200), size=(400, 200))
frame.fill_color = (100, 200, 100, 255) frame.fill_color = mcrfpy.Color(100, 200, 100, 255)
ui.append(frame) ui.append(frame)
caption = mcrfpy.Caption((400, 300), "If you see this, windowed mode is working!", mcrfpy.default_font) caption = mcrfpy.Caption(pos=(400, 300), text="If you see this, windowed mode is working!")
caption.size = 24 caption.font_size = 24
caption.fill_color = (255, 255, 255) caption.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(caption) ui.append(caption)
print("Script started. Window should appear unless --headless was specified.") print("Script started. Window should appear unless --headless was specified.")

View file

@ -115,18 +115,18 @@ mcrfpy.setScene("metrics_test")
ui = mcrfpy.sceneUI("metrics_test") ui = mcrfpy.sceneUI("metrics_test")
# Create various UI elements # Create various UI elements
frame1 = mcrfpy.Frame(10, 10, 200, 150) frame1 = mcrfpy.Frame(pos=(10, 10), size=(200, 150))
frame1.fill_color = (100, 100, 100, 128) frame1.fill_color = mcrfpy.Color(100, 100, 100, 128)
ui.append(frame1) ui.append(frame1)
caption1 = mcrfpy.Caption("Test Caption", 50, 50) caption1 = mcrfpy.Caption(pos=(50, 50), text="Test Caption")
ui.append(caption1) ui.append(caption1)
sprite1 = mcrfpy.Sprite(100, 100) sprite1 = mcrfpy.Sprite(pos=(100, 100))
ui.append(sprite1) ui.append(sprite1)
# Invisible element (should not count as visible) # Invisible element (should not count as visible)
frame2 = mcrfpy.Frame(300, 10, 100, 100) frame2 = mcrfpy.Frame(pos=(300, 10), size=(100, 100))
frame2.visible = False frame2.visible = False
ui.append(frame2) ui.append(frame2)

View file

@ -11,17 +11,20 @@ print("=" * 50)
mcrfpy.createScene("test") mcrfpy.createScene("test")
grid = mcrfpy.Grid(grid_x=5, grid_y=5) grid = mcrfpy.Grid(grid_x=5, grid_y=5)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Initialize # Initialize
for y in range(5): for y in range(5):
for x in range(5): for x in range(5):
grid.at(x, y).walkable = True grid.at(x, y).walkable = True
grid.at(x, y).color = mcrfpy.Color(200, 200, 200) # Light gray color_layer.set(x, y, mcrfpy.Color(200, 200, 200)) # Light gray
# Add entities # Add entities
e1 = mcrfpy.Entity(0, 0) e1 = mcrfpy.Entity((0, 0), grid=grid)
e2 = mcrfpy.Entity(4, 4) e2 = mcrfpy.Entity((4, 4), grid=grid)
grid.entities.append(e1) e1.sprite_index = 64
grid.entities.append(e2) e2.sprite_index = 69
print(f"Entity 1 at ({e1.x}, {e1.y})") print(f"Entity 1 at ({e1.x}, {e1.y})")
print(f"Entity 2 at ({e2.x}, {e2.y})") print(f"Entity 2 at ({e2.x}, {e2.y})")
@ -35,24 +38,25 @@ PATH_COLOR = mcrfpy.Color(100, 255, 100) # Green
print(f"\nSetting path cells to green ({PATH_COLOR.r}, {PATH_COLOR.g}, {PATH_COLOR.b})...") print(f"\nSetting path cells to green ({PATH_COLOR.r}, {PATH_COLOR.g}, {PATH_COLOR.b})...")
for x, y in path: for x, y in path:
cell = grid.at(x, y)
# Check before # Check before
before = cell.color[:3] # Get RGB from tuple before_c = color_layer.at(x, y)
before = (before_c.r, before_c.g, before_c.b)
# Set color # Set color
cell.color = PATH_COLOR color_layer.set(x, y, PATH_COLOR)
# Check after # Check after
after = cell.color[:3] # Get RGB from tuple after_c = color_layer.at(x, y)
after = (after_c.r, after_c.g, after_c.b)
print(f" Cell ({x},{y}): {before} -> {after}") print(f" Cell ({x},{y}): {before} -> {after}")
# Verify all path cells # Verify all path cells
print("\nVerifying all cells in grid:") print("\nVerifying all cells in grid:")
for y in range(5): for y in range(5):
for x in range(5): for x in range(5):
cell = grid.at(x, y) c = color_layer.at(x, y)
color = cell.color[:3] # Get RGB from tuple color = (c.r, c.g, c.b)
is_path = (x, y) in path is_path = (x, y) in path
print(f" ({x},{y}): color={color}, in_path={is_path}") print(f" ({x},{y}): color={color}, in_path={is_path}")

View file

@ -21,10 +21,8 @@ for i in range(5):
grid.at(5, i + 2).walkable = False grid.at(5, i + 2).walkable = False
# Create entities # Create entities
e1 = mcrfpy.Entity(2, 5) e1 = mcrfpy.Entity((2, 5), grid=grid)
e2 = mcrfpy.Entity(8, 5) e2 = mcrfpy.Entity((8, 5), grid=grid)
grid.entities.append(e1)
grid.entities.append(e2)
# Test pathfinding between entities # Test pathfinding between entities
print(f"Entity 1 at ({e1.x}, {e1.y})") print(f"Entity 1 at ({e1.x}, {e1.y})")

View file

@ -10,7 +10,7 @@ def test_properties(runtime):
# Test Frame # Test Frame
try: try:
frame = mcrfpy.Frame(10, 10, 100, 100) frame = mcrfpy.Frame(pos=(10, 10), size=(100, 100))
print(f"Frame visible: {frame.visible}") print(f"Frame visible: {frame.visible}")
frame.visible = False frame.visible = False
print(f"Frame visible after setting to False: {frame.visible}") print(f"Frame visible after setting to False: {frame.visible}")

View file

@ -11,51 +11,51 @@ def create_test_scenes():
# Scene 1: Red background # Scene 1: Red background
mcrfpy.createScene("red_scene") mcrfpy.createScene("red_scene")
ui1 = mcrfpy.sceneUI("red_scene") ui1 = mcrfpy.sceneUI("red_scene")
bg1 = mcrfpy.Frame(0, 0, 1024, 768, fill_color=mcrfpy.Color(255, 0, 0, 255)) bg1 = mcrfpy.Frame(pos=(0, 0), size=(1024, 768), fill_color=mcrfpy.Color(255, 0, 0, 255))
label1 = mcrfpy.Caption(512, 384, "RED SCENE", font=mcrfpy.Font.font_ui) label1 = mcrfpy.Caption(pos=(512, 384), text="RED SCENE", font=mcrfpy.Font.font_ui)
label1.color = mcrfpy.Color(255, 255, 255, 255) label1.fill_color = mcrfpy.Color(255, 255, 255, 255)
ui1.append(bg1) ui1.append(bg1)
ui1.append(label1) ui1.append(label1)
# Scene 2: Blue background # Scene 2: Blue background
mcrfpy.createScene("blue_scene") mcrfpy.createScene("blue_scene")
ui2 = mcrfpy.sceneUI("blue_scene") ui2 = mcrfpy.sceneUI("blue_scene")
bg2 = mcrfpy.Frame(0, 0, 1024, 768, fill_color=mcrfpy.Color(0, 0, 255, 255)) bg2 = mcrfpy.Frame(pos=(0, 0), size=(1024, 768), fill_color=mcrfpy.Color(0, 0, 255, 255))
label2 = mcrfpy.Caption(512, 384, "BLUE SCENE", font=mcrfpy.Font.font_ui) label2 = mcrfpy.Caption(pos=(512, 384), text="BLUE SCENE", font=mcrfpy.Font.font_ui)
label2.color = mcrfpy.Color(255, 255, 255, 255) label2.fill_color = mcrfpy.Color(255, 255, 255, 255)
ui2.append(bg2) ui2.append(bg2)
ui2.append(label2) ui2.append(label2)
# Scene 3: Green background # Scene 3: Green background
mcrfpy.createScene("green_scene") mcrfpy.createScene("green_scene")
ui3 = mcrfpy.sceneUI("green_scene") ui3 = mcrfpy.sceneUI("green_scene")
bg3 = mcrfpy.Frame(0, 0, 1024, 768, fill_color=mcrfpy.Color(0, 255, 0, 255)) bg3 = mcrfpy.Frame(pos=(0, 0), size=(1024, 768), fill_color=mcrfpy.Color(0, 255, 0, 255))
label3 = mcrfpy.Caption(512, 384, "GREEN SCENE", font=mcrfpy.Font.font_ui) label3 = mcrfpy.Caption(pos=(512, 384), text="GREEN SCENE", font=mcrfpy.Font.font_ui)
label3.color = mcrfpy.Color(0, 0, 0, 255) # Black text on green label3.fill_color = mcrfpy.Color(0, 0, 0, 255) # Black text on green
ui3.append(bg3) ui3.append(bg3)
ui3.append(label3) ui3.append(label3)
# Scene 4: Menu scene with buttons # Scene 4: Menu scene with buttons
mcrfpy.createScene("menu_scene") mcrfpy.createScene("menu_scene")
ui4 = mcrfpy.sceneUI("menu_scene") ui4 = mcrfpy.sceneUI("menu_scene")
bg4 = mcrfpy.Frame(0, 0, 1024, 768, fill_color=mcrfpy.Color(50, 50, 50, 255)) bg4 = mcrfpy.Frame(pos=(0, 0), size=(1024, 768), fill_color=mcrfpy.Color(50, 50, 50, 255))
title = mcrfpy.Caption(512, 100, "SCENE TRANSITION DEMO", font=mcrfpy.Font.font_ui) title = mcrfpy.Caption(pos=(512, 100), text="SCENE TRANSITION DEMO", font=mcrfpy.Font.font_ui)
title.color = mcrfpy.Color(255, 255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255, 255)
ui4.append(bg4) ui4.append(bg4)
ui4.append(title) ui4.append(title)
# Add instruction text # Add instruction text
instructions = mcrfpy.Caption(512, 200, "Press keys 1-6 for different transitions", font=mcrfpy.Font.font_ui) instructions = mcrfpy.Caption(pos=(512, 200), text="Press keys 1-6 for different transitions", font=mcrfpy.Font.font_ui)
instructions.color = mcrfpy.Color(200, 200, 200, 255) instructions.fill_color = mcrfpy.Color(200, 200, 200, 255)
ui4.append(instructions) ui4.append(instructions)
controls = mcrfpy.Caption(512, 250, "1: Fade | 2: Slide Left | 3: Slide Right | 4: Slide Up | 5: Slide Down | 6: Instant", font=mcrfpy.Font.font_ui) controls = mcrfpy.Caption(pos=(512, 250), text="1: Fade | 2: Slide Left | 3: Slide Right | 4: Slide Up | 5: Slide Down | 6: Instant", font=mcrfpy.Font.font_ui)
controls.color = mcrfpy.Color(150, 150, 150, 255) controls.fill_color = mcrfpy.Color(150, 150, 150, 255)
ui4.append(controls) ui4.append(controls)
scene_info = mcrfpy.Caption(512, 300, "R: Red Scene | B: Blue Scene | G: Green Scene | M: Menu", font=mcrfpy.Font.font_ui) scene_info = mcrfpy.Caption(pos=(512, 300), text="R: Red Scene | B: Blue Scene | G: Green Scene | M: Menu", font=mcrfpy.Font.font_ui)
scene_info.color = mcrfpy.Color(150, 150, 150, 255) scene_info.fill_color = mcrfpy.Color(150, 150, 150, 255)
ui4.append(scene_info) ui4.append(scene_info)
print("Created test scenes: red_scene, blue_scene, green_scene, menu_scene") print("Created test scenes: red_scene, blue_scene, green_scene, menu_scene")

View file

@ -13,13 +13,13 @@ def test_scene_transitions():
# Scene 1 # Scene 1
mcrfpy.createScene("scene1") mcrfpy.createScene("scene1")
ui1 = mcrfpy.sceneUI("scene1") ui1 = mcrfpy.sceneUI("scene1")
frame1 = mcrfpy.Frame(0, 0, 100, 100, fill_color=mcrfpy.Color(255, 0, 0)) frame1 = mcrfpy.Frame(pos=(0, 0), size=(100, 100), fill_color=mcrfpy.Color(255, 0, 0))
ui1.append(frame1) ui1.append(frame1)
# Scene 2 # Scene 2
mcrfpy.createScene("scene2") mcrfpy.createScene("scene2")
ui2 = mcrfpy.sceneUI("scene2") ui2 = mcrfpy.sceneUI("scene2")
frame2 = mcrfpy.Frame(0, 0, 100, 100, fill_color=mcrfpy.Color(0, 0, 255)) frame2 = mcrfpy.Frame(pos=(0, 0), size=(100, 100), fill_color=mcrfpy.Color(0, 0, 255))
ui2.append(frame2) ui2.append(frame2)
# Test each transition type # Test each transition type

View file

@ -8,7 +8,7 @@ def simple_test(runtime):
try: try:
# Test basic functionality # Test basic functionality
frame = mcrfpy.Frame(10, 10, 100, 100) frame = mcrfpy.Frame(pos=(10, 10), size=(100, 100))
print(f"Frame created: visible={frame.visible}, opacity={frame.opacity}") print(f"Frame created: visible={frame.visible}, opacity={frame.opacity}")
bounds = frame.get_bounds() bounds = frame.get_bounds()

View file

@ -18,13 +18,13 @@ def create_demo():
scene = mcrfpy.sceneUI("text_demo") scene = mcrfpy.sceneUI("text_demo")
# Background # Background
bg = mcrfpy.Frame(0, 0, 800, 600) bg = mcrfpy.Frame(pos=(0, 0), size=(800, 600))
bg.fill_color = (40, 40, 40, 255) bg.fill_color = mcrfpy.Color(40, 40, 40, 255)
scene.append(bg) scene.append(bg)
# Title # Title
title = mcrfpy.Caption("Text Input Widget Demo", 20, 20) title = mcrfpy.Caption(pos=(20, 20), text="Text Input Widget Demo")
title.fill_color = (255, 255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255, 255)
scene.append(title) scene.append(title)
# Focus manager # Focus manager
@ -62,8 +62,8 @@ def create_demo():
inputs.append(comment_input) inputs.append(comment_input)
# Status display # Status display
status = mcrfpy.Caption("Ready for input...", 50, 360) status = mcrfpy.Caption(pos=(50, 360), text="Ready for input...")
status.fill_color = (150, 255, 150, 255) status.fill_color = mcrfpy.Color(150, 255, 150, 255)
scene.append(status) scene.append(status)
# Update handler # Update handler

View file

@ -69,11 +69,11 @@ def main():
mcrfpy.setScene("test") mcrfpy.setScene("test")
# Create multiple captions for testing # Create multiple captions for testing
caption1 = mcrfpy.Caption(50, 50, "Caption 1: Normal", fill_color=(255, 255, 255)) caption1 = mcrfpy.Caption(pos=(50, 50), text="Caption 1: Normal", fill_color=mcrfpy.Color(255, 255, 255))
caption2 = mcrfpy.Caption(50, 100, "Caption 2: Will be invisible", fill_color=(255, 200, 200)) caption2 = mcrfpy.Caption(pos=(50, 100), text="Caption 2: Will be invisible", fill_color=mcrfpy.Color(255, 200, 200))
caption3 = mcrfpy.Caption(50, 150, "Caption 3: 50% opacity", fill_color=(200, 255, 200)) caption3 = mcrfpy.Caption(pos=(50, 150), text="Caption 3: 50% opacity", fill_color=mcrfpy.Color(200, 255, 200))
caption4 = mcrfpy.Caption(50, 200, "Caption 4: 25% opacity", fill_color=(200, 200, 255)) caption4 = mcrfpy.Caption(pos=(50, 200), text="Caption 4: 25% opacity", fill_color=mcrfpy.Color(200, 200, 255))
caption5 = mcrfpy.Caption(50, 250, "Caption 5: 0% opacity", fill_color=(255, 255, 200)) caption5 = mcrfpy.Caption(pos=(50, 250), text="Caption 5: 0% opacity", fill_color=mcrfpy.Color(255, 255, 200))
# Add captions to scene # Add captions to scene
ui = mcrfpy.sceneUI("test") ui = mcrfpy.sceneUI("test")
@ -84,7 +84,7 @@ def main():
ui.append(caption5) ui.append(caption5)
# Also add a frame as background to see transparency better # Also add a frame as background to see transparency better
frame = mcrfpy.Frame(40, 40, 400, 250, fill_color=(50, 50, 50)) frame = mcrfpy.Frame(pos=(40, 40), size=(400, 250), fill_color=mcrfpy.Color(50, 50, 50))
frame.z_index = -1 # Put it behind the captions frame.z_index = -1 # Put it behind the captions
ui.append(frame) ui.append(frame)

View file

@ -18,6 +18,9 @@ mcrfpy.createScene("visibility_test")
grid = mcrfpy.Grid(grid_x=20, grid_y=15) grid = mcrfpy.Grid(grid_x=20, grid_y=15)
grid.fill_color = mcrfpy.Color(20, 20, 30) # Dark background grid.fill_color = mcrfpy.Color(20, 20, 30) # Dark background
# Add a color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
# Initialize grid - all walkable and transparent # Initialize grid - all walkable and transparent
print("\nInitializing 20x15 grid...") print("\nInitializing 20x15 grid...")
for y in range(15): for y in range(15):
@ -25,7 +28,7 @@ for y in range(15):
cell = grid.at(x, y) cell = grid.at(x, y)
cell.walkable = True cell.walkable = True
cell.transparent = True cell.transparent = True
cell.color = mcrfpy.Color(100, 100, 120) # Floor color color_layer.set(x, y, mcrfpy.Color(100, 100, 120)) # Floor color
# Create some walls to block vision # Create some walls to block vision
print("Adding walls...") print("Adding walls...")
@ -47,14 +50,14 @@ for wall_group in walls:
cell = grid.at(x, y) cell = grid.at(x, y)
cell.walkable = False cell.walkable = False
cell.transparent = False cell.transparent = False
cell.color = mcrfpy.Color(40, 20, 20) # Wall color color_layer.set(x, y, mcrfpy.Color(40, 20, 20)) # Wall color
# Create entities # Create entities
print("\nCreating entities...") print("\nCreating entities...")
entities = [ entities = [
mcrfpy.Entity(2, 7), # Left side mcrfpy.Entity((2, 7)), # Left side
mcrfpy.Entity(18, 7), # Right side mcrfpy.Entity((18, 7)), # Right side
mcrfpy.Entity(10, 1), # Top center (above wall) mcrfpy.Entity((10, 1)), # Top center (above wall)
] ]
for i, entity in enumerate(entities): for i, entity in enumerate(entities):
@ -138,17 +141,17 @@ grid.position = (50, 50)
grid.size = (600, 450) # 20*30, 15*30 grid.size = (600, 450) # 20*30, 15*30
# Add title # Add title
title = mcrfpy.Caption("Knowledge Stubs 1 - Visibility Test", 200, 10) title = mcrfpy.Caption(pos=(200, 10), text="Knowledge Stubs 1 - Visibility Test")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)
# Add info # Add info
info = mcrfpy.Caption("Perspective: -1 (omniscient)", 50, 520) info = mcrfpy.Caption(pos=(50, 520), text="Perspective: -1 (omniscient)")
info.fill_color = mcrfpy.Color(200, 200, 200) info.fill_color = mcrfpy.Color(200, 200, 200)
ui.append(info) ui.append(info)
# Add legend # Add legend
legend = mcrfpy.Caption("Black=Never seen, Dark gray=Discovered, Normal=Visible", 50, 540) legend = mcrfpy.Caption(pos=(50, 540), text="Black=Never seen, Dark gray=Discovered, Normal=Visible")
legend.fill_color = mcrfpy.Color(150, 150, 150) legend.fill_color = mcrfpy.Color(150, 150, 150)
ui.append(legend) ui.append(legend)

View file

@ -4,28 +4,10 @@
import mcrfpy import mcrfpy
import sys import sys
# Colors as tuples (r, g, b, a) # Colors
WALL_COLOR = (60, 30, 30, 255) WALL_COLOR = mcrfpy.Color(60, 30, 30)
FLOOR_COLOR = (200, 200, 220, 255) FLOOR_COLOR = mcrfpy.Color(200, 200, 220)
PATH_COLOR = (100, 255, 100, 255) PATH_COLOR = mcrfpy.Color(100, 255, 100)
def check_render(dt):
"""Timer callback to verify rendering"""
print(f"\nTimer fired after {dt}ms")
# Take screenshot
from mcrfpy import automation
automation.screenshot("visual_path_test.png")
print("Screenshot saved as visual_path_test.png")
# Sample some path cells to verify colors
print("\nSampling path cell colors from grid:")
for x, y in [(1, 1), (2, 2), (3, 3)]:
cell = grid.at(x, y)
color = cell.color
print(f" Cell ({x},{y}): color={color[:3]}")
sys.exit(0)
# Create scene # Create scene
mcrfpy.createScene("visual_test") mcrfpy.createScene("visual_test")
@ -34,20 +16,38 @@ mcrfpy.createScene("visual_test")
grid = mcrfpy.Grid(grid_x=5, grid_y=5) grid = mcrfpy.Grid(grid_x=5, grid_y=5)
grid.fill_color = mcrfpy.Color(0, 0, 0) grid.fill_color = mcrfpy.Color(0, 0, 0)
# Add color layer for cell coloring
color_layer = grid.add_layer("color", z_index=-1)
def check_render(dt):
"""Timer callback to verify rendering"""
print(f"\nTimer fired after {dt}ms")
# Take screenshot
from mcrfpy import automation
automation.screenshot("visual_path_test.png")
print("Screenshot saved as visual_path_test.png")
# Sample some path cells to verify colors
print("\nSampling path cell colors from grid:")
for x, y in [(1, 1), (2, 2), (3, 3)]:
color = color_layer.at(x, y)
print(f" Cell ({x},{y}): color=({color.r}, {color.g}, {color.b})")
sys.exit(0)
# Initialize all cells as floor # Initialize all cells as floor
print("Initializing grid...") print("Initializing grid...")
for y in range(5): for y in range(5):
for x in range(5): for x in range(5):
grid.at(x, y).walkable = True grid.at(x, y).walkable = True
grid.at(x, y).color = FLOOR_COLOR color_layer.set(x, y, FLOOR_COLOR)
# Create entities # Create entities
e1 = mcrfpy.Entity(0, 0) e1 = mcrfpy.Entity((0, 0), grid=grid)
e2 = mcrfpy.Entity(4, 4) e2 = mcrfpy.Entity((4, 4), grid=grid)
e1.sprite_index = 64 # @ e1.sprite_index = 64 # @
e2.sprite_index = 69 # E e2.sprite_index = 69 # E
grid.entities.append(e1)
grid.entities.append(e2)
print(f"Entity 1 at ({e1.x}, {e1.y})") print(f"Entity 1 at ({e1.x}, {e1.y})")
print(f"Entity 2 at ({e2.x}, {e2.y})") print(f"Entity 2 at ({e2.x}, {e2.y})")
@ -60,7 +60,7 @@ print(f"\nPath from E1 to E2: {path}")
if path: if path:
print("\nColoring path cells green...") print("\nColoring path cells green...")
for x, y in path: for x, y in path:
grid.at(x, y).color = PATH_COLOR color_layer.set(x, y, PATH_COLOR)
print(f" Set ({x},{y}) to green") print(f" Set ({x},{y}) to green")
# Set up UI # Set up UI
@ -70,7 +70,7 @@ grid.position = (50, 50)
grid.size = (250, 250) grid.size = (250, 250)
# Add title # Add title
title = mcrfpy.Caption("Path Visualization Test", 50, 10) title = mcrfpy.Caption(pos=(50, 10), text="Path Visualization Test")
title.fill_color = mcrfpy.Color(255, 255, 255) title.fill_color = mcrfpy.Color(255, 255, 255)
ui.append(title) ui.append(title)

View file

@ -16,11 +16,11 @@ def test_issue_38_children():
print("\nTest 1: Passing children argument to Frame constructor") print("\nTest 1: Passing children argument to Frame constructor")
try: try:
# Create some child elements # Create some child elements
child1 = mcrfpy.Caption(mcrfpy.Vector(10, 10), text="Child 1") child1 = mcrfpy.Caption(pos=(10, 10), text="Child 1")
child2 = mcrfpy.Sprite(mcrfpy.Vector(10, 30)) child2 = mcrfpy.Sprite(pos=(10, 30))
# Try to create frame with children argument # Try to create frame with children argument
frame = mcrfpy.Frame(10, 10, 200, 150, children=[child1, child2]) frame = mcrfpy.Frame(pos=(10, 10), size=(200, 150), children=[child1, child2])
print("✗ UNEXPECTED: Frame accepted children argument (should fail per issue #38)") print("✗ UNEXPECTED: Frame accepted children argument (should fail per issue #38)")
except TypeError as e: except TypeError as e:
print(f"✓ EXPECTED: Frame constructor rejected children argument: {e}") print(f"✓ EXPECTED: Frame constructor rejected children argument: {e}")
@ -30,12 +30,12 @@ def test_issue_38_children():
# Test 2: Verify children can be added after creation # Test 2: Verify children can be added after creation
print("\nTest 2: Adding children after Frame creation") print("\nTest 2: Adding children after Frame creation")
try: try:
frame = mcrfpy.Frame(10, 10, 200, 150) frame = mcrfpy.Frame(pos=(10, 10), size=(200, 150))
ui.append(frame) ui.append(frame)
# Add children via the children collection # Add children via the children collection
child1 = mcrfpy.Caption(mcrfpy.Vector(10, 10), text="Added Child 1") child1 = mcrfpy.Caption(pos=(10, 10), text="Added Child 1")
child2 = mcrfpy.Caption(mcrfpy.Vector(10, 30), text="Added Child 2") child2 = mcrfpy.Caption(pos=(10, 30), text="Added Child 2")
frame.children.append(child1) frame.children.append(child1)
frame.children.append(child2) frame.children.append(child2)
@ -65,33 +65,33 @@ def test_issue_42_click_callback():
return True return True
try: try:
frame1 = mcrfpy.Frame(10, 10, 200, 150) frame1 = mcrfpy.Frame(pos=(10, 10), size=(200, 150))
ui.append(frame1) ui.append(frame1)
frame1.on_click = correct_callback frame1.on_click = correct_callback
print("✓ Click callback with correct signature assigned successfully") print("✓ Click callback with correct signature assigned successfully")
except Exception as e: except Exception as e:
print(f"✗ Failed to assign correct callback: {type(e).__name__}: {e}") print(f"✗ Failed to assign correct callback: {type(e).__name__}: {e}")
# Test 2: Callback with wrong signature (no args) # Test 2: Callback with wrong signature (no args)
print("\nTest 2: Click callback with no arguments") print("\nTest 2: Click callback with no arguments")
def wrong_callback_no_args(): def wrong_callback_no_args():
print(" Wrong callback called") print(" Wrong callback called")
try: try:
frame2 = mcrfpy.Frame(220, 10, 200, 150) frame2 = mcrfpy.Frame(pos=(220, 10), size=(200, 150))
ui.append(frame2) ui.append(frame2)
frame2.on_click = wrong_callback_no_args frame2.on_click = wrong_callback_no_args
print("✓ Click callback with no args assigned (will fail at runtime per issue #42)") print("✓ Click callback with no args assigned (will fail at runtime per issue #42)")
except Exception as e: except Exception as e:
print(f"✗ Failed to assign callback: {type(e).__name__}: {e}") print(f"✗ Failed to assign callback: {type(e).__name__}: {e}")
# Test 3: Callback with wrong signature (too few args) # Test 3: Callback with wrong signature (too few args)
print("\nTest 3: Click callback with too few arguments") print("\nTest 3: Click callback with too few arguments")
def wrong_callback_few_args(x, y): def wrong_callback_few_args(x, y):
print(f" Wrong callback called: x={x}, y={y}") print(f" Wrong callback called: x={x}, y={y}")
try: try:
frame3 = mcrfpy.Frame(10, 170, 200, 150) frame3 = mcrfpy.Frame(pos=(10, 170), size=(200, 150))
ui.append(frame3) ui.append(frame3)
frame3.on_click = wrong_callback_few_args frame3.on_click = wrong_callback_few_args
print("✓ Click callback with 2 args assigned (will fail at runtime per issue #42)") print("✓ Click callback with 2 args assigned (will fail at runtime per issue #42)")

View file

@ -7,24 +7,24 @@ import sys
def test_grid_none_texture(runtime): def test_grid_none_texture(runtime):
"""Test Grid functionality without texture""" """Test Grid functionality without texture"""
print("\n=== Testing Grid with None texture ===") print("\n=== Testing Grid with None texture ===")
# Test 1: Create Grid with None texture # Test 1: Create Grid with None texture
try: try:
grid = mcrfpy.Grid(10, 10, None, mcrfpy.Vector(50, 50), mcrfpy.Vector(400, 400)) grid = mcrfpy.Grid(grid_size=(10, 10), pos=(50, 50), size=(400, 400))
print("✓ Grid created successfully with None texture") print("✓ Grid created successfully with None texture")
except Exception as e: except Exception as e:
print(f"✗ Failed to create Grid with None texture: {e}") print(f"✗ Failed to create Grid with None texture: {e}")
sys.exit(1) sys.exit(1)
# Add to UI # Add to UI
ui = mcrfpy.sceneUI("grid_none_test") ui = mcrfpy.sceneUI("grid_none_test")
ui.append(grid) ui.append(grid)
# Test 2: Verify grid properties # Test 2: Verify grid properties
try: try:
grid_size = grid.grid_size grid_size = grid.grid_size
print(f"✓ Grid size: {grid_size}") print(f"✓ Grid size: {grid_size}")
# Check texture property # Check texture property
texture = grid.texture texture = grid.texture
if texture is None: if texture is None:
@ -33,39 +33,41 @@ def test_grid_none_texture(runtime):
print(f"✗ Grid texture should be None, got: {texture}") print(f"✗ Grid texture should be None, got: {texture}")
except Exception as e: except Exception as e:
print(f"✗ Property access failed: {e}") print(f"✗ Property access failed: {e}")
# Test 3: Access grid points and set colors # Test 3: Access grid points using ColorLayer (new API)
# Note: GridPoint no longer has .color - must use ColorLayer system
try: try:
# Add a color layer to the grid
color_layer = grid.add_layer("color", z_index=-1)
# Create a checkerboard pattern with colors # Create a checkerboard pattern with colors
for x in range(10): for x in range(10):
for y in range(10): for y in range(10):
point = grid.at(x, y)
if (x + y) % 2 == 0: if (x + y) % 2 == 0:
point.color = mcrfpy.Color(255, 0, 0, 255) # Red color_layer.set(x, y, mcrfpy.Color(255, 0, 0, 255)) # Red
else: else:
point.color = mcrfpy.Color(0, 0, 255, 255) # Blue color_layer.set(x, y, mcrfpy.Color(0, 0, 255, 255)) # Blue
print("✓ Successfully set grid point colors") print("✓ Successfully set grid colors via ColorLayer")
except Exception as e: except Exception as e:
print(f"✗ Failed to set grid colors: {e}") print(f"✗ Failed to set grid colors: {e}")
# Test 4: Add entities to the grid # Test 4: Add entities to the grid
try: try:
# Create an entity with its own texture # Create an entity with its own texture
entity_texture = mcrfpy.Texture("assets/kenney_tinydungeon.png", 16, 16) entity_texture = mcrfpy.Texture("assets/kenney_tinydungeon.png", 16, 16)
entity = mcrfpy.Entity(mcrfpy.Vector(5, 5), entity_texture, 1, grid) entity = mcrfpy.Entity((5, 5), texture=entity_texture, sprite_index=1, grid=grid)
grid.entities.append(entity) grid.entities.append(entity)
print(f"✓ Added entity to grid, total entities: {len(grid.entities)}") print(f"✓ Added entity to grid, total entities: {len(grid.entities)}")
except Exception as e: except Exception as e:
print(f"✗ Failed to add entity: {e}") print(f"✗ Failed to add entity: {e}")
# Test 5: Test grid interaction properties # Test 5: Test grid interaction properties
try: try:
# Test zoom # Test zoom
grid.zoom = 2.0 grid.zoom = 2.0
print(f"✓ Set zoom to: {grid.zoom}") print(f"✓ Set zoom to: {grid.zoom}")
# Test center # Test center (uses pixel coordinates)
grid.center = mcrfpy.Vector(5, 5) grid.center = (200, 200)
print(f"✓ Set center to: {grid.center}") print(f"✓ Set center to: {grid.center}")
except Exception as e: except Exception as e:
print(f"✗ Grid properties failed: {e}") print(f"✗ Grid properties failed: {e}")
@ -86,7 +88,7 @@ mcrfpy.setScene("grid_none_test")
# Add a background frame so we can see the grid # Add a background frame so we can see the grid
ui = mcrfpy.sceneUI("grid_none_test") ui = mcrfpy.sceneUI("grid_none_test")
background = mcrfpy.Frame(0, 0, 800, 600, background = mcrfpy.Frame(pos=(0, 0), size=(800, 600),
fill_color=mcrfpy.Color(200, 200, 200), fill_color=mcrfpy.Color(200, 200, 200),
outline_color=mcrfpy.Color(0, 0, 0), outline_color=mcrfpy.Color(0, 0, 0),
outline=2.0) outline=2.0)

View file

@ -11,8 +11,8 @@ def test_UICollection():
ui = mcrfpy.sceneUI("collection_test") ui = mcrfpy.sceneUI("collection_test")
# Add various UI elements # Add various UI elements
frame = mcrfpy.Frame(10, 10, 100, 100) frame = mcrfpy.Frame(pos=(10, 10), size=(100, 100))
caption = mcrfpy.Caption(mcrfpy.Vector(120, 10), text="Test") caption = mcrfpy.Caption(pos=(120, 10), text="Test")
# Skip sprite for now since it requires a texture # Skip sprite for now since it requires a texture
ui.append(frame) ui.append(frame)
@ -74,9 +74,9 @@ def test_UICollection():
# Test type preservation (Issue #76) # Test type preservation (Issue #76)
try: try:
# Add a frame with children to test nested collections # Add a frame with children to test nested collections
parent_frame = mcrfpy.Frame(250, 10, 200, 200, parent_frame = mcrfpy.Frame(pos=(250, 10), size=(200, 200),
fill_color=mcrfpy.Color(200, 200, 200)) fill_color=mcrfpy.Color(200, 200, 200))
child_caption = mcrfpy.Caption(mcrfpy.Vector(10, 10), text="Child") child_caption = mcrfpy.Caption(pos=(10, 10), text="Child")
parent_frame.children.append(child_caption) parent_frame.children.append(child_caption)
ui.append(parent_frame) ui.append(parent_frame)

View file

@ -18,50 +18,50 @@ def test_screenshot_validation():
print("Creating UI elements...") print("Creating UI elements...")
# Bright red frame with white outline # Bright red frame with white outline
frame1 = mcrfpy.Frame(50, 50, 300, 200, frame1 = mcrfpy.Frame(pos=(50, 50), size=(300, 200),
fill_color=mcrfpy.Color(255, 0, 0), # Bright red fill_color=mcrfpy.Color(255, 0, 0), # Bright red
outline_color=mcrfpy.Color(255, 255, 255), # White outline_color=mcrfpy.Color(255, 255, 255), # White
outline=5.0) outline=5.0)
ui.append(frame1) ui.append(frame1)
print("Added red frame at (50, 50)") print("Added red frame at (50, 50)")
# Bright green frame # Bright green frame
frame2 = mcrfpy.Frame(400, 50, 300, 200, frame2 = mcrfpy.Frame(pos=(400, 50), size=(300, 200),
fill_color=mcrfpy.Color(0, 255, 0), # Bright green fill_color=mcrfpy.Color(0, 255, 0), # Bright green
outline_color=mcrfpy.Color(0, 0, 0), # Black outline_color=mcrfpy.Color(0, 0, 0), # Black
outline=3.0) outline=3.0)
ui.append(frame2) ui.append(frame2)
print("Added green frame at (400, 50)") print("Added green frame at (400, 50)")
# Blue frame # Blue frame
frame3 = mcrfpy.Frame(50, 300, 300, 200, frame3 = mcrfpy.Frame(pos=(50, 300), size=(300, 200),
fill_color=mcrfpy.Color(0, 0, 255), # Bright blue fill_color=mcrfpy.Color(0, 0, 255), # Bright blue
outline_color=mcrfpy.Color(255, 255, 0), # Yellow outline_color=mcrfpy.Color(255, 255, 0), # Yellow
outline=4.0) outline=4.0)
ui.append(frame3) ui.append(frame3)
print("Added blue frame at (50, 300)") print("Added blue frame at (50, 300)")
# Add text captions # Add text captions
caption1 = mcrfpy.Caption(mcrfpy.Vector(60, 60), caption1 = mcrfpy.Caption(pos=(60, 60),
text="RED FRAME TEST", text="RED FRAME TEST",
fill_color=mcrfpy.Color(255, 255, 255)) fill_color=mcrfpy.Color(255, 255, 255))
caption1.size = 24 caption1.font_size = 24
frame1.children.append(caption1) frame1.children.append(caption1)
caption2 = mcrfpy.Caption(mcrfpy.Vector(410, 60), caption2 = mcrfpy.Caption(pos=(410, 60),
text="GREEN FRAME TEST", text="GREEN FRAME TEST",
fill_color=mcrfpy.Color(0, 0, 0)) fill_color=mcrfpy.Color(0, 0, 0))
caption2.size = 24 caption2.font_size = 24
ui.append(caption2) ui.append(caption2)
caption3 = mcrfpy.Caption(mcrfpy.Vector(60, 310), caption3 = mcrfpy.Caption(pos=(60, 310),
text="BLUE FRAME TEST", text="BLUE FRAME TEST",
fill_color=mcrfpy.Color(255, 255, 0)) fill_color=mcrfpy.Color(255, 255, 0))
caption3.size = 24 caption3.font_size = 24
ui.append(caption3) ui.append(caption3)
# White background frame to ensure non-transparent background # White background frame to ensure non-transparent background
background = mcrfpy.Frame(0, 0, 1024, 768, background = mcrfpy.Frame(pos=(0, 0), size=(1024, 768),
fill_color=mcrfpy.Color(200, 200, 200)) # Light gray fill_color=mcrfpy.Color(200, 200, 200)) # Light gray
# Insert at beginning so it's behind everything # Insert at beginning so it's behind everything
ui.remove(len(ui) - 1) # Remove to re-add at start ui.remove(len(ui) - 1) # Remove to re-add at start

View file

@ -11,16 +11,16 @@ mcrfpy.setScene("timer_works")
ui = mcrfpy.sceneUI("timer_works") ui = mcrfpy.sceneUI("timer_works")
# Add visible content # Add visible content
frame = mcrfpy.Frame(100, 100, 300, 200, frame = mcrfpy.Frame(pos=(100, 100), size=(300, 200),
fill_color=mcrfpy.Color(255, 0, 0), fill_color=mcrfpy.Color(255, 0, 0),
outline_color=mcrfpy.Color(255, 255, 255), outline_color=mcrfpy.Color(255, 255, 255),
outline=3.0) outline=3.0)
ui.append(frame) ui.append(frame)
caption = mcrfpy.Caption(mcrfpy.Vector(150, 150), caption = mcrfpy.Caption(pos=(150, 150),
text="TIMER TEST SUCCESS", text="TIMER TEST SUCCESS",
fill_color=mcrfpy.Color(255, 255, 255)) fill_color=mcrfpy.Color(255, 255, 255))
caption.size = 24 caption.font_size = 24
ui.append(caption) ui.append(caption)
# Timer callback with correct signature # Timer callback with correct signature