Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fell View Computer Club StarLogo TNG – Session Two.

Similar presentations


Presentation on theme: "Fell View Computer Club StarLogo TNG – Session Two."— Presentation transcript:

1 Fell View Computer Club StarLogo TNG – Session Two

2 Our first game We’re going to try and write our first game. It’s the simplest game I can think of. Let’s call it Bat & Ball. The objective of the game will be to keep balls in play by bouncing them off a bat. The first commercially successful computer game was like this. It was called Pong and was written in 1972. At first it was just in Arcades and then a home console was released in 1975 – imagine today buying a console that only played one game!

3 Agents Before we can start our game we need to learn about agents. Agents are the things that do things in a game or simulation. The default agent is the turtle but we can change, add or delete agent. When you’re planning a game the first thing to do is think about what agents are needed. For our game, Bat & Ball what agents shall we have? A Bat… And a Ball… Agent are assigned a breed. You can manage the agents by clicking the ‘Edit Breeds’ button For each breed of agent that we create we get an area to write the commands that will control our agent

4 Setup the game We’ll start by creating a bat and a ball and putting them in the game starting position. We need to understand the grid of our world so we can set the coordinates of our agents. Our bat is created at (-40, 0) Our ball is created at (40, random Y)

5 Move the bat We need to be able to move the bat. Let’s create a procedure (who can remember what is procedure is?) and call it “moveBat”. Notice that we can only move up if we’re not at the top of the grid and only move down if we’re not at the bottom of the grid. While we’re experimenting with the game then we can create a variable called “batSpeed” and attach a slider control so that we can change the bat speed. Instead of hard-coding the bat movement we use the batSpeed variable…

6 Move the ball Now move the bat. Let’s create a procedure and call it “moveBall” Unlike the bat the ball moves by itself. Like the bat we can create a variable and attach a slider so we can change the ball speed. Our ball will bounce forever which would make a boring game so we need to lose if the ball gets past the bat. When it does we play a sound and kill the ball

7 Running the game Now we’ve defined how our two agents, the bat and ball, behave, we can set the game running. In the runtime tab we choose the forever control and call our moveBat and moveBall procedures… So far our games not very interesting. We can move the bat and the ball bounces around but we need our agents to interact – i.e. we want to ball to bounce off the bat.

8 Bounce the ball off the bat StarLogo TNG creates command blocks to control what happens when a pair of agents hit each other. In our game we have two agents, the bat and ball, so we get a collision command that says what happens when a bat hits a ball; a command for when a bat hits a bat; and a command for when a ball hits a ball. The bat doesn’t do anything when it hits ball so we just make a boing sound but we want the ball to bounce back the way it came. To do this we can set it’s heading. We want to add (or take away) 180⁰ to reverse it’s direction.

9 Challenges Change the program to have more than one ball bouncing at the same time. Make the balls bounce off each other.

10 Next session We’ll split into groups and choose a game to develop: – Make the bat and ball game more interesting – destroying bricks; levels; score; lives – A lunar lander game where you have to use limited fuel to gently land on the moon’s surface – A car driving game where you need to collect balls and avoid the trees – A light cycle game (Tron)


Download ppt "Fell View Computer Club StarLogo TNG – Session Two."

Similar presentations


Ads by Google