#### Archived

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

# Tetris clone in an hour with C++.

This topic is 2114 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, i was able to get all the code to compile on VS.NET 2003 (i created a blank win32 project for this) but when I try to run it, nothing happens, no errors, nothing. Has anyone else had this problem???

Not sure what to do...

##### Share on other sites
Did you create the bitmap file that it requires?

-Greven

##### Share on other sites
I just copied the bitmap file from his tutorial

##### Share on other sites
Well, I don''t have VS.NET but it sounds to me like the program is exiting immediately, if nothing is showing up at all.

This could be caused by a few things. Check your WinMain() function to see if it is correct, and also check TheWindowProc() function.

For instance, if in TheWindowProc() you happen to have:

//check for escape keyif(wParam=VK_ESCAPE)				{DestroyWindow(hWndMain);				return(0);//handled message	}

//check for escape keyif(wParam==VK_ESCAPE)				{DestroyWindow(hWndMain);				return(0);//handled message	}

You won''t recieve any errors... and it will exit instantly and you''ll never even see the window created.

Check for something like that.

-Greven

##### Share on other sites
Wow. If this is the basics of basic game programming, I'm screwed!

No, really. I kinda understand what's going on in the tutorial, but not enough to be confident in creating my own tetris clone without the help of the tutorial.

It isn't that the tut is bad, its just hard for me, personally, to learn from just looking at/typing up someone else's code. It doesn't click for me.

In order for me to learn well, I generally have to tinker. I've done some tinkering with the things I understand here (changing the size of the tiles and such) but I need some guidance as to how this code can be changed and what the changes would do.

I already have some ideas, like I'm guessing that if I changed the numbers [-][-] in the switch (newblock) statement I'd end up with some pretty funky looking block groupss! I also suppose that I could fairly easily ADD groups of blocks to the game so long as I make appropriate changes to the newblock=rand()%[number]; line.

Any other suggestions for tinkering that would help me understand the code better?

Thanks for the tutorial btw. I read that article that said the first step to learning to program was making a tetris clone, to which I responded 'Well, how do I do that?' Now I can find out... eventually.

[edited by - ArtGeek on April 16, 2004 11:06:12 PM]

[edited by - ArtGeek on April 16, 2004 11:41:18 PM]

##### Share on other sites
Okay, I did some more tinkering, but I can''t figure out what this little bit of code does.

if(killblock)
{
for(i=0; i<4; i++)
for(j=0; j<4; j++)
sPiece.size[ i ][j]=TILENODRAW;
}

I tried changing EVERYTHING in this bit of code, even commenting it out completely and I didn''t see any difference.

##### Share on other sites
Lol. More questions. Tinkering with this code is great fun, but I hope you don't get sick of my pestering!

I just added the code to count/display score. The only thing is that the score counting is pretty... stupid. All it does at the moment is give you 5 points every time a row is destroyed. Whoop.

I was wondering how I would go about counting the number of rows destroyed at once. That way I could have a scoring system like.

switch (numberRowsDestroyed)
{
case 1: Score=Score+5; break;
case 2: Score=Score+15; break;
case 3: Score=Score+25; break;
case 4: Score=Score+50; break;
}

EDIT: Nevermind! I figured it out by myself.

[edited by - ArtGeek on April 17, 2004 3:20:04 PM]

##### Share on other sites
quote:
Original post by ArtGeek
Okay, I did some more tinkering, but I can''t figure out what this little bit of code does.

if(killblock)
{
for(i=0; i<4; i++)
for(j=0; j<4; j++)
sPiece.size[ i ][j]=TILENODRAW;
}

I tried changing EVERYTHING in this bit of code, even commenting it out completely and I didn''t see any difference.

it does nothing, if you look in NewBlock(), you''ll see
this code:
//initialize the piece to all blank.	for(i=0; i<4; i++)		for(j=0; j<4; j++)			sPiece.size[ i ][j]=TILENODRAW;

which does exactly the same thing, and because NewBlock is always called after the killblock code, it makes it useless

hope that helps !
Matt

##### Share on other sites
I want to add the ability to ''land'' a group of blocks by pressing SPACEBAR. I''ve tried several things, but none of them have worked very well. I''m thinking that I might have to create an entirely new function to pull this off, but the only way I can see to do this would involve duplicating a bunch of code in the Move() function.

