• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Tetris clone in an hour with C++.

## 149 posts in this topic

k thanx i am trying it now
and i know for sure that it works now i just tried it
www.roksta.com/helpsniper.zip
0

##### Share on other sites
k i duno wat happened i now get 13 errors

Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\sniper_tris\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\sniper_tris\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include"

In file included from main.cpp:13:
bitmapobject.h:4:9: warning: #pragma once is obsolete
bitmapobject.h:7:10: #include expects "FILENAME" or
In file included from main.cpp:13:
bitmapobject.h:10: parse error before {'' token

bitmapobject.h:26: parse error before public''

bitmapobject.h:31: destructors must be member functions
bitmapobject.h:34: parse error before .'' token

bitmapobject.h:49: operator HDC__*()'' must be a nonstatic member function
bitmapobject.h:49: operator HDC__*()'' must take exactly one argument
bitmapobject.h:50: parse error before }'' token

main.cpp:70: ''BitMapObject'' is used as a type, but is not defined as a type.
main.cpp:73: ''BitMapObject'' is used as a type, but is not defined as a type.

main.cpp: In function LRESULT TheWindowProc(HWND__*, unsigned int, unsigned
int, long int)'':
main.cpp:134: bmoMap'' undeclared (first use this function)
main.cpp:134: (Each undeclared identifier is reported only once for each
function it appears in.)

main.cpp: In function bool GameInit()'':
main.cpp:279: bmoBlocks'' undeclared (first use this function)

make.exe: *** [main.o] Error 1

Execution terminated

what i done is at
www.roksta.com/helpsniper.zip
I wana see this complie suscessfully
Thanx
0

##### Share on other sites
Well, I get 36 errors, heh.

in BitMapObject.h:
Change:
//we need this for windows stuff.#include

to:
//we need this for windows stuff.#include <windows.h>

In BitMapObject.cpp:
#include "bitmapobject.h"

at the top of the file.

This fixes basically all the errors. However, you did not copy the NewBlock() function into your program. Refer to the original post for that, as it is somewhat lengthy.
It is listed in main.cpp between DrawMap() and RotateBlock().

That should fix it. Also, though, I noticed that in the file you have for download, you still have:
//class stylewcx.nostyle = CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;

when it should be:
//class stylewcx.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;

-Greven

[Edited by - Evil_Greven on July 13, 2004 12:53:22 AM]
0

##### Share on other sites
i did all that but i still get 12 errors

Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\sniper_tris\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\sniper_tris\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include"

In file included from main.cpp:13:
bitmapobject.h:4:9: warning: #pragma once is obsolete
In file included from main.cpp:13:
bitmapobject.h:10: parse error before {'' token

bitmapobject.h:26: parse error before public''

bitmapobject.h:31: destructors must be member functions
bitmapobject.h:34: parse error before .'' token

bitmapobject.h:49: operator HDC__*()'' must be a nonstatic member function
bitmapobject.h:49: operator HDC__*()'' must take exactly one argument
bitmapobject.h:50: parse error before }'' token

main.cpp:70: ''BitMapObject'' is used as a type, but is not defined as a type.
main.cpp:73: ''BitMapObject'' is used as a type, but is not defined as a type.
main.cpp: In function LRESULT TheWindowProc(HWND__*, unsigned int, unsigned
int, long int)'':

main.cpp:134: bmoMap'' undeclared (first use this function)
main.cpp:134: (Each undeclared identifier is reported only once for each
function it appears in.)

main.cpp: In function bool GameInit()'':
main.cpp:279: bmoBlocks'' undeclared (first use this function)

make.exe: *** [main.o] Error 1

Execution terminated

yeh and i updated www.roksta.com/helpsniper.zip to what i am up to .
thanx heaps for the help so far ..
i cant wait 2 play my first game
sniper_snes
0

##### Share on other sites
i did all that but i still get 12 errors

Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\sniper_tris\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\sniper_tris\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include"

