Breakout game

You need to use the starting file. You should be able to expand the Objects folder and see these objects ready to go, and the Rooms folder has a room in it.


1. Bat & Ball

make sure the bat doesn't leave the room

Open the bat object and add the following action:

  • Collision with wall 
    • Bounce (all objects)

Make the bat move a bit left or right of where it is by adding Keyboard events for <Left> and <Right>... for each event add the Jump to Position action - setting the X values (Left = "-12", Right = "12"), and checking the relative box.

ball moves on its own

Open the ball object. 

Add the Create event with the Move action (4 corners, speed 8).

ball bouncing off walls

  • Collision with wall 
    • Bounce (all objects)

ball bouncing off bat

  • Collision with bat  
    • Bounce (precisely, all objects)

ball bouncing off stones

Add more events... Collision with all the stones. You can duplicate the Collision with bat event for all the stones - they're all bouncing precisely with all objects...

  • Collision with stone 
  • Collision with damaged1  
  • Collision with damaged2 
  • Collision with damaged3

When you've duplicated that event for all the stones, your ball object should look like this...

when ball leaves the room

Add another event: Collision with die

    • Jump to Start (default)
    • Set Lives to "-1", relative
    • Sleep (just pauses 1 second)

Room

Open the room already started.

Open the room already started. For now keep the grid at 16x16 

  1. Place the die marker along the bottom row.
  2. Place the ball somewhere in the middle.

Change the grid to 32x32. Then add stones near the top, spaced out like this...

Test it out - make sure the bat is moving properly to edges of the room; the ball should bounce off the stones and walls, if the bottom, then it starts in the middle starting position again.


2. Stones Decaying

change into next type of stone

In the ball object, we need to add some an action to the Collision events (with the stones).

  • in the Collision with stone event you already have...
    • Change Instance (other, change into "damaged 1", perform "not")
      set to "other" (or else it will affect the ball if set to "self").
  • Collision with damaged1
    • Change Instance (other, change into "damaged 2", perform "not")
  • Collision with damaged2
    • Change Instance (other, change into "damaged 3", perform "not")

The last one, we again change it into the last damaged stone, but this time say "yes" to perform so it performs the event under the "damaged3" object.

  • Collision with damaged3
    • Change Instance (other, change into "damaged 3", perform "yes")

make last stone disappear

So when the last stage of stone appears, we want it to totally disappear. We also want to give the player points every time we destroy a stone. This must be before it's destroyed or it won't happen!

 

Go into the damaged3 object. Add a Create event with a Destroy Instance action (default/self).

  • also add the action Set Score to 10, relative 

TEST YOUR ROOM: You should test out your room - do the stones get destroyed gradually? If you see it work for a couple stones, you can keep going.


3. Score, Lives

Obj: controller

Create a new controller object, with no sprite. 

  • Create 
    • Set Lives to 10, not rel.
    • Set Score to 0, not rel.
  • No More Lives
    • Show highscore table (default sttgs)
    • Restart the Game
  • Draw
    • Draw Score (40,40), caption "Score:", not relative
    • Draw Lives (150, 40), caption "Lives:", not relative

Room

Make sure the grid size is still 32x32 and place 12 stones like this. Place the controller object in the room and test it out:

  • do you get points as you destroy a stone?
  • does the score and lives show?

When you're playing you must see the score and lives at the top with spacing before the stones start. When you start your game it should look like this...

After playing a bit, you should see the score and lives amounts change...


4. All stones destroyed?

Now we need to set things up for what happens when all the stones are destroyed.

  1. Create a variable that will first count how many stones are in the room.
  2. Then have a Step event so it constantly checks if all the stones are gone.

count how many stones in room

Go into your controller's Create event and add Set Variable - give it a name MyStones and type in instance_number(stone). Make sure you use round brackets, and that your "stone" object name matches.

check if all stones gone

Then add a Step event with the following actions:

  • Test Score - see if all the stones are gone = calculation of "My Stones" multiplied by 10pts each - when player reaches that score, it means all the stones are gone.
  • If yes, then (put both inside start & end blocks)...
    • Display message "Congratulations!# You've completed the game"
      # means it goes onto the next line in the message.
    • Show highscore table
    • End the game

Room

Now when you play your game

  1. show the teacher when you've destroyed a few stones, how it looks.
  2. Continue playing until all the stones are destroyed - call the teacher over to see when you've destroyed all the stones and get the message.