Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Tetris clone in an hour with C++.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
149 replies to this topic

#121 Goosey   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 March 2004 - 01:45 PM

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!

Sponsor:

#122 WH   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 March 2004 - 04:31 AM

nice job! thanks man

#123 Drevay   Banned   -  Reputation: 100

Like
Likes
Like

Posted 06 March 2004 - 09:46 AM

Very cool, very impressive, and very nice of you to do such a thing.

Two thumbs up.




#124 CyberSlag5k   Members   -  Reputation: 514

Like
Likes
Like

Posted 06 April 2004 - 05:19 AM

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...

#125 DigitalChaos   Members   -  Reputation: 214

Like
Likes
Like

Posted 07 April 2004 - 12:45 AM

I''m so glad this was re-stickied. It is awesome and a great tutorial!

#126 Fishy1500   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 April 2004 - 11:13 AM

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...

#127 Evil_Greven   Members   -  Reputation: 410

Like
Likes
Like

Posted 13 April 2004 - 02:59 PM

Did you create the bitmap file that it requires?

-Greven

#128 Fishy1500   Members   -  Reputation: 122

Like
Likes
Like

Posted 15 April 2004 - 11:12 AM

I just copied the bitmap file from his tutorial

#129 Evil_Greven   Members   -  Reputation: 410

Like
Likes
Like

Posted 15 April 2004 - 01:22 PM

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 key
if(wParam=VK_ESCAPE)
{
DestroyWindow(hWndMain);
return(0);//handled message
}


instead of:


//check for escape key
if(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

#130 ArtGeek   Members   -  Reputation: 122

Like
Likes
Like

Posted 16 April 2004 - 04:02 PM

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]

#131 ArtGeek   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 April 2004 - 06:40 AM

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.

#132 ArtGeek   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 April 2004 - 07:52 AM

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]

#133 lemurion   Members   -  Reputation: 336

Like
Likes
Like

Posted 17 April 2004 - 08:58 AM

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

#134 ArtGeek   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 April 2004 - 10:49 AM

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?

#135 Evil_Greven   Members   -  Reputation: 410

Like
Likes
Like

Posted 17 April 2004 - 03:16 PM

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


#136 ArtGeek   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 April 2004 - 03:33 PM

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.

#137 Evil_Greven   Members   -  Reputation: 410

Like
Likes
Like

Posted 17 April 2004 - 07:25 PM

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

#138 MetaCipher   Members   -  Reputation: 145

Like
Likes
Like

Posted 18 April 2004 - 03:59 PM

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 STL
using 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 function
void GameLoop(); //where the game actually takes place
void GameDone(); //clean up!
void DrawTile(int x, int y, int tile); //coordinates & tile type
void DrawMap(); //draw the whole map.. render function, basically
void 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 blocks
void 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 Surface
void 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 timing
bool 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]

#139 lesion   Members   -  Reputation: 122

Like
Likes
Like

Posted 18 April 2004 - 05:00 PM

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.

#140 MetaCipher   Members   -  Reputation: 145

Like
Likes
Like

Posted 19 April 2004 - 05:35 AM

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]




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS