Agreon

Member
  • Content count

    15
  • Joined

  • Last visited

Community Reputation

167 Neutral

About Agreon

  • Rank
    Member
  1. Thank you for your suggesstion, but let's say i have a game with many entities; That would be very confused in the game class.
  2. Hello. I think the best way is to start with an example of my problem. I made a little game with diffrent objects. Each object interacts with the others and access them. (Like if a bullet hits a enemy, it destroys the enemy). So maybe you would put all this code in the Game-function()-Method. I read somewhere that each object should update itself. So i made a Update()-function for every class.   Example: I got a Ball-Class that checks in his Update()-Function if it collides with the player or other game objects. If the ball touches the lower border, the players lifes are decreased. The Question: How do i realise that? I first thought of giving the player each game-loop through the update-function. That wasn't that clean. So i changed the Ball Class Ball::Ball( Player *player, posX, .... Now i could access the player in the Update()-function to change its values. But i dont know if this is good practise. One big thing is, that i dont only have to access the player, but nearly every object in the game. Here is an example of my Ball Class-Structure: class Ball : public cEntity { private: double m_VelX; double m_VelY; double m_Speed; bool m_Super; Player* m_Player; vector<Ufo*> *m_Ufos; vector<PowerUp*> *m_PowerUps; cAnimationManager *m_AnimationManager; cSound *m_Sound; public: Ball(cGraphics *graphics, cAnimationManager *animManager, cSound *sound, Player *player, vector<Ufo*> *ufos, vector<PowerUp*> *powerups, string texture, int posX, int posY, int width, int height); ~Ball(); void Update( double delta ); void CheckCollision(); void Draw(); void Reset(); Should i continue this way?   Thanks,   Daniel
  3. Earth Defender

    2 Weeks ago, the youtuber Let’s Game Dev started a Community Challenge. You had to make a curiose Pong clone in 2 Weeks. So i sat down and wrote a Game. During the development i learned how to connect C++ with a mysql-database. As always the Sound and the Animations were the biggest problems.( I got the sounds from Freesound.org.) But now i finished it and created a youtube-video. It would be cool if you can give me feedback :)   Daniel   https://www.youtube.com/watch?v=cUFn80fNUfA   Links:   Download: http://www.mediafire.com/download/t2fggc2v3nnoun4/EarthDefender.zip Source: https://github.com/Agreon/EarthDefender  
  4. Thanks, i will try it out!   Ok, that was my problem. Thanky you!
  5. Hey,   I switched to Ubuntu yesterday and wanted to continue my project. And everything works fine but one little thing not: I am reading some img-paths from a text file, sorted like this:   img/ground/grass1.png img/ground/grass2.png ...   On Windows everything worked fine. When i now want to start the program with Linux it works, but it cannot open the files with the path that was read from the config-file. If i use the function manualy like loadTexture("img/ground/grass1.png") it works! ( Function: loadTexture( const char* path ) ).   Is there a known bug with File handling in Linux?   Thanks,   Daniel  
  6.   How to delete or merge a post?
  7. Hey, I always create an huge enum in my project and one function where all the 'loadTexture' functions are called. I think its not the best way so i thougt i could easy read the img src from an extern file (url:foo.png name:TEXTURE_TREE). The only problem is: I still have to declare the enum. ( In there are some values like 'TEXTURE_TREE' and so on that are called on orher places). Is there a way to automatically fill this enum, or do you have a better idea?   thanks,   Daniel
  8. Hey, I always create an huge enum in my project and one function where all the 'loadTexture' functions are called. I think its not the best way so i thougt i could easy read the img src from an extern file (url:foo.png name:TEXTURE_TREE). The only problem is: I still have to declare the enum. ( In there are some values like 'TEXTURE_TREE' and so on that are called on orher places). Is there a way to automatically fill this enum, or do you have a better idea?   thanks,   Daniel
  9. SDL input manager

    Perhaps you could share your solution so others can benefit from this thread. Otherwise, it may as well not have been started.   It was my fault. I dont know why, but i forgot to call the event function -.-.
  10. Hey, in my previous post i asked about my Input Manager. But then something came in my mind. Instead of calling the "isKeyDown" function everytime, couldn´t i just set a global variable bool key[] and only change and check them? Or when i want to get my mouse coordinates, do i call "getMousePositionX" or do i just create global variables "mouseX" and "mouseY"? Whats cleaner?
  11. SDL input manager

    I solved my problem thanks
  12. SDL input manager

      bool m_keys[323];   SDLK_ESCAPE has the value 27. But thats not the problem. Every other Key doesnet work.     With PollEvent i get all the events, so that i can handle them. I call it everytime in the loop, before update, where i check the m_keys.    
  13. Hy, I worked on an Input manager but it doesnt work. This is, what it looks like:   #include "cInput.h" cInput::cInput(void) { m_MouseX = 0; m_MouseY = 0; for(int i = 0; i < 323; i++) { m_keys[i] = false; } } void cInput::handleInput(SDL_Event evt) { while(SDL_PollEvent(&evt)) { switch(evt.type) { case SDL_QUIT: running = false; break; case SDL_KEYDOWN: m_keys[evt.key.keysym.sym] = true; //if i add if(evt.key.keysym.sym == SDLK_ESACPE) running = false; it works. break; case SDL_KEYUP: m_keys[evt.key.keysym.sym] = false; break; case SDL_MOUSEBUTTONDOWN: if(evt.button.button == SDL_BUTTON_LEFT) { m_leftMouse = true; } else { m_rightMouse = true; } m_MouseX = evt.button.x; m_MouseY = evt.button.y; break; case SDL_MOUSEBUTTONUP: if(evt.button.button == SDL_BUTTON_LEFT) { m_leftMouse = false; } else { m_rightMouse = false; } m_MouseX = evt.button.x; m_MouseY = evt.button.y; break; case SDL_MOUSEMOTION: m_MouseX = evt.button.x; m_MouseY = evt.button.y; break; } } } bool cInput::keyPressed(SDLKey key) // Here is the function { return m_keys[key]; } bool cInput::leftMousePressed() { return m_leftMouse; } bool cInput::rightMousePressed() { return m_rightMouse; } int cInput::getMousePositionX() { return m_MouseX; } int cInput::getMousePositionY() { return m_MouseY; } But now, when i try to use it in my main update function, it doesnt work. The Function "keyPressed" returns false every time.   if(Input->keyPressed(SDLK_ESCAPE)) { running = false; }   Does anybody have an Idea what im doing wrong?    
  14. Hy, I worked on an Input manager but it doesnt work. This is, what it looks like:   #include "cInput.h" cInput::cInput(void) { m_MouseX = 0; m_MouseY = 0; for(int i = 0; i < 323; i++) { m_keys[i] = false; } } void cInput::handleInput(SDL_Event evt) { while(SDL_PollEvent(&evt)) { switch(evt.type) { case SDL_QUIT: running = false; break; case SDL_KEYDOWN: m_keys[evt.key.keysym.sym] = true; //if i add if(evt.key.keysym.sym == SDLK_ESACPE) running = false; it works. break; case SDL_KEYUP: m_keys[evt.key.keysym.sym] = false; break; case SDL_MOUSEBUTTONDOWN: if(evt.button.button == SDL_BUTTON_LEFT) { m_leftMouse = true; } else { m_rightMouse = true; } m_MouseX = evt.button.x; m_MouseY = evt.button.y; break; case SDL_MOUSEBUTTONUP: if(evt.button.button == SDL_BUTTON_LEFT) { m_leftMouse = false; } else { m_rightMouse = false; } m_MouseX = evt.button.x; m_MouseY = evt.button.y; break; case SDL_MOUSEMOTION: m_MouseX = evt.button.x; m_MouseY = evt.button.y; break; } } } bool cInput::keyPressed(SDLKey key) { return m_keys[key]; } bool cInput::leftMousePressed() { return m_leftMouse; } bool cInput::rightMousePressed() { return m_rightMouse; } int cInput::getMousePositionX() { return m_MouseX; } int cInput::getMousePositionY() { return m_MouseY; } But now, when i try to use it, it doesnt work. The Function "keyPressed" returns false every time.   if(Input->keyPressed(SDLK_ESCAPE)) { running = false; } Does anybody have an Idea what im doing wrong?