Bubble. Net handheld computer games

Source: Internet
Author: User

Program download


Introduction:
This is a compact framework I provide.
I like traditional games like bubble bubbles. Simple and fun. Many different versions can run on many platforms, but the only version I see on my handheld computer is not open source. So I built a. NET Framework-based compact game. I started the project in December April. When I saw a discussion about this, the project was not completed until December April. Only functions, images, and random game levels are available. Fortunately, others have made improvements, so I have time to advance the project. In any case, many things can be further improved:

Better image (not perfect yet, bubble looks pretty ,)
Some sounds
Credit System
Game Level Control
More levels (the case level is established by notepad. This makes it easy to complete the level editor !)
Add special bubbles (explosion, multiple colors, or others)
Maybe Gapi is used to increase the animation speed (this is rare)
An outstanding multi-user network version (maybe V2.0 or V3.0)
Worse, I don't have a handheld computer. I borrowed one from my boss in the early stage of the project to see if the animation speed is suitable. Then I just used a simulator, therefore, I want to check whether the game works well in a real handheld computer environment. On the game menu, I can find a 'constant frame rate' button. If the game speed is slow, I can adjust it.

Game rules:
The dominant idea is based on the bubble dragon game: The main intention of the game is to clear all bubbles. You have a time limit to launch bubbles. The bubble will stick to the first bubble. If there are more than three adjacent bubbles in the same color, the bubbles will blow up and all the bubbles sticking to the bubbles will fade. The bubble level adds a layer every 8 seconds. The game ends when the underlying layer comes into contact with the transmitter.

Code:
Here are some classes to implement all the parts of the game:
Bubblegame: a main game class that contains all high-level features and game logic (many of which use the 'go' method)
Bubble: This class displays bubbles on the game interface, including relevant information such as the bubble type (color), the position on the game panel, and the bubble in the rectangular area on the screen.
Bubbleimages: in this class, you can find some static methods and fields, which are similar to the buffer of bubble images.
Launcherimages: like the bubbleimages class, which is used to display images.
Bubblesprite: Implements mobile bubbles (player bubbles, and bubbles used for falling and explosion). This class tracks the direction and path of each bubble, make the position on the screen consistent with that on the game panel.
Movingsprites: This class handles the explosion and fall of all bubbles when moving.
Gameboard: This class provides game panels. It can call a hierarchical method to detect the collision events of player bubbles, detect adjacent bubbles and falling bubbles, and detect whether the level is connected to the bottom line. There is a 'createboardbitmap' method used to create the bitmap of the game Panel (Complete background, wall, puzzle, and locked bubble ). This bitmap is cached and used (through the bubblegame class) as the background throughout the game. We only need to draw bubble images from different angles and distances.
Anglehelper: this class is used to calculate the angle and distance of the player bubble.
Graphicshelper: This class contains static members, which are used by different GDI methods (some of which are used for testing purposes ).
Gxinput: This class comes from an msdn game project. This class registers the hardware information of all the handheld computers, which is very important. In this way, when you press a button, a corresponding program will run in the game window.
Several areas of interest:
The first problem is that the control button is more accurate than the related window events.
Fortunately, there is a function in 'coredll. dll 'to solve similar problems:

[Dllimport ("coredll. dll")]
Public static extern int getasynckeystate (INT vkey );

We can use this function in the main game loop (the 'go' method of the 'bubblegame' class ):

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 technology was used at the beginning of the project. At that time, I read some good articles about game development on msdn and used it on the handheld computer. NET development, the author has another point of view: capture hardware clicks, these keys as hot keys: directly run or activate a software. It is very effective in constant use, but it is another annoyance in the game, because in the game we use these buttons for some special features. However, we cannot have dllimport and P/invoke. This reference gxinput: Here is the URL of this article on msdn (http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/dnnetcomp/html/wrapgapi3.asp), register the hardware buttons and use them in the program! In fact, gxinput does other things besides the Registration button, but it has not been used since I added it to the project.
In addition, I have to work around a strange problem: in the main framework of the game, I want to have a menu display button in the upper left corner. The framework itself defines filling the entire screen (minimizebox = false, maximizebox = false, windowstate = maximized ).. No menu is displayed, and the frame is displayed as expected. However, when I add a menu, the window is no longer in full screen mode (the title and start menu appear, to solve this problem, I added a button in the lower left corner of the Framework. When I click this button, the menu is displayed.

Hierarchical Design:
Hierarchical Design is saved in a text file (I created a 'codeproject. LVL 'file, and set 10 levels), you can create your own level, by editing the file, I create a new (required. LVL extension), and then copy it to the game directory. Then you can select it from the menu.
[Level]


, 02
, 03

 

 

Each level design starts with '[level]', and then a series of numbers specify the bubble color.
00 = no bubble
01 = black
02 = blue
03 = green
04 = Magenta
05 = Orange
06 = red
07 = white
08 = yellow

8 bubbles can be arranged for each row, and 10 Bubbles can be arranged. A hierarchical editor will be available in later versions.
How is this done?
The gameboard class contains an array of bubbles:
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 loadlevel method of the gameboard class.

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]);
}
}

