jakubg1 / OpenSMCE

Game engine which allows creating a broad range of marble popper games.
MIT License
14 stars 11 forks source link

Sphere selectors #39

Closed jakubg1 closed 4 months ago

jakubg1 commented 3 years ago

Allow to create, based on some criteria such as position or color, an instance of a class that would contain a list of spheres with which you can do varius stuff, such as change their color or destroy them. This would be useful for most powerups which mess with spheres. Currently, all that stuff is in Session.lua which isn't the best place to store all these functions.

TF3RDL commented 1 year ago

This can hopefully improve flexibility on powerups that affect spheres in any way (like color replacer should affect two colors and leave wild spheres intact when they hit a wild ball per #65)

jakubg1 commented 1 year ago

That's good you mentioned color replacers, they may be a bit of a problem because there would need to be various parameters for sphere selectors which exist in one context but not in the other, such as color. That remains to be seen, though.

jakubg1 commented 10 months ago

Under the hood, sphere destruction should support #121. Example sphere selectors:

sphere_selectors/color_bomb_1.spsel:

{
    "conditions": [
        {
            "type": "color",
            "colors": [1]
        },
        {
            "type": "isOffscreen",
            "value": false
        }
    ]
}

or alternatively:

{
    "condition": "$expr{[color] == 1 && ![isOffscreen]}"
}

sphere_selectors/fireball.spsel:

{
    "conditions": [
        {
            "type": "distance",
            "max": 75
        }
    ]
}

or alternatively:

{
    "condition": "$expr{[distance] < 75}"
}

sphere_selectors/lightning.spsel:

{
    "conditions": [
        {
            "type": "distanceX",
            "max": 50
        }
    ]
}

or alternatively:

{
    "condition": "$expr{[distanceX] < 50}"
}

sphere_selectors/everything.spsel:

{
    "conditions": []
}

or alternatively:

{
    "condition": "$expr{true}"
}

Problem with Expressions: how do we calculate only necessary variables?

jakubg1 commented 8 months ago

Another approach: sphere_selectors/color_bomb_1.json:

{
  "operations": [
    {"type": "add", "condition": "$expr{[sphere.color] == 1 && ![sphere.isOffscreen]}"}
  ],
  "scoreEvent": "score_events/color_bomb.json"
}

sphere_selectors/fireball.json:

{
  "operations": [
    {"type": "add", "condition": "$expr{[sphere.distance] < 100}"}
  ],
  "scoreEvent": "score_events/fireball.json"
}

sphere_selectors/lightning.json:

{
  "operations": [
    {"type": "add", "condition": "$expr{[sphere.distanceX] < 50}"}
  ],
  "scoreEvent": "score_events/lightning.json"
}

sphere_selectors/everything.json:

{
  "operations": [
    {"type": "add", "condition": true}
  ]
}

And hypothetical sphere_selectors/limited_color_bomb_2.json:

{
  "operations": [
    {"type": "add", "condition": "$expr{[sphere.color] == 2 && ![sphere.isOffscreen]}"},
    {"type": "pickRandomly", "count": 20}
  ],
  "scoreEventForSphere": "score_events/color_bomb.json"
}

The difference between scoreEvent and scoreEventForSphere fields being that the former is executed once for the entire batch, and the latter is executed for each sphere separately (these fields should actually belong to powerup effect config instead, lol)

jakubg1 commented 4 months ago

Implemented: https://github.com/jakubg1/OpenSMCE/commit/45dc56bf4ae41f976d83a0300569a4da6ca542e9