Build a Paintball Game (part 4 of 6)

Tagged:

Previous: Launching Paintballs (part 3 of 6)

Collisions

Now that Mario can move around and launch paintballs, we actually want the paintballs to change the color of the turtles that they collide into. We do this using a Collision block between the Paint and Turtles breeds.  Drag out the appropriate collision block from the Turtles tab (My Blocks palette) and put it on the Collisions section of the canvas.

In the Turtles part of the Collision block, attach a Set Color block (Traits tab) and change the color to the color of the sphere being collided with. You can get that color by going to the Other Agents tab and grabbing a Color-Of block. Attach a Collidee block to the Color-Of block and the agent running the code will set its color to the color of the agent it is colliding with.

Once the Paint agent has Collided with a Turtle agent, the Paint agent's job is done and it can disappear or "die". Grab a Die block from the Logic tab and attach it to the Paint part of the Collision block.

Now try running the project. You should be able to paint the turtles now.

Next: "Speech" (part 5 of 6) Back To Top