Jump to content
  • Advertisement

WaleedH95

Member
  • Content Count

    33
  • Joined

  • Last visited

Community Reputation

102 Neutral

About WaleedH95

  • Rank
    Member
  1. WaleedH95

    SDL FPS and Incrementing Issues

    Thanks alot, bro.
  2. WaleedH95

    SDL FPS and Incrementing Issues

    And how do I fix that?
  3. WaleedH95

    SDL FPS and Incrementing Issues

    I wasn't sure where this belonged.
  4. [size=2]Ok, so what I want to accomplish here is everytime I click on the screen a square (SDL_Rect) appears and moves downwards, once it reaches the end of the screen it's supposed to go back up to the top and back down again, and so on. But I have two problems. First, the rate at which the square is moving downwards varies, like first it'll go down slowly suddenly speed up and slow down again. Second, when the square reaches the end of the window I increment it's y value by -10 but all it does is go straight back up, doesn't even move backwards. Thanks in advance. #include <SDL.h> #include <SDL_mixer.h> #include <SDL_image.h> #include <vector> using namespace std; int main(int argc,char*args[]){ SDL_Event event; bool running = true; SDL_Init(SDL_INIT_EVERYTHING); // the rectangle vector<SDL_Rect> daSquares; SDL_Rect daSquare; // keys inputted Uint8*keys = SDL_GetKeyState(NULL); // regulating fps int start; int fps = 20; // the screen SDL_Surface* screen; screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE); while(running == true){ start = SDL_GetTicks(); while(SDL_PollEvent(&event)){ if(event.type == SDL_MOUSEBUTTONDOWN){ if(event.button.button == SDL_BUTTON_LEFT){ int x = event.button.x; int y = event.button.y; daSquare.x = x; daSquare.y = y; daSquare.w = 20; daSquare.h = 20; daSquares.push_back(daSquare); } } if(event.type == SDL_QUIT){ running = false; } } // uodating the screen and regulating frameraate SDL_Flip(screen); if(1500/fps > start - SDL_GetTicks()){ SDL_Delay(1500/fps - (start - SDL_GetTicks())); } // filling the rectangles SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0,0,0)); // updating their locations for(int i = 0; i <daSquares.size(); i++){ SDL_FillRect(screen,&daSquares,SDL_MapRGB(screen->format,0,200,0)); daSquares.y += 10; if(daSquares.y >= 460) { while(daSquares.y >= 10) {daSquares.y -= 10;} } } } SDL_Quit(); return 0;}
  5. Ok, so what I want to accomplish here is everytime I click on the screen a square (SDL_Rect) appears and moves downwards, once it reaches the end of the screen it's supposed to go back up to the top and back down again, and so on. But I have two problems. First, the rate at which the square is moving downwards varies, like first it'll go down slowly suddenly speed up and slow down again. Second, when the square reaches the end of the window I increment it's y value by -10 but all it does is go straight back up, doesn't even move backwards. Thanks in advance. #include <SDL.h> #include <SDL_mixer.h> #include <SDL_image.h> #include <vector> using namespace std; int main(int argc,char*args[]){ SDL_Event event; bool running = true; SDL_Init(SDL_INIT_EVERYTHING); // the rectangle vector<SDL_Rect> daSquares; SDL_Rect daSquare; // keys inputted Uint8*keys = SDL_GetKeyState(NULL); // regulating fps int start; int fps = 20; // the screen SDL_Surface* screen; screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE); while(running == true){ start = SDL_GetTicks(); while(SDL_PollEvent(&event)){ if(event.type == SDL_MOUSEBUTTONDOWN){ if(event.button.button == SDL_BUTTON_LEFT){ int x = event.button.x; int y = event.button.y; daSquare.x = x; daSquare.y = y; daSquare.w = 20; daSquare.h = 20; daSquares.push_back(daSquare); } } if(event.type == SDL_QUIT){ running = false; } } // uodating the screen and regulating frameraate SDL_Flip(screen); if(1500/fps > start - SDL_GetTicks()){ SDL_Delay(1500/fps - (start - SDL_GetTicks())); } // filling the rectangles SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0,0,0)); // updating their locations for(int i = 0; i <daSquares.size(); i++){ SDL_FillRect(screen,&daSquares,SDL_MapRGB(screen->format,0,200,0)); daSquares.y += 10; if(daSquares.y >= 460) { while(daSquares.y >= 10) {daSquares.y -= 10;} } } } SDL_Quit(); return 0;}
  6. WaleedH95

    What to learn and when?

    I need help deciding what to learn and when. First of all I'm improving my basic C++ skills currently, but I am planning to learn SFML programming. Should I learn OpenGL afterwards or should I learn Ogre3D and havok first? Also, what about Nvidia's PhysX SDK. Help?
  7. WaleedH95

    SDL_Rect & Game Loop [Help Please]

    I did the button thing, I admit, I was blindly following Lazyfoo that's why I had it on motion. Thanks for that. And the daSquare.y += 10 worked, but there's still one problem and that is whenever I build the program the entire screen is red. Thanks again.
  8. WaleedH95

    SDL_Rect & Game Loop [Help Please]

    Dude what I want to happen is this, the user clicks on a place in the window and the rectangle is formed, after that the rectangle moves downwards by 10 pixels until it hits the bottom of the window. Then it goes up. If I did what you suggested when the user clicked the rectangle would appear 10 pixels below the rectangle, and it wouldn't be able to update either. Is there any way I can make those variables global by any chance? If not what do you suggest I do to keep the rectangle updating, I need the y+=10 right after the FillRect so it keeps on updating. If I had it in the button loop it would only work when I clicked. Thanks for replying.
  9. Variables declared in my if loop and when I add y+=10 for the square to go down I get an error. Also when I run it the screen is completely red, even though I still didn't declare x or y as zero. Help please while(running == true){ start = SDL_GetTicks(); while(SDL_PollEvent(&event)){ if(event.type == SDL_MOUSEBUTTONDOWN){ if(event.button.button == SDL_BUTTON_LEFT){ int x = event.motion.x; <--- These variables arent defined in the FillRect function int y = event.motion.y; daSquare.x = x; daSquare.y = y; daSquare.w = 20; daSquare.h = 20; } } if(event.type == SDL_QUIT){ running = false; } } SDL_FillRect(screen,&screen->clip_rect,SDL_MapRGB(screen->format,0,0,0)); SDL_FillRect(screen,&daSquare,SDL_MapRGB(screen->format,0xff,0,0)); // y+=10;<--- Error is here if added. SDL_Flip(screen); if(1000/fps > start - SDL_GetTicks()){ SDL_Delay(1000/fps - (start - SDL_GetTicks())); } }
  10. WaleedH95

    Game Loop Explanation?

    Thanks for your answers. They've helped me out. I appreciate it.
  11. WaleedH95

    Game Loop Explanation?

    Hey guys, I'm new to SDL and the game loop etc. And I find the game loop incredibly confusing. Is it possible for you guys to write a game loop and explain it thoroughly? Thanks.
  12. WaleedH95

    Classes and Functions [Help?]

    Thanks a lot for your help guys, I finally got it to compile! (First OOP program by me ) Thanks rip-off, that definitely gave me some new info, and thanks mrbastard(lol) that helped out a lot.
  13. WaleedH95

    Classes and Functions [Help?]

    @ Ashalah: Thanks for replying. @ rip-off: I googled SDL_GetDisplaySurface() but I got no results at all. Maybe you meant SDL_GetVideoSurface()?
  14. Alright so I have my rectangle class which is included in my gameClass class. I tried to include the gameClass class into my rectangle class but I got an error and it told me it included itself, so I just made a gameClass object hoping that I would be able to use the screen surface in the fillRect function, but that is not the case. Some help please? Any code-criticism would also be welcome. Rectangle Class: #include "Integer.h" #include <SDL.h> #include <vector> using namespace std; class Rectangle{ public: vector <SDL_Rect> square; SDL_Rect make_rect(int x, int y, int w, int h); void fillRect(); int i; void doCrap(); SDL_Event event; }; SDL_Rect Rectangle::make_rect(int x, int y, int w, int h) { SDL_Rect rect = {x, y, w, h}; return rect; } void Rectangle::fillRect(){ i = 0; gameClass gO; SDL_FillRect(gO.screen,&square,SDL_MapRGB(gO.screen->format,0xff,0,0)); <-- Tells me I'm not allowed to use the screen from the gameClass i++; } void Rectangle::doCrap(){ int x = event.motion.x; int y = event.motion.y; square.push_back(make_rect(x,y,20,20)); fillRect(); } gameClass class: #include"Rectangle.h" #include <SDL.h> #include <vector> using namespace std; class gameClass{ public: void init(); void handleEvents(); void clean_up(); bool gameRunning; SDL_Surface*screen; }; void gameClass::init(){ screen = SDL_SetVideoMode(scr_w,scr_h,scr_bpp,SDL_SWSURFACE); SDL_WM_SetCaption("Gravityness",NULL); } void gameClass::handleEvents(){ SDL_Event event; if(SDL_PollEvent(&event)){ if(event.type == SDL_QUIT){ gameRunning = false; SDL_Quit(); exit(0); } if(event.type == SDL_MOUSEBUTTONDOWN){ if(event.type == SDL_BUTTON_LEFT){ Rectangle rObj; rObj.doCrap(); } } } SDL_Flip(screen); } void gameClass::clean_up(){ SDL_FreeSurface(screen); }
  15. WaleedH95

    How do I use classes with SDL variables

    Thanks, I actually did all that, but I realized I didnt put a semi-colon at the end of my class.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!