Can someone please give me ideas on how to do this with the least amount of code?

##### Share on other sites
Well, it''s your code, so do whatever you want with it. Suggestion wise... well you could add a Top Scores portion, which shouldn''t be too long. You could also add a Menu system with options etc (and then make it Mouse compatible to boot). That''s what I did to finish up my first Tetris clone... polish!

Also, lemurion is correct that that portion is rather useless. Can''t say I made the tutorial without errors, I guess

Now, to land a piece, you could do it pretty easily.

Create a global variable called Dropping or something... make it a boolean/int just as a flag for yes/no. You could set the flag as true(1, whatever) with Spacebar if you wanted in TheWindowProc().

Next, in the Move() function, in the if(CollisionTest(x,y)) {}code block, you would set the Dropping flag as false to halt movement. Then in the else {} portion, you could put an if(Dropping) Move(0,1); after the sPiece.y+=y;

That''s pretty simple.

-Greven

##### Share on other sites
Urm. Silly me forgot to define what I meant by ''land.'' I had intended to, but I think I cut it out while I was shortening my post.

When Spacebar is hit, I want the dropping block to drop all the way down immediately. I tried to figure out some sort of equation that could be sent to the move function (my best shot was move(0,MAPHEIGHT-sPiece.y) but I can''t figure out anything that would work properly.

If I understand your post, Greven, that just sorta ''pauses'' the game. Useful, but not what I was looking for.

##### Share on other sites
ArtGeek,

Thank you for further explaination; however I did understand what you intended the first time.

This should do what you want; dropping the block to the bottom instantly. I have not tested it, but feel free to.

-Greven

##### Share on other sites
To appeal to all people out there, I converted Evil_Greven's code (which he deserves all the credit) for use with SDL. I hope this will help more people out because I am sure Evil_Greven wants to reach all people (Not just Window's users, but Linux as well).

EDIT: Be sure to Link the appropriate SDL libraries:
sdl.lib sdlmain.lib