In file included from main.cpp:13:
bitmapobject.h:4:9: warning: #pragma once is obsolete
In file included from main.cpp:13:
bitmapobject.h:10: parse error before {' token

bitmapobject.h:26: parse error before public'

bitmapobject.h:31: destructors must be member functions
bitmapobject.h:34: parse error before .' token

bitmapobject.h:49: operator HDC__*()' must be a nonstatic member function
bitmapobject.h:49: operator HDC__*()' must take exactly one argument
bitmapobject.h:50: parse error before }' token

main.cpp:70: 'BitMapObject' is used as a type, but is not defined as a type.
main.cpp:73: 'BitMapObject' is used as a type, but is not defined as a type.
main.cpp: In function LRESULT TheWindowProc(HWND__*, unsigned int, unsigned
int, long int)':

main.cpp:134: bmoMap' undeclared (first use this function)
main.cpp:134: (Each undeclared identifier is reported only once for each
function it appears in.)

main.cpp: In function bool GameInit()':
main.cpp:279: bmoBlocks' undeclared (first use this function)

make.exe: *** [main.o] Error 1

Execution terminated

yeh and i updated www.roksta.com/helpsniper.zip to what i am up to .
thanx heaps for the help so far ..
i cant wait 2 play my first game
sniper_snes

[edited by - sniper_snes on December 8, 2003 12:49:17 AM]
0

##### Share on other sites
Are you sure you uploaded the updated files?

I''m looking at the ''updated'' files. None of the errors above have I seen fixed.

Fixing the errors that I pointed out above gives me a working version. Either you didn''t update the files in the zip or you didn''t fix any of the errors...

-Greven
0