When a bubble is created, the constructor specifies its position and type. From the position on the mesh, you can calculate its position on the screen (a rectangle on the screen contains a bubble ). The updatebubblerectangle method of the bubble class updates the information required by the rectangle:
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 position of the bubble on the screen is saved in a rectangle:
The X position is obtained by multiplying the X of the gridposition of the bubble by the width of the bubble, increasing the x offset of the gameboard (on the game panel ), the half width of the bubble is added only when the bubble is on an odd column. The Y position uses the Y value of the gridposition of the bubble to multiply the height of the bubble and the previous constant (bubblebitmap. height * gameboard. row_dist), so each column is 'exceeded ', and the y offset of the gameboard is added at the end (the offset will be changed at each level-this will change the offset of the 8 bubbles at a time ).
The width and height of the rectangle are the height and width of the bubble bitmap.
After a hierarchical editing file is called, createboardbitmap () of the gameboard class is called and a bitmap object is returned. As the background of the game, add the current bubble image with a simple background image. The entire background will be refreshed. When the player's bubble hits the bubble in the game, some bubbles may burst 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

The animation of the transmitter and player is displayed on this 'complete backgrounds (like the fallen and destroyed bubbles ). The bubblesprite class handles player bubble animation. This class has a bubblerectangle attribute that returns the rectangular area of the bubble. (Like the bubble class, this property is used to display animations on the screen ). It also has a positionongrid attribute, which returns a vertex information of the animation. (Compared with the updatebubblerectangle method of the bubble class, this method is mainly used for collision detection ).
This detection occurs every time the player's bubble moves, but is completed in two states:
First, we need to know whether there is one or more bubbles around the player's bubbles. The adjacent information of the current bubble is used for detection. This is the role of the positionongrid method. At the same time, A getneighbors method in the gameboard class returns an array list of adjacent bubble information.
Second, there should be at least one bubble around the player bubble. We need more precise collision detection between the player bubble and the adjacent bubble. This is implemented by the checkspritecollision method of the gameboard class.
The following test is used to calculate the distance between the player and the adjacent bubble:
Dist = (sprite. bubblerectangle. X-OneBubble.BubbleRectangle.X)
* (Sprite. bubblerectangle. X-OneBubble.BubbleRectangle.X) +
(Sprite. bubblerectangle. Y-OneBubble.BubbleRectangle.Y )*
(Sprite. bubblerectangle. Y-OneBubble.BubbleRectangle.Y );

If the distance is smaller than a specified value, the player bubble must be added to the game panel.
After adding the bubble, you need to check whether it is connected by at least two bubbles. If so, these bubbles must be destroyed. Use the getsamekindneighbors method of the gameboard class. Call the getneighbors method of each bubble. Once all adjacent bubbles of the same type are detected around the player, they are removed from the game panel and added to movingsprites. This method is used to track falling or exploding bubbles and animated display.
If some bubbles are destroyed, we need to check whether they disappear from the bubbles on the game panel. The getneighbors of the bubbles that are retained in the game are recursively called from each column, So we confirm that these bubbles should be retained on the game panel. A gameboard class's getfallingbubbles () method. The remaining bubbles will be cleared and added to movingsprites to display the animation effect of the falling part.
Aside from this, there is nothing special: Dual buffering is used to eliminate jitter (many articles have introduced this technology, so I also use it) and uses GDI to draw images and animations.
Conclusion:
I hope to have more time to complete the game and add some better features, such as network functions or special bubbles. I don't know when V2.0 will be updated, if any. I developed it using a simulator because I don't have a handheld computer, and I hope that I can get a good result from this discussion (maybe there will be other better works ). If you want to test the game on your handheld computer, please give your opinion so that I can continue to adjust the code. Thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.