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

Pages: [1]
1
Fixed, i forgot to add a text file in main folder :D

2
Hi. I m programming a game. Everything was normal, i m using visual studio 2017.

Release mod was working normal (64bit) i was starting my game without ide.

But today i received an error message from console window like this:

AL lib (EE) ALC CmmdevPlayback_MixerProc: Wait for single object ex error 0x102

and computer freeze. What does this error mean? Thanks for suggestions and wasting your time with my problem.

3
General / Re: Erasing An Enemy From Enemy Class
« on: April 23, 2021, 10:22:00 pm »
thanks for advice. i learned this code from a website and with searching and listening from persons who gave me advices like you i m still trying to learn. i will do something thanks best regards :) if i success to make a game prototype then i will share on game section of forum.

4
General / Re: Erasing An Enemy From Enemy Class
« on: April 23, 2021, 06:12:00 pm »
Thanks for answer its working but i m getting same problem. Last element of array does exist i want to erase all :/

5
General / Erasing An Enemy From Enemy Class
« on: April 23, 2021, 03:51:54 am »
Hi everyone. i have a problem. I learn to coding and making little projects for improving my skills. I wrote a code like this:

//enemy class
class enemy {
public:
   sf::RectangleShape rect;
   float bottom, left, right, top;
   bool touch = false;
   sf::Sprite itemss;
   sf::Texture enemyt;
   enemy(sf::Vector2f position, sf::Vector2f size, sf::Color color) {
      rect.setPosition(position);
      rect.setSize(size);
      rect.setFillColor(color);
      enemyt.loadFromFile("inv/invpouch.png");
      enemys.setTexture(enemyt);
   }
   void kill()
   {
      std::cout << "Killing Enemy >> " << std::endl;
   }
   ~enemy() {

   }
   void update() {
      bottom = rect.getPosition().y + rect.getSize().y;
      left = rect.getPosition().x;
      right = rect.getPosition().x + rect.getSize().x;
      top = rect.getPosition().y;
      if (right > recx && left < recx + 30 && top < recy + 30 && bottom > recy) {
         enemys.setColor(sf::Color(255, 255, 255, 155));
      }
   }
   bool collision(enemy e) {
      if (right < e.left || left > e.right || top > e.bottom || bottom < e.top) {
         return false;
      }
      return true;
   }
};

    //create enemies
   std::vector <enemy*>  enemies1;
   for (unsigned i = 0; i < 5; ++i) {
      enemies1.push_back(new enemy(sf::Vector2f(100 * i + 800, 500), sf::Vector2f(15, 10), sf::Color(255, 255, 255, 0)));
   }

    //update
    for (unsigned i = 0; i < 5; ++i) {
            enemies1->update();
        }
      
      if (!enemies1.empty()){
         enemies1.erase(std::remove_if(enemies1.begin(), enemies1.end(), [](const auto &itr) {return itr->touch; }), enemies1.end());
        }
      
    //render
    for (unsigned i = 0; i < 5; ++i) {
            window.draw(enemies1->enemysprite);
        }

my goal is erase some enemies. with this code i can do that but problem is that
1- i cant erase last enemy of enemies1 vector. 1,2,3,4th values are erasing but not number 5(array no 4)
2- Using vectors Is a good way for create and delete enemies because in my game there will be some npc's and they will spawn, die and they will have their own stats and such.
I appreciate for every advice.

Pages: [1]
anything