Ok, Im confused

This is a discussion on Ok, Im confused within the C++ Programming forums, part of the General Programming Boards category; Ive written a tetris clone one of my first reall programs. While I used a tutorial to get the basic ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    11

    Question Ok, Im confused

    Ive written a tetris clone one of my first reall programs. While I used a tutorial to get the basic outline and functions I didnt use there code. After several days of learning GDI calls I finaly managed to get the block on screen and falling down. I was pretty estatic. A few switched variable fixes later I had it up and running pretty well i thought. That was untill I answed the phone and was chatting letting the program run. My collision detection isnt the greatest, took a few revisions to get it right but i thought i had it working great. ( and i did as i later discoverd) when i saw all the blocks just clump up at the top and it not starting a new game. I thought for shure it was my detection wasnt returning true when the blocks moved meaning to start a new game. After an hour or so in the debugger I found it wasnt my collision at all. It was the newgame call.

    Code:
    void NewGame()
    {
    	start_time = GetTickCount();
    	GAMESTARTED = false;
    	int y = 0, x = 0 ;
    
    	//startout the map
    	for(;x<MAPWIDTH;x++)
    	{
    		for(;y<MAPHEIGHT+1;y++)
    		{
    			if(y==MAPHEIGHT)  Map[x][y] = TILEGREY;
    			else
    				Map[x][y] = TILEBLACK;
    		}
    	}
    thats my new game function. it gets called on initalazion and when collision returns true during the movement function.

    What ended up causeing the error is where i declare y and x as 0.

    if i change it to..
    Code:
    	//startout the map
    	for(int x = 0;x<MAPWIDTH;x++)
    	{
    		for(int y = 0;y<MAPHEIGHT+1;y++)
    it works. I have no idea why from everything ive learned that should be the exact same save for where its done. Newgame is only called on initalize and a true on collision during move. So its not run though part way at any other time and even if it were the loops would be run any way. I cant figure out how thats any diffrent and why its causeing problems. Can any one else explain it?

    Thanks
    ~Meloshski

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Posts
    5,439
    the problem is the 'y' variable in the second loop needs to be initialized each iteration of the first loop...
    Code:
    int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000
    <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan
    (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000
    )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    11
    Oh my god... I think im just going to go shoot my self and save the world some of my stupidity.

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused
    By jeev2005 in forum C Programming
    Replies: 5
    Last Post: 06-01-2006, 02:04 PM
  2. Confused
    By (TNT) in forum C# Programming
    Replies: 1
    Last Post: 11-23-2005, 03:49 PM
  3. why wont this compile?!? :confused:
    By jdude in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2004, 12:13 AM
  4. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM
  5. Extern Question, really confused
    By SourceCode in forum C Programming
    Replies: 10
    Last Post: 03-26-2003, 10:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21