Alice Methods and Classes. Methods and Classes Methods – Coordinated sequence of instructions carried out when requested (e.g. move, turn to, etc.) Class.

Slides:



Advertisements
Similar presentations
Mike Scott University of Texas at Austin
Advertisements

Princess & Dragon – Version 2 By Michael Hoyle under the direction of Professor Susan Rodger Duke University July 2012 Part 2: Using Methods.
Princess & Dragon – Version 2 By Michael Hoyle under the direction of Professor Susan Rodger Duke University July 2012 Part 3: Billboards, Events, Sounds,
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Class-level Methods Chapter 6. Class-level Method Is specific to a class of objects We can give a class new abilities/methods Only involves this one class.
Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
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.
Alice and Media Computation August 2009 Animation Storyboard  Code Steve Cooper Barbara Ericson.
CSC1401 Animation Creating methods/instructions (class-level)
Parameters and World-level methods Alice. Our Dragon world The dragon must to take off and fly, to carry the princess.
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Lesson 7B Creating Our Own Methods Slides are adapted from aliceprogramming.net or
Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
World-level Methods with Parameters Alice. Larger Programs As you become more skilled in writing programs, you will find that your programs quickly begin.
Repetition Structures
Blockly Minecraft Task 1 ) Please copy the example task. Task by task
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Alice Variables Pepper. Set to Java look Edit / preferences restart.
Exploring Events. Try this Start Alice and create a blank world using the grass template. Add an instance of a BlueBallerina. Add an instance of a PinkBallerina.
1 An introduction to programming concepts with Scratch.
Alice: A Free 3D Animation World for Teaching Programming Barbara Ericson Georgia Institute of Technology Oct 2005.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
Alice Learning to program: Part Two by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Class-level Methods Chapter 6 part 1. Classes and Objects Classes o In Alice, classes are predefined as 3D models Objects o An object is an instance of.
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.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
2015 CSE/EGR Summer Camps 1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed.
Storyboarding1 Steve Cooper Barb Ericson August 2009 Storyboarding.
Mathematical Expressions, Conditional Statements, Control Structures
Alice Learning to program: Part Two Writing Your Own Methods by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Copyright 2008 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Functions, Loops, and Parameters.
Methods (part 2) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS 120 Lecture 03 4 September 2012.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
5 Event Handling Interactive Programming Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term.
Alice: A Free 3D Animation World for Teaching Programming.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Programming in Alice IT-IDT-9 Design, develop, test and implement programs using visual programming. 9.1 Utilize drag and drop software to develop programs.
CompSci 4 Chap 5 Sec 1 and 2 Oct 14, 2010 Prof. Susan Rodger.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
The Essentials of Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University May 2009.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Creating a UFO Rescue Game in Alice
Create a Halloween Computer Game in Scratch
Classes, Objects, and World-level Methods
Control Structures
Creating a UFO Rescue Game in Alice
World-level Methods with Parameters
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Refining our Animations
Alice in Action with Java
Making Procedural Methods
Alice Variables Pepper.
Using Functions
Introduction to Object-Oriented Programming in Alice
Classes / Objects / Methods
Presentation transcript:

Alice Methods and Classes

Methods and Classes Methods – Coordinated sequence of instructions carried out when requested (e.g. move, turn to, etc.) Class – A class defines an object, in our cases the 3D models – Classes contain Data: e.g. position, color Methods that pertain to the specific object – A class is a blueprint that tells Alice how to create, display, and manipulate the object – When an object is created we call this instantiation and we create an instance of the class

Classes vs. Objects Bird Class TweetyDaffyBigBird To do: Add three birds to an Alice world

Methods Methods must be associated with some object – Might be the world object – Should only deal with things specific to the object for which it is defined Methods give us a way to divide a program up into small, manageable pieces that work together – Process called abstraction – Makes programs easier to write and debug than one giant code block – The process of breaking a problem into methods is called stepwise refinement Methods may take parameters – Input data that the method should operate on, like a function

World Methods For example, consider our world where we had the alien on wheels randomly try to get close to the washing machine This is not too complex on its own, but when part of a larger script it can get messy

World Methods We can create a method named “AlienSeek” that runs this code Under “World”, click “Methods” and “Create New Method” and name it “AlienSeek” – Put code into the new method To invoke it, we just drag out “AlienSeek” from the World methods where we want to use it – Greatly simplifies the invoking code and also gives it a name to make it more meaningful To do: Create method in Alice

Another Method Example Create a new world with three Birds Create a World method called “RandomFly” While true – With 50% chance Make Bird1 turn to the left randomly up to 0.25 – Otherwise Make Bird1 turn to the right randomly up to 0.25 – Go forward some random distance from 0 to 0.5

Problem: How about for all birds? What if we want all birds to fly? The new method only moves Bird1 and it would be nice to avoid having to copy the method for Bird2, Bird3 when it should be the same Solution – Make the method take a parameter that specifies which bird object to move RandomFly Method: Parameter – BirdObj ( Manipulate the BirdObj) Bird2Bird1

Creating a Parameter Click “Create new Parameter” button in the method Give it a name like birdObj Drag birdObj in place of Bird1

Invoking the Method We need to specify the parameter when we invoke the method All the birds now fly together!

Refinement Maybe we want the birds to fly random lengths from 0 to 1 but at the same speed Problem: Duration should then match the distance We want these the same value But if we pick another random number it may be different

Solution: Variable Create a variable that holds the random number, then we can reference that same variable in both places Click “Create New Variable”, give it a name, and assign its value

Further Refinement: Flock Let’s keep the birds from flying too far away from each other Not very elegant but workable solution: – If distance to otherBirdA > 3 then Turn to face otherBirdA – Else If distance to otherBirdB > 3 then – Turn to face OtherBirdB Else – Do the random direction selection – Fly forward random amount Can do this by adding two more parameters for the other birds

Bird Flock More elegant solutions exist, but we will skip them here

Bird Sounds What if we would like each bird to play a different sound as it flies? We can send that in as a separate parameter too. – Can record a new sound for Bird1 Create a new parameter, select Other, and pick “Sound” as the type of parameter

Class Methods We can also define methods for specific classes Such methods should ONLY apply to behaviors of the selected class / object – E.g. Select Bird1 – Shouldn’t add anything relating to other birds/objects inside this method – Can add a “FlapWings” method Set the Pose to Fly1 Set the Pose to Fly2 Notice that the new method only applies to Bird1 – If you want the method for all birds, you can save Bird1 as a new object, then load the new object in and you will be creating multiple instances of the Bird1 class

All birds flapping To make all the birds flap we can make a World method that takes a Bird object as input and flaps its wings

Exercise : Magic Act A magician is performing a levitation illusion in which objects rise magically into the air. The magician points at a rabbit and it floats; then he points at his assistant and she floats. Use a single method with parameters to communicate which object is to float and the distance the object is to move upward and downward.