//=============================================================================//FALLING BLOCK GAME!//main.cpp//Needed for all the SDL stuff#include <SDL.h>//need this for srand and rand#include <stdlib.h>//Used for Error checking#include <iostream>//=============================================================================//To gain access to STLusing namespace std;//=============================================================================#define WWIDTH		160									//Width of Window#define WHEIGHT		480									//Height of Window#define WBIT		16									//16-bit colors#define WFLAGS		SDL_HWSURFACE | SDL_DOUBLEBUF		//Set up for Video Hardware and Double Buffering//let's give our window a title...er caption.#define WINDOWTITLE "A Falling Block Game!"//=============================================================================//since we're using square blocks, let's only use a single size.const int TILESIZE=16;//now for the map...const int MAPWIDTH=10;const int MAPHEIGHT=30;const int GREY=8;const int TILENODRAW=-1;const int TILEBLACK=0;const int TILEGREY=1;const int TILEBLUE=2;const int TILERED=3;const int TILEGREEN=4;const int TILEYELLOW=5;const int TILEWHITE=6;const int TILESTEEL=7;const int TILEPURPLE=8;//=============================================================================bool GameInit(); // game initialization functionvoid GameLoop(); //where the game actually takes placevoid GameDone(); //clean up! void DrawTile(int x, int y, int tile); //coordinates & tile typevoid DrawMap(); //draw the whole map.. render function, basicallyvoid NewBlock(); //create a new block!void RotateBlock(); //rotate a block.. if you can!void Move(int x, int y); //coordinates to move.int CollisionTest(int nx, int ny); //test collision of blocksvoid RemoveRow(int row); //remove a row.. that would be the 'x'.void NewGame(); //make a new game!//Makes it easier to Blit a Surface to another Surfacevoid Blit(SDL_Surface *Dest, int DestX, int DestY, SDL_Surface *Src);void Blit(SDL_Surface *Dest, int DestX, int DestY, SDL_Surface *Src, int SrcX, int SrcY, int SrcW, int SrcH);          //-----------------------------------------------------------------------------SDL_Surface* Display;	//Our main display surface//-----------------------------------------------------------------------------int Map[MAPWIDTH][MAPHEIGHT+1]; //the game map!//-----------------------------------------------------------------------------struct Piece {	int size[4][4];	int x;	int y;};Piece sPrePiece; //preview piece.Piece sPiece; //the 's' prefixes indicate this is a 'structure'//-----------------------------------------------------------------------------double start_time;  //used in timingbool GAMESTARTED=false; //used by NewBlock()//-----------------------------------------------------------------------------SDL_Surface* surfBlocks;bool GAMERUNNING = true;//=============================================================================void OnEvent() {	SDL_Event Event;	//===  Event loop ===//	//Grab any events in the queue	while (SDL_PollEvent(&Event)) {		switch (Event.type) {			case SDL_QUIT:		//Found a quit event				GAMERUNNING = false;				break;			case SDL_KEYDOWN:	//A key has been pressed				int Sym = Event.key.keysym.sym;				switch(Sym) {					case SDLK_ESCAPE:						GAMERUNNING = false;						break;					case SDLK_DOWN:						Move(0, 1);						break;					case SDLK_UP:						RotateBlock();						break;					case SDLK_LEFT:						Move(-1, 0);						break;					case SDLK_RIGHT:						Move(1, 0);						break;				}				break;		}	}}//-----------------------------------------------------------------------------int main(int argc, char* argv[]) {	//Make sure when we are done we clean up	atexit(GameDone);	//===  Start SDL Routines  ===//	//Start up just the Video	if (SDL_Init(SDL_INIT_VIDEO) < 0) {        cout << "OnInit > Cannot Initialize SDL Systems: " << SDL_GetError() << endl;		return 0;    }    //===  Create a video surface  ===//	//Create the Window	Display = SDL_SetVideoMode(WWIDTH, WHEIGHT, WBIT, WFLAGS);	if (!Display) {        cout << "OnInit > Cannot set Video Mode:" << SDL_GetError() << endl;		return 0;    }	//===  Window Stuff  ===//	//Set the Window Caption	SDL_WM_SetCaption(WINDOWTITLE, WINDOWTITLE);	//if program initialization failed, then return with 0	if(!GameInit()) {		cout << "OnInit > Game Init failed!" << endl;		return 0;	}	//Main game loop	while(GAMERUNNING) {		OnEvent();		GameLoop();		DrawMap();	}	return 1;}//-----------------------------------------------------------------------------bool GameInit() {	surfBlocks = SDL_LoadBMP("blocks.bmp");	if(!surfBlocks) {		cout << "GameInit > File not Found: blocks.bmp" << endl;		return false;	}	NewGame();	return(true);//return success}//-----------------------------------------------------------------------------void GameDone() {	//Free all the Surfaces we created	SDL_FreeSurface(Display);	SDL_FreeSurface(surfBlocks);	//Shut down SDL	SDL_Quit();}//-----------------------------------------------------------------------------void GameLoop() {	if((SDL_GetTicks() - start_time) > 1000) {		Move(0,1);		start_time = SDL_GetTicks();	}}//-----------------------------------------------------------------------------void NewGame() {	start_time  = SDL_GetTicks();	GAMESTARTED = false;	//start out the map	for(int x=0;x< MAPWIDTH;x++) {		for(int y=0;y< MAPHEIGHT+1;y++) {			if(y==MAPHEIGHT) //makes Y-collision easier.				Map[x][y]=TILEGREY;			else				Map[x][y]=TILEBLACK;		}	}	NewBlock();	DrawMap();}//-----------------------------------------------------------------------------void DrawTile(int x,int y,int tile) {	//Draw the Tile	Blit(Display, x*TILESIZE, y*TILESIZE, surfBlocks, tile*TILESIZE, 0, TILESIZE, TILESIZE);}//-----------------------------------------------------------------------------void DrawMap() {	int xmy, ymx;	//place the toolbar	for(xmy=MAPWIDTH; xmy< MAPWIDTH+GREY; xmy++)		for(ymx=0; ymx< MAPHEIGHT; ymx++)			DrawTile(xmy, ymx, TILEGREY);	//draw preview block	for(xmy=0; xmy<4; xmy++)		for(ymx=0; ymx<4; ymx++)			if(sPrePiece.size[xmy][ymx] != TILENODRAW)				DrawTile(sPrePiece.x+xmy, sPrePiece.y+ymx, sPrePiece.size[xmy][ymx]);		//draw the map	//loop through the positions	for(xmy=0;xmy< MAPWIDTH;xmy++)		for(ymx=0;ymx< MAPHEIGHT;ymx++)				DrawTile(xmy,ymx,Map[xmy][ymx]);	//draw moving block	for(xmy=0; xmy<4; xmy++)		for(ymx=0; ymx<4; ymx++)			if(sPiece.size[xmy][ymx] != TILENODRAW)				DrawTile(sPiece.x+xmy, sPiece.y+ymx, sPiece.size[xmy][ymx]);	//Redraw the entire Display	SDL_Flip(Display);}//-----------------------------------------------------------------------------void NewBlock() {	int newblock;	int i,j;	//  0   1   2   3   4    5   6    	//   X                             These	//   X   XX   X  XX   XX  XX   XX  are	//   X   XX  XXX  XX XX    X   X   block	//   X                     X   X   types	//begin game! make generate a block and then one in preview.	srand(SDL_GetTicks());	//initialize the piece to all blank.	for(i=0; i<4; i++)		for(j=0; j<4; j++)			sPiece.size[ i ][j]=TILENODRAW;	sPiece.x=MAPWIDTH/2-2;	sPiece.y=-1;	//let's see if the game's started yet	if(GAMESTARTED == false)	{		//guess not..  		//Generate a piece right off.		//From now on, use previous preview block.		GAMESTARTED=true;		newblock=rand()%7;		switch (newblock)		{		case 0: //Tower!			{				sPiece.size[1][0]=TILERED;				sPiece.size[1][1]=TILERED;				sPiece.size[1][2]=TILERED;				sPiece.size[1][3]=TILERED;				sPiece.y=0;			}break;		case 1: //Box!			{				sPiece.size[1][1]=TILEBLUE;				sPiece.size[1][2]=TILEBLUE;				sPiece.size[2][1]=TILEBLUE;				sPiece.size[2][2]=TILEBLUE;			}break;		case 2: //Pyramid!			{				sPiece.size[1][1]=TILESTEEL;				sPiece.size[0][2]=TILESTEEL;				sPiece.size[1][2]=TILESTEEL;				sPiece.size[2][2]=TILESTEEL;			}break;		case 3://Left Leaner			{				sPiece.size[0][1]=TILEYELLOW;				sPiece.size[1][1]=TILEYELLOW;				sPiece.size[1][2]=TILEYELLOW;				sPiece.size[2][2]=TILEYELLOW;			}break;		case 4://Right Leaner			{				sPiece.size[2][1]=TILEGREEN;				sPiece.size[1][1]=TILEGREEN;				sPiece.size[1][2]=TILEGREEN;				sPiece.size[0][2]=TILEGREEN;			}break;		case 5://Left Knight			{				sPiece.size[1][1]=TILEWHITE;				sPiece.size[2][1]=TILEWHITE;				sPiece.size[2][2]=TILEWHITE;				sPiece.size[2][3]=TILEWHITE;			}break;		case 6://Right Knight			{				sPiece.size[2][1]=TILEPURPLE;				sPiece.size[1][1]=TILEPURPLE;				sPiece.size[1][2]=TILEPURPLE;				sPiece.size[1][3]=TILEPURPLE;			}break;		}	}	else	{		for(i=0; i<4; i++)			for(j=0; j<4; j++)				sPiece.size[ i ][j]=sPrePiece.size[ i ][j];	}	newblock=rand()%7;	for(i=0; i<4; i++)		for(j=0; j<4; j++)			sPrePiece.size[ i ][j]=TILENODRAW;	sPrePiece.x=MAPWIDTH+GREY/4;	sPrePiece.y=GREY/4;	switch (newblock)	{		case 0: //Tower!			{				sPrePiece.size[1][0]=TILERED;				sPrePiece.size[1][1]=TILERED;				sPrePiece.size[1][2]=TILERED;				sPrePiece.size[1][3]=TILERED;			}break;		case 1: //Box!			{				sPrePiece.size[1][1]=TILEBLUE;				sPrePiece.size[1][2]=TILEBLUE;				sPrePiece.size[2][1]=TILEBLUE;				sPrePiece.size[2][2]=TILEBLUE;			}break;		case 2: //Pyramid!			{				sPrePiece.size[1][1]=TILESTEEL;				sPrePiece.size[0][2]=TILESTEEL;				sPrePiece.size[1][2]=TILESTEEL;				sPrePiece.size[2][2]=TILESTEEL;			}break;		case 3://Left Leaner			{				sPrePiece.size[0][1]=TILEYELLOW;				sPrePiece.size[1][1]=TILEYELLOW;				sPrePiece.size[1][2]=TILEYELLOW;				sPrePiece.size[2][2]=TILEYELLOW;			}break;		case 4://Right Leaner			{				sPrePiece.size[2][1]=TILEGREEN;				sPrePiece.size[1][1]=TILEGREEN;				sPrePiece.size[1][2]=TILEGREEN;				sPrePiece.size[0][2]=TILEGREEN;			}break;		case 5://Left Knight			{				sPrePiece.size[1][1]=TILEWHITE;				sPrePiece.size[2][1]=TILEWHITE;				sPrePiece.size[2][2]=TILEWHITE;				sPrePiece.size[2][3]=TILEWHITE;			}break;		case 6://Right Knight			{				sPrePiece.size[2][1]=TILEPURPLE;				sPrePiece.size[1][1]=TILEPURPLE;				sPrePiece.size[1][2]=TILEPURPLE;				sPrePiece.size[1][3]=TILEPURPLE;			}break;	}	DrawMap();}//-----------------------------------------------------------------------------void RotateBlock() {	int i, j, temp[4][4];	//copy &rotate the piece to the temporary array	for(i=0; i<4; i++)		for(j=0; j<4; j++)			temp[3-j][ i ]=sPiece.size[ i ][j];	//check collision of the temporary array with map borders	for(i=0; i<4; i++)		for(j=0; j<4; j++)			if(temp[ i ][j] != TILENODRAW)				if(sPiece.x + i < 0 || sPiece.x + i > MAPWIDTH - 1 ||					sPiece.y + j < 0 || sPiece.y + j > MAPHEIGHT - 1)					return;	//check collision of the temporary array with the blocks on the map	for(int x=0; x< MAPWIDTH; x++)		for(int y=0; y< MAPHEIGHT; y++)			if(x >= sPiece.x && x < sPiece.x + 4)				if(y >= sPiece.y && y < sPiece.y +4)					if(Map[x][y] != TILEBLACK)						if(temp[x - sPiece.x][y - sPiece.y] != TILENODRAW)							return;	//end collision check	//successful!  copy the rotated temporary array to the original piece	for(i=0; i<4; i++)		for(j=0; j<4; j++)			sPiece.size[ i ][j]=temp[ i ][j];		DrawMap();}//-----------------------------------------------------------------------------void Move(int x, int y) {	if(CollisionTest(x, y)) {		if(y == 1) {			if(sPiece.y<1) {				NewGame(); //you lose!  new game.			}else{				bool killblock = false;				int i,j;				//new block time! add this one to the list!				for(i=0; i<4; i++)					for(j=0; j<4; j++)						if(sPiece.size[ i ][j] != TILENODRAW)							Map[sPiece.x+i][sPiece.y+j] = sPiece.size[ i ][j];				//check for cleared row!				for(j=0; j< MAPHEIGHT; j++) {					bool filled=true;					for(i=0; i< MAPWIDTH; i++)						if(Map[ i ][j] == TILEBLACK)							filled=false;					if(filled) {						RemoveRow(j);						killblock=true;					}				}				if(killblock) {					for(i=0; i<4; i++)						for(j=0; j<4; j++)							sPiece.size[ i ][j]=TILENODRAW;				}				NewBlock();			}		}	}else{		sPiece.x+=x;		sPiece.y+=y;	}	DrawMap();}//-----------------------------------------------------------------------------int CollisionTest(int nx, int ny) {	int newx=sPiece.x+nx;	int newy=sPiece.y+ny;	int i,j,x,y;	for(i=0; i< 4; i++)		for(j=0; j< 4; j++)			if(sPiece.size[ i ][j] != TILENODRAW)				if(newx + i < 0 || newx + i > MAPWIDTH - 1 ||					newy + j < 0 || newy + j > MAPHEIGHT - 1)					return 1;	for(x=0; x< MAPWIDTH; x++)		for(y=0; y< MAPHEIGHT; y++)			if(x >= newx && x < newx + 4)				if(y >= newy && y < newy +4)					if(Map[x][y] != TILEBLACK)						if(sPiece.size[x - newx][y - newy] != TILENODRAW)							return 1;	return 0;}//-----------------------------------------------------------------------------void RemoveRow(int row) {	int x,y;	int counter=0;	for(x=0; x< MAPWIDTH; x++)		for(y=row; y>0; y--)			Map[x][y]=Map[x][y-1];}//-----------------------------------------------------------------------------void Blit(SDL_Surface *Dest, int DestX, int DestY, SDL_Surface *Src) {	//Create a Rect, and store the coordinates in it.	//Because SDL likes it this way. 	SDL_Rect DestR;	DestR.x = DestX; DestR.y = DestY;	//Draw to the Dest	SDL_BlitSurface(Src, NULL, Dest, &DestR);}//-----------------------------------------------------------------------------void Blit(SDL_Surface *Dest, int DestX, int DestY, SDL_Surface *Src, int SrcX, int SrcY, int SrcW, int SrcH) {	//Create a 2 Rects. The first is for where we want to Blit to.	//The other is for clipping the 'Src' so we only draw the portion we want	SDL_Rect DestR;  SDL_Rect SrcR;	DestR.x = DestX; DestR.y = DestY;	SrcR.x = SrcX;   SrcR.y = SrcY;	SrcR.w = SrcW;   SrcR.h = SrcH;	//Draw to the Dest	SDL_BlitSurface(Src, &SrcR, Dest, &DestR);}//=============================================================================