##### Share on other sites
DAMIT i did it all over again and uploaded it to
www.roksta.com/helpsniper.zip
i am now using visual C++ instead of Dev C++ and i know get 30 errors :''(
here they are
:::::::::::::
--------------------Configuration: main - Win32 Debug--------------------
Compiling...
main.cpp
c:\dev-cpp\sniper_tris\bitmapobject.h(10) : error C2447: missing function header (old-style formal list?)
c:\dev-cpp\sniper_tris\main.cpp(70) : error C2079: ''bmoMap'' uses undefined class ''BitMapObject''
c:\dev-cpp\sniper_tris\main.cpp(73) : error C2079: ''Blocks'' uses undefined class ''BitMapObject''
c:\dev-cpp\sniper_tris\main.cpp(136) : error C2664: ''BitBlt'' : cannot convert parameter 6 from ''int'' to ''struct HDC__ *''
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
c:\dev-cpp\sniper_tris\main.cpp(275) : error C2228: left of ''.Create'' must have class/struct/union type
c:\dev-cpp\sniper_tris\main.cpp(276) : error C2664: ''FillRect'' : cannot convert parameter 1 from ''int'' to ''struct HDC__ *''
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
c:\dev-cpp\sniper_tris\main.cpp(279) : error C2228: left of ''.Load'' must have class/struct/union type
c:\dev-cpp\sniper_tris\main.cpp(334) : error C2664: ''BitBlt'' : cannot convert parameter 1 from ''int'' to ''struct HDC__ *''
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
c:\dev-cpp\sniper_tris\main.cpp(345) : error C2664: ''BitBlt'' : cannot convert parameter 1 from ''int'' to ''struct HDC__ *''
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
bitmapobject.cpp
c:\dev-cpp\sniper_tris\bitmapobject.h(10) : error C2447: missing function header (old-style formal list?)
c:\dev-cpp\sniper_tris\bitmapobject.cpp(2) : error C2027: use of undefined type ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.h(9) : see declaration of ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.cpp(4) : error C2065: ''hdcMemory'' : undeclared identifier
c:\dev-cpp\sniper_tris\bitmapobject.cpp(5) : error C2065: ''hbmNewBitMap'' : undeclared identifier
c:\dev-cpp\sniper_tris\bitmapobject.cpp(6) : error C2065: ''hbmOldBitMap'' : undeclared identifier
c:\dev-cpp\sniper_tris\bitmapobject.cpp(7) : error C2065: ''iWidth'' : undeclared identifier
c:\dev-cpp\sniper_tris\bitmapobject.cpp(8) : error C2065: ''iHeight'' : undeclared identifier
c:\dev-cpp\sniper_tris\bitmapobject.cpp(9) : warning C4508: ''BitMapObject'' : function should return a value; ''void'' return type assumed
c:\dev-cpp\sniper_tris\bitmapobject.cpp(11) : error C2027: use of undefined type ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.h(9) : see declaration of ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.cpp(12) : error C2084: function ''int __cdecl BitMapObject(void)'' already has a body
c:\dev-cpp\sniper_tris\bitmapobject.cpp(15) : error C2065: ''Destroy'' : undeclared identifier
c:\dev-cpp\sniper_tris\bitmapobject.cpp(18) : error C2027: use of undefined type ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.h(9) : see declaration of ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.cpp(25) : error C2440: ''='' : cannot convert from ''struct HDC__ *'' to ''int''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\dev-cpp\sniper_tris\bitmapobject.cpp(28) : error C2440: ''='' : cannot convert from ''struct HBITMAP__ *'' to ''int''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\dev-cpp\sniper_tris\bitmapobject.cpp(42) : error C2027: use of undefined type ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.h(9) : see declaration of ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.cpp(49) : error C2440: ''='' : cannot convert from ''struct HDC__ *'' to ''int''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\dev-cpp\sniper_tris\bitmapobject.cpp(52) : error C2440: ''='' : cannot convert from ''struct HBITMAP__ *'' to ''int''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\dev-cpp\sniper_tris\bitmapobject.cpp(62) : error C2027: use of undefined type ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.h(9) : see declaration of ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.cpp(63) : error C2373: ''Destroy'' : redefinition; different type modifiers
c:\dev-cpp\sniper_tris\bitmapobject.cpp(81) : error C2027: use of undefined type ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.h(9) : see declaration of ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.cpp(87) : error C2027: use of undefined type ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.h(9) : see declaration of ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.cpp(93) : error C2027: use of undefined type ''BitMapObject''
c:\dev-cpp\sniper_tris\bitmapobject.h(9) : see declaration of ''BitMapObject''
Error executing cl.exe.

main.exe - 30 error(s), 1 warning(s)

i fixed everything u said 2 but stil cant figure this out
could u send the working source code to sniper@roksta.com
thanx
0

##### Share on other sites
thanx but theres still that no style error but i fixed that and brang it down 2 four errors

Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\sniper_tris\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\sniper_tris\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include"

In file included from main.cpp:13:
bitmapobject.h:4:9: warning: #pragma once is obsolete

g++.exe -c bitmapobject.cpp -o bitmapobject.o -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include"

In file included from bitmapobject.cpp:1:
bitmapobject.h:4:9: warning: #pragma once is obsolete
bitmapobject.cpp:11: redefinition of BitMapObject::BitMapObject()''
bitmapobject.cpp:3: BitMapObject::BitMapObject()'' previously defined here
bitmapobject.cpp:11: no BitMapObject::BitMapObject()'' member function declared
in class BitMapObject''
bitmapobject.cpp:12: confused by earlier errors, bailing out

make.exe: *** [bitmapobject.o] Error 1

Execution terminated

0

##### Share on other sites
where can i get "bitmapobject.h"??

0

##### Share on other sites
Sniper, did the files I sent work?

Anonymous Poster,
The bitmapobject.h is listed in the original post, though since I built the tutorial as I went, it is created where it is first needed, which is slightly down from the beginning of the file.

-Greven
0

##### Share on other sites
hey this is sniper
na they didnt work i got the above errors i posted above only 4 through and thats afta fixingg da nostyle and some other things u said

closet i been 2 complieng ( 4 errors )
:D
0

##### Share on other sites
Hmm.

I would guess the "redefinition" error is a mistype by you.

Specifically, having two Constructors rather than a Constructor (BitMapObject::BitMapObject)and a Deconstructor (BitMapObject::~BitMapObject).

Check the Deconstructor for a ~ before the class name. This would be in bitmapobject.cpp.

Make sure the bitmapobject.h has both of these declared, also.

-Greven
0

##### Share on other sites
hmmm i checked them here is wat they are atm:

itMapObject::BitMapObject()
{
hdcMemory=NULL;
hbmNewBitMap=NULL;
hbmOldBitMap=NULL;
iWidth=0;
iHeight=0;
}

BitMapObject::~BitMapObject()

is that how they should be ?
i know get 19 errors :S my complier mite be fuked
still all to do wit BitMapObjext

Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Dev-Cpp\sniper_tris\working version\main.cpp" -o "C:\Dev-Cpp\sniper_tris\working version\main.exe" -I"C:\Dev-Cpp\include" -I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
In file included from C:/Dev-Cpp/sniper_tris/working version/main.cpp:13:
C:/Dev-Cpp/sniper_tris/working version/bitmapobject.h:4:9: warning: #pragma once is obsolete

C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x11a):main.cpp: undefined reference to BitMapObject::operator HDC__*()''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x134):main.cpp: undefined reference to BitBlt@36''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x22f):main.cpp: undefined reference to GetStockObject@4''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x3b7):main.cpp: undefined reference to BitMapObject::Create(HDC__*, int, int)''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x3c7):main.cpp: undefined reference to GetStockObject@4''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x3d9):main.cpp: undefined reference to BitMapObject::operator HDC__*()''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x40d):main.cpp: undefined reference to BitMapObject::Load(HDC__*, char const*)''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x4d6):main.cpp: undefined reference to NewBlock()''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x502):main.cpp: undefined reference to BitMapObject::operator HDC__*()''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x522):main.cpp: undefined reference to BitMapObject::operator HDC__*()''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x52b):main.cpp: undefined reference to BitBlt@36''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x54c):main.cpp: undefined reference to BitMapObject::operator HDC__*()''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x56c):main.cpp: undefined reference to BitMapObject::operator HDC__*()''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0x575):main.cpp: undefined reference to BitBlt@36''

