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.


Topics - argh

Pages: [1]
1
I have a vector, where i add bullets if a key is pressed. I would like to assign a direction (left/right) - or + upon creation. I can't figure it out. I thought about creating another vector for the bullets that i want going left, but it seems not the smartest solution.  :-\
       
this is how a new bullet is been created. IS it possible to add something like (-1*)so later when i call move on bullets the negative ones will fly left?
             
       sf::Sprite *nshot = new sf::Sprite;
        nshot->setPosition(player.getPosition());
        nshot->setTexture(shoot);
        bullets.push_back(*nshot);
 

this is how i move them atm. (direction_left is true when leftkey is pressed), this is no good, because when i press right they change their direction.
 for (auto i = bullets.begin(); i != bullets.end(); i++)
    {
      //according to direction fly left or right
      if (direction_left)
       i->move(-1000.f * bulletSpeed.asSeconds(), 0);
      else
       i->move(1000.f * bulletSpeed.asSeconds(), 0);
    }

2
SFML projects / Red Plane (Rotes Flugzeug)
« on: October 04, 2015, 04:02:53 pm »
Hi all!

BACKGROUND:
For the last month I have been learning SFML by developing my first game. I call it Rotes Flugzeug (Red Plane in English) after one of my childhood favorites. Another inspiration for Red Plane was Starray by Atari (from the '80s).

GAMELOGIC:
You - the plane - flies around in a circle (gamemap is a circle) and needs to destroy all the bombs that fall from the sky. You destroy enemies by shooting at them and blowing them up. You must do so before they hit the ground - if too many reach the ground you lose. Survive long enough and you will advance a level. To fly around use arrows(all directions) and to shoot press space.

INFO:
Screensize: 800x600
OS: Windows only
Size: 1,20MB (with artwork and sfml dlls)
Code: GitHub
Preview: Tiny video of gameplay

download Rotes Flugzeug(.zip)
The download contains the game.exe, artwork and SFML dll-s. Should be everything you need to run it on windows.



Future updates still TODO:
  • Make the game challenging
  • Make the background loop smooth

3
General / Collision: Erasing two sprites from two different vectors (Solved)
« on: September 19, 2015, 05:09:42 pm »
Hi everyone,

I have a problem erasing two elements when they collide. I go thru the 2 vectors of sprites and check if they have intersected with each other, if true, then I erase the two elements from the two vectors (bullets & enemies).

My problem is the following: I can erase one, but how can I erase the second one?

That is how the function looks like so far.
void collision()
  {
          for (auto e = enemies.begin(); e != enemies.end(); e++)
          {
                  for (auto i = bullets.begin(); i != bullets.end(); i++)
                  {
                          sf::FloatRect enemiez = e->getGlobalBounds();
                          sf::FloatRect bulletz = i->getGlobalBounds();

                          if (bulletz.intersects(enemiez))
                          {
                                bullets.erase(i);
              //enemies.erase(e); <-- if i uncomment this line i get a "vector iterator not incrementable!" exception.
                                break;
                          }
                  }
          }
  }
 


I understand that it is a problem with the size and the index in the vector and erasing won't work in the same iteration of the loop. I tried also to erase the enemies(e) in the outer loop, but no good.

I have no idea how else I can solve this? Should I try a totally different approach or am I on the right track?

Thank you for your help in advance!
PS This is my first project with SFML (newest version of SFML and Visual Studio 2013).

Pages: [1]
anything