Space War�(The concept of cloning)
Vineet Srivastava
So, what is cloning
2
www.wibyte.in
Control
The three relevant blocks
Let’s start with an example
3
www.wibyte.in
Create Knight and KnightWeapon sprites
4
Knight is a built-in sprite, knight Weapon we painted. Make sure the painted sprite is in the centre of the canvas.
www.wibyte.in
Getting Knight to shoot Weapons
5
After the flag is clicked, If I click SPACE bar, Create a CLONE of the sprite ‘KNIGHT Weapon’
When a CLONE is created, make it go to the KNIGHT and then move.
Every time the space bar is clicked, the ‘knight’ appears to shoot a new Weapon.
www.wibyte.in
Speed of the Weapons
6
With this variable, we can control how fast (how many steps) the Weapon moves
Note, this is NOT a new loop. Just a replacement of 10 with the variable knight Weapon speed.
www.wibyte.in
DELETE the clones too
7
One the sprite reaches the ‘EDGE’, delete the clone.
This is extremely important as every clone takes up memory. If we do not delete them, eventually the program will crash.
www.wibyte.in
A point of caution
8
Moving the knight
9
www.wibyte.in
Add Knight’s Enemy – A retro robot
10
Note: We changed the SIZE to 40%, and used FLIP HORIZONTAL to make the Retro Robot face the knight.
www.wibyte.in
Code to move Retro Robot
11
www.wibyte.in
Keeping track of the score
12
Add this to the KnightWeapon code
Variable
If the Weapon hits RETRO
Remember to delete
www.wibyte.in
Let’s give some ammunition to RETRO also
13
www.wibyte.in
Make changes to the RETRO Weapon CODE
14
On becoming a clone, go to RETRO ROBOT
Move according to RETRO ROBOT speed.
If touching knight, increase retro score.
Negative, because RETRO Weapon must move LEFTWARDS
www.wibyte.in
Creating clones of RETRO Weapon
15
Every ‘retro Weapon wait’ seconds, Create a clone of RetroWeapon.
Variable added
www.wibyte.in
Coding the ENDING Conditions
16
www.wibyte.in
Implementation
17
TIME OVER
RETRO REACHED ITS TARGET AND WON
KNIGHT REACHED ITS TARGET AND WON
Relevant Variables
www.wibyte.in
Receiving Ending Broadcast messages
18
www.wibyte.in
And you are all set!
19
www.wibyte.in
Extra Innings
20
Cloning is NOT the same as STAMPING
www.wibyte.in
Ideas to make your game more difficult (1)
22
Note: For this, RETRO Weapon SPEED must be made more than 0. This is unlike earlier when we did not touch the direction of the Weapon and hence had to make it move <negative> number of steps
www.wibyte.in
Ideas to make your game more difficult (2)
23
www.wibyte.in
Ideas to make your game more difficult (3)
24
www.wibyte.in
Ideas to make your game more difficult (4)
25