C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0xa34):main.cpp: undefined reference to NewBlock()''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0xc14):main.cpp: undefined reference to BitMapObject::BitMapObject()''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0xc33):main.cpp: undefined reference to BitMapObject::BitMapObject()''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0xc52):main.cpp: undefined reference to BitMapObject::~BitMapObject()''
C:\DOCUME~1\rockes\LOCALS~1\Temp/ccg5baaa.o(.text+0xc71):main.cpp: undefined reference to BitMapObject::~BitMapObject()''

Execution terminated
0

##### Share on other sites
Your compiler isn''t fuked. Your command line is fuked. You only included main.cpp, leaving out the other files. You also need to link with the windows libraries (gdi32, user32, kernel32).
0

##### Share on other sites
Cool. I''ll check it out tomorrow. Its 4:30AM now an im gonna goto sleep.
0

##### Share on other sites
Hi, well first of all I need to thankyou for writting such a helpful tutorial Evil_Greven
But now i''v got two noob questions.... Would the easiest way to write a score to the screen be using the OpenGL Bitmap Fonts like in NeHe''s tutorials? And also, how would i go about loading the sidepanel as a seperate, complete bitmap and still be able to position the next block in there?
0

##### Share on other sites
Bzurk,

Well, you could do that if you wanted to, but you could also just build on to the functions that are already there.

Add (horizontally) 10 blocks to the bitmap, and number them 0 through 9. Then, add a few lines into the program:

...TILEPURPLE=9;TILEZERO=10;TILEONE=11;...TILENINE=19;   

And just use the DrawTile() function we previously made, and you''re off!

