So I'm doing a little object oriented experiment with dictionaries and behaviors, but I've ran into this problem.
This is the function where it happens, in Line 49.
def _step_enemy(obj):
print(environment[obj].get('cnt'))
environment[obj].__setitem__("cnt", environment[obj].get('cnt') + 0.1)
if environment[obj].get('cnt') < 20:
if environment[obj].get('posy') == 4:
del environment[obj]
else:
if environment[obj].get('posy') < 4:
environment[obj].__setitem__("posy", environment[obj].get('posy') + 1)
else:
environment[obj].__setitem__("cnt", environment[obj].get('cnt'))
This is what the stuff above looks like.
#Entorno de los objetos
environment = {"Player":{"posx": 2, "posy": 2},
"Enemy":{"posx": 4, "posy": 0, "cnt": 0.0 }
}
# Funciones basicas del engine
def gfx():
display.clear()
for obj in environment.items():
# Obtener posiciones y graficar en pixeles
v1 = obj[1]["posx"]
v2 = obj[1]["posy"]
display.set_pixel(v1, v2, 9)
def log():
# Array para determinar si no hay enemigos
checkarray = []
for obj in environment:
if obj == "Enemy":
checkarray.append(obj)
_step_enemy(obj)
if len(checkarray) == 0: # Si no hay enemigos
# Crear enemigos
environment["Enemy"] = {"posx": random.randrange(0, 4), "posy": 0}