LOOPS - INTRODUCTION When writing code, we often want to repeat the same action. Using loops, we can reduce redundancy in our code - that is, we can avoid writing the same code multiple times.
TASK Go to here to open the loops activity. Complete tasks 1-3
USING FOR INDEX, REPEAT AND OTHER LOOPS Games often need to keep multiple variables to keep track of how well a player is doing. When programming in blocks, there are many ways game code needs to increase (or decrease) a count.
TASK Go to here to open the Button Speed activity. Watch the video and read and understand the examples. Using the examples do the Tasks 1-3.
PROJECTILES Projectiles are regular sprites that destroy themselves when they go off of the visible screen. Projectile sprite blocks also expose the properties for velocity (vx, vy), when they are created.
Depending on the game, a projectile can be dangerous, friendly, or even just a decoration that floats across the screen.
Typically, we use projectiles because we want movement for meteors, laser beams, cars, or whatever we decide we need in our games. In many games, a large number of projectiles are created, so the ability for them to be automatically destroyed as they leave the screen will often be very helpful in making sure our games run efficiently.
TASKS Go to here to start doing the projectiles tasks. Watch the videos first.
LOGIC INTRO Logic in software development allows for flexible programs that respond appropriately to different conditions. In this section, we will identify how comparisons can be used within our code. In these activities learners will work with 'if' and comparison operators e.g. <, >, =.
IF AND ELSE COMPARISIONS In our games we will often want to compare values, and take an action based on the result of the comparison.
We could do a comparison test to see: if player score is greater than the enemy score, then we gain points on overlap if the player has 0 lives left, then we set to game over if we have the secret key, then we can enter the room.
TASK Go to here for the 'if and else comparisons' tutorial.
INTRO TO FUNCTIONS In Blocks, FUNCTIONS served as a powerful tool in making complex games easier to read, as well as reducing redundancy within the games. These benefits remain in JavaScript, along with many more features of functions that were unavailable in Blocks.
TASK Functions are created in this tutorial using the text based language called JavaScript. Although it may be strange and different at the start if you stick with it, it's a good learning experience. NOTE: Functions are required for the assessment.