As for making the sidebar a single bitmap, yeah you can do that too. The size should be GREY*TILESIZE (mine is 8*16, so 128 pixels) wide by MAPHEIGHT*TILESIZE (mine is 30*16, so 480 pixels)tall.

As for code... first, you need a new BitMapObject:
...//block imagesBitMapObject bmoBlocks;//Sidebar imageBitMapObject bmoSidebar;   

Next, you''ll have to load the sidebar bitmap in the GameInit() function:

	bmoBlocks.Load(NULL,"blocks.bmp");	bmoSidebar.Load(NULL,"sidebar.bmp");  	NewGame(); 

Then, you''ll have to remove the portion of code that draws the sidebar:
//place the toolbar	for(xmy=MAPWIDTH; xmy< MAPWIDTH+GREY; xmy++)		for(ymx=0; ymx< MAPHEIGHT; ymx++)			DrawTile(xmy, ymx, TILEGREY); 

And replace it with a single pair of BitBlt() calls (we need the starting position to be the right-most edge of the map, so MAPWIDTH*TILESIZE, and 0):
//mask firstBitBlt(bmoMap,MAPWIDTH*TILESIZE,0,GREY*TILESIZE,MAPHEIGHT*TILESIZE,bmoSidebar,0,0,SRCAND);//then imageBitBlt(bmoMap,MAPWIDTH*TILESIZE,0,GREY*TILESIZE,MAPHEIGHT*TILESIZE,bmoSidebar,0,0,SRCPAINT);   

-Greven
0

##### Share on other sites
Oh, one other thing. If you wanted to make the numbers (0-9) transparent, you only need to change the bitmap, with this system.

How you do this, well...

Suppose we are using the color yellow, let's call that Y. Next, we need the colors black (B) and white (W).

Now, from previous experiance with the bitmap, you know that the upper row is the image that is printed, and the lower row is simply a 'footprint' as it were. We can change the mask into a 'shadow.' You know how shadows are.. totally black. Let's pretend the ground around the shadow is entirely white. Thus, the bottom row represents the ground with a shadow on it. Let's also pretend that the upper row is in space, thus what you don't want drawn, you will make black.

Top row, the tile is TILEZERO. First, let's make this a yellow 0 on a black background:

B B B B B B B B B B B B B B B BB B B B B Y Y Y Y Y B B B B B B B B B B Y B B B B B Y B B B B B B B B Y B B B B B B B Y B B B B B B B Y B B B B B B B Y B B B BB B B Y B B B B B B B Y B B B B B B B Y B B B B B B B Y B B B B B B B Y B B B B B B B Y B B B BB B B Y B B B B B B B Y B B B BB B B Y B B B B B B B Y B B B B B B B Y B B B B B B B Y B B B B B B B Y B B B B B B B Y B B B B B B B Y B B B B B B B Y B B B BB B B B Y B B B B B Y B B B B B B B B B B Y Y Y Y Y B B B B B B B B B B B B B B B B B B B B B B  

Now, you'd see just a yellow 0 with a black background. However, when we change the BOTTOM row (the one under the tile, only) from just pure black to something ELSE...

W W W W W W W W W W W W W W W WW W W W W B B B B B B W W W W WW W W W B W W W W W W B W W W WW W W B W W W W W W W W B W W WW W W B W W W W W W W W B W W WW W W B W W W W W W W W B W W WW W W B W W W W W W W W B W W WW W W B W W W W W W W W B W W WW W W B W W W W W W W W B W W WW W W B W W W W W W W W B W W WW W W B W W W W W W W W B W W WW W W B W W W W W W W W B W W WW W W B W W W W W W W W B W W WW W W W B W W W W W W B W W W WW W W W W B B B B B B W W W W WW W W W W W W W W W W W W W W W 

Now, when TILEZERO is displayed, it is a yellow 0 on top of whatever background it is. Congratulations, you have achieved transparancy.

Now, to explain it a bit more technical, first consider how bitwise operators work.

