Jump to content
  • Advertisement

grechzoo

Member
  • Content Count

    19
  • Joined

  • Last visited

Community Reputation

100 Neutral

About grechzoo

  • Rank
    Member
  1. thanks guys. and 0circle0 i think it was my pc (needs a reformat) still i want to learn a more advanced API and oto OpenGL looks like the way to go,
  2. (this is a personally question regarding my project and I am not trying to make another SDL vs DirectX vs OpenGL) I will be working on a new 2d top down game, that will not really need any 3d assets, but I want to ask about my choices. Previously I have used SDL but I feel like the performanceof the image blitting is a little sluggish, even on a 2.4ghz processor one of my game prototypes would sometimes chug. And I need this game to perform well as it’s a big project rather than a simple prototype, so the choice I make must be flexible, powerful and reliable. So basically my question is, even for a 2d game, are OpenGL and DirectX the more flexible choices, and will they significantly open up my possibilities with my game compared to just using SDL alone? Or does their focus on 3D make their benefits negligible for my purposes? Also which would you recommend? I know with OpenGL, SDLs input controls and audio mixer are still needed. Is DirectX the better choice for those types of things then? (im porgramming in C++) Anyway depending on my advice i am going to start learning one of them no matter what. Are there any recommendations on books that don’t just focus on the 3d rendering side of the APIs? Considering I wont be using that aspect for this project. Many thanks and I truly appreciate any advice offered.
  3. the show function has its own counter that controls how fast the animation frames progress. so yeah, it looks like the best way to fix this problem will probably be to cap the framerate i think. (will also make the animation easier to deal with as well)
  4. Okay, so I have been working on a little platforming game,its pretty much complete. Played successfully on four computers, but none with CPU’smore powerful than 2.4ghz. However when I sent it to my friend who has a 3.8ghzi7, he noticed that the jump height of the character was about 10 pixels lessthan it should have been, and hence wasn’t able to navigate the platform. The code is below, im hoping there is a reason why a superclockedprocessor causes change in the movement physics, if the velocity change is timebased and not CPU power based. I need this to work well on any computer as itwill be on a portfolio. So I really hope you guys can help. The main loop is below. int main (int argc, char* args[]) { bool quit = false; int xPlayMenu = 0; initFunc(); Timer Delta; Player myPlayer; Level myLevel; loadAudio(); Mix_PlayMusic( soundTrack, -1 ); Delta.start(); // Game loop while (quit == false) { while (SDL_PollEvent (&event)) { myPlayer.handleInput(); if (event.type == SDL_QUIT) { quit = true; } } mainSoundCheck(); myPlayer.move(Delta.getTime()); Delta.start(); myLevel.draw(); myPlayer.show(Delta.getTime()); if( SDL_Flip( screen ) == -1 ) { return 1; } } Basically the delta clock is set the same way as LazyFoosets it in his tutorial (independence from frames.) The move function is below. void Player::move(Uint32 deltaTime) { checkCollisions(playerBox, platform); velocityCalc(); playerBox.x += xVelocity * (deltaTime / 1000.f); playerBox.y += yVelocity * (deltaTime / 1000.f); } Again the movement is based on the timing. So should imhoping im missing something obvious. Just in case, here is the movement and acceleration and physicsfunction called to calculate the velocity during the move function. void Player::velocityCalc() { if (rightDown == true) { if (grounded == true) { if (xVelocity < 0) { xVelocity += (ACCELERATION*2); } else if (xVelocity >= 400) { xVelocity = 400; } else { xVelocity += ACCELERATION; } } else if (grounded == false) { if (xVelocity < 0) { xVelocity += (ACCELERATION*0.5); } else if (xVelocity >= 400) { xVelocity = 400; } else { xVelocity += (ACCELERATION*0.25); } } } if (leftDown == true) { if (grounded == true) { if (xVelocity > 0) { xVelocity -= (ACCELERATION*2); } else if (xVelocity <= -400) { xVelocity = -400; } else { xVelocity -= ACCELERATION; } } else if (grounded == false) { if (xVelocity > 0) { xVelocity -= (ACCELERATION*0.5); } else if (xVelocity <= -400) { xVelocity = -400; } else { xVelocity -= (ACCELERATION*0.25); } } } else if ((leftDown == false) && (rightDown == false)) { if (xVelocity+(ACCELERATION*2) < 0) { xVelocity+=(ACCELERATION*2); } else if (xVelocity - (ACCELERATION*2) > 0) { xVelocity-=(ACCELERATION*2); } else { xVelocity = 0; } } if (jumping == true) { if (yVelocity < 0) { yVelocity +=(ACCELERATION*1.7); } if (yVelocity >= 0) { yVelocity = 0; jumping = false; } } if (falling == true) { if (yVelocity >= 1500) { yVelocity = 1500; } else { yVelocity += (ACCELERATION*1.5); } } } and finally this is the code that is executed when the jump button is pressed if (playKeystates[SDLK_SPACE]) { if (grounded) { Mix_PlayChannel( -1, jumpSound, 0 ); jumping = true; yVelocity = -750; } } i know this is a long topic and a weird problem. but Im hoping there is something obvious in the code that cause these different physics on a much faster machine (and i imagine much slower ones cause the opposite problem). Would truly be more grateful than can be imaginable for any help.
  5. thanks, yeah this was a key point to what i decided to do. on the key events i set up key down and up boolean flags. then in the main loop called a function to edit the x and y velocities based on those flags. this way the right key will continually be registered as true until it is released and the flag is turned to false. each time through the loop if the right key was still true, xVelocity was increase. got a very nice smooth run in now, with easily configurable momentum using a weight variable. it was tough to get my head around so i thank everyone who helped. really does feel great knowing i've finally figured it out.
  6. Im still having some problems. a problem i have tried many things to resolve. and that is when HOLDING the right key down. the xVelocity does not rise, it stays the same, the block moves at a constant speed instead of what should be accelerating at a constate rate. the reason for this is that even though the event handling function is called tens if not hundred of times a second, if the right key is HELD the values aren't updated. However if i tap the right key, through each tap the speed of the player increases by the amount i set. but HOLDING i cant get this to work. i have tried keystates, key events, or even a combination of both. the line : case SDLK_RIGHT: xVelocity -= ACCELERATION; if held, is simply set once, and the xVelocity stays constant. when really every time the event handling function is called i want this line executed if the right key is being held. a snippet of the full event handling function and move function is below. void Player::handleInput() { if (event.type == SDL_KEYDOWN) { switch ( event.key.keysym.sym) { case SDLK_UP: yVelocity -= playerBox.h / 3; break; case SDLK_DOWN: yVelocity += playerBox.h / 3; break; case SDLK_LEFT: xVelocity -= ACCELERATION; break; case SDLK_RIGHT: xVelocity += ACCELERATION; default : ; } } else if( event.type == SDL_KEYUP ) { switch( event.key.keysym.sym ) { case SDLK_UP: yVelocity += playerBox.h / 3; break; case SDLK_DOWN: yVelocity -= playerBox.h / 3; break; case SDLK_LEFT: xVelocity += ACCELERATION; break; case SDLK_RIGHT: xVelocity -= ACCELERATION; break; default : ; } } Uint8 *playKeystates = SDL_GetKeyState(NULL); if (playKeystates[SDLK_ESCAPE]) { isPaused = true; } if (playKeystates[SDLK_d]) { isDead = true; } if (playKeystates[SDLK_SPACE]) { Mix_PlayChannel( -1, jumpSound, 0 ); } } void Player::move(Uint32 deltaTime) { //check platform collisions //move player playerBox.x += xVelocity * (deltaTime / 1000.f); playerBox.y += yVelocity * (deltaTime / 1000.f); //constrain to level if ( ( playerBox.x < 0) || ((playerBox.x + playerBox.w) > LEVEL_WIDTH) ) { isDead = true; } if ((playerBox.y < 0) || ((playerBox.y + playerBox.h) > LEVEL_HEIGHT)) { isDead = true; } //check win collisions if (((playerBox.x + playerBox.w) >= winRect.x) && (playerBox.y <= winRect.y+winRect.h)) { isWin = true; } } I know im useless at this, i should be better at problem solving, but soemtime when i have been working on something for a while my brain just blocks up.
  7. i did try that before but it didn't work, tried it again now and now things are great. maybe i needed to save all my files before it would work. thanks a lot!!!!
  8. [size="4"]using globals.h im hoping to store a vector of rectangles and also a collision box and a few global bools [size="4"]globals.h [color="#000000"] extern SDL_Rect winRect; extern std::vector<SDL_Rect> platform; extern bool paused; extern bool exit; [size=2]i then set the bool to false as so in the globals.cpp. [size="4"] bool paused = false; bool exit = false; [size="4"]however then when i try and use the global winRect SDL_Rect or the global vector of SDL_Rects in other classes the compiler spits out the "undefined reference to platform" or "to winRect". which i cant understand because they are set up in the globals.h file, and the globals.h is included within the class header that is trying to use them [size="4"]do i need to define anything else regarding the vector and Rect in the globals.cpp file? [size="4"]might there be something wrong with the order of my header inclusions for the class im trying to manipulate the globals with? [size="4"]hope there is an easy solution to this, im sure im just missing something.
  9. truly i thank you for your take on this, it looks great, and very similar to what i had in mind, just couldn't get to the endpoint. and thanks i will cap to time not frame for sure. again really thank you for explaining it out so clearly, it has definitely reinvigorate my approach to this and i should hopefully get something playable hashed out today. you are awesome
  10. [color="#202020"][font="Verdana, Arial, Helvetica, sans-serif"]Okay I need big advice on how to incorporate some simple momentum into my player movement. I want him to speed up and slow down naturally and have a good jumping and falling arc etc. I drew movement curves on graph paper, (I have a background in animation, so I know how to make it fluid and smooth.) So lateral + X and – X movement, as well as curves for jumping and falling (- Y and + Y) I mapped out these curves to values (e.g. pixels per frame) and percentages through a 24 frame accceleration cycle (on the X) and 12 frame deceleration. (want to player to stop fast, but still stop naturally) Here are the graphs that i mapped out: lateral negative and positive X movement http://postimage.org/image/1xyxmohpg/ Y jumping and falling http://postimage.org/image/1xz48tvok/ And here is my excel file. (numbers taken from plotting movement curves) http://postimage.org/image/1gltq11r8 Basically I have no idea how to incorporate this properly into my program, taking into account my input handling, and how switching from left to right quickly could really cause slower response for example. Is there an easier method that I can get my head around? Have I gone about this the totally wrong way? I have tried reading physics books for programmers, even beginner ones but not once have I seen easy to read and understand code really walked through for me because trust me I need someone to hold my hand to understand it. Even this integration article that discusses euler and rk4 which is meant to be beginner friendly gave me no clues. Any advice on where to go or what to do to try and find a way to overcome this problem would be sooooooooooo gratefully appreciated Thanks[/font] [color="#202020"][font="Verdana, Arial, Helvetica, sans-serif"] [/font] [color="#202020"][font="Verdana, Arial, Helvetica, sans-serif"]ps:(I know I started a topic specifically asking for advice on this topic a short while ago before i started making this game, and through all the reading and research I still haven't found a clear clear way to grasp how to do this, I have tried doing all these graphs and problem solving a way to incorporate it in my own way but that hasn't worked )[/font]
  11. grechzoo

    SDL games, use of vector causing crash

    ahh thanks knew it wasn't a bug really, as it worked for me. just totally missed than line with my STUPID eyes sorry if this was such a simple error. im just trying to learn by doing and basically doing ym best impression of a sponge
  12. grechzoo

    SDL games, use of vector causing crash

    I love you!!!! seriously. i thought this was gonna delay me for a day, but instead it was 30 minutes. people like you make the world a much better place to learn how to code!!!!!! ALSO great thansk to Sircrane it is odd how i saw no code regarding these necessary vector commands in lazofoo's code though. anyway who care now. thanks!!!!!!
  13. grechzoo

    SDL games, use of vector causing crash

    i thought vectors dont need to be assigned a size, and are as big as the definitions amount. Lazfoo's code doesn't seem to define it. but if this might cause the error to go away can you please tell me what exactly i need to add? just a [ "number" ] ? on the end of the definition?
  14. Okay, having a little problem in a basic platformer im trying to make after studying some awesome lazyfoo stuff. My problem is, for the creation of the level im trying to make a vector filled with platforms of different sizes and positions. I set up the class like this shown below: #include "SDL/SDL.h" #include "globals.h" #include <vector> #include "player.h" class Level { public: Level(); void setPlatform(); void draw(); protected: std::vector<SDL_Rect> platform; }; Then in the level.cpp set the platforms, using the set platform functions: #include "level.h" Level::Level() { } void Level::setPlatform() { platform[0].x = 200; platform[0].y = 300; platform[0].w = 200; platform[0].h = 50; platform[1].x = 400; platform[1].y = 200; platform[1].w = 100; platform[1].h = 50; } So in the main.cpp with the gameloop, and with the level.h included, I run the main game loop. int main (int argc, char*args[]) { bool quit = false; initFunc(); Timer fps; Player myPlayer; Level myLevel; while (quit == false) { fps.start(); while (SDL_PollEvent (&event)) { myPlayer.handleInput(); if (event.type == SDL_QUIT) { quit = true; } } myPlayer.move(); SDL_FillRect( screen,&screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) ); myLevel.setPlatform(); <------------------------- CRASH!!!!!!! myPlayer.show(); /////////////-------------------rest of loop not necessary (code crashes on above line every time--------/////////////////// so without the setPlatform function used in the main loop, the game boots up as normal and works perfectly, however when it is used in the main loop, the SDL program simply flashed a black screen for half a second and closes again. I have no idea whats going on and REALLY hope someone can see an error? it cant be SDL because Lazyfoo using this exact vector in his per pixel collision tutorial. ps:( for the record: all the values are safely in bounds, and i tried this with a normal array and it worked fine. however i need the features of the vector in order to do some things i have planned, so really want to get it working.)
  15. thanks guys, ill give it all as much research as possible today see what i can find. if anyone has a good book recommendation that focuses on these physics and maths for beginners in the context of programming i would also be extremely grateful. btw im only planning on doing 2D games for forseeable future (ps: box2D looks cool, but im trying to really learn everything i can and stretch my brain, so i really want to tackle this certain problem with my own code.)
  • 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!