I’m making a game where the player is a molecule and must eat other smaller particles to increase in size.
The problem is that each particle and the player has a property (float) that defines its size, and I do not know how to make those that have the property (size) smaller than the player, change to another state.
I hope someone can help me, no matter if it is with logical blocks or with python. Beforehand thank you very
If it’s what I’m looking for … But to be more specific, I want the player with property (size = 10,000) can only absorb particles whose size is less than 10,000 and they look green and if the size is bigger than That, are red and if the player collides with a smaller particle is added the number of its size. But if it collides with a larger particle it will take away the size of the player. And I use blender 2.74.
Sorry to keep bothering you, but I do not know anything about python. I want to know what the complete code is like if the particle changes to state 2 when the particle is smaller than the player.
import bge
STATE_SMALLER = 2
controller = bge.logic.getCurrentController()
if all(sensor.positive for sensor in controller.sensors):
scene = bge.logic.getCurrentScene()
objects = scene.objects
player = objects["Player"]
particles = [object for object in objects if "particle" in object]
for particle in particles:
if (particle["size"] < player["size"]):
particle.state = STATE_SMALLER
Assumptions:
the player object is called “Player”
the particles have a property called “particle”
player and particles have a float or int property
How it works:
it checks that all sensors are positive (Similar to an AND controller)
it finds the player object
it finds all particles in the scene
it iterates over all particles
if “size” of particle is less than “size” of player: the state of the particle gets set to state 2
You should trigger that code when:
the player’s size changes
new particles are added
the size of a particle changes
It can be triggered by any object of the scene.
The code does not activate/deactivate any actuator!