Play my pong game!

Started by
23 comments, last by supercoder74 18 years, 6 months ago
Quote:Original post by dudedbz1
Why threads? I have a mario clone that uses two places for input and one never stops the other... I didnt look at your code, so sorry I am mistaken, but are you using a
Uint8 *somenameforyourkeys/*mine is just "keys"*/;keys = SDL_GetKeyState(0);
? If not, try it.

Edit: I looked, and it seems you did... Do you know where the bug is? I mean, wont my mario clone mess up too if they use the same kind of input?


Really? Could you some of your code that deals with the keyboard?
I program in my sleep,but when I sleep I use the partition in my head that doesnt have g++ or the .net library, so im kinda screwed.
Advertisement
Yeah, sure! Here:
Uint8 *keys = SDL_GetKeyState(NULL);	    	    SDL_Event event;    		        if (SDL_PollEvent(&event) == true)    	{    		if (event.type == SDL_QUIT && Quit())    	        isRunning = false;    	}    	    	if (keys[SDLK_ESCAPE])    	    isRunning = false;    	            if ((Mario.x + Mario.Char->w) < Luigi.x)            Luigi.Char = Luigi.CharLeft;        if (Mario.x > (Luigi.x + Luigi.Char->w))            Luigi.Char = Luigi.CharRight;    	    	//------------------------------//    	//          MARIO               //    	//------------------------------//        if (keys[SDLK_UP])        {        	Mario.Jump = true;        }        if (keys[SDLK_LEFT] &&             Mario.x >= 0 &&            Mario.CollideOnRight(Luigi) == false)        {            Mario.x -= 3;                        Mario.Char = Mario.CharLeft;        }        if (keys[SDLK_RIGHT] &&             (Mario.x + Mario.Char->w) <= 800 &&            Mario.CollideOnLeft(Luigi) == false)        {            Mario.x += 3;                        Mario.Char = Mario.CharRight;        }    	    	//------------------------------//    	//           Luigi              //    	//------------------------------//        if (keys[SDLK_KP8])        {        	Luigi.Jump = true;        }        ...  Same input as mario        ...  Just with the keypad(keys[SDLK_KP4] .. etc.)}

Thats pretty much it. I'm making my pong clone to be two-player too, so when I finish I will tell you if the same problem persists. Good-luck.
I dont know if that'll help you much though...
-----------------------------....::::DRAGON BALL Z::::....C<<"+"<<"+"; // Go C++ !!!-----------------------------
Quote:Original post by dudedbz1
Yeah, sure! Here:
*** Source Snippet Removed ***
Thats pretty much it. I'm making my pong clone to be two-player too, so when I finish I will tell you if the same problem persists. Good-luck.
I dont know if that'll help you much though...


Hmm. It looks the same. The problem may lie somewhere else.
Nice code, by the way! I might try some 2d scroller sometime. I bet I could reuse that entity code for it..
I program in my sleep,but when I sleep I use the partition in my head that doesnt have g++ or the .net library, so im kinda screwed.
Yeah, maybe so... Uhhh... Could it be in your velocities? Cuz I never understood them and I never used them. In my pong I have this:
if (Keys[SDLK_LEFT])    P1_Paddle.Setx(P1_Paddle.Getx() - 1);if (Keys[SDLK_RIGHT])    P1_Paddle.Setx(P1_Paddle.Getx() + 1);

So maybe you should check those. And I reuse my old code too. Much of the initializing is from my mario clone. Just different variables. Good luck.
-----------------------------....::::DRAGON BALL Z::::....C<<"+"<<"+"; // Go C++ !!!-----------------------------
Quote:Original post by dudedbz1
Yeah, maybe so... Uhhh... Could it be in your velocities? Cuz I never understood them and I never used them. In my pong I have this:
if (Keys[SDLK_LEFT])    P1_Paddle.Setx(P1_Paddle.Getx() - 1);if (Keys[SDLK_RIGHT])    P1_Paddle.Setx(P1_Paddle.Getx() + 1);

So maybe you should check those. And I reuse my old code too. Much of the initializing is from my mario clone. Just different variables. Good luck.


What you just used right there are velocities. Well, kinda. You add the velocity to the x and y. so if the velocity is -1, and you add it to x, it makes x go down by one. The reason this is useful is that if you just change the line that declares the velocity everything instantly moves faster if you add to it, or moves slower if you decrease from it. I dont think that is the problem, because the paddle velocity remains constant.
I program in my sleep,but when I sleep I use the partition in my head that doesnt have g++ or the .net library, so im kinda screwed.

This topic is closed to new replies.

Advertisement