Thread: Ok, Im confused

  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
    Location
    Waterloo, Texas
    Posts
    5,708
    the problem is the 'y' variable in the second loop needs to be initialized each iteration of the first loop...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 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, 04:49 PM
  3. why wont this compile?!? :confused:
    By jdude in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2004, 01: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, 11:11 PM