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

Pages: 1 [2]
16
Graphics / Re: Collision - want remove Sprite from List + Update
« on: December 27, 2013, 08:59:19 pm »
Ouh, thank you fallahn :)

That was the problem. A simply problem.

I changed it into this code:
void Collision::Collision2Attack(std::list<sf::Sprite>&enemyList,
                                                                std::list<sf::Sprite>::iterator &enemyIt,
                                                                sf::Sprite hitBoxR,
                                                                RenderWindow &window
                                                                )

.. and its working now. Thank you! :)

17
Graphics / [solved]Collision - want remove Sprite from List + Update
« on: December 27, 2013, 06:19:48 pm »
Hello ^_^

im working on my project and I have a problem with the collision-class.

All is working fine and if getGlobalBounds turn to "true", the collision is detect. But.. it dont delete the Sprite from the list. It still "moving" and my list is still "full".

Please, dont be angry. Im still in practice. ._. Im trying my best. But the Collision is very hard (not to create - its only because of make OOP and use the right syntax and right return-methods(?)). So I hope you can show me, what I can do. I know, the Code is not "clean". But for the first one, it should be a good step.

Collision.hpp:
#ifndef COLLISION_HPP
#define COLLISION_HPP

#include "Enemy.hpp"
#include "Player.hpp"
#include <SFML\Graphics.hpp>
#include <list>

using namespace sf;

class Collision
{
public:
        void            Collision2Attack(std::list<sf::Sprite>enemyList,
                                                                std::list<sf::Sprite>::iterator enemyIt,
                                                                sf::Sprite hitBoxR,
                                                                RenderWindow &window
                                                                );
        void            update4List(std::list<sf::Sprite>enemyList,
                                                                std::list<sf::Sprite>::iterator enemyIt
                                                                );
};

#endif

Collision.cpp:
#include "Enemy.hpp"
#include "Player.hpp"
#include "Collision.hpp"
#include <SFML\Graphics.hpp>
#include <list>

using namespace sf;

Enemy enemy;
Player player;

void Collision::Collision2Attack(std::list<sf::Sprite>enemyList,
                                                                std::list<sf::Sprite>::iterator enemyIt,
                                                                sf::Sprite hitBoxR,
                                                                RenderWindow &window
                                                                )
{

        for(enemyIt=enemyList.begin();enemyIt!=enemyList.end();)
        {
                if( hitBoxR.getGlobalBounds().intersects(enemyIt->getGlobalBounds() ))
                {
                        //enemyIt=enemyList.erase(enemyIt);
                        enemyIt->setPosition(0,0);
                        std::cout << "delete" << std::endl;
                        Collision::update4List(enemyList, enemyIt);
                }
                else
                {
                        enemyIt++;
                }
        }

       
}

void Collision::update4List(std::list<sf::Sprite>enemyList,
         std::list<sf::Sprite>::iterator enemyIt
         )
{
        ::enemy.update4ListE(enemyList,
                                                enemyIt
                                                );
}

Enemy.cpp:
#include "Enemy.hpp"
#include "Collision.hpp"
#include <SFML\Graphics.hpp>
#include <iostream>
#include <string>

using namespace sf;

Enemy::Enemy()
{
        Speed = 300.f;
        enemyTex.loadFromFile("enemy_l.png");
        enemyTime = 0.0000;
}

void Enemy::Draw(RenderWindow &window, float ElapsedTime)
{
        for(enemyIt=enemyList.begin();enemyIt!=enemyList.end();enemyIt++)
        {
                enemyIt->move(-Speed*ElapsedTime,0);
                window.draw(*enemyIt);
        }
}

void Enemy::Process(RenderWindow &window, float ElapsedTime, float enemyTimer)
{
        enemyTime += enemyTimer;

        if(enemyTime>=9000)
        {
                enemySprite = new sf::Sprite;
                enemySprite->setTexture(enemyTex);
                enemySprite->setPosition(720, 410);
                enemySprite->setScale(0.6,0.6);
                enemyList.push_back(*enemySprite);
                enemyTime=0;
        }

        for(enemyIt=enemyList.begin();enemyIt!=enemyList.end();)
        {
                if(enemyIt->getPosition().x<=0)
                {
                        enemyList.erase(enemyIt);
                        enemyIt=enemyList.begin();
                }
                else
                {
                        enemyIt++;
                }
        }

}

void Enemy::update4ListE(std::list<sf::Sprite>enemyList,
                                                std::list<sf::Sprite>::iterator enemyIt
                                                )
{
        enemyList = enemyList;
        enemyIt = enemyIt;
       
        std::cout << static_cast<int>(enemyList.size() ) << std::endl;

}

So I didnt know, how the Enemy-Class can get the "new List", so I thought i just create a simply "update4ListE" method for updating the current List on the other class, but it isnt working.

So I want to ask you (because you all have more skills). ._.

Greetings

18
Graphics / Re: Bad Movement (judder) for Player-image
« on: December 24, 2013, 07:47:37 pm »
Hello, I found the mistake, guys. :)

It was because of my Background-Class. It was a really bad code and I dont know, why.

I rewritten the background class and the movement are smoth now. The order was important too. I changed it too. But thank you very much guys for your replys :).

My order in main.cpp:

