![]() ![]() Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) I want the ball to reappear twice, once after each death (the player has 3 lives). When the number of score reaches 112 (Total number of brick), the game will stop and display ‘You Win” Screen.Hey! I am currently coding a simple brick breaker game in Greenfoot and I am struggling with getting the ball to reappear on the screen after falling off the world at the bottom. Type the number of points needed to win the game. Insert the Score block into the equals block from the Operators category. When the number of lives reaches 0, the game will stop and display a Game Over Screen.So let’s first create a new Game Over backdrop: Type the number of lives needed to lose the game. Insert the Lives block into the equals block from the Operators category. Winning and Losing Condition For BackdropĪlways start the game with our main background by adding this code to the backdrop Keep “score”, which will increase by 1 when the brick is hit by the ball. The brick should appear at the start of the game and disappear when the ball touches it. Forever, check if it is touching the ball.When the green flag is clicked, show itself.The bricks are pretty simple to program – they only need to do two things. Cloning saves you a lot of time! Make the Brick Disappear When Ball Hits Then, if you wanted to change the code or color, you’d have to change it to all 112 Brick sprites. Imagine if you duplicated the sprites instead of cloning them. After all the clones have been created, the original sprite hides itself.14 Brick clones in a a row multiplied by 8 rows results in total 112 Brick clones.The repeat 8 block repeats the row-creating code to create 8 rows of Brick clones. ![]() The repeat 14 block repeatedly moves 30 steps to the right while making clones of itself, resulting in a row of 14 Brick clones.Move the original brick sprite to the top-left corner of the Stage.If the ball touches the Line 3 times, stop the game completely! Brick Breaker Scratch Game Code Brick Breaker Game on ScratchĬloning should be used whenever a project should have many similar sprites doing similar things. Create one Brick sprite and then clone it using ‘ create clone of myself’ block from “Control”. Bounce Off the Line: Every time the ball touches the ground, one life is lost. Bounce Off the Paddle: Make the ball bounce,When the ball hits the paddle.Ĭ. Bounce Off the Walls: Make the ball bounce when it hits an edge using the ‘If on edge bounce’ block.ī. you’ll make the ball sprite bounce around the screen.Ī. Insert the pick random block and type in -75 to 75. But also the bit where the game starts to come together.Ĭlick to select the Ball sprite. Make sure it covers the whole stage, but is completely below the paddle. Place the ‘Line sprite’ at the bottom of the screen. Tip: If the paddle hits the ball, make it smaller to make the game harder! The Line: If the left key is pressed, the paddle should move left, and if the right key is pressed, the paddle should move right.Alternatively, arrow key on keyboard can also be used to control the paddle.If the mouse moves left, the paddle should move left, similarly, if the mouse moves right, the paddle should move right.Make sure the paddle moves with the mouse.The paddle is pretty easy to code, just a couple of simple instructions. Paddle can be controlled either using mouse or keyboard. Make the paddle controlled with the mouse. Make the Brick disappear when ball touched.Make the paddle that moves left and right with mouse.Lets sketch out the Brick Breaker Game on Scratch. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |