Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Lambert

Pages: [1]
1
General discussions / Re: SFML 3 - What is your vision?
« on: April 26, 2014, 04:33:54 pm »
Simple and Fast Multimedia Library

By downloading and using such named thing, I would expect simple and fast coding. SFML is one of few good libraries known to me that support full OOP (and by fully I mean it's really simple to use, for example Qt is unintuitive, especially with main function design), which is insanely helpful. However your library should be scalable. It should be as good for newbies as for pros. That's why you should add simple demos and free stuff for first-time-use. Some free music, textures etc. Also default font would be nice improvement. I never understood why original author didn't include it.
 
As it goes for pros, I think that adding 3D support is obligatory. I don't know any fully OOP libraries (with such good API as SFML) supporting 3D and it isn't so hard I think, it just need good packing OpenGL functions into classes and a bit of optimization.

Native supports for widgets. I know I can import another library or create my own GUI, but neither is simple nor fast.

As it comes for C++11 and C++14 I don't see any reason to not make them obligatory. Compilers that won't support these features when SFML 3 would be released will be greatly outdated and there is no reason to outdate SFML itself because of it.

Advanced functions, like mentioned above mathematical operations on vectors in etc. should be also included. "Fast" means for me not only that program itself will be fast, but also that I won't have to waste my time looking for additional dependencies, while "Simple" means that everything what is needed to create game or application (from programming side ofc, not resources) will be provided to me in an easy, simple way. It won't affect library efficiency as everything is modular and I include only these files I want to include.


Worst you can do is to expect people to install hundreds of additional libraries to make their games and apps work, just because "they can do it". We are not talking about SFML 2.x, but SFML 3 and it's long-time project, so there is no reason to reject any idea just because it's "time wasting" and "it is already done in XYZ library".

2
Graphics / How to make my own "progress bar"?
« on: September 22, 2013, 03:46:00 pm »
I want to create something like progress/loading bar, with custom texture. Depending on current value of certain variable, it would increase/decrease. I thought about resizing sprite, but it won't work if I will create circular indicator (like a circle around some icon). Any ideas?

3
General / Re: [Help] Errors when Compiling
« on: September 09, 2013, 06:52:37 am »
Well, you provided very small amount of informations, but I will guess that something is wrong with your SFML Audio package. Check your installation of SFML (especially if you linked audio libraries) and if that doesn't help - reinstall SFML.

4
General / Re: Compiles fine, runs on XP, does not work on Win7
« on: September 09, 2013, 06:50:06 am »
I found something like this: http://cpp0x.pl/forum/temat/?id=4733
It's Polish forum so I will only say that guy had similar case - he used SFML 1.6 and it worked in Windows XP x86, but in Windows 7 x64 it hanged up without showing window. His solution was upgrading SFML to 2.0.

5
General / Re: Collisions in simple platform game
« on: September 08, 2013, 10:18:05 pm »
O, I like the way you are thinking. Yet I believe static variables are declared only once. At least this is what I see, because while jumping (what I can totally do), right before landing and mini-jump bug, jumpTime takes almost exactly my jumpMaxTime value. BTW it's only temporary, I will make them Player class fields after everything works.

I'm sorry if I sound like i demand instant fix to my code, it wasn't my purpose. I just thought that as a total newbie I may do common errors with this collision detection, since I didn't read any tutorial, just wrote it from my head.

6
General / Re: Collisions in simple platform game
« on: September 08, 2013, 09:05:50 pm »
At the moment I added comments to my code, I hope it makes more sense now.

I'm thankful for all advices how to code better (that info about for loop was important for me, as I often play with algorithms too) and I'm aware of how my code may be illegible, yet I was expecting more collision-related replies. I wrote what exactly is wrong with my code, so please share with me your collision detection systems experiences. Like, for example, if I check correct positions and if my way is correct.

7
General / Re: Collisions in simple platform game
« on: September 08, 2013, 08:27:01 pm »
Code is nightmare to read because it's in very beta stage. I'm changing little things everyday, adding and deleting stuff as well. I feel that it's pretty impractical to make this code clean at this stage, yet you may have right, I should cleaned it before posting here.

Gobbles - what is wrong with checking keyboard and collisions at once? I want to move sprite only if all these conditions are true, how to achieve it in different way? I will check this site, thanks. Of course I checked values in console, you can even see that in my post, when I'm explaining jumping bug ;) Yeah, I tried to use VS debugger as well and I have a small idea I mentioned below.

Nexus - yeah, as i stated above, I was constantly doing changes with code. For most time Map::checkPosition() was of type bool, but I wanted to add feature of returning value of Y axis of sprite that collide with character sprite. I forgot to add this to main post - I'm thinking that jumping bug may be caused by these equations for jumping and falling. They may took too big delta values for too small distance between collision point and current Y of character sprite. But it didn't work and I deleted part of code with setting obstacle Y to character Y in case of collision detection. I seriously doubt that mixing float and double may be a problem - I don't go under ~0.0001 values, but I'm total newbie here - seriously may it be so buggy? And about creating unnecessary copies of sf::Sprite - I don't understand? I just changed these for loops from old-fashioned way with (int i;i<vector.size();++i) and never used range version before.

8
General / Collisions in simple platform game
« on: September 08, 2013, 02:10:35 pm »
I'm creating a simple Mario-style game. It's my first project like this. I have problem with collision system in my game.

My map object has this method for checking collisions:
int Map::checkPosition(double x, double y, bool returnY)
{
        if(x>800 || x<0 || y>600 || y<0)
                if(returnY == false) return false;
                else return 600;
        else
                for(sf::Sprite sprite : mapEnviromentSprites_)
                        if(x > sprite.getPosition().x && x < sprite.getPosition().x + sprite.getGlobalBounds().width && y > sprite.getPosition().y && y < sprite.getPosition().y + sprite.getGlobalBounds().height)
                                if(returnY == false) return false;
                                else return sprite.getPosition().y;
        return true;
}

My player object uses it by checking few "checkpoints" on character sprite and, if every returns true, allows change to character position made by this method:
void Player::movePlayer(Map& map, int frameTime)
{
       //temporary variables until everything is working fine here
        const float moveSpeed = 150.0f;
        static float jumpTime = 0;
        static float jumpBeginY = 0;
        static bool jumpBeginYMarker = false;
        static float deltaTime;

        const float jumpMaxHeight = 100.0f;
        const float jumpMaxTime = 1.0f;
        const float a = 4*jumpMaxHeight/(jumpMaxTime*jumpMaxTime);
        const float b = 4*jumpMaxHeight/jumpMaxTime;
       
        //I'm taking current values of position of character sprite to modify them later
        x = player.getPosition().x;
        y = player.getPosition().y;
        //I get frame time right after displaying window in main loop, as microseconds
        deltaTime = frameTime*0.000001f;

        //I'm using PlayerState enum type to determine what texture should I set to character spite
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                playerState_ = PlayerState::CROUCH;

        //I want to move character sprite only if he isn't pressing at obstacle at any point (up, down corners and middle point at approbate site)
       //Here is one problem - if I check raw values I can "freeze" on obstacle until I release left/right arrow, but if I check a little further, no less than 2 pixels, everything is fine
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && map.checkPosition(x+player.getGlobalBounds().width/2+0.1,y+player.getGlobalBounds().height/2) && map.checkPosition(x+player.getGlobalBounds().width/2+0.1,y-player.getGlobalBounds().height/2) && map.checkPosition(x+player.getGlobalBounds().width/2+0.1,y))
                {
                        playerState_ = PlayerState::WALK;
                        x += moveSpeed * deltaTime;
                        player.setScale(1,1);
                }

        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && map.checkPosition(x-player.getGlobalBounds().width/2-0.1,y+player.getGlobalBounds().height/2) && map.checkPosition(x-player.getGlobalBounds().width/2-0.1,y-player.getGlobalBounds().height/2) && map.checkPosition(x-player.getGlobalBounds().width/2-0.1,y))
                {
                        playerState_ = PlayerState::WALK;
                        x -= moveSpeed * deltaTime;
                        player.setScale(-1,1);
                }
       
        //Obviously I don't want to allow jumping while jumping or falling)
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up) && !isFalling) isJumping = true;

        //I want player sprite to be in falling state always if it does not stand still on obstacle
        //Here is something bugged I think, isFalling is always on
        if(!isJumping && map.checkPosition(x+player.getGlobalBounds().width/2,y+player.getGlobalBounds().height/2-5) && map.checkPosition(x-player.getGlobalBounds().width/2,y+player.getGlobalBounds().height/2-5))
                isFalling = true;
        else isFalling = false;

        //again, PlayerState setting
                if(isJumping || isFalling)
                {
                        playerState_ = PlayerState::JUMP;
       
        //a part for taking y_0 of my jump
                        if(!jumpBeginYMarker)
                        {
                                        jumpBeginY = player.getPosition().y;
                                        jumpBeginYMarker = true;
                        }

         //equations for jumping and falling
                        if(isJumping) y = jumpBeginY -b*jumpTime + a*jumpTime*jumpTime;
                        if(isFalling) y = jumpBeginY + a*jumpTime*jumpTime;
        //updating jumping time, necessary in above equations
                        jumpTime += deltaTime;
        //I don't want to jump any longer if I hit obstacle with my head, so I start a fall
                        if(!map.checkPosition(x+player.getGlobalBounds().width/2,y-player.getGlobalBounds().height/2) || !map.checkPosition(x-player.getGlobalBounds().width/2,y-player.getGlobalBounds().height/2))
                        {
                                jumpTime = 0;
                                isJumping = false;
                                isFalling = true;
                                jumpBeginYMarker = false;
                        }
        //and again, I don't want to fall any longer if I hit obstacle with my feets
                        if(!map.checkPosition(x-player.getGlobalBounds().width/2,y+player.getGlobalBounds().height/2) || !map.checkPosition(x+player.getGlobalBounds().width/2,y+player.getGlobalBounds().height/2))
                        {
                                jumpTime = 0;
                                isJumping = false;
                                isFalling = false;
                                jumpBeginYMarker = false;
                                jumpBeginY = 0;
                        }
                }

        //another PlayerState stuff
        if(!sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && !sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && !sf::Keyboard::isKeyPressed(sf::Keyboard::Down) && isJumping == false && isFalling == false)
                playerState_ = PlayerState::STAND;

        //6 control points - up left/right, down left/right and middles of both sides
        //I don't want to allow player to take inaccessible areas, so I check above control points for collissions
        if(map.checkPosition(x+player.getGlobalBounds().width/2,y+player.getGlobalBounds().height/2) && map.checkPosition(x+player.getGlobalBounds().width/2,y-player.getGlobalBounds().height/2) && map.checkPosition(x-player.getGlobalBounds().width/2,y+player.getGlobalBounds().height/2) && map.checkPosition(x-player.getGlobalBounds().width/2,y-player.getGlobalBounds().height/2) && map.checkPosition(x+player.getGlobalBounds().width/2,y) && map.checkPosition(x-player.getGlobalBounds().width/2,y))
                player.setPosition(x,y);
}

There are three problems:
1. Falling never stops - when character is very close to surface of obstacle, it's just keep doing "little jumps", that last for around 0.001 second according to console log.
2. When I move on alone obstacle (70 pixel width), my character stands still (jumping ofc, like stated above) only on edges, but if it crosses centre (wide-wise) of this obstacle, it falls down through it. This problem doesn't exist if two or more obstacles are placed next to each other. It's like collision detecting method checks only corners of obstacles and all pixels around character sprite, but it's clearly designed in opposite way.
3. When I move horizontally towards an obstacle, especially when jumping, I freeze on it until I release left/right arrow. However if I set condition to check a two pixels further than player sprite, it works (in pasted code I tried to set 0.1, with negative result).

I'm sorry for my bad English, especially grammatical ones, it's not my primary language.

Pages: [1]