Code a Family Christmas Game ...With Cats | Keyhole Software
source link: https://keyholesoftware.com/2021/12/21/code-a-family-christmas-game-with-cats/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Code a Family Christmas Game …With Cats
Ryan Brewer December 21, 2021 Community, Tutorial Leave a Comment
‘Twas the night before Christmas, when near and within the tree,
Lay a fallen Star Topper …and sounds of rustling!”
Recommended ages: 7+ w/parent
Completion time: ~30 minutes, plus optional drawing time
What You’ll Make
You’ll create a game for you and your family.
Play as the Christmas Tree Star, who’s been knocked off the tree by the (crazy) house cat. Like every Star, you’re far from helpless. You’ll jump your way back to the top. But beware! The (truly crazy) cat is still inside the tree …with black eyes open wide …hunting you.
Getting Started
- Go ahead and play a quick round of the finished game. You’ll click the green flag to start the game.
- Create a Scratch account. (There isn’t an age requirement, but you will need an email address. Politely ask a parent for help!)
- Follow this link to the Tree Topper vs. Crazy Cat Starter Project page and click the green Remix button. When you Remix a Scratch project, you’re just making a copy for yourself.
You should now see something like this:
Click the Tutorials button at the top of the page, and watch the Getting Started video.
Real Star Power
Ensure the Star sprite is selected…
Jumping Power
- Drag the “if playing” block under the “when space key pressed” block to connect them. We’re setting things up so the spacebar only does stuff while someone is playing–and does nothing when the game is over.
- Connect the blue Glide Block below our last Purple block. These four blocks will be our “jump.” The glide block is enough to do this. But since we’re literally a Star, we’re adding some pizzazz by crouching first.
- Move our 4 connected blocks inside the “if playing” block. To move a group of connected blocks, grab them by the block on top (the purple one). See the picture below.
Now read the whole block back to yourself. It isn’t perfect English, but it is readable! “When the space key is pressed, if the game is being played then crouch for a short spell, stand, and glide! AKA Jump!”
Try using the pictures instead!
The GIVEN, WHEN, THEN style of describing our game is popular amongst bonafide software engineers!
Tinker with it! Change each of the numbers in it, but just one at a time. Play the game after each change. How does each one affect the jump?
The Power to Win
- We have two blocks left. Grab the light blue “touching mouse-pointer” block and drop it into the pink “End Game If” block.
- Change “mouse-pointer” to “edge”
- Drag the pink block inside the “If” block, so it’s the last one inside.
Crazy Cats get Written Up
It’s time to write code for that cat. Click the Cat Sprite to select it.
Cats Prefer Stalking to Stockings
Noodle on that for a second. Can you figure out which two blocks can make that happen?
Micro hint: they’ll connect to the “when I receive start game” block.
- Attach the “repeat until” block to the “start game” block.
- Drag the pink “hunt” block inside the “repeat until” block.
Say Bah Humbug Without Saying Bah Humbug.
Can you fit the rest of the blocks together just by reading the statement above? If not, follow the next steps.
- Attach the “if cat found the star” block below the “hunt” block, but inside the “repeat until” block.
- Drag the pink “attack” block inside the “if” block.
Now that the Cat can hunt, read the blocks back to yourself. Just like our Cat, it’s (somewhat) readable! “When I–a most amazing cat–hear that a game has begun, so long as someone is playing this game I can Hunt the helpless little Star, and bat it from my tree.”
Put a Bow on It
Make this game your own. Draw your own Star and Cat!
Draw your own Star
- Select the Star character
- Go to the Costumes tab
- Select “My Stand” and draw your star, standing
- Select “My Crouch” and draw your star, crouching
- Go back to the Code tab and change the Costume Blocks to use “My Crouch” and “My Stand”
Try to make your standing and crouching Stars roughly the same size as mine. You don’t have to be exact.
Draw your own Cat
Follow the same steps as you did for the Star. To find the purple costume blocks, scroll to the right. See them? They’re under the Cat’s “Attack” block!
That’s a Wrap!
You may have noticed we didn’t code all of the features, like the Timer or the Introduction (when the Cat knocks the Star from the top of the tree). I hid these since they were a bit too complicated for this tutorial.
One of my favorite ways to learn to code is to tinker, so go ahead and play around! You can save copies of your project by clicking File, then Save as copy.
Enjoy your game! And have a very Merry Christmas!
Side note: If getting paid to write blogs in your free time is something you’d enjoy, check out our Careers page. It’s an exciting time to join the Keyhole team, and we may just have a spot for you!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK