Aktor > Sensor

Aktor > Sensor#

Sensoren sind Hilfs-Actors, die an einen anderen Actor angehaengt werden koennen, um nahe Objekte und Interaktionen zu erkennen.

API-Referenz#

Sensor#

class miniworlds.actors.sensors.sensor_actor.Sensor(actor, *args, **kwargs)[Quellcode]

An invisible sensor attached to another actor.

A Sensor follows the actor it is attached to and detects nearby objects. The sensor itself is not visible and will never detect the actor it belongs to.

Use actor.register_sensor(Sensor) to attach a sensor to an actor.

Parameter:

actor – The parent actor this sensor is attached to.

Examples

from miniworlds import *
world = World()
player = Actor((100, 100))

# Attach a sensor that detects enemies 30 pixels ahead
player.register_sensor(Sensor)

world.run()

Kreissensor#

class miniworlds.actors.sensors.circle_sensor.CircleSensor(actor, distance, **kwargs)[Quellcode]

A circular invisible sensor attached to another actor.

CircleSensor creates a circle of a given distance (radius) around the parent actor. Any actor that overlaps with this circle will be detected. The sensor itself is invisible and never detects the parent actor.

Use actor.register_sensor(CircleSensor, distance=<pixels>) to attach.

Parameter:
  • actor – The parent actor this sensor belongs to.

  • distance – Radius of the circular detection area in pixels.

Examples

from miniworlds import *
world = World()
player = Actor((100, 100))
player.add_costume("images/player.png")

# Detect enemies within 50 pixels
player.register_sensor(CircleSensor, distance=50)

world.run()