McRogueFace/quick_index_test.py
John McCardle 923350137d Implement Entity.index() method for Issue #73
Added index() method to Entity class that returns the entity's
position in its parent grid's entity collection. This enables
proper entity removal patterns using entity.index().
2025-07-03 21:02:14 -04:00

12 lines
No EOL
397 B
Python

import mcrfpy
t = mcrfpy.Texture("assets/kenney_ice.png", 16, 16)
g = mcrfpy.Grid(5, 5, t, (0, 0), (100, 100))
e1 = mcrfpy.Entity((1, 1), t, 1, g)
e2 = mcrfpy.Entity((2, 2), t, 2, g)
g.entities.append(e1)
g.entities.append(e2)
print("Entity 1 index:", e1.index())
print("Entity 2 index:", e2.index())
# Test removal
g.entities.remove(e1.index())
print("After removal, Entity 2 index:", e2.index())