Alex_Ken

Созданные ответы форума

Просмотр 12 сообщений - с 1 по 12 (из 12 всего)
  • Автор
    Сообщения
  • в ответ на: Множественное наследование в SFML #4601
    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    Пример кода, связанный с игровым персонажем киньте пожалуйста

    в ответ на: Анимация объекта #4522
    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    Анимации почему-то нету, та и зеркально не полностью отображается,только половина обьекта….

     

    #include <SFML/Graphics.hpp>
    using namespace sf;
    class Entity
    {
    public:
    float dx, dy, x, y, speed;
    int h, w, health;
    bool onGround;
    String name;
    Image image;
    Texture texture;
    Sprite sprite;
    Entity(Image &image, String Name, float X, float Y, int W, int H)
    {
    health = 100; onGround = false; speed = 0; x = X; y = Y; w = W; h = H; name = Name; dx = 0; dy = 0;
    texture.loadFromImage(image);
    sprite.setTexture(texture);
    //sprite.setOrigin(w/2, h/2);
    }
    };

    class Player :public Entity
    {
    public:
    float CF = 0;
    float time;
    enum {right, left, jump, down, stay} state;
    Player(Image &image, String Name, float X, float Y, int W, int H) :Entity(image, Name, X, Y, W, H)
    {
    state = stay;
    if (name == “Player1″){
    sprite.setTextureRect(IntRect(0, 0, w, h));
    }
    }

    void control()
    {
    time = time / 800;
    if (Keyboard::isKeyPressed)
    {
    if (Keyboard::isKeyPressed(Keyboard::Right))
    {
    state = right; speed = 0.1;
    CF += 0.005*time;
    if (CF > 6) CF -= 6;
    sprite.setTextureRect(IntRect(36 * int(CF), 48, 30, 48));
    }
    if (Keyboard::isKeyPressed(Keyboard::Left))
    {
    state = left; speed = 0.1;
    CF += 0.005*time;
    if (CF > 6) CF -= 6;
    sprite.setTextureRect(IntRect(36 * int(CF) + 36, 48, -30, 48));
    }
    }
    }

    void update(float time)
    {
    control();
    switch (state)
    {
    case right: dx = speed; break;
    case left: dx = -speed; break;
    }
    x+=dx*time;
    y+=dy*time;
    speed = 0;
    sprite.setPosition(x+w/2,y+h/2);
    }
    };

    int main()
    {
    RenderWindow window(VideoMode(640, 480), “Donald Duck”);

    Clock clock;

    Image duck;
    duck.loadFromFile(“images/duck.png”);

    Player p(duck, “Player1″, 200, 200, 27.0, 48.0);

    while (window.isOpen())
    {
    float time = clock.getElapsedTime().asMicroseconds();
    clock.restart();
    time = time / 800;

    Event event;
    while (window.pollEvent(event))
    {
    if (event.type == Event::Closed)
    window.close();
    }

    p.update(time);
    window.clear();
    window.draw(p.sprite);
    window.display();
    }
    return 0;
    }

    в ответ на: Анимация объекта #4430
    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    #include <SFML/Graphics.hpp>
    using namespace sf;
    class Entity
    {
    public:
    float dx, dy, x, y, speed;
    int h, w, health;
    bool onGround;
    String name;
    Image image;
    Texture texture;
    Sprite sprite;
    Entity(Image &image, String Name, float X, float Y, int W, int H)
    {
    health = 100; onGround = false; speed = 0; x = X; y = Y; w = W; h = H; name = Name; dx = 0; dy = 0;
    texture.loadFromImage(image);
    sprite.setTexture(texture);
    //sprite.setOrigin(w/2, h/2);
    }
    };

    class Player :public Entity
    {
    public:
    float CF = 0;
    float time;
    enum {right, left, jump, down, stay} state;
    Player(Image &image, String Name, float X, float Y, int W, int H) :Entity(image, Name, X, Y, W, H)
    {
    state = stay;
    if (name == “Player1″){
    sprite.setTextureRect(IntRect(0, 0, w, h));
    }
    }

    void control()
    {
    time = time / 800;
    if (Keyboard::isKeyPressed)
    {
    if (Keyboard::isKeyPressed(Keyboard::Right))
    {
    state = right; speed = 0.1;
    CF += 0.005*time;
    if (CF > 6) CF -= 6;
    sprite.setTextureRect(IntRect(36 * int(CF), 48, 30, 48));
    }
    if (Keyboard::isKeyPressed(Keyboard::Left))
    {
    state = left; speed = 0.1;
    CF += 0.005*time;
    if (CF > 6) CF -= 6;
    sprite.setTextureRect(IntRect(36 * int(CF), 48, -30, 48));
    }
    }
    }

    void update(float time)
    {
    control();
    switch (state)
    {
    case right: dx = speed; break;
    case left: dx = -speed; break;
    }
    x+=dx*time;
    y+=dy*time;
    speed = 0;
    sprite.setPosition(x+w/2,y+h/2);
    }
    };

    int main()
    {
    RenderWindow window(VideoMode(640, 480), “Donald Duck”);

    Clock clock;

    Image duck;
    duck.loadFromFile(“images/duck.png”);

    Player p(duck, “Player1″, 200, 200, 27.0, 48.0);

    while (window.isOpen())
    {
    float time = clock.getElapsedTime().asMicroseconds();
    clock.restart();
    time = time / 800;

    Event event;
    while (window.pollEvent(event))
    {
    if (event.type == Event::Closed)
    window.close();
    }

    p.update(time);
    window.clear();
    window.draw(p.sprite);
    window.display();
    }
    return 0;
    }

    в ответ на: Анимация объекта #4429
    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    В одну сторону просто картинка едет (не анимация), а в обратную – полоска, картинки вообще нету. Как сделать чтоб и в одну и в другую сторону была анимация? Спрайт только в одну сторону, в другую он отображается зеркально. Код ниже

    в ответ на: Отображение спрайта зеркально #4404
    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    Хотя нет, все норм, просто персонаж норм не идет а моргает

    в ответ на: Отображение спрайта зеркально #4403
    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    Надо чтоб персонаж ходил, а не просто движущийся спрайт без анимации

    в ответ на: Вопрос по уничтожению обьекта #4397
    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    это типа в ветке else такое писать чтоль? p.sprite.setTexture(t_boom), а вывести как? window.draw(p.sprite)?

    в ответ на: Обьекты на карте #4396
    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    А я думал в коде что-то надо сделать, так то я понял

    в ответ на: Вопрос по уничтожению обьекта #4392
    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    Это типо так?

    if (p.life) {
    gameTime = gameTimeClock.getElapsedTime().asSeconds();
    }
    else
    {
    text3.setString(“GAME OVER”);
    text3.setPosition(250, 200);

    p.sprite=s_boom;
    }

    смотри ветку else, в ней указываются действия когда жизни закончились у игрока.

    p.sprite – спрайт игрока

    s_boom – спрайт взрыва

    в ответ на: Вопрос, касающийся спрайта #4391
    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    ясно, спасибо

    в ответ на: Обьекты на карте #4390
    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    Можно пример кода как это сделать?

    Alex_Ken
    Alex_Ken
    Участник
    Сообщений:12

    Зарегистрирован:
    07.01.2017

    Репутация:0

    Обрежь картинку спрайта ровно или задай координаты так, чтоб не было пустых мест вокруг нее

Просмотр 12 сообщений - с 1 по 12 (из 12 всего)