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 - jonas

Pages: [1]
1
General / collision system for a platform rpg
« on: September 17, 2011, 11:45:25 am »
hello everybody, my second topic over here :P

i've got a question about collision: I need a good working collision sytem for a platform rpg like the titel says. I've wrote my own collision system, but it doesn't work if i use more than 1 object in the game. So if i draw 1 object, a platform, in the game, i can walk on it , jump on it, and let the gravity do it's work. This works perfect...But not with more than 1 object or platform, so when i draw platforms, the collision will only work on 1 of the 2 platforms. If i have platform1 and platform2, it will only work for example on platform2. I'll be able to jump and walk on platform 2, but not on platform1. I just go through the platform number1...

this is the code i wrote:
Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

int main()
{
    //integers voor de coördinaten bij te houden
    int spritePosX = 20;
    int spritePosY = 25;
    int floorPosX = 0;
    int floorPosY = 160;
    int platformPosX = 250;
    int platformPosY = 140;
    //bool voor het springen als de grond geraakt wordt
    bool canJump = true;
    //bool voor de collision
    bool isCollision = false;

    //window renderen
    sf::RenderWindow game(sf::VideoMode(640, 320, 32), "engine test");

    //maak een rood plaatje voor de speler
    sf::Image imgRed;
    //maak er een vierkantje van
    imgRed.Create(32, 32, sf::Color(0xff, 0x00, 0x00));
    //maak een rode texture
    sf::Texture textureRed;
    //laad het plaatje in de rode texture
    textureRed.LoadFromImage(imgRed);
    //maak een sprite van de rode texture
    sf::Sprite player(textureRed);
    //zet de player op positie
    player.SetX(20);
    player.SetY(25);

    //maak een blauwe ondergrond
    sf::Image imgBlue;
    //maak er een rechthoek van
    imgBlue.Create(640, 160, sf::Color(0x00, 0x00, 0xff));
    //maak een blauwe texture
    sf::Texture textureBlue;
    //laad de ondergrond in de blauwe texture
    textureBlue.LoadFromImage(imgBlue);
    //maak een sprite van de ondergrond
    sf::Sprite floor(textureBlue);
    //zet de sprite op positie
    floor.SetX(0);
    floor.SetY(160);

    //maak een blauw platje voor een platform
    sf::Image imgPlatform;
    //maak er een rechthoekje van
    imgPlatform.Create(50, 10, sf::Color(0x00, 0x00, 0xff));
    //maak een blauwe texture
    sf::Texture texturePlatform;
    //laad het platform in de texture
    texturePlatform.LoadFromImage(imgPlatform);
    //maak een sprite van het platform
    sf::Sprite platform(texturePlatform);
    //zet de sprite op positie
    platform.SetX(250);
    platform.SetY(140);


    //clock instellen om ervoor te zorgen dat het lopen op elke computer even snel gaat
    sf::Clock clock;

    while (game.IsOpened())
    {
        if (clock.GetElapsedTime() >= 5)
        {
            if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Up) && canJump == true)
            {
                player.Move(0, -60);
                spritePosY -= 60;
                canJump = false;
            }
            if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Left))
            {
                player.Move(-2, 0);
                spritePosX -= 2;
            }
            if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Right))
            {
                player.Move(2, 0);
                spritePosX += 2;
            }

            //de collision met de ondergrond
            if (spritePosX <= floorPosX + 640 && spritePosX + 32 >= floorPosX && spritePosY <= floorPosY + 160 && spritePosY + 32 >= floorPosY)
            {
                isCollision = true;
                canJump = true;
            }
            else
            {
                isCollision = false;
                player.Move(0, 2);
                spritePosY += 2;
            }

            //de collision met het platform
            if (spritePosX <= platformPosX + 50 && spritePosX + 32 >= platformPosX && spritePosY <= platformPosY + 10 && spritePosY + 32 >= platformPosY)
            {
                isCollision = true;
                canJump = true;
                player.Move(0, 0);
            }
            else
            {
                isCollision = false;
            }

            clock.Reset();
        }



        //scherm clearen
        game.Clear();
        //sprites tekenen
        game.Draw(floor);
        game.Draw(player);
        game.Draw(platform);
        //geef de window weer
        game.Display();
    }
    return 0;

}
 


de commments with the code are written in Dutch, but i think it's clear to understand wath happens in the code, because it isn't that difficult code.

In the code there is the player, a platform and a floor. I think it was the platform where i can stand on, but i don't remember which one it was. But i do know it was one of the two that doesn't work...So does one of you guys know what's wrong with this code? I allready tried to make a variable  and get the changes of the player in that variable and than let the player move to the changed coordinates that are in that one variable, but it doesn't work at all, so i'll do not post that code here.

If someone knows what's wrong with the code here, please tell it to me, because it's very important for my game to have a good collision system...

And if someone has another code for collision, you can show it too :) I've already seen the collision codes here on the forum, but it isn't really what i ws looking or...It has to work with bounding boxes around the sprite, but here i'm still using some squares for the tests.

Thank you already,

Jonas.

2
General / installing sfml on a Mac computer
« on: September 13, 2011, 08:13:36 pm »
ok, thank you for your answer first of all :) I've read it attentive and i think it should be a little bit easier right now :P But there's one more question: what's the difference between picking the framework or the dylib library? Like i've said i don't have the mac right now, so i don't really know the OS and Xcode, but maybe i'll get it when you'll explain it :)

Jonas.

3
General / installing sfml on a Mac computer
« on: September 13, 2011, 07:51:40 pm »
hello everyone,

i'm new here, and i like it to program with sfml and qt on my (old) windows computer, but i'm getting a Mac computer, and i asked myself how i could get sfml 2.0 working with QT creator, Xcode, or an other IDE. It actually doesn't matter with what IDE it works, i just want to be sure it works in a Mac. So, is there any tutorial in which it is explained step by step how i could get sfml 2.0 working with an IDE on a mac computer? I guess it's usual to use it with Xcode on a Mac, but it doesn't really matter. I'm already happy if it works on a Mac, so i wouldn't have to use my old windows computer. I'm busy with a project working with sfml in windows, so it would be just nice to know when i get a mac i will be abe to work on my mac on the same project...

So, if there's anyone can help me, go ahead :P

Pages: [1]
anything