Class 13
Class 13
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
PRO-C13
1. Practice the switch statements, It is used to control the flow of a program, it is also
known as a type of conditional statements. Switch statements allow the execution of
a specific code block based on the value passed to it. You developed a code to check
whether an alphabet is a vowel or not.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
PRO-C13
2. Use switch statements in Trex to give different obstacle images to the same sprite.
3. Start with fixing the memory leak issue: Even after sprites are gone out of canvas, it
still occupies space in the memory, which eventually makes the game slow or crash.
This is known as the Memory Leak issue. To fix this issue:
● We need to remove each sprite manually
● Or make them destroy by giving them a lifetime.
● We assigned lifetime to each cloud variable which is getting created.
● Formula for lifetime: Time = Distance/ Speed; 400 /3 = 134
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
PRO-C13
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
PRO-C13
5. Use string concatenation, two strings / numbers & string can be joined together using
+ sign. Like this: "Hello" and "World":
OUTPUT:
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
PRO-C13
OUTPUT:
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
PRO-C13
6. Build a simple scoring system. We used the frameCount as the score., as frame count
keeps increasing as the game progresses. String concatenation concept is used to
display the score:
OUTPUT:
7. Create an empty function called spawnObstacles and call it inside the draw()
function:
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
PRO-C13
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.
PRO-C13
OUTPUT
What’s next?
In the next class we will write code to build collisions with the obstacles and use game
states which we learned in the last class.
© 2019 The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to
share any part of this message with any third party without a written consent of the sender. If you received this message by mistake,
please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.