SDL timing not working!

So I read lazyFoo's SDL tutorial and now I wanna make my own game.
I'm making my own rendition of tetris.

The Problem:
the blocks wont fall down unless my mouse is moving over the window. How do i fix this.


PS. I think the code might be irrelevant but i'll add my main() and the snippet that explains my blocks falling. Incase it helps.


look at line 13 of the first snippet and line 29 of the second


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
int main(int argc, char* args[])
{
	bool quit = false;

	if(!init())
		return 1;
	
	// 2 timers 1 to control fps and other to control drop movement
	Timer t1;

	Cube jj;
	
	down.start();
	while(!quit)
	{
		t1.start();
		

		while(SDL_PollEvent(&event))
		{
			if(event.type == SDL_QUIT)
				quit = true;
			jj.handleEvent();
		}
	

		SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0xFF,0xFF,0xFF));
		applysurface(0,0,background,screen);
		jj.show();

		if(SDL_Flip(screen) ==-1)
			return 1;

		if(t1.get_ticks() < 1000/FPS)
			SDL_Delay(1000/FPS - t1.get_ticks());
		
	}

	bye();
	return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
void Cube::handleEvent()
{
	if(event.type == SDL_KEYDOWN)
	{
		switch(event.key.keysym.sym)
		{
		case SDLK_RIGHT: xVel += 34;break;
		case SDLK_LEFT: xVel -= 34; break;
		case SDLK_DOWN: yVel += 34; break;
		}
	}
		
	cube.x += xVel;
	b1.move(xVel,0);
	b2.move(xVel,0);
	b3.move(xVel,0);
	b4.move(xVel,0);

	//dont go outside the grid
	if(cube.x < 100 || cube.x > 440-cube.w)
		{
			cube.x -= xVel;
			b1.move(-xVel,0);
			b2.move(-xVel,0);
			b3.move(-xVel,0);
			b4.move(-xVel,0);	
		}

	//fall autonomously
	if(down.get_ticks() >= 1000)
	{
			yVel += 34;
			down.start();
	}

	
	cube.y += yVel;
	b1.move(0,yVel);
	b2.move(0,yVel);
	b3.move(0,yVel);
	b4.move(0,yVel);
		


	if(cube.y+ 68 > 710)
	{
		cube.y -= yVel;
		b1.move(0,-yVel);
		b2.move(0,-yVel);
		b3.move(0,-yVel);
		b4.move(0,-yVel);
	}

	// stop movement when not intended
	xVel = 0;
	yVel = 0;
}

Topic archived. No new replies allowed.