0% found this document useful (0 votes)
22 views2 pages

Bomberman Project

This activity will use the Bomberman sprites and masks to create a BitBlt application. Set the picture boxes to 'Visible False' and make the form and pictures 'AutoRedraw True'
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Bomberman Project

This activity will use the Bomberman sprites and masks to create a BitBlt application. Set the picture boxes to 'Visible False' and make the form and pictures 'AutoRedraw True'
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Bomberman

For this activity, we will use the Bomberman sprites and masks to create a BitBlt application. Try to follow the directions as closely as is possible. Any missed steps will prevent your application from working. 1. Open the project bomber from the OutBox (Johnston) and save as the project and form to your G:\ drive. You will build a working BitBlt application from this file. 2. Set the picture boxes to Visible False, and make the form and pictures AutoRedraw True. 3. Add the code module from BitBltExample (from the OutBox). To do this, go to the Project menu and select Add Module, then choose the Existing tab and find the Module file from the OutBox. By doing this, you dont have to type in any BitBlt function coding and can just focus on the command line coding. 4. Create a KeyDown event for the Form, and in it. Declare and Define 3 constants imgWidth (=41), imgHeight(=59), and MoveAmount (=4). The first 2 correspond to the size of each sprite and mask, and the third one defines how far the Bomberman will move on each cursor strike from the user. Declare a static variable called Frame as Integer. Static a variable called FrameDirection as Integer that will correspond to the 4 directions or cursor keys as represented by 0,1,2, and 3. 5. Code a large if/endif or Select/Case to deal with the key being any of the 4 cursor keys. For any of them, a) move the TopPos or the LeftPos appropriately, and b) define the FrameDirection as 0,1,2, or 3. This sequence should match the arrangement in the provided Sprite. For instance, the first column of the Sprite has the DOWN direction, so FrameDirection 0 should correspond to Down. See the Sprite for the proper sequence of directions for 1,2, and 3. Do not draw the image yet. 6. Now draw the sprite and mask. The specific coding is Me.Cls BitBlt Me.hDC, LeftPos, TopPos, imgWidth, imgHeight, picMask.hDC, _ FrameDirection * imgWidth, Frame * imgHeight, SRCAND BitBlt Me.hDC, LeftPos, TopPos, imgWidth, imgHeight, picSprite.hDC, _ FrameDirection * imgWidth, Frame * imgHeight, SRCINVERT If the above 2 lines dont make sense to you, stop and review the BitBlt handout until it does. 7. Change the Frame (or version of Bomberman as you go down a given column) by adding 1 to Frame (unless its already at 2 in that case, make it 0). This will require a simple if sequence. Now run the program. If all has gone well you should have a working animation effect in BitBlt for perhaps the first time. Celebrate!

8. Okay, stop celebrating. Were now going to add the element of collision detection so that your Bomberman cant go through walls. Lets add a shape in the middle of your form. Well arrange to have Bomberman bounce off of it: (see next page)

To be in collision, he has to have 4 conditions all True. For shapes a and b above (which both have Top & Left, and Height & Width), the 4 conditions are: 1. The right edge of a has to be > the left edge of b 2. The left edge of a has to be < the right edge of b 3. The bottom edge of a has to be > the top of b 4. The top of a has to be < the bottom of b If all of these conditions are True, then you have collision. Satisfy yourself of this fact before going on. Then, code this structure with 4 ifs and 4 endifs, nicely nested and indented. In the middle of all of this is the coding line where we are in collision. Here, simply copy the if/endif or select/case from part 5 above and move the TopPos or LeftPos back to where it came from. This will mean a) reversing the sign in the counter (- becomes +, etc.), and b) deleting the FrameDirection statement (we dont need it here). Stop and run the program again. Hopefully, you now have animated Bomberman and he cannot go through our shape. Celebrate again You are doing very well! 9. Now, lets add a bunch of other shapes forming a Control Array of 6 shapes. Work with the handlebars of each shape to make them look like walls. In the coding from the last section, you just need to put the nested ifs inside a for/next loop (from 0 to 5) and change each occurrence of shape1 to Shape1(x) if you use x as the loop counter. I recommend that you use the Replace option from the Edit menu to do this all at once to save time. Run the program again to see if it works for all of the walls. 10. Now, make a game of some kind out of this program. Use your imagination!

You might also like