- If you are coding outside of WoofJS.com (like in Sublime), insert the Woof_JS source tag into the <head>section of your project page:
<script src="https://rawgit.com/stevekrouse/WoofJS/master/dist/woof.js"></script>
Your code now speaks Woof!
- Find an appropriate backdrop (farm if you are catching apples, a circus tent if juggling pins) and add the url to the setBackdropURL call.
- On the web, find two transparent images: an apple (or whatever you are ctching) and a farmer or another catcher. Save the URL's for the images.
- Add two image sprites. Use code from the Sprites & Backgrounds section of the Woof documentation.
Now change the url: attribute in the sprite objects to be that of the images you found.
- Add a forever function to your code. (Hint: look in the Control section of the Woof documentation)
This will take care of updating changes in the game in real time.
- Inside the forever function, get your Catcher to move right or left if arrow keys are pressed.
Look in the Sensing section if there is an instruction that checks if a key is pressed. Copy it and put it inside an if statement:
Something like:
if (keysDown.includes('LEFT')) { //move the catcher left 10 pixels }
- Declare a text label for the score using a Text sprite.
- Create a variable (call it appleSpeed) and inside the forever loop, have the apple drop by that number.
- Check for apple hitting the bottom of the screen. If that happens, subtract 1 point and return the apple to the top of the screen.
- Add a check for the catcher catching the apple. If this happens, add points, and also return the apple to the top of the screen.
- Show the score in the score label
How do like the game now? Are you ready to have many apples falling at the same time?
- Add an array called all_apples.
- Outside the forever loop, add an Every loop that creates a new apple every 2 seconds, and pushes it into the all_apples array
- Inside the forever loop, add a forEach function that cycles through all the apples.
all_apples.forEach ( apple => { //move the code to move the apple, check if the apple was //caught or hit the bottom of the screen HERE })
- Increase the speed of the apples as the score gets higher
- Play a sound every time an apple is caught
- Keep working on the project and customizing until you are satisfied.
Ask your teacher/TA to upload it to your public folder.