0 OR 0 = 0.0 OR 1 = 1.1 OR 0 = 1.1 OR 1 = 1.0 AND 0 = 0.0 AND 1 = 0.0 AND 1 = 0.1 AND 1 = 1. 

Next, consider how colors are defined:
Red:00000000 00000000 11111111Green:00000000 11111111 00000000Blue:11111111 00000000 00000000White:11111111 11111111 11111111Black:00000000 00000000 00000000 

Thus, yellow is a combination of Red and Green:
Yellow:00000000 11111111 11111111 `

First, you mask it with SRCAND. Remember, SRCAND is the AND bitwise operator, so it copies only if there is a 1 and 1, accordingly. However, because the destination color is unknown, we must first destroy that color, by using AND with 0 (SRCAND with black pixels, 0...) and preserve the colors around it (SRCAND with white pixels, 1...). This creates the shadow.

Next, we put in the color we want. This time, since we use BLACK to preserve the color already there, by using OR with 0 (SRCPAINT with black pixels, 0...) and printing the color we want over the changed portion (where you put the black with SRCAND).

This is how BitBlt() works, using the flags SRCPAINT and SRCAND.

You can do this with other colors, as well as interesting things with those colors.

-Greven

Edit to explain better, oops :/

[edited by - Evil_Greven on December 14, 2003 10:39:28 PM]
0

##### Share on other sites
Cool, thanks
I got the score working, just fixing up the side panel and splitting the game into levels now so it will gradually speed up after every 10 rows completed.
0

##### Share on other sites
Really nice work dude. Nice to see someone put so much time into something, to help the rest of us. I do have one question, however, regarding the use of hbmOldBitMap. Am I right in saying that there''s a chance you can select an HBITMAP handle into the graphics DC, using SelectObject(), that has already been destructed? What would happen if that were the case?

I could be completely wrong, but it seems as though you could instantiate several BitMapObject objects, which all select in the old bitmap. Then, what''s to stop one of those objects being destructed in the wrong order and having the resource handle, stored in hbmOldBitMap, selected back into the DC after it''s been destructed?

Again, I might be totally off my nut here (bit tired as it happens), but after taking a look at that, it''s the first thing that crossed my mind.

Other than that, really good stuff dude and thanks for sharing.

-hellz
0

##### Share on other sites
hellz,

It should function like you never loaded it. Therefore, a black picture of height X width size. At least, that''s what I''ve had happen, I suppose it could do something unexpected though, considering we''re playing with memory.

Each of the BitMapObjects are completely seperate; destroying one instance will have no effect on others. I had one game I''ve made that has an Enemy class, and within that class, a BitMapObject. You can use the same bitmap in multiple BitMapObjects... closing one out does nothing to the others.

-Greven
0

##### Share on other sites
Okie, thanks man. =)

-hellz
0

##### Share on other sites
Wutz up,
the code is done really well, one of the few code tutorials that actually worked, except... i cant get mine to run...
it Compiles great 0 errors and 0 warnings.. just when i run... nothing runs. and it''z not a run-time error. just nothing runs. i built the blocks.bmp as well but either i didn''t do it right or i missed something if you could send me the source. and your thoughts on it, i''d be forever thankful,

- Deamonslayer
KewlSoftwarz
E-mail - deamonslayer@kewlsoftwarz.zzn.com
0

##### Share on other sites
If you compiled it, and then executed it, and it comes up with a blank/black background, then the .bmp file isn''t in your Projects folder, thus not showing the falling blocks.
0

##### Share on other sites
-Deamonslayer

no window is showing up at all, but compiles fine. then hit run, and it doesnt work it just says no errors or warnings.

- any help would be appreciated. damn errors that arnt given. heh my OS is Windows 98, and Compiler Microsoft Visual C++ Enterprise Edition.

if you can help just e-mail me. i check my e-mail often.
- Thanks Greven for trying to help me, hope you can help figure out what the hell is going on.

- e-mail deamonslayer@kewlsoftwarz.zzn.com
0