main.cpp
        // Player check Controll
                player.CheckInput(window);
                player.Animation(window, ElapsedTime);

    // delete windows
                window.clear();
               
        // draw background
                background.Draw(window);

        // draw player
                player.Draw(window);
       
        // display window
                window.display();

What do you think? Its okay? Or bad?

19
Graphics / Re: Bad Movement (judder) for Player-image
« on: December 24, 2013, 04:53:14 pm »
Hello! Thank you for your replys!

I used two new methods. Method 1 by BaneTrapper (boolean method) and method 2 by Raincode.
"setFrameLimit" is removed.

But: Both are not works (same problem - there is no smooth movement).

Have a look at this code. Did I something wrong? I hope you can tell me more. :(

method 1 (current method):

Player.cpp
void Player::CheckInput(RenderWindow &window)
{
        float x = sP.getPosition().x;
        float y = sP.getPosition().y;

                if(Keyboard::isKeyPressed(Keyboard::Left)&& x>=10)
                {
                        Player::left=true;
                }
                else
                {
                        Player::left=false;
                }
                if(Keyboard::isKeyPressed(Keyboard::Right)&& x<=680)
                {
                        Player::right=true;
                }
                else
                {
                        Player::right=false;
                }

}

void Player::Animation(RenderWindow &window, float ElapsedTime)
{

                if(Player::left==true)
                {
                        sP.move( -Speed*ElapsedTime, 0);
                }
               
                if(Player::right==true)
                {
                        sP.move(Speed*ElapsedTime, 0);
                }
}

Player.hpp:

#include <SFML\Graphics.hpp>

using namespace sf;

class Player
{

public:
        void                    Animation(RenderWindow &window, float ElapsedTime);
        void                    Draw(RenderWindow &window);
        void                    CheckInput(RenderWindow &window);
        Vector2f                getPosition();
        Player();

public:
        Texture tP;
        Sprite sP;

        bool right;
        bool left;

private:
        float Speed;

};

---

method 2:

Player.cpp
        float x = sP.getPosition().x;
        float y = sP.getPosition().y;

                if(Keyboard::isKeyPressed(Keyboard::Left))
                {
                        if(x >= 10)
                        {
                                sP.move( -Speed*ElapsedTime, 0);
                        }
                        else
                        {
                                x = 10;
                        }
                }
                if(Keyboard::isKeyPressed(Keyboard::Right))
                {
                        if(x <= 690)
                        {
                                sP.move(Speed*ElapsedTime, 0);
                        }
                        else
                        {
                                x = 690;
                        }
                }
                                std::cout << x << std::endl;
}

20
Graphics / Bad Movement (judder) for Player-image
« on: December 22, 2013, 04:00:16 pm »
Hello guys, thank you for joining this community.

Im new on SFML and C++ and want to learn several things. At first, im sorry for my bad english skills.

I want to make a little game. All works fine, but if I moving the "player sprite", so its like a "move judder".
I dont understand why and I hope you can give me the answer for this (maybe I did something wrong?)

The first one: Its SFML version 2.1, and Im working with Visual Studio 10.

The Codes are:

main.cpp
// internal
#include "Background.hpp"
#include "Player.hpp"

// external
#include <SFML/Graphics.hpp>
#include <iostream>

using namespace sf;

int main()
{

        // settings
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Window");
window.setFramerateLimit(60);

        // classes
Background background;
Player player;

        // variable
sf::Clock clock;

        // Start the game loop
        while (window.isOpen())
        {
        // Process events
        sf::Event event;

        float ElapsedTime = clock.restart().asMilliseconds();

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

        // Clear the screen
                window.clear();

        // draw background
                background.Update(window);
               
        // draw player plus animation
                player.Animation(window, ElapsedTime);
                player.Draw(window);
       
        // display window
                window.display();
        }
        return EXIT_SUCCESS;
}
 

player.hpp:
#include <SFML\Graphics.hpp>

using namespace sf;

class Player
{

public:
        void                    Animation(RenderWindow &window, float ElapsedTime);
        void                    Draw(RenderWindow &window);
        Vector2f                getPosition();
        Player();

public:
        Texture tP;
        Sprite sP;

private:
        float Speed;

};

player.cpp:
// internal
#include "Player.hpp"

// external
#include <SFML\Graphics.hpp>
#include <iostream>

using namespace sf;

Player::Player()
{
        Speed = .4f;
       
        tP.setSmooth(true);    
        tP.loadFromFile("player1_r.png");
        sP.setTexture(tP);
        sP.setPosition(50,50);
}

void Player::Animation(RenderWindow &window, float ElapsedTime)
{
        float x = sP.getPosition().x;
        float y = sP.getPosition().y;

                if(Keyboard::isKeyPressed(Keyboard::Left))
                {
                        if(x <= 10)
                        {
                                x = 10;
                        }else{
                                x = x - (Speed*ElapsedTime);
                        }                                              
                }
                if(Keyboard::isKeyPressed(Keyboard::Right))
                {
                        if(x >= window.getSize().x - 10)
                        {
                                x = window.getSize().x - 10;
                        }else{
                                x = x + (Speed*ElapsedTime);                   
                        }
                }
                sP.setPosition(x,y);
}

void Player::Draw(RenderWindow &window)
{
        window.draw(sP);
}

Vector2f Player::getPosition()
{
        return sP.getPosition();
}

Pages: 1 [2]