Build a Paintball Game (part 1 of 6)

Tagged:

The Paintball project illustrates some of the basic game-play elements that can be easily programmed with StarLogo TNG. This includes movement, collisions, terrain and "say bubbles." In this game we'll create an agent breed called "Mario" who will run around and fire spheres of paint at some turtles to give them some color.

Setting up Breeds

We start this game by thinking about the breeds that we'll need. Let's leave the Turtle breed (though we'll change its shape in a minute). But let's add two new breeds. We'll add Mario who will look like Mario. And we'll add Paint that Mario can throw. Open the Breed Editor by clicking on the Edit Breeds button to the right of the My Blocks button. Click New to add a new breed, give the name Mario to the breed and select Mario as the shape.

Make another breed called Paint and select the sphere shape. Finally click on the Turtles breed and select the turtle shape with a slight blue background in the Animals category - these are turtles that can be painted different colors.

Setup Block

Navigate to the Setup section of the canvas. Click on the Setup and Run tab and drag out the Setup block. We will fill this with commands to clear everyone from the previous run, create one Mario agent and a bunch of Turtle agents, and set the camera angle to show Mario's perspective.

Click on the Setup and Run tab, drag out the Clear Everyone block and attach it to the Setup block.

Click on the My Blocks button, open the Turtles drawer, drag out the Create Turtles block, and attach it below the Clear Everyone block. Change the number to 50. 

Click on the Turtles tab again, drag out the Scatter Turtles block and attach it to stack in the Setup block. This block will scatter the turtles randomly around Spaceland.

Test out your Setup code by clicking on the Setup button in the Runtime window.

Go back to the Setup block and click on the Mario tab in the My Blocks palette. Drag out a Create Mario Do block. This block has two parts - the top part specifies the number of agents to create, and the second part specifies additional instructions for these newly created agents to do once. Change the pink number to 1.

Click on the My Factory button and click on the Controls tab. Drag out the Set Camera block and attach it to the Do section of the Create Mario Do block. Set Camera takes an argument that's the ID of an agent. In this case, we want Mario's ID, so we just go to the Traits tab, drag out the ID block, and attach it to the Set Camera block.

Finally, to set the camera view so that we "see" from Mario's perspective, click the Controls tab and drag out the Over Shoulder block. Attach this block below the Set Camera block.

Now test out the Setup code again by clicking the Setup button in the Runtime window.

Next: Movement (part 2 of 6) Back To Top