Author Topic: Ch. 3 Blocks Game: Enhancements  (Read 205 times)

0 Members and 1 Guest are viewing this topic.

Offline SJS1971

  • Visitor
  • *
  • Join Date: Aug 2012
  • Posts: 1
  • Karma: 0
Ch. 3 Blocks Game: Enhancements
« on: August 29, 2012, 07:28:35 AM »
I'm a dad, and I've been using J. Harbour's book to teach programming to my 11-year old daughter.  She has played breakout-style games on the computer and on cell phones, and so she's brimming with ideas to expand the Ch. 3 blocks game.  (In the long run it may be better to extend the GDI+ blocks game from the later chapters.)

I thought I'd share her enhancements so far.  First, she added a Pause button at the top of the form called btnPause. Here's its Click event:

Code: [Select]
    Private Sub btnPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPause.Click
        If btnPause.Text = "Resume" Then
            btnPause.Text = "Pause"
            Timer1.Enabled = True
        Else
            Timer1.Enabled = False
            btnPause.Text = "Resume"
        End If
    End Sub

This simple routine stops the timer and changes the text of the button to "Resume".  In that state, pressing the button restarts the timer and changes the text back to "Pause".  (The text property must be set to "Pause" initially.)

More interesting, she decided that black blocks wouldn't be breakable blocks, they'd just be barriers.  This turned out to be very easy, because the CheckCollisions subroutine in Ch. 3 already had an argument for whether or not to hide a PictureBox after it had been "hit".  This was to keep the Paddle from disappearing, but it also means you can easily keep any block from disappearing too.  We wrote a Function to determine if a block was breakable by checking its color:

Code: [Select]
    Private Function BreakableBlock(ByRef block As PictureBox) As Boolean
        If block.BackColor = Color.Black Then Return False Else Return True
    End Function

Then it was just necessary to alter the CheckCollisions subroutine:

Code: [Select]
        CheckCollision(Paddle, False)
        CheckCollision(Block1, BreakableBlock(Block1))
        CheckCollision(Block2, BreakableBlock(Block2))
...etc.

The first line is unchanged - the program checks the Paddle for a collision but because the False argument is sent, the Paddle is not hidden when a collision is detected.  For each block, True or False is sent to CheckCollision() depending of what Function BreakableBlock decides.

Next we will work on the AllGone logic so that a level ends when all of the breakable blocks have been destroyed.  I think she is going to brainstorm other color-based properties for the blocks.  Some can be worth more points, some could provide an extra life, some could shrink or expand the paddle, speed up or slow down the ball, and so on.  There's a lot of room for creativity with this game.  If we get really ambitious, we could make a Level Editor that works along the lines of the RPG level editor in the later chapters.  That will require rewriting how the screen is drawn, but it would be a good learning experience.



Online twobitcoder

  • Administrator
  • Expert Member
  • *****
  • Join Date: Mar 2007
  • Posts: 4,437
  • Karma: 64
    • www.jharbour.com
Re: Ch. 3 Blocks Game: Enhancements
« Reply #1 on: August 29, 2012, 08:31:07 AM »
That's a great way to learn! Good job, dad and daughter team!
Teach Yourself Android Game Programming in 24 Hours