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().
This commit is contained in:
parent
6134869371
commit
923350137d
6 changed files with 234 additions and 5 deletions
12
quick_index_test.py
Normal file
12
quick_index_test.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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())
|
||||
Loading…
Add table
Add a link
Reference in a new issue