[edited by - MetaCipher on April 18, 2004 11:00:36 PM]

##### Share on other sites
great tutorial!

first, sorry for being a complete newb, hehe. but i was wondering a couple things if anyone would be so kind to help.

im trying to understand the timing rate at which the block falls. right now it looks like it is just set to x+=x,y+=y.
if i was to edit that it would just cause a "jumpy" effect to the blocks. so i guess the question is, is there a way to edit the falling rate or can u point me in the direction of creating one?

secondly, the "Grey" side panel where the next block is displayed, where is the grey color set. the GREY variable is just an int which dictates the width. but where is the color set?

thanks for any help!

again good tutorial.

##### Share on other sites
Whoops, seems I forgot to put the thing that displays the next block. Oh well, that'll give SDL users something to do.

Well, the code is there, but the next block is being displayed off the screen. So increasing the WWIDTH should do it.

[edited by - MetaCipher on April 19, 2004 12:51:49 PM]

##### Share on other sites
got this: compiles fine but Bulding...that''s a difrfernt story:
------------------Configuration: tetris - Win32 Debug--------------------Linking...main.obj : error LNK2001: unresolved external symbol "public: __thiscall BitMapObject::~BitMapObject(void)" (??1BitMapObject@@QAE@XZ)main.obj : error LNK2001: unresolved external symbol "void __cdecl RotateBlock(void)" (?RotateBlock@@YAXXZ)main.obj : error LNK2001: unresolved external symbol "void __cdecl Move(int,int)" (?Move@@YAXHH@Z)main.obj : error LNK2001: unresolved external symbol "void __cdecl DrawMap(void)" (?DrawMap@@YAXXZ)main.obj : error LNK2001: unresolved external symbol "void __cdecl NewBlock(void)" (?NewBlock@@YAXXZ)Debug/tetris.exe : fatal error LNK1120: 5 unresolved externalsError executing link.exe.tetris.exe - 6 error(s), 0 warning(s)

##### Share on other sites
Artgeek, I would suggest if you want to understand and tinker with the code, you need to get it into your memory more. Get a book on WinAPI as a reference and a book on DX just for some fun so ya don''t have to go through all that code with no result.. WinAPI is complicated and extremely hard to remember at times, but the key is repetition and taking a break with something fun..for instance DirectX, there are lots of stuffs you can tinker with. And with DirectX alot of it uses winapi as a backbone so you get the best of both worlds. Btw, whoever said the key to learning to program is to make a tetris clone..is an idiot.. The key to learning how to program is repetition, result, and fun.. heh btw nice game Compiles great for me on dev-cpp. Duno about Linux tho, i''ll have to test that out on my debian box.
-Vigo.

##### Share on other sites
Good job however,
I am running visual c++ 6.0 and I am getting these errors, any ideas?? cuz I am all out of them.

--------------------Configuration: Tetris - Win32 Debug--------------------
Compiling...
main.cpp
F:\Projects\Tetris\main.cpp(144) : error C2601: ''WinMain'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(208) : error C2601: ''GameInit'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(225) : error C2601: ''GameDone'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(230) : error C2601: ''GameLoop'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(239) : error C2601: ''NewGame'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(260) : error C2601: ''DrawTile'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(269) : error C2601: ''DrawMap'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(298) : error C2601: ''NewBlock'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(447) : error C2601: ''RotateBlock'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(479) : error C2601: ''Move'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(532) : error C2601: ''CollisionTest'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(556) : error C2601: ''RemoveRow'' : local function definitions are illegal
F:\Projects\Tetris\main.cpp(567) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

