Checking for Collisions: Using Functions in Alice

Slides:



Advertisements
Similar presentations
Getting Started With Alice: The Basics By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Advertisements

Visual Lists By Chris Brown under Prof. Susan Rodger Duke University July 2012.
Coloring Randomly: Random Selection in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
How Tall Are You? Introducing Functions By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made June 2014 by.
Using Functions in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University July 2008.
SETTING UP CAMERA VIEWS LESSON Setting camera views using objects, based on a lesson by Bella. Adventures in Alice Susan Rodger Duke University July 2013.
Using Functions in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University July 2008.
Lights Camera Action! Part 3: BDE Events By Deborah Nelson under the direction of Professor Susan Rodger Duke University July 2008.
Wizard Game: Class-Level Variables in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July
Alice Learning to program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Creating Functions Deborah Nelson Duke University Professor Susan Rodger July 22, 2008.
Shorter of two objects and changing color Functions, events and setting the color Susan Rodger, Duke University June 2008.
Checking for Collisions Ellen Yuan Under the direction of Professor Susan Rodger at Duke University June 2014.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Shorter of two objects and changing color V2 Functions, events and setting the color in sequence and randomly This is a modification of the Changing Color.
Checking for Collisions: Alternative Method Erin Taylor Under the Direction of Susan Rodger July 2015 Duke University.
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Methods Tutorial: Part Two By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
A Simple Quiz: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011.
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
The Essentials of Alice (Bunny) By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
Illuminating Computer Science CCIT 4-6Sep
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Simple Collision Detection By David Yan Under the direction of Professor Susan Rodger and Chari Distler Duke University, June 2015.
Tutorial on Kangaroo visiting his animal friends - parameters, events Susan Rodger Duke University June 2009.
Learning to Program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
BDE tutorial By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 13, 2008.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June.
How Tall Are You? Introducing Functions for Alice 3 By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made.
Making Billboards By Deborah Nelson Duke University, Under the direction of Professor Susan Rodger, July 14, 2008.
Tutorial on Bunny visiting his animal friends - parameters, events for Alice 3 Susan Rodger Duke University June 2009 Updated by Yossra Hamid on October.
The Essentials of Alice (Bunny)
Getting Started With Alice: The Basics
A Simple Quiz for Alice 3.2:
An Introduction to Alice (Short Version)
Changing Camera Views! Part 1: Set Point of View to By Bella Onwumbiko
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Changing Color, Using Text Objects, and Random Selection in Alice
Tutorial on Kangaroo visiting his animal friends - parameters, events
Let's Race! Typing on the Home Row
Vehicles and Conditionals
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Skater World: Part Three
Alice Learning to program: Part Three By Ruthie Tucker and Jenna Hayes, Under the direction of Professor Rodger Duke University, 2008.
A Simple Quiz for Alice 3.2:
Methods Tutorial: Part Two
Making Objects Move in Unison: Using Lists
An Introduction to Alice
Restricting an Event with a Conditional
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events
How Tall Are You? Introducing Functions
Getting Started With Alice
Learning to Program: Part 3 Camera Control, Invisibility and 3-D Text
Professor Susan Rodger
Headshots in Alice Duke University Professor Susan H. Rodger
Getting Started With Alice: The Basics
Professor Susan Rodger
Making Objects Move in Unison: Using Lists
under the direction of Professor Susan Rodger
Restricting Events Creating Conditional Events in Alice By Henry Qin
Presentation transcript:

Checking for Collisions: Using Functions in Alice By Henry Qin under the direction of Professor Susan Rodger Duke University July 2008

Step 1: Building the World This tutorial will demonstrate how to use a tool called a Function in Alice, to tell if one object is relatively close to another object. In order to do this we will build a simple world and a simple function to tell if two objects are colliding (on top of each other). To build it simply choose a grass scene in Alice and add a bunny and a cow from the animals folder of the local gallery.

Step 2: Creating a Function The first thing that we need to do is create a function in the world. Click Done to go back to the main window. Click on world in the object tree and and then the functions tab. Click on the gray “Create new function” button. We are going to name this one “overlapTest.” Make sure you select the Boolean type. After you write the name a green tab should appear on in your method editor.

Step 3: If/Else Condition Next we need to drag an if/else statement into the place that currently says “do nothing.” Select true. Now lets go to world level functions and drag the a < b tab over the true in the if/else. Just pick 1 for both a and b, they are simply place holders for the moment.

Step 3: If/Else Condition For the first 1 we are going to go to the cow’s functions and choose “cow distance to” bunny, (the entire bunny). Now find the function labeled “cow’s width.” Drop on top of the 1 in the second space.

Step 3: If/Else Condition Now, click on the down arrow immediately next to width and select math. Select “cow’s width /” and 2 to divide the width in half. Click on the down arrow next to the “2 )”. Select math again and choose “(cow’s width / 2) +” and choose 1 as a placeholder.

Step 3: If/Else Condition Replace the 1 with the same expression only this time using the bunny. Drag in bunny’s width from the bunny’s functions over the 1. Select the down arrow next to bunny’s width and select math. Select “bunny’s width /” and 2 to divide the width in half.

Step 4: Return Statements This function is going to check and see if the cow is closer than the length of the cow’s width to the bunny. In other words, is the cow colliding with the bunny? We want to return “true” if the cow is overlapping with the bunny. Drag a Return statement into the first Do Nothing and select true. Drag a second Return statement into the remaining Do Nothing and select false. Since if the cow and bunny aren’t close enough, they are not colliding.

Step 5: Calling the Function Now we need to write a method to call this function. Lets go into World.myfirstmethod and drop in an “if statement.” Now drop in your “overlapTest” function on top of the “if statement.” We want the cow to say something if overlapTest is true. Let’s have him say, “We are colliding, how can this be?”

Step 5: Calling the Function Now, in the else statement have the cow say, “Checking… we are not colliding.” Now play your world. Since the cow is next to the bunny he should say “Checking…..we are not overlapping.”

Step 5: Calling the Function Now drag the cow on top of your bunny in the add objects screen and play it again. The cow should say “We are colliding, how can this be?” You can use functions like this in your Alice worlds to determine if objects in your world are within a certain distance of each other. Check out some of the example worlds that require colliding with another object (such as games where try to catch something) to see how we can use this code. That’s all folks!