|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis is my contribution to the CodeProject compact framework contest. (and my first CodeProject article !) I always loved the original Puzzle Bobble game. It's simple, yet addictive. Many variants are playable on many platforms, but the only clones I saw for Pocket Pc were not free. So why not create a free and open source .Net compact framework variant of this famous game ? I started this project from scratch at the beginning of April, when I saw that CodeProject organized a contest, but at the end of April, it wasn't finished. It was functional, but did not have any graphics, and only had a random level generator... Happily, they extended the deadline, so I had time to improve the whole thing :). Anyway, a lot of things could be enhanced further more:
It's worth to be noted that I currently do not own a Pocket PC, I borrowed my boss' ppc at the beginning of the project (thank Patrick !) just to see if the animation speed would be decent, but after that I only used the emulator, so I hope that it will perform nicely on a 'real' pocket pc ! In the 'Menu' button on the game screen, you'll find a 'Constant frame rate' entry, uncheck it if the game is too slow... Game rulesThe main idea is based on the famous Puzzle Bobble game: the goal of the game is to destroy every bubble on the board. You have a limited time to launch a colored bubble on the board. The bubble will 'stick' on the first encountered bubble. If there's more than three bubble of the same color on the board, they explore, and every bubble that's not attached will fall as well. The ceiling will get down every 8 launched bubbles. You lose a live when a bubble reach the deadline (the red line). Using the codeThere's a class for each important part of the game:
Points of InterestOne of the first problem I had on this project, was to handle the key presses more accurately than the key related events of the winforms... Happily, there's a function in 'coredll.dll' that satisfied this need: [DllImport("coredll.dll")]
public static extern int GetAsyncKeyState(int vkey);
We can use this function in the main game loop (the if ((GetAsyncKeyState((int)System.Windows.Forms.Keys.Left) & 0x8000) !=0)
angle+=2; //x--;
if ((GetAsyncKeyState((int)System.Windows.Forms.Keys.Right) & 0x8000) !=0)
angle-=2; //x++;
This technique was used at the very beginning of this project, but
meanwhile, I read a series of excellent articles on MSDN that talked about game
development on Pocket PC with the .Net Compact Framework, and the author
addressed another issue: intercepting the hardware keys. Those keys are like
hot keys: they launch or activate an application directly. The feature is
useful in day-to-day use, but is very annoying for games, because sometimes we
want to use those keys for specific tasks. But we can't without some cumbersome
Otherwise, I had to work around a strange problem: in the Main game form, I
wanted a menu to appears at the bottom left corner. The form itself was
configured to fill the whole screen ( Level DesignThe level design is saved as plain text file (I created a 'codeproject.lvl' sample file with ten levels), you can create your own levels by editing the sample file, or by creating new files (those files must have a .LVL extension), and they must be copied in the game directory. After that you can select the level file on the main menu. The structure of the file is very simple: here is the first level: [Level]
06,06,08,08,02,02,03,03
06,06,08,08,02,02,03,00
02,02,03,03,06,06,08,08
02,03,03,06,06,08,08,00
Each level begins with '[Level]', after that, we have a series of numbers indicating the bubble color of each cell: 00 = no bubble
01 = Black
02 = Blue
03 = Green
04 = Magenta
05 = Orange
06 = Red
07 = White
08 = Yellow
Each line can have up to 8 numbers, and each level can have up to 10 lines (such a level is hard to finish, because the last line is very near the deadline !!!). In future releases, there will be a level editor that will enable you to create levels more easily... How is it done ?The private Bubble[][] gameBoard = new Bubble[GRID_X_SIZE][];
Each Bubble has a kind (a color) and a position on grid, those bubbles are created
in the int[,] BubbleData= this.GetLevelData(LevelFile,LevelNum);
for (int x=0;x<GRID_X_SIZE;x++)
for (int y=0;y<GRID_Y_SIZE;y++)
{
if (x!=GRID_X_SIZE-1 || y%2==0)
{
if (BubbleData[x,y]!=0)
this.gameBoard[x][y] = new Bubble(x,y,(BubbleKind)BubbleData[x,y]);
}
}
Each time a bubble is created, its position on grid is specified in the
constructor, as well as its kind. From its position on the grid (the public void UpdateBubbleRectangle()
{ this.bubbleRectangle = new Rectangle(
(int)((this.gridX*this.bubbleBitmap.Width)+
GameBoard.X_POS_OFFSET +((this.bubbleBitmap.Width/2)
* (this.gridY%2))),
(int)(this.gridY*(this.bubbleBitmap.Height*GameBoard.ROW_DIST)
+GameBoard.Y_POS_OFFSET),
this.bubbleBitmap.Width, this.bubbleBitmap.Height); }
The on-screen position of the bubble is stored in a Rectangle with the following bounds:
CreateBoardBitmap()
of the GameBoard class is called and returns a
Bitmap object. This Bitmap is used as the 'full background' of the
game, since it's made up of the 'simple background' (the ceiling, floor, walls,
and background image) plus the images of the remaining bubbles of the current
level. This 'full background' will only be refreshed if the player bubble hit
another bubble and stick on the board, or if, after a collision, some bubbles
pops out or fall.
public Bitmap CreateBoardBitmap()
...
for (int x=0;x<GRID_X_SIZE;x++)
for (int y=0;y<GRID_Y_SIZE;y++)
{
oneBubble= this.gameBoard[x][y];
if (oneBubble!=null)
{
oneBubble.UpdateBubbleRectangle();
// update the bubble rectangle in case of board shift down
gameBoardGraphics.DrawImage(oneBubble.BubbleBitmap,
oneBubble.BubbleRectangle,0,0,
oneBubble.BubbleBitmap.Width, oneBubble.BubbleBitmap.Height ,
GraphicsUnit.Pixel,
BubbleImages.GetTranspImageAttr());
}
}
...
return gameBoardBitmap
On this 'full background' the launcher and the player sprite are drawn (as
well as falling and destroyed bubbles). The player sprite is managed by the
This detection occurs each time the player bubble moves, but is done in two phases:
After the player bubble is added to the gameboard, we need to test if this
bubble is surrounded by at least two bubble of the same kind, if it's the case
those bubbles must be destroyed. This test is done by the
If some bubbles were destroyed, we need to test if they leaved some 'floating'
bubbles on the GameBoard. The 'floating' bubbles are detected by recursively
calling Beside this, there's nothing really special: double-buffer was used to prevent flicker (there's a lot of articles that detail the use of double-buffering technique, so I won't dive into it...), and GDI+ was used to draw the sprites on screen... Last words...I hope that i will have some time to finish this game, and add some cool features, like network multiplayer mode, or special kind of bubbles... I don't know when the v2.0 version will be out, if there's any! I developed this game with the emulator, as i don't own a real Pocket PC. That's why i entered this contest, hoping i would have a chance to win... (Seeing the awesome work of some other competitors, it will be very hard !). That's why i created a GotDotNet workspace at http://workspaces.gotdotnet.com/bobblenet. If you are interested and you have cool ideas, some graphics or code that you think useful to this project, join me !And please, give me some feedback if you tested this game on a real Pocket PC, so i can fine-tune the code... Thanks ! Useful Links
History
|
||||||||||||||||||||||