Programming in Alice Chapter 2 Part 2 Events

  • Slides: 21
Download presentation
Programming in Alice Chapter 2 Part 2

Programming in Alice Chapter 2 Part 2

Events Editor Identifies what method is executed (run) when the “Play” button is hit

Events Editor Identifies what method is executed (run) when the “Play” button is hit 2

Deleting Instructions § Right-click the instruction and select delete § Drag the instruction tile

Deleting Instructions § Right-click the instruction and select delete § Drag the instruction tile to the trash can 3

Copying Instruction § Right-click the instruction and select make copy § Drag the instruction

Copying Instruction § Right-click the instruction and select make copy § Drag the instruction tile to the clipboard o o When the clipboard turns green, drop the tile Click on the clipboard and drag it back to the Method Editor 4

Objects With Custom Methods § In addition to primitive methods some objects § §

Objects With Custom Methods § In addition to primitive methods some objects § § have custom methods When objects are selected from gallery, a listing of custom methods appears Names of the custom methods give clues as to what the method does What do you think the foottap custom method does? 5

Naming Conventions § Names are known as identifiers because they § identify items in

Naming Conventions § Names are known as identifiers because they § identify items in a program Use a name that provides meaning o Name of method should indicate the method’s purpose Which one coaches the Knights and which one coaches the Cougars? 6

Naming Conventions § Dot notation o world. my first method the period is called

Naming Conventions § Dot notation o world. my first method the period is called a “dot” § Dot (period) separates pieces of information o Left side: object that the method belongs to Ø o The WORLD object in this case Right side: name of the method Ø “my first method” in this case 7

Naming Conventions § Most programming languages do NOT recognize spaces o Alice allows spaces,

Naming Conventions § Most programming languages do NOT recognize spaces o Alice allows spaces, good practice is to not use them method. my first method Note the space § Without spaces, how do you have more than one word in names? o o o Lower case first letter Capitalize first letter of next words Called camel. Case (camel’s hump) Which is easier to read? onehumpcamel or one. Hump. Camel 8

Class Names § Method names begin with a lower case letter § Class names

Class Names § Method names begin with a lower case letter § Class names are capitalized § No spaces, so each word is capitalized o This convention is called Pascal. Case 9

Renaming § Objects o Right-click object’s tile in the object tree and select rename

Renaming § Objects o Right-click object’s tile in the object tree and select rename § Custom methods o o Select the world object Select the methods tab from the Details Panel Right-click the my first method tile and select rename If right-click does not work then hit Control & click 10

Orientation and Movement n A translation in computer graphics o o Moves an object

Orientation and Movement n A translation in computer graphics o o Moves an object a specified distance in a specified direction Move instruction in Alice moves object Ø n Left, right, up, down, forward, backward All movements of objects are egocentric o They move from their perspective, not ours 11

Pivot Point Examples Center of rotation 12

Pivot Point Examples Center of rotation 12

Turn Method n n Causes rotational motion Can turn an object o Left, right

Turn Method n n Causes rotational motion Can turn an object o Left, right – similar to turning door on hinges Ø o Along the horizontal plane Forward, backward – lifting or closing hinged lid on a box Ø Along the vertical plane forward and backward 13

Roll Method n Object is rotated left or right o n Along the vertical

Roll Method n Object is rotated left or right o n Along the vertical plane clockwise or counter-clockwise Rotation depends on where center is 14

Subpart Rotation n Center for rotational motion is where subpart connects to object o

Subpart Rotation n Center for rotational motion is where subpart connects to object o n Also called a pivot point Turn rotation of Monkey’s left arm subpart 15

Orient to Method n n n Used when two objects need to move together

Orient to Method n n n Used when two objects need to move together synchronization Objects might be pointing in different directions Use orient to method to align them o Argument is object to orient to method Forward Notice change orientation of ball changed 16

Circling Other Objects § Object’s turn method spins the object around o § §

Circling Other Objects § Object’s turn method spins the object around o § § Can also get an object circle around another object The as. Seen. By optional argument causes an object to turn around the as. Seen. By’s objects center point Example: hawk turns one complete revolution around the tree from the tree’s perspective 17

Facing and Pointing Objects n Turn to face o n Causes object to turn

Facing and Pointing Objects n Turn to face o n Causes object to turn toward another object Point at o o Aligns two objects from the center of one to center of other Centers are not always in good spot Ø They could collide in odd places or cause odd movement 18

“Move to” Instruction n Moves an object to another object o n The centers

“Move to” Instruction n Moves an object to another object o n The centers of both objects align o n Instead of a distance with move instruction This will make it look like they collide Better to use “move toward” instruction o o Need to know distance though and be careful of center Be very careful Will match center of both objects together Ø If centers are at different heights the object will be moved off ground or into ground to align centers Ø Use “turn to face” object then move distance to object Ø 19

Exporting Code for Printing n n n Code can be exported to an HTML

Exporting Code for Printing n n n Code can be exported to an HTML file From File – Choose Export Code for Printing You MUST add your name as the author o Author’s name is printed with the exported code 20

Homework n n Read chapter 2 Do lab assignments in handout o n Exercise

Homework n n Read chapter 2 Do lab assignments in handout o n Exercise 6, 7 and custom exercise of fish circling island Due one week after its assigned 21