This add-on will walk you through how to code a hidden surprise in your display window.
To start, add a new sprite by clicking on “choose new sprite from library.”
This project will use the gift to surprise the shopper with a discount, but you can pickany sprite you’d like. Next, make the sprite go to a location whenthe flag is clicked. Drag out a “when flag clicked,” and a “go to” block.
Snap them together. Now, whenever the flag is clicked, the sprite will go to the same x and y pointon the stage. Next, decide what kind of surprise you wantto program for your window display. Drag out an “if-then” statement from thecontrol menu and snap it under the “go to” block. Add a “touching” block from thesensing menu into the “if-then” statement. Select “mouse-pointer” from the dropdown menuin the “touching” block so the condition reads: “if touching mouse-pointer, then...”
In this example, the gift will say “You get 20% off!” using a say block from thelooks menu. You can make your sprite do whatever you want when the mouse-pointer touches it.
Now, test it out!
Nothing happens when the mouse-pointer touches the gift. That’s because the sprite checksif it's touching the mouse pointer once.This sprite should check the conditional statement continuously,so place a “forever loop” around the “if-then” statement.
Now test the code.
Awesome! The gift says “you get 20% off!” when the mouse-pointer touches it.
For an added challenge, you can program the gift to hide when the green flag is clicked,and appear when the mouse-pointer touches it.
Click on the Looks menu, and add a “hide” block right after the “when flag clicked”block, and add a “show” block inside the “if then” statement.
Test this out!
Awesome. You can also add a “pick random” blockinto the x and y coordinates of the “go to” block. This will increase the difficultyof a shopper finding your hidden surprise. Do this by dragging a “pick random” blockfrom the operators menu, and placing it inside the x and y positions in the “go to” block.
The sprite will now go to a random position when the green flag is clicked.
The values in the pick random blocks should not go outside of the range of the storefront window.
The width of the storefront is negative 240 to positive 240. Enter these values intothe “pick random” block for the x-coordinates. The height of the storefront is from negative180 to positive 100. These values should go into the “pick random” block for the y-coordinates.
Test this out.
Every time the green flag is clicked, the gift hides, goes to a random spot within thestorefront, and waits until the mouse-pointer touches it. Once the mouse-pointer touchesthe hidden gift, it says “You get 20% off!”
You can make anything happen using the motion and looks blocks. Consider using sound blocks as well!
Remember to test your code often, and put up a sticky note to get the attention of yourCS First Guru if you have a question.
Choose an Add-On
Create a sprite that changes colors when the mouse hovers over it.
Create a sprite that will perform different actions in response to its surroundings.
Code a hidden surprise in your display window.
Code your sprite to go crazy when the mouse-pointer touches it.