Need help with my Pong game

Started by
13 comments, last by eektor 18 years, 4 months ago
Hmmm... Just to clarify myself, this is what I do:
// CApp_Input.h#ifndef CAPP_INPUT_H#define CAPP_INPUT_H#include <SDL/SDL.h>class CApp_Input{    public:        CApp_Input();        ~CApp_Input();        Uint8 GetKey(int aKey);};#endif//CApp_Input.cpp#include <SDL/SDL.h>#include "CApp_Input.h"CApp_Input::CApp_Input(){}CApp_Input::~CApp_Input(){}Uint8 CApp_Input::GetKey(int aKey){    return (SDL_GetKeyState(NULL)[aKey]);}// in my actual game code (yup, a pong clone too)if (m_MainApp.GetKey(SDLK_LEFT))        m_Paddles[m_P1].Setx(m_Paddles[m_P1].Getx() - m_Paddles[m_P1].GetxSpeed());    if (m_MainApp.GetKey(SDLK_RIGHT))        m_Paddles[m_P1].Setx(m_Paddles[m_P1].Getx() + m_Paddles[m_P1].GetxSpeed());


That's what I do. You can implement that into your class easily. The m_Paddles[...] code is just an example, it's what I do. But your code may be extremely different.

C++
Advertisement
Sorry, for the late reply. I didn't get much chance to work on my game this weekend.

I did what you said and the controls are still choppy. I think it has something to do with my update function that I posted earlier. My first version of pong worked fine when I calculated the movement based on frame rate. This time I tried to make it time based and it's not working well.
Quote:Original post by eektor
Sorry, for the late reply. I didn't get much chance to work on my game this weekend.

I did what you said and the controls are still choppy. I think it has something to do with my update function that I posted earlier. My first version of pong worked fine when I calculated the movement based on frame rate. This time I tried to make it time based and it's not working well.


Ok.. Well, you're multipling m_Vy with deltaTime, correct? What happens if you just add the velocities, without the delta time? Is it still choppy? Because technically that should be correct. Maybe you're passing in too many different times, like 0.05, 1, 5, 0.3 and so on...

Good luck!

C++
As for the rounding, you could do this:
static_cast<typeOfYourChoice>(someValueToBeConvertedToTypeOfYourChoice);//you can use it likefloat bob = static_cast<float>(bill);// if bill was 5, bob would become 5.0
Ok, so I capped the frame rate and put the addition of delta velocity instead of multiplaction and the controls and ball movement is nice and smooth.

Only problem is somehow the screen seems to be shifting the left. Both paddles which should not move in the x direction are moving right. Do you know what could be wrong?

This topic is closed to new replies.

Advertisement