martin2k
ForumsVB6GamesSoftwareDirectoryHTMLArticlesBlogContact

May 2014

Blog

2017

Current Month

August

July

March

February

2014

August

May

January

2013

November

October

September

August

July

June

April

March

February

January

2012

December

October

September

August

2010

June

2009

August

May

February

2008

November

October

July

January

2007

December

November

October

Subscribe Subscribe

 

Saturday 31st May 2014

[Top]

Martris

As promised yesterday, here is an overview of how I went about creating my Martris game.  The story behind this is fairly simple.  Those who know me know that I enjoy playing retro games.  It is a cliché, but just because games these days can now be played in full HD, it does not necessarily mean that they are more enjoyable than those played in 4 colours at a resolution of 160 × 144 pixels.  Back then, we had to use our imagination more than with today's games.

One of the biggest selling games for the Game Boy was Tetris.  Unless you're over the age of 60, then it is likely that you are aware of this game or have even played it.  Sometimes I go through phases of playing certain retro games and back in March this year, Tetris (and Dr. Mario) were my games of choice.  This lead me wanting to create my own version using my usual programming language of choice - VB6.

I have had experience of creating games before with game creation software.  This started with Klik & Play and after that with slightly more advanced software, namely The Games Factory.  My last game was made with Multimedia Fusion (MMF).  My list of games on martin2k Games can be found here.  With VB6, making games is a completely different ball game, so to speak.  Essentially, when starting a new VB6 project, you are presented with an empty form and a text editor, where you must enter instructions defining how everything works together.  There is no event editor as such and no quick and easy way to detect object collisions, etc.

New VB6 Project
New VB6 Project

Fortunately I had some past experience with creating VB6 games.  In a course I did once upon a time, I made a Pong game.  This pretty much included all of the main elements needed - collisions, moving objects and sound effects.  VB6 was never really intended as a way of creating graphical games and as such does not include any built-in functionality for this.  The fundamental component, in this case the BitBlt functionality, has to be called from an external source.  The command needed to include this in my project is:

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Const SRCAND = &H8800C6
Const SRCPAINT = &HEE0086
Const SRCCOPY = &HCC0020

Very simply, this allows bitmaps to be manipulated within a container, which in my project is a PictureBox control.  It allows me to update the display with the new position of the block when it falls or is moved by the player, without interfering with the rest of what is displayed, such as blocks that had landed previously.  This is something that would be dealt with automatically by software such as MMF, but when writing real programs, everything has to be considered.  The benefit is that you have much finer control over how everything works, but there is also much more of a chance that things can go wrong and be more complicated to implement.

Fortunately sounds are much simpler.  I used sndPlaySound of winmm.dll.  It is just a case of using the following line to play a .wav file (where 'ap' is a variable representing the application path):

sndPlaySound ap & "\linedone.wav", SND_ASYNC

Another thing that you don't have to think about with software such as MMF is the location of objects already in the game.  For Tetris, when a block lands, the game needs to keep track of this so that when another block falls down, it does not just fall straight through.  In other words, what happens on screen has to be kept track of in the background.  To achieve this, I used my ever versatile Configuration File ActiveX control.  While playing, this contains an array of X and Y coordinates to indicate where individual blocks are located.  Every time the game detects a movement of a game piece, it first refers to this array to check that there is nothing in the way of where the piece is due to go.  If there is not, the game allows the piece to move, otherwise it does not.  A similar method is employed to detect if the player is due to move a piece into one of the walls that are situated on the left and right of the screen.  When a player wants to rotate a piece, the game first has to check that the rotated piece will not end up in the same position as other blocks that have already landed.

Blocks on top of other blocks
Blocks on top of other blocks

When the player gets a line, the Y coordinates of all blocks above where the line occurred have to be reduced by one.  Additionally, BitBlt is used to move them graphically down one line's worth too.  The game gives more points for getting more than one line at a time i.e. you would get points more for getting two lines at once rather than one line after another.  The game also keeps a high score list:

High Scores
High Scores

There are no predefined game pieces in Martris.  All pieces, regardless of whether they are made from 1 or 8 blocks, are randomly generated.  This includes the colour of the blocks too where the game chooses at random from bitmaps located in the same folder as the game.  I kept 8 as the most blocks a piece could be made from, otherwise it could make for a very difficult game for the player.  To illustrate this, I changed the code so that pieces made from 20 blocks are generated.  As you can see, there is no way you would get anywhere with pieces like this!

20 blocks per piece!
20 blocks per piece!

The beauty is that you can start the game with 4 blocks per piece and you are then playing the game with the traditional pieces:

New Game window
New Game window

The game uses a standard VB6 Timer control to determine when a piece should drop.  As the level of the game increases, the Interval property of the Timer is increased to make the piece fall quicker.

I was hoping to record a video of me playing a normal game, but have run out of time for today.  Instead, you can watch the video of when I played using a game width of 4.  See yesterday's blog entry for this.  Please get in contact if you have any questions or want to know more.

The forum link for Martris can be found here: Martris and you can download the game from CNET Download.com:

Get it from CNET Download.com!

 

Friday 30th May 2014

[Top]

Anniversaries

Firstly, I cannot believe that I have not posted a blog entry since January!  Thanks to the Open University degree that I am undertaking at the moment, it has been impossible to fit things like this in.  Frankly I have grown tired of looking at that 'Placeme' entry on the home page for such a long time!

However, I am now on a break and intend to make the most of it.  One thing I was able to do when not studying was to develop an app, which has so far proven to be pretty useful to my wife and I.  One problem we both have had for a while was trying to remember people's birthdays and anniversaries.  So as always, I thought "I can make an app for that!"

Basically, my app consists of a grid allowing the user to enter a birthday or wedding anniversary for any date of the year:

Anniversaries Main Screen
Anniversaries Main Screen

It is not much to look at right now, but really it's only intended for my use at the moment.  This is not the real beauty of the app, however.  By adding a scheduled task (for me I have set this to 8:30pm daily), to run the app with a '/sendmail' argument, it will send my wife and I an e-mail on the day that someone has their birthday or anniversary.  Not only that, but I have configured it to warn us when an event is due to take place in 1, 2, 3, 4, 5 and 10 days time.  An example of an e-mail that would be sent out today (30th May) based on the sample information in the screenshot, would be:

Subject: Birthdays & Anniversaries

The following events are happening today:

Chris's 25th Birthday


The following events will happen in 1 day (1st June 2014):

Jane's 50th Birthday

Please get in contact if you would be interested in having a copy of this app.  One day I hope to release it, although I am aware that there are other apps, etc. which can do this already.

Martris

Soon I hope to post a blog entry about how I created my VB6 Tetris-clone, Martris.  The forum link to it is here: Martris

Martris (Tetris-clone) 4 x 27 Game Size

 


blog comments powered by Disqus
Martin Allen 1999 - 2014.  Last updated Saturday 31 May 2014 11:58:11 PM.
Powered by Blog2k