Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you call "an annoying switch statement" i would call "a great game" so you are on the right track.</p> <p>Having a function for every interaction/game rule is exactly what I would suggest. It makes it easy to find, debug, change and add new functionality:</p> <pre><code>void PlayerCollidesWithWall(player, wall) { player.velocity = 0; } void PlayerCollidesWithHPPotion(player, hpPoition) { player.hp = player.maxHp; Destroy(hpPoition); } ... </code></pre> <p>So the question is really how to detect each of these cases. Assuming you have some sort of collision detection that results in X and Y collide (as simple as N^2 overlap tests (hey, it works for plants vs zombies, and that's got a lot going on!) or as complicated as sweep and prune + gjk)</p> <pre><code>void DoCollision(x, y) { if (x.IsPlayer() &amp;&amp; y.IsWall()) { // need reverse too, y.IsPlayer, x.IsWall PlayerCollidesWithWall(x, y); // unless you have somehow sorted them... return; } if (x.IsPlayer() &amp;&amp; y.IsPotion() { ... } ... </code></pre> <p>This style, while verbose is</p> <ul> <li>easy to debug </li> <li>easy to add cases</li> <li>shows you when you have logical/design inconsistencies or omissions "oh what if a X is both a player and a wall due to the "PosessWall" ability, what then!?!" (and then lets you simply add cases to handle those)</li> </ul> <p>Spore's cell stage uses exactly this style and has approximately 100 checks resulting in about 70 different outcomes (not counting the param reversals). It's only a ten minute game, that's 1 new interaction every 6 seconds for the whole stage - now that's gameplay value!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload