Archived

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

Evil_Greven

Tetris clone in an hour with C++.

Recommended Posts

Hey Greven, a thousand thanks for the tutorial! It's fun to learn while actually making the game

But every time I try to compile, I get a

fatal error C1010: unexpected end of file while looking for precompiled header directive

at the end of my main.cpp and bitmapobject.cpp files

Any idea what I can do to fix this? Could it have anything to do with the fact that when I created the project, it gave me a source file named "Falling Blocks Game" (name of my project) but I didn't use it for anything?

Edit: Oops forgot, I am running VC++ .NET

[edited by - Jupiter Hessius on January 27, 2004 5:45:10 PM]

Share this post


Link to post
Share on other sites
fatal error C1010: unexpected end of file while looking for precompiled header directive

---You're using precompiled headers! Bad human (imho)!

Be sure to have #include "stdafx.h" at the very beginning (before the #pragma once, even) of every file that complains like that, and that should fix it.

Edit: That's if you're using Microsoft's Visual Studio to do the project. I'm not sure who else does precompiled headers, or what they'd want you to include.




"Remember: Silly is a state of Mind, Stupid is a way of Life." -- Dave Butler


[edited by - Indigo Darkwolf on January 27, 2004 5:40:34 PM]

Share this post


Link to post
Share on other sites
Woohoo it works Thanks much!

Haha, that is, it works after I go back and delete extra semicolons I didn''t need, and put it other ones I did need (I just can''t get used to the semicolons at the end of every line yet I guess). And of course, made sure everything was capitalized properly.

But I did need that file at the top. Woohoo, now I can go about doing many great things, such as oh, changing the blocks into penguins!

Share this post


Link to post
Share on other sites
Evil_Greven    410
Penguins scare me.

But yeah, have fun with it; change anything and everything you can, while keeping it running. If you''re not having fun making a game, you should question your motivations for programming games in the first place. Is it because you want a career in game development or is it a hobby? Myself, I''ve not yet decided which route to take.

-Greven

Share this post


Link to post
Share on other sites
kingpinzs    117
I really Like this tut.

It was easy and really basic.

Now I just need to figure out all the ins and out's of it.

I was wondering Can this game be made into a break out clone game very easly?

Or how about into a pong clone?



[edited by - kingpinzs on February 17, 2004 6:41:14 PM]

Share this post


Link to post
Share on other sites
kingpinzs    117
For some reson My score part to work. It just reads 3002 and changes to 4 when the up button is pushed then back to 3002. It wont count the times a row disapers. Can any one help?

Share this post


Link to post
Share on other sites
Evil_Greven    410
You can modify it fairly easily. I changed this general structure a bit and made a 2D space shooter out of it. You'll probably want to make another bitmap for the ball (you could even do one with multiple frames to make it look good).

Can you post the code that controls your scoring?

-Greven

[edited by - Evil_Greven on February 18, 2004 12:38:10 PM]

Share this post


Link to post
Share on other sites
kingpinzs    117
I am not sure how do it yet.

this is what I was thinking

int v_score;
int temp = v_score ;
DrawTile(MAPWIDTH+1,GREY,(9+temp/100000));
if(temp >= 100000)
temp-=(100000*(temp/100000));
DrawTile(MAPWIDTH+2,GREY,(9+temp/10000));
if(temp >= 10000)
temp-=(10000*(temp/10000));
DrawTile(MAPWIDTH+3,GREY,(9+temp/1000));
if(temp >= 1000)
temp-=(1000*(temp/1000));
DrawTile(MAPWIDTH+4,GREY,(9+temp/100));
if(temp >= 100)
temp-=(100*(temp/100));
DrawTile(MAPWIDTH+5,GREY,(9+temp/10));
if(temp >= 10)
temp-=(10*(temp/10));
DrawTile(MAPWIDTH+6,GREY,(9+temp));



and put the counter in here some were I just dont know were to add it.

void Move(int x, int y)
{
if(CollisionTest(x, y))
{
if(y == 1)
{
if(sPiece.y<1)
{
//you lose! new game.

NewGame();
}

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

Share this post


Link to post
Share on other sites
kingpinzs    117
never mind I was amking it to hard. I just needed to declare a globel varible and put it to zero then in the fill loop add 1 to the varible then in my print score loop I just called the gloable varible and it worked.

Share this post


Link to post
Share on other sites
MarpleSoft    122
hmm i had to fix a few errors i had, but i after i did i got no errors, great job with the tutorial, i'm looking foward to making graphics and sound for this game.

[edited by - MarpleSoft on February 22, 2004 4:39:53 PM]

Share this post


Link to post
Share on other sites
TsukasaZero    122
Awesome tutorial man, but in Dev C/C++ I get 2 warnings and 1 error. The error occurs on line 277 (starting the definition of the RotateBlock() function) and it says "parse error before ''{'' token".

I tried everything, copy and pasting the functions before it, the function itself, but the same thing always comes up. Help?

Share this post


Link to post
Share on other sites
I don''t think I will ever be able to do it because the only think I can is to write scenarios for the games. We will start with programing this year at school so I should get better soon. It''s kinda'' hard to learn it because there aren''t many guides in Bulgaria.

Share this post


Link to post
Share on other sites
Skalol    122
Hi!
Thanks for that tutorial! The zip file seems not to be downloadable, so i slowly work with the first post.

Sorry, i edited my post 'cause i've made a big mistake. Now it compiles..

Lolo from france.

[edited by - Skalol on February 27, 2004 4:28:33 AM]

Share this post


Link to post
Share on other sites
Goosey    122
I am getting two errors:

tetrisClone error LNK2019: unresolved external symbol "void __cdecl DrawTile(int,int,enum TILECOLOR)" (?DrawTile@@YAXHHW4TILECOLOR@@@Z) referenced in function "void __cdecl DrawMap(void)" (?DrawMap@@YAXXZ)

tetrisClone fatal error LNK1120: 1 unresolved externals


I don''t know what this error is about. I''ve been comparing my code to the post''s source for the last hour.. Please someone help me :|

AIM: DarkGoosey
ICQ: 14128911
MSN: DarkGoosey@hotmail.com
Email: td1@sssnet.com

Share this post


Link to post
Share on other sites
georgia    122
Hey I just tried it and it runs perfectly!!!
Thanks Evil_Greven... Now I have to work on changes!!! I hope I will manage to do it!!

Georgia

Share this post


Link to post
Share on other sites
SimonTreloar    122
This tutorial was fantastic!

I''ve been looking everywhere for a Tetris clone that I could follow through the code and work it out bit by bit.

I''ve only just started C++ programming but a lot of this makes sense to me and your commenting really helps.

Thanks for making this available to everyone!! For people like me, it''s a godsend!

Share this post


Link to post
Share on other sites
Evil_Greven    410
If these suggestions don''t help, please post your code.

TsukasaZero,

Double-check the code where the RotateBlock() function is, and also just above it for mistakes.

Elfs1der,

That''s rather odd. You should double-check the two bitmapobject files for mistakes, it might be the problem.

Goosey,

Make sure the call to DrawTile() in function DrawMap() is correctly copied. If it is, make sure you have the DrawTile() function declared correctly at the top like the rest of them.

-Greven

Share this post


Link to post
Share on other sites
Goosey    122
Thx for the help Greven. I found my error.. I had decided to use an enum instead of the const int''s for the list of TILECOLORs.. Well in the prototype I had accounted for this alteration, but I did not anywhere else in the code! Have it working perfectly now.

Thanks a lot for the help and for the great tutorial!

Share this post


Link to post
Share on other sites
CyberSlag5k    514
Awsome. Definitely article worthy.

When you find yourself in the company of a halfling and an ill-tempered Dragon, remember, you do not have to outrun the Dragon...

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.