Alice Concepts: Aiming and Projectiles: "Vehicle", Events, and Properties

Many games use the idea of one Object throwing or "shooting" another object.  These instructions show how to create a "Thrower" object that aims and "shoots" a projectile Object.
 



Key Vocabulary:

Objects
Methods
Events
Vehicle
Properties



Objects: Anything in an Alice World. 
Examples:
World
Ground
Camera
Light
Chicken
Tank
Humans
Characters

Methods:  Actions objects do.  Programmers can create new Methods by stringing other Methods together.

Examples:
Move
Turn
Roll
Resize

Events: Events are anything a User or "outside force" does to a program.  An event is like a User input.

Examples:
User Left Clicking Mouse on an icon.
User typing a Key.


Vehicle:  All Alice objects are attached to a "Vehicle."   All movement by the object is done in relation to the Vehicle.  If a Vehicle moves, the Object moves with it. 

For example, if you have a scene where you have a "Human" and a "Car," and you want the Human to "ride" or "stick" to the Car.  In the "Human's" properties tab, you would set the Vehicle=Car.  Thus, when the Car moves around the World - the Human goes with it.  

By default - Alice Objects Vehicles are set to the "World."


In Alice programming - you assign Methods to Events:

1. Programmer creates Method "DriveForward" in Car Object
2. Programmer creates Event "When Up Key pressed -> The Car DriveForward Method is called to action.
3. When Up Key pressed, do Car.DriveForward


Keyword Chart:

Objects: "Things" in Alice World
Methods: What Objects Can Do
Move
Turn
Roll
Resize
Make Sounds
Change Shape
Change Properties
Properties: Qualities Objects Have
Vehicle
Color
Size
Location
Orientation in space
Opacity


To demonstrate these concepts we will create a tank that can aim and shoot a projectile object (in our example - the chicken.)

How to create "Aiming Object":

1. Start Alice
2. Click "Cancel" on First Window. (Or go "File-New" to start a new world.
3. Click the green "Add Objects" button and add an Object.  (I picked the Tank Object.)
4. Click "DONE"
5. Click on "tank" in Object Tree



6. Create Method "aimRight"
    a. Click "create new method"
    b. Name method "aimRight"



7. Click on "+" sign next to "tank" in object tree.
8. Click on "turret."



9. Drag "turret turn" into "tank.aimRight" method window.
    a. Select "right" for direction
    b. Set revolutions to "0.1"
    d. Set duration to "0.25" seconds



10. Create Method "aimLeft"
    a. Click on "tank"
    b. Click "create new method"
    c. Name method "aimLeft"
11. Click on "turret."
12. Drag "turret turn" into "tank.aimLeft" method window.
    a. Select "left" for direction
    b. Set revolutions to "0.1"
    c. Set duration to "0.25" seconds

13. Create Method "aimUp"
    a. Click on "tank"
    b. Click "create new method"
    c. Name method "aimUp"
14. Click on "+" sign next to "turret"
15. Click on "barrel"
16. Drag "barrel" turn into tank.aimUp method window.
    a. Select "turn" and "backward" for direction.
    b. Set revolutions to "0.1"
    c. Set duration to "0.25 seconds.

17. Create Method "aimDown"
    a. Click on "tank"
    b. Click "create new method"
    c. Name method "aimDown"
18. Click on "barrel"
19. Drag "barrel" turn into tank.aimDown method window.
    a. Select "turn" and "forward" for direction.
    b. Set revolutions to "0.1"
    c. Set duration to "0.25" seconds.

20. Set Events for Aiming ->
    a. Right Arrow = aimRight
    b. Left Arrow = aimLeft
    c. Up Arrow = aimUp
    d. Down Arrow = aimDown

To Set an Event:

21. Click "create new event."



22. Select "When a key is typed."



23. Change "any key" to "Right"
24. Change "Nothing" to "tank.aimRight."



25. Set remaining Events:
    a. Left Arrow = tank.aimLeft
    b. Up Arrow  = tank.aimUp
    c. Down Arrow = tank.aimDown



26. Click "Play" to and type the arrow keys to see your tank in action!

Ready - Aim - Chicken!!!

Our Tank is going to shoot Chickens out of the Tank!  Here is an overview the steps:

A. Import Chicken Object
B. Create chicken.fire method for the "flying chicken"
    a. Call method chicken orient to tank.turret.barrel
    b. Set Chicken to Visable
    c. Set Chicken Vehicle to World
    d. Call method "move forward" 10 meters.
    e. Set Chicken to Invisable
    f. Call method chicken move to tank.barrel.turret.
    g. Set Chicken Vehicle to tank.barrel.turret.
C. Create Event for Space Bar to call method chicken.fire

Step by Step Directions:

A. Import Chicken Object:

1. Click "Add Objects
2. Click "Local Gallery"
3. Click "Animals"
4. Select the "Chicken"
5. Click "Done"

(The chicken might be hiding inside the tank.  Do not worry if you don't see the chicken.)

B. Create "Chicken.fire" method:

6. Click Chicken on Object Tree.
7. Click "create new method"
8. Name method "fire"
9. Drag "Chicken orient to" to method window
10. Select tank.turret.barrel
11. Set duration to 0 seconds
12. Click "Properties"
13. Drag Opacity to Chicken.fire method and set to 100% and duration to 0 seconds.
14. Drag Vehicle to method and set to "world."
15. Click "methods" tab.
16. Drag "Chicken move" to method and set following parameters:
    a. forward
    b. 10 meters
    c. duration = 0.5 seconds
17. Click on "properties" tab.
18. Drag Opacity to method and set to 0% with a duration of 0 seconds.
19. Click on "methods" tab.
20. Drag "Chicken move to" to method and set to "tank.turret."
21. Click on "properties."
22. Drag "vehicle" to method and set to "tank.turret."
23. Entire "Chicken.fire" method should look like this:



C. Create Event for Space Bar calling Chicken.fire method.

24. Click "create new event."
25. Select "When a key is typed."
26. Select Space Bar
27. Select Chicken.fire
28. Finished "Events" window should look like:



29. Run your program by clicking "Play."

(You might need to add some methods to "world.my first method" to move the chicken to the turret.)

Assignment:

1. Select an Aiming Object and a Projectile Object. 

2. Create a program where the aiming Object aims and shoots the projectile.  Examples Include:

Cannon and Cannon Ball.
Person throwing ball or other object.
Catapult.
Person kicking an object.

3. Save your project into your file area.