Help ... Molecular game

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

The question is: When should that happen?

I guess when they collide with each other.

Due to it’s dynamic nature you will need Python to read handle that operation.


import bge

controller = bge.logic.getCurrentController()

if all(sensor.positive for sensor in controller.sensors):
    player = controller.owner
    particle = controller.sensors["collide with particle"].hitObject
    
    playerSize = player["size"]
    particleSize = particle["size"]

    if (playerSize > particleSize):
        playerEats(particle)
    if (playerSize < particleSize):
        particleEats(player)
    else:
        handleSameSize(player, particle)


Just an idea…

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.

That is what playerEats(particle) and particleEats(player) is for. You add your specific code there.

E.g.



def playerEats(particle):
    player["size"] += particle["size"]

def particleEats(player):
    player["size"] -= particle["size"]


Yes you can rename the functions, or code the outcome without the use of functions at all.

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!

Does this help a bit?