main.obj - 13 error(s), 0 warning(s)

##### Share on other sites
One more question, does the ''WinMain'' class replace the normal ''void main'' class when you are using windows.h? I am new to windows programming so I am just trying to figure this all out.

GloveMan

##### Share on other sites
quote:
Original post by GloveMan
One more question, does the ''WinMain'' class replace the normal ''void main'' class when you are using windows.h? I am new to windows programming so I am just trying to figure this all out.

GloveMan

Yes it does, and do keep in mind that the C++ standard now is to use ''int main''.

##### Share on other sites
Maybe I just don't know enough C++ yet, but I think this was a terrible "lesson". I didn't even bother finishing because I had no idea what I was doing. I found myself copying what you had provided and trying to make sense of it myself since there was no explanation given.

##### Share on other sites
You realise the last reply to this was [i]7 years ago[/i], and that the original post is from [i]2003[/i]?

I'm sure this topic was helpful to a lot of people, but you're right that it isn't the best learning resource available. You're unlikely to get any response or updates from the original poster at this point though. If you're interested in C++ game development and have spent some time learning the basics you could consider trying [url="http://lazyfoo.net/SDL_tutorials/index.php"]Lazy Foo's SDL tutorials[/url].

##### Share on other sites
it may be an old post, but i think its just as valuable today as it was then, i just found it myself and wish ppl where still paying attention enough to answer questions, i have one or two

##### Share on other sites
for example this one...i know im a noob but anyone know what this error is from?

Building Makefile: "C:\Dev-Cpp\projects\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\projects\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

g++.exe main.o bitmapobject.o -o "tetris.exe" -L"C:/Dev-Cpp/lib" -mwindows

C:/Dev-Cpp/lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'
collect2: ld returned 1 exit status

make.exe: *** [tetris.exe] Error 1

Execution terminated

##### Share on other sites
Hehe, and that[i] last[/i] time I replied was around a year ago today. To be honest, you'd be better off simply starting a new topic; you could link to this one if you'd like to refer other people to it. The code in question is pretty old, and likely has a number of problems including incompatibility with more modern versions of the libraries used.

I'm going to close this topic -- but as mentioned, feel free to start a new one and link to this if you would like to.

I will however firstly point out [url="http://www.jasonbadams.net/20081218/why-you-shouldnt-use-dev-c/"]why you shouldn't use Dev-C++[/url], and also re-iterate what I said a year ago; while there is possibly still some value in this topic, as a beginner starting now you're probably better off with a more recently updated resource such as [url="http://lazyfoo.net/SDL_tutorials/index.php"]Lazy Foo's SDL tutorials[/url] (linked above). The original post of this topic is now 10 years old, and unfortunately that means that a lot of it simply isn't relevant any more, and the choice of Dev-C++ as a development environment will be nothing but harmful to your learning experience.