SFML community forums

General => SFML projects => Topic started by: nebula on November 03, 2013, 03:53:40 am

Title: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on November 03, 2013, 03:53:40 am
(http://fs2.directupload.net/images/150910/goxv9yge.png) (http://www.directupload.net)

Okay, let me introduce "Pew",
my first Game - a simple 2D Space Shooter.


I start with some pictures.

menugamesettingsgame overhighscore
(https://img0.suckmypic.net/img/l/E/rC9f1DCt/mainmenu-png_thumb.jpg) (https://suckmypic.net/rC9f1DCt.png)(https://img0.suckmypic.net/img/v/C/jqvkXIlY/game-png_thumb.jpg) (https://suckmypic.net/jqvkXIlY.png)(https://img0.suckmypic.net/img/A/p/sBg1uy12/settings-png_thumb.jpg) (https://suckmypic.net/sBg1uy12.png)(https://img0.suckmypic.net/img/P/Z/9Ykcd541/gameover-png_thumb.jpg) (https://suckmypic.net/9Ykcd541.png)(https://img0.suckmypic.net/img/o/z/YJekb98T/highscore-png_thumb.jpg) (https://suckmypic.net/YJekb98T.png)

A video of the Game
http://youtu.be/Gwmj3inet-g


Update
http://youtu.be/Lz6h8L5a3ls

(click to show/hide)

At the moment the game has no goal but to survive and I think that this will not change until I have the final boss.
Feel free to tell me what you think of it.


here you can get the release:
http://www.xup.in/dl,13847981/Pew.zip/ (http://www.xup.in/dl,13847981/Pew.zip/)

(if you can not play it, just inform me. I will try to help  ;))

the code is at github (i will try to keep that up to date, so changes will be seen first there):
https://github.com/nebula2/Pew (https://github.com/nebula2/Pew)


Control:
Q and E to change weapons (you get the second weapon at 1000 points, the third after the first boss)
WASD to move
Left Mouse Button to shoot


Title: Re: Pew
Post by: Nexus on November 03, 2013, 11:27:30 am
Hey,
i am currently learning c++ and from some tutorials on youtube it came that i am using sfml.
Please don't. YouTube is the worst source when it comes to learning C++ and SFML. The video creaters often use very bad code style and omit important background information. See also my explanations here (http://en.sfml-dev.org/forums/index.php?topic=10167.msg69883#msg69883) and here (http://en.sfml-dev.org/forums/index.php?topic=12226.msg84907#msg84907). Especially for C++, there is no way around a good book (http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list).
 
i will put in my code here. but i cannot give you the sound and images, neither screenshots or something, because i used some stuff i googled and i am not sure about the copyright.
Ok, but doesn't this somehow miss the point of a project presentation? If I were you, I'd create own assets or at least use free ones. You'll probably also want people to play your game one day. Code itself is not very interesting and will only confirm the hypothesis about bad YouTube tutorials :P
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: Raincode on November 16, 2013, 09:08:34 pm
Alright, here's the deal. The zipped package won't work. Simply the fact that it ships with the debug .dlls seems wrong.

So try to build in in release mode and put in the release dlls and upload it again

Kind Regards,
Raincode
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on November 16, 2013, 10:28:59 pm
oO okay.. a few of my friends tested it and it worked.. or do you mean the second link?

the debug dll files are meant to be there. I tried to rebuild sfml with cmake just like in the tutorial, but at the compilation i get errors..

so to get this work I googled and just got answers that couldnt help. So i put in all libraries into the release mode. and now it works at other pc's.
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on November 17, 2013, 01:05:49 am
added cooldown for the third weapon

but i have a problem with the CircleShape..

you will see this is you get to 2000 points :D

http://www22.zippyshare.com/v/52718290/file.html (http://www22.zippyshare.com/v/52718290/file.html)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: Raincode on November 17, 2013, 09:14:47 am
Yes, and the same goes for the link you just posted. It complains about not finding "sfml-graphics-2.dll", there are only the "sfml-bla-d-2.dll" ones and if I try adding the right ones (which was pretty certain not to work), it complains about not finding ceratin Points in the dll files.

why not
sf::FloatRect controlR( control.getGlobalBoundz() ); ?

instead of
sf::Rect<float> controlR = sf::Rect<float>::Rect(control.getGlobalBoundz());

I also advise you not do do the "using namespace sf", and I wouldn't put it in header files...
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on November 17, 2013, 02:34:40 pm
Quote
Yes, and the same goes for the link you just posted. It complains about not finding "sfml-graphics-2.dll", there are only the "sfml-bla-d-2.dll" ones and if I try adding the right ones (which was pretty certain not to work), it complains about not finding ceratin Points in the dll files.

okay that is strange. but i do not know how to fix this. if I build the release (I use visual basic 2010 express) it creates a release directory with exactly the sfml-bla-d-2.dll files and it works. I will see what I can make.

Quote
why not
sf::FloatRect controlR( control.getGlobalBoundz() ); ?

instead of
sf::Rect<float> controlR = sf::Rect<float>::Rect(control.getGlobalBoundz());

I also advise you not do do the "using namespace sf", and I wouldn't put it in header files...

that is because I started the project when i started with c++ and sfml. I removed the namespaces. you can see it on github ;-) so how the hell do I solve the dll problem :'D
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: Raincode on November 17, 2013, 03:24:44 pm
I would guess simply emit the "-d" in the names of the .lib files in your Project settings when building the release version.

Maybe it's some problem with my system, I don't know...
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on November 17, 2013, 03:30:35 pm
I would guess simply emit the "-d" in the names of the .lib files in your Project settings when building the release version.

Maybe it's some problem with my system, I don't know...

I will try some ways maybe I get something to work for you :D
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on November 17, 2013, 03:45:23 pm
here is what i get:

properties:

(http://img0.www.suckmypic.net/img/J/H/uLwMv7mf/neu-1-png_thumb.jpg) (http://www.suckmypic.net/uLwMv7mf.png)

(if I set static here i get only errors)
(http://img0.www.suckmypic.net/img/S/C/znwXwo56/neu-2-png_thumb.jpg) (http://www.suckmypic.net/znwXwo56.png)

what I get
(http://img0.www.suckmypic.net/img/m/Y/Rn37sGuw/neu-11-png_thumb.jpg) (http://www.suckmypic.net/Rn37sGuw.png)

Note that I do not even put the d-2.dll files into the linker :D
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: Raincode on November 17, 2013, 03:59:28 pm
Hey,

I believe it's because you are using 2.1, I had 2.0

I'll just try it with the right dlls this time

Raincode
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on November 17, 2013, 04:07:15 pm
okay ;) would be nice if this problem is solved. I am just at the beginning of learning how to program so I am not that helpful at the moment :D
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: wintertime on November 18, 2013, 12:14:16 am
On the picture is at least sfml-graphics twice in different versions included and maybe more if scrolling down. This can yield errors.

Better consider this when sorting them in the list:
- graphics depends on window
- window, audio, network depends on system
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on November 19, 2013, 05:44:17 pm
sry for not answering i got a new pc and i first need to set it up. maybe i can set everything static now :D i will keep you guys updated ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on November 22, 2013, 08:38:43 pm
So, I tried it again and again :D nothing changed.

I sorted the lib files to the dependencies but that did not affect anything (I think that this even ain't a problem in visual).

I further came to the conclusion that I only get errors if I set SFML_STATIC. Dynamic linking works smoothly. But tonight i am going to try recompiling SFML with cmake again. let's see how this works out.
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on December 05, 2013, 11:21:50 pm
i recompiled sfml using the sfml-installer.

i reworked the code (because i now program with visual studio 2013)

but i cannot set sfml static anymore, but i will work on it.

tomorrow i will give you an update on where i am currently ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on December 06, 2013, 06:07:08 pm
Helloooooooo :D

As promised i updated my repo:
https://github.com/nebula2/Pew (https://github.com/nebula2/Pew)

So I...
added some stuff
rewrote the collision using templates.
killed some fool stuff.
added a highscore.. which is currently just a gamelog but its something :D

I wont show you a release because i just cant set a static version :D but I am working on presenting you at least something. I am also planning on uploading a video. that is on my list :D

If someone reads this, please tell me what you think.

I know I am not a good programmer but i am working to get better :D just so you know

__________________________________________________________________________________
the latest release is always on the main post ;) got that dll thing going
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on December 08, 2013, 05:27:26 am
whats uuup :D

i added the settings for the volume. I will write this for everything. and write savestuff :D I will update this as soon as i am finished ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on December 10, 2013, 08:39:13 pm
Okay I updated the first post ;)

soundsettings are now completely supported.

Just an info:

i dont have much time so dont wonder why this project keeps going so slow :D if anyone is interested, just give me some critics :D
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on December 14, 2013, 05:17:07 pm
added a new enemy here is the link:

http://www.xup.in/dl,82308411/Release.rar/ (http://www.xup.in/dl,82308411/Release.rar/)

repo is up to date.

because no one gives a shit i will only try to fix bugs, upload it and then end the updates on this site.

i just think it makes no sence anymore
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on December 21, 2013, 06:38:56 pm
added a new enemy and reworked code a little. It can all be seen on github.
fixed a bug bla bla.

changelog is also on github, avaliable in german and english
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on December 25, 2013, 07:41:59 pm
Hey Guys,

today i worked on the settings.

they are now fully supported. downloadlink is in the main post, repo is up to date too ;)
____________________________________________________________________
edit: http://www.xup.in/dl,66808995/Pew.rar/ (http://www.xup.in/dl,66808995/Pew.rar/)
there were 2 images missing
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: AlexAUT on December 25, 2013, 09:10:03 pm
The game isn't bad just unpolished but why should i play/test it with texts like "du lusche" (for the non german guys: "looser"). Thats not even funny just rude.

Btw you are not allowed to distribute the arial.ttf. You should switch to a "free" font...

AlexAUT
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on December 26, 2013, 12:33:10 am
The game isn't bad just unpolished but why should i play/test it with texts like "du lusche" (for the non german guys: "looser"). Thats not even funny just rude.

Btw you are not allowed to distribute the arial.ttf. You should switch to a "free" font...

AlexAUT

The "looser" is just for fun :D i can remove it if it bothers people :P
for the arial.ttf, sry i did not know that, i will replace it ;)

may i ask what you mean with unpolished? i really want to improve this so every hint counts to me, thanks
____________________________________________________________________________
edit: I uploaded the game with another font http://www.dafont.com/ (http://www.dafont.com/) and changed the lose screen picture ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: AlexAUT on December 26, 2013, 12:35:27 pm
may i ask what you mean with unpolished? i really want to improve this so every hint counts to me, thanks

For the menu:

For the game (depends on what game you are planning, just a few suggestions):


AlexAUT
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on December 26, 2013, 05:13:19 pm

For the menu:
  • Add a fancy sprite as background or let enemies fly around in the background. Because only a black screen is boring  ;D
  • In the graphics options you can't see the active entry, because both are orange, so you have to try with "left/right" which entry is currently selected.
  • Fullscreen do not work?
  • Sound menu: its hard to select 50 as volume level. Maybe you should increase the value slower and jump 5% every interval. Or increase the value by 10 every key-press, so the user has to click right 10times to increase the value from 0 to 100

For the game (depends on what game you are planning, just a few suggestions):
  • More enemy types
  • I don't know how good your drawing skills are, but maybe better sprites  ;)
  • More powerups. E.g. shield, faster/slower movement, a bomb which destroys every enemy (Serious Sam  8)), another weapon (e.g. splash damage), slow-motion... there are a lot of possibilities
  • Maybe the enemies fly in formations.
  • Bosses? Because who is throwing the cows at me? ::)
  • Online highscore?  :)

AlexAUT


Thanks a lot for this! i will try to implement your suggestions. regarding to the fullscreen setting:
when you set it to true it will take effect if you restart the game (the window gets initialized once in the game)
to the active settings. for the fullscreen the active setting is shown, but not for the setSmooth thing. but i will make this with ease :D

Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on December 26, 2013, 06:05:44 pm
I will now try to make the wished changes to my game which are above.

Tanks a lot to AlexAUT for the critics.

I made some changes so far:

here is the release:
http://www.xup.in/dl,12140230/Pew.rar/
 (http://)
i will keep you updated ;)

PS: repo is up to date too
________________________________
I made a big mistake :D the font i used does not have numbers included :D well, I took another font.
i had to replace some things to get the new font fitting into the HUD of the game but its okay now
________________________________
made another mistake :D forgot to put 2 .png files into the rar archive :D seems to be not my day
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on December 28, 2013, 03:39:42 am
Update


here a picture of the formation
(http://img0.www.suckmypic.net/img/M/E/05L21yht/enemyFormation-jpg_thumb.jpg) (http://www.suckmypic.net/05L21yht.jpg)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on January 09, 2014, 06:22:43 pm
currently i am working on adding the option to play with two players(first player keyboard, sec player mouse). i have to rework the movement of the second player and i will upload it as soon as it is completely included.

another thing i want to mention:

if you cannot start the game you probably need this:

http://www.microsoft.com/de-de/download/details.aspx?id=5555 (http://www.microsoft.com/de-de/download/details.aspx?id=5555)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: zsbzsb on January 09, 2014, 06:29:33 pm
another thing i want to mention:

if you cannot start the game you probably need this:

http://www.microsoft.com/de-de/download/details.aspx?id=5555 (http://www.microsoft.com/de-de/download/details.aspx?id=5555)

You might want to provide the english link (http://www.microsoft.com/en-us/download/details.aspx?id=5555).

http://www.microsoft.com/en-us/download/details.aspx?id=5555 (http://www.microsoft.com/en-us/download/details.aspx?id=5555)

Also if you are using visual studio 2010 you might want to consider an upgrade to 2012 (if not 2013) to take advantage of C++11 features.  ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on January 11, 2014, 12:42:03 pm
oops :D

well i am working with visual studio 2013 :P
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on January 14, 2014, 09:43:02 pm
added Coop mode:

Quote
cl13:
- Coop added
-> second player is controlled by mouse (left mouse button for shoot)
-> players share their life until one is dead
-> a dead player will be revieved when the other gains 100 life
-> only first player can switch weapons
-> both share the same weapon at a time

release is up to date on the main post as always ;)
i did not test any bugs. if you find something please tell me
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew
Post by: nebula on January 17, 2014, 09:42:08 pm
a quick info:
i think it may be important to mention some things

as you can see the main focus is on expanding the game. after i have my basic enemy types i plan to make a multiplayer mode (LAN and / or Web) depending on how good i manage to get that going.
For the android users here: if there is an ending in sight an app will be programmed to get this on android

well, thats it for the moment ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: AlexAUT on January 18, 2014, 05:50:13 pm
Nice improvements  :)

Some ideas:


AlexAUT
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on January 19, 2014, 01:08:40 am
thank xou!

i wanted to do a pause option but i do not konw ho i can implement it :(
maybe you can follow my code (i will help you if you want)
reload time for the third weapon is already implemented but not correctly shown
normal enemies spawning durning boss spawn... i will do this
for closing the game, i will implement a button as you wish ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: AlexAUT on January 19, 2014, 01:26:40 am
i wanted to do a pause option but i do not konw ho i can implement it :(

I would really like to dig through the whole code and help you, but sadly currently I have no time for it  :'(

But I had a look at the main parts and there are 2 options for you.


I hope I described both ways well enough to follow

Maybe I will have time in about 2weeks during my military service to have a closer look


i will do this for closing the game, i will implement a button as you wish ;)

Why not set the window style to sf::Style::Close or sf::Style::Default and then respond to the sf::Event::Closed event (Would be easier than a button made by yourself  :) )?

AlexAUT
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on January 19, 2014, 10:22:54 am
i understand what you mean with the pause. i try it ;)
and i can also change the window style :P

thank you for your comments
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on January 19, 2014, 05:36:16 pm
okay, i implemented a pause option. but there is a problem i need help with^^

all the movements are bound to elapsedTime = clock.restart().asMilliseconds() in their speed or spawn.
if i pause it stays like this, but if i resume the game, the timer gets very high a moment and that is not wanted, because the game "jumps" forward. my theory is that the clock simply doesn't get restarted. so the longer you stay in pause the higher gets the elapsedTime after you resume. here is the code:

//Game.cpp

#include "Game.h"

HighscoreManager Game::getHighScore()
{
        return highscore;
        elapsedTime = 0;
}

int Game::Run(sf::RenderWindow &window)
{
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        //++++++++++++++++++++++++++++++++-PREGAME STUFF-+++++++++++++++++++++++++++++++++++++++                                                                               
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        bool Running = true;
        paused = false;

        //sound & music
        IOsound iosound;
        iosound.ReadSoundSettings(volume);
        IngameSound sound;
        sound.LoadSoundBuffer();
        sound.setBuffer(volume);
        IngameMusic music;
        music.LoadMusic(volume);
        music.PlayMusic("ingamesong");

        //background and HUD
        MovableBackground bg("graphics//core//background.jpg", window);
        Background hud("graphics//core//hud.png");
        bgSpeed = 0.3;
        bgDirection = true;
        Healthbar hudHealth;
        WeaponManager weapon;

        //basic stuff
        IOtwoPlayer secPlayer;
        Player player1("graphics//player.png");
        Player2 player2("graphics//player2.png");

        player1health = player1.getHealth();
        player2health = player2.getHealth();

        //what happens if sec player is active
        if (!secPlayer.ReadSettings())
        {
                player2.active = false;
               
        }

        Game::highscore;
        UpdateManager updateMng;
        RenderManager renderMng;
        filename = "screenshot.png";

        //unlock pew
        boss1Dead = false;
        gotPew = false;
        pewOnCooldown = false;
        GUIcircleShape pewCD;

        //counter + random-x-spawn
        bulletTimeCount     = 0;
        enemyTimeCount      = 0;
        enemyFormationCount = 0;
        shitCount               = 0;
        healthDropCount     = 0;
        cowTimeCount        = 0;
        randomX                     = 0;
        showLvUp                    = 0;
        damageChill                 = 0;
        boss1WeaponCount    = 0;
        boss2WeaponCount    = 0;

        //health, points & alive
        Health health("graphics//health.png");
        health.setPosition(0, 12.5);

        Text pHealthS(18);
        pHealthS.setPosition(23, 12.5);
        pHealthS.setColor(sf::Color::Green);

        points = 0;
        Text pointS(25);
        pointS.setPosition(650, 8);
        pointS.setColor(sf::Color::Black);
        std::stringstream pointStream;

        Text lvUp("NEW WEAPON", 60);
        lvUp.setColor(sf::Color::Yellow);
        lvUp.setOrigin(lvUp.getGlobalBounds().width / 2, lvUp.getGlobalBounds().height / 2);
        lvUp.setPosition(window.getSize().x / 2, window.getSize().y / 2);

        Text gameOver("GAME OVER", 56);
        gameOver.setPosition(210, 250);
        gameOver.setColor(sf::Color::White);


        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        //+++++++++++++++++++++++-UPDATE STUFF & INITIALIZE-++++++++++++++++++++++++++++++++++++                                                                               
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        while (Running)
        {
                //handle events
                while (window.pollEvent(event))
                {
                        //close
                        if (event.type == sf::Event::Closed)
                        {
                                return (-1);
                        }
                        //menu
                        if (event.type == sf::Event::KeyPressed)
                        {
                                if (event.key.code == sf::Keyboard::Escape)
                                {
                                        //reset stuff (bugfix)
                                        Game::ClearStuff();

                                        return (0);
                                }
                                if (event.key.code == sf::Keyboard::P)
                                {
                                        if (!paused)
                                        {
                                                Game::StartPause();
                                        }
                                        else
                                                Game::EndPause();
                                }
                        }
                }

                std::cout << elapsedTime << std::endl;

                if (!paused)
                {
                        //initialize counts & background movement
                        elapsedTime = clock.restart().asMilliseconds();//<-SEE HERE
                        enemyTimeCount += elapsedTime;
                        bulletTimeCount += elapsedTime;
                        p2bulletTimeCount += elapsedTime;
                        shitCount += elapsedTime;
                        boss1WeaponCount += elapsedTime;
                        boss2WeaponCount += elapsedTime;
                        healthDropCount += elapsedTime;
                        cowTimeCount += elapsedTime;
                        damageChill += elapsedTime;
                        enemyFormationCount += elapsedTime;
                        bg.Update(window, elapsedTime, bgSpeed, bgDirection);

                        //sync health
                        player1health = player1.getHealth();
                        player2health = player2.getHealth();

                        //spawns
                        updateMng.EnemySpawn(enemyTimeCount, enemyv, enemyFormationv, randomX);//enemy
                        updateMng.EnemyFormationSpawn(enemyFormationCount, enemyFormationv, boss2v);//enemyFormation
                        updateMng.HealthDropSpawn(healthDropCount, healthv, randomX);//health
                        updateMng.SpaceMonkeySpawn(points, monkeyv, boss2v);//monkey
                        updateMng.ShitSpawn(shitCount, monkeyv, shitv, sound);//shit
                        updateMng.Boss1Spawn(points, boss1v);//boss1
                        updateMng.UnlockPewSpawn(boss1Dead, unlockPewv);//unlockpew
                        updateMng.Boss1WeaponSpawn(boss1WeaponCount, b1Weaponv, boss1v, sound);//b1Weapon
                        updateMng.CowSpawn(cowTimeCount, cowv, randomX, sound);//cow
                        updateMng.Boss2Spawn(boss2v, points);//boss2
                        updateMng.Boss2WeaponSpawn(boss2WeaponCount, boss2Weaponv, boss2v);//b2Weapon
                        pewCD.Update(pewOnCooldown, elapsedTime);//pewCooldown

                        //player weapon spawn
                        if (player1.active)
                        {
                                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
                                {
                                        updateMng.BulletSpawn(bulletTimeCount, bulletv, highscore, weapon, player1, sound);//bullet
                                        updateMng.DoubleShotSpawn(bulletTimeCount, dShotv, highscore, weapon, player1, sound);//Doubleshot
                                        updateMng.PewSpawn(pewv, highscore, weapon, player1, sound, pewOnCooldown);//Pew
                                }
                        }

                        if (player2.active)
                        {
                                if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
                                {
                                        updateMng.BulletSpawn2(p2bulletTimeCount, bulletv, highscore, weapon, player2, sound);//bullet
                                        updateMng.DoubleShotSpawn2(p2bulletTimeCount, dShotv, highscore, weapon, player2, sound);//Doubleshot
                                        updateMng.PewSpawn2(pewv, highscore, weapon, player2, sound, pewOnCooldown);//Pew
                                }
                        }

                        //hud update
                        hudHealth.Update(window, player1.getHealth());
                        weapon.setWeapon(elapsedTime, points, gotPew);
                        weapon.Update();
                }
                //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                //++++++++++++++++++++++++++++++++-DRAW & COLLISION-++++++++++++++++++++++++++++++++++++                                                                               
                //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                window.clear();
                bg.Render(window);

                if (!paused)
                {

                        if (player1.active)
                        {
                                Rm::StdDraw(healthv, elapsedTime, window);//health
                                Rm::StdDraw(unlockPewv, elapsedTime, window);//unlockPew
                                Rm::StdDraw(monkeyv, elapsedTime, window);//monkey
                                Rm::StdDraw(boss1v, elapsedTime, window);//boss1
                                Rm::StdDraw(cowv, elapsedTime, window);//cow
                                Rm::StdDraw(enemyFormationv, elapsedTime, window);//enemyFormation
                                Rm::StdDraw(boss2v, elapsedTime, window);//boss2
                                Rm::EnemyStdWeapon(shitv, shititerator, window, elapsedTime);//shit
                                Rm::EnemyStdWeapon(b1Weaponv, bWeaponIt, window, elapsedTime);//b1Weapon

                                renderMng.Boss2WeaponDraw(boss2Weaponv, boss2WeaponIt, elapsedTime, player1, window);//b2Weapon
                                renderMng.EnemyDraw(enemyv, elapsedTime, highscore, window);//Enemy
                                renderMng.BulletDraw(bulletv, bulletviterator, points, sound, highscore, enemyv, monkeyv, shitv, boss1v, boss1Dead, boss2Weaponv, enemyFormationv, window, elapsedTime);//bullet
                                renderMng.DoubleShotDraw(dShotv, dShotIt, points, sound, highscore, enemyv, monkeyv, shitv, boss1v, boss1Dead, boss2Weaponv, enemyFormationv, window, elapsedTime);//doubleShot
                                renderMng.PewShotDraw(pewv, pewIt, points, sound, highscore, enemyv, monkeyv, shitv, boss1v, boss2v, boss2Weaponv, enemyFormationv, window, elapsedTime);//Pew
                        }

                        //player collision
                        if (player1.active)
                        {
                                coll::PlayerEnemyInactive(enemyv, player1, sound);//enemy
                                coll::PlayerEnemyInactive(shitv, player1, sound);//shit
                                coll::PlayerEnemyInactive(b1Weaponv, player1, sound);//b1Weapon
                                coll::PlayerEnemyInactive(boss2Weaponv, player1, sound);//b2Weapon
                                coll::PlayerEnemyInactive(enemyFormationv, player1, sound);//enemyFormation

                                coll::PlayerHealthGet(healthv, player1, sound);//health
                                coll::PlayerUnlockPew(unlockPewv, player1, sound, gotPew, pewOnCooldown);//unlockPew

                                //for enemies that are not set inactive there is a damagechill.. otherwise player would instantly die
                                if (damageChill > 500)
                                {
                                        coll::PlayerEnemyActive(boss2v, player1, sound);//boss2
                                        coll::PlayerEnemyActive(cowv, player1, sound);//cow
                                        coll::PlayerEnemyActive(monkeyv, player1, sound);//monkey
                                        coll::PlayerEnemyActive(boss1v, player1, sound);//boss1
                                        damageChill = 0;
                                }
                        }

                        if (player2.active)
                        {
                                coll::PlayerEnemyInactive(enemyv, player2, sound);//enemy
                                coll::PlayerEnemyInactive(shitv, player2, sound);//shit
                                coll::PlayerEnemyInactive(b1Weaponv, player2, sound);//b1Weapon
                                coll::PlayerEnemyInactive(boss2Weaponv, player2, sound);//b2Weapon
                                coll::PlayerEnemyInactive(enemyFormationv, player2, sound);//enemyFormation

                                coll::PlayerHealthGet(healthv, player2, sound);//health
                                coll::PlayerUnlockPew(unlockPewv, player2, sound, gotPew, pewOnCooldown);//unlockPew

                                //for enemies that are not set inactive there is a damagechill.. otherwise player would instantly die
                                if (damageChill > 500)
                                {
                                        coll::PlayerEnemyActive(boss2v, player2, sound);//boss2
                                        coll::PlayerEnemyActive(cowv, player2, sound);//cow
                                        coll::PlayerEnemyActive(monkeyv, player2, sound);//monkey
                                        coll::PlayerEnemyActive(boss1v, player2, sound);//boss1
                                        damageChill = 0;
                                }
                        }

                        //health & points into string
                        pHealthS.Update(healthStream, player1.getHealth());
                        pointS.Update(pointStream, points);

                        //players
                        if (player1.active)
                        {
                                player1.Update(window, elapsedTime);
                                player1.Render(window);

                                //sync health
                                if (player2.active)
                                {
                                        if (player2.getHealth() < player1.getHealth())
                                        {
                                                player1.setHealth(player2health);
                                        }
                                        if (player1.getHealth() < player2.getHealth())
                                        {
                                                player2.setHealth(player1health);
                                        }
                                }
                        }

                        if (player2.active)
                        {
                                player2.Update(window, elapsedTime);
                                player2.Render(window);
                        }

                        //revieve a player
                        if (secPlayer.ReadSettings())
                        {
                                if (player1.active && player1.getHealth() == 100 && !player2.active)
                                {
                                        player2.active = true;
                                        player2.setHealth(100);
                                }
                                if (player2.active && player2.getHealth() == 100 && !player1.active)
                                {
                                        player1.active = true;
                                        player1.setHealth(100);
                                }
                        }

                        //draw HUD
                        hudHealth.RenderBG(window);
                        hudHealth.Render(window);
                        hud.Render(window);
                        pHealthS.Render(window);
                        health.Render(window);
                        pointS.Render(window);
                        weapon.Render(window);
                        pewCD.Render(window);

                        //new weapon draw
                        if (points >= 1000 && points <= 1050)
                        {
                                showLvUp += elapsedTime;
                                if (showLvUp >= 0 && showLvUp <= 2000)
                                {
                                        lvUp.Render(window);
                                }
                                else if (showLvUp > 2000)
                                {
                                        showLvUp = 0;
                                }
                        }

                        //Game over
                        if (!player1.active)
                        {
                                //adjust highscore and show "Game Over"
                                highscore.setPoints(points);
                                gameOver.Render(window);
                                window.display();

                                //reset stuff (bugfix)
                                Game::ClearStuff();

                                //delay until the highscore screen appears
                                sf::sleep(sf::seconds(1));
                                return 5;
                        }
                }
                window.display();
        }
        return -1;
}

void Game::ClearStuff()
{
        points = 0;

        //restart counters
        enemyTimeCount = 0;
        bulletTimeCount = 0;
        p2bulletTimeCount = 0;
        shitCount = 0;
        boss1WeaponCount = 0;
        boss2WeaponCount = 0;
        healthDropCount = 0;
        cowTimeCount = 0;
        damageChill = 0;
        enemyFormationCount = 0;

        //clear vectors
        healthv.clear();
        enemyv.clear();
        monkeyv.clear();
        shitv.clear();
        boss1v.clear();
        cowv.clear();
        boss2v.clear();
        boss2Weaponv.clear();
        enemyFormationv.clear();
}

void Game::StartPause()
{
        paused = true;
        //TODO
}

void Game::EndPause()
{
        //TODO
        paused = false;
}

i hope you manage to get through it (i think my style is not very good, because i am learning this mostly by myself) if anyone has a simple answer i would be pleased to hear it ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on January 19, 2014, 05:48:55 pm
nevermind i solved it simply by adding:
                if (paused)
                {
                        clock.restart();
                }

world can be so easy :D

so i will add some stuff to let the pause look like the game is paused and upload it ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on January 19, 2014, 06:20:02 pm
Okay, I uploaded todays changes.

Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: kingcools on January 19, 2014, 07:23:34 pm
You can easily improve your code:

split your Game::Run() function into many small functions.

on first look your Game::Run() function could look like this:


Game::Run()
{
//All the following functions could be added to another init() function as well, then you would just write init()
//here instead of flooding the run function with ~5 init functions
initSound();
initBackGround();
initPlayers();
initCounter();
initPoints();

while(running)
{
handleEvent();
if(!pause)
{
update(); //all those time updates you do
draw();    //contains specialicst draw functions for all the stuff you need to draw
}
}
}
}


}

This should be your run() method. Way easier to grasp, maintain and it is more motivating to work with it.


I find it way more relaxing to have many rather small functions then a few giant ones.
Rule of thumb for me is something like "7 lines is great (of course not always doable), max around 40 lines."
Beyond about 40 lines it just becomes a mess and something is most likely wrong.
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on January 19, 2014, 07:49:13 pm
thank you ;) i will edit my code like you say. it seems logic
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on January 31, 2014, 06:06:11 pm
Hey,

I've been really buisy lately, so I just managed to do a little hotfix regarding to the coop thing.

if you are at the third boss, there is now tracking added for the sec player if the first is dead ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: Cadisol87 on February 14, 2014, 06:40:18 pm
Looks like an funny shooter, made just 4fun. Like it! :)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on February 21, 2014, 04:47:37 pm
Looks like an funny shooter, made just 4fun. Like it! :)

Thank you ;)

I thought that I keep you guys updated :D Been really busy recently..
I managed to get the intro to start when the user wants it to. But the project got really spaghetti-like.
Because of that i thought about some changes in the structure. I have no idea of how to make an uml-diagram out of my c++ code, so i painted it :'D. Here is the photo:

(http://img0.www.suckmypic.net/img/H/s/utubKDnR/IMG_13671-jpg_thumb.jpg) (http://www.suckmypic.net/utubKDnR.jpg)


For the ones that have no idea of my code, i will put the music into the main.cpp and make one file out of all the IOxxx files. As you can imagine, this will take some time ;)

Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on February 21, 2014, 07:13:04 pm
A little update (and a question for help :D)

i managed to get the input/output stuff into 2 files (one .h and one .cpp) but now i have problems with the music

this is how my main.cpp looks like in this moment:
//main.cpp

#include <vector>
#include <iostream>
#include "StateManager.h"
#include "WindowStates.h"
#include "IOstuff.h"
#include "Music.h"

int main()
{

        //StateManager IDs
        std::vector<StateManager*> states;
        int screenState = 0;

        //create window
        IOscreen ioscreen;
       
        sf::RenderWindow window;
        window.setFramerateLimit(60);
       
        //set window style
        if (ioscreen.getScreenSettings())
        {
                window.create(sf::VideoMode(800, 600, 32), "Pew", sf::Style::Fullscreen);
                window.setMouseCursorVisible(false);
        }
        else
        {
                window.create(sf::VideoMode(800, 600, 32), "Pew", sf::Style::Default);
        }

        //Music

        int volume;
        int volumeCheck = NULL; //will later be interesting when i change the volume i want to keep that updated
        IOsound iosound;
        iosound.ReadSoundSettings(volume);
        IngameMusic ingMusic;
        ingMusic.LoadMusic(volume);
        MenuMusic       menMusic;
        menMusic.LoadMusic(volume);
        menMusic.PlayMusic("menusong");

        //states
        Menu state0;
        states.push_back(&state0);
        Intro state1;
        states.push_back(&state1);
        Settings state2;
        states.push_back(&state2);
        Game state3;
        states.push_back(&state3);
        GraphicSet state4;
        states.push_back(&state4);
        Highscore state5;
        states.push_back(&state5);
        SoundSet state6;
        states.push_back(&state6);
        DiffSet state7;
        states.push_back(&state7);
        CoopSet state8;
        states.push_back(&state8);

        //runs states & switches between them
        while (screenState >= 0)
        {
                //main loop
                screenState = states[screenState]->Run(window);

                std::cout << screenState << std::endl;

                //when screen changes
                if (screenState == 5)//to give the highscore
                {
                        state5.setHighscoreManager(state3.getHighScore());
                }

                else if (screenState != 3)//to clear the game
                {
                        state3.ClearStuff();
                }

                //Control Music
                if (screenState == 1 || screenState == 3)
                {
                        menMusic.Pause("menu");
                }
                if (screenState == 1)
                {
                        menMusic.Pause("menu");
                        menMusic.PlayMusic("introsong");
                }
                if (screenState != 3)
                {
                        ingMusic.Pause();
                }
                if (screenState == 3)
                {
                        menMusic.Pause("intro");
                        ingMusic.PlayMusic();
                }
                if (screenState != 3 || screenState != 1)
                {
                        menMusic.Pause("intro");
                        menMusic.UnpauseMenu();
                }
        }
        return 0;
}

so here is the problem:
when the screenState changes, the music does not stop like i planned it. any suggestions? :D if i find a solution i will keep you updated ;)
___________________________
I checked it again and came to the result, that only the menu music does not stop
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on February 22, 2014, 01:49:46 am
i could fix it by deleting my resume function.. seems to cause issues somehow...
but nevermind. now i got the changes i wanted.. well almost likely.

the only problem is that as soon as you hit the main menu again the menu theme starts playing again.
but before that was normal every time someone changed the screenstate, so there is progress :D

tomorrow i will make a new video for the main page... the one here is not very up to date^^

i uploaded the changes as always ;)

______________________________________________________

cl15:
- codechanges:
  ->input/output summed up to IOstuff
  ->music is now controlled in the main.cpp
- music will now play correctly in menu,
  as long as you are not again in main menu
______________________________________________________
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on February 28, 2014, 10:58:17 pm
(http://img0.www.suckmypic.net/img/q/d/jvNM32ol/krassertyp-jpg_thumb.jpg) (http://www.suckmypic.net/jvNM32ol.jpg)

time to do the third boss :D

(http://img0.www.suckmypic.net/img/7/G/s1FPwC93/cowmashine-jpg_thumb.jpg) (http://www.suckmypic.net/s1FPwC93.jpg)

as you can see my painting skills did not really improve :'D but hey, this enemy will have 3 states.

1.)
2.)
3.)

well, that is how i imagined it... kinda :D you'll see
__________________________________________
after that enemy, the following will happen
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on March 22, 2014, 07:06:57 pm
Finally the third boss is at a state where i can release it :D

here a video:
http://www.youtube.com/watch?v=Xm5MyB9HHS4&feature=share&list=UUtkyMAtEDYu2_Re2F1rYMIw

changes...
cl16:
- third boss added
  -> includes 3 states
  -> 1 - cowheads; 2 - cows; 3 - mashine
- pew sound (third weapon) changed


as always, the release is at the main post ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on March 22, 2014, 07:48:39 pm
there seems to be a problem with playing the .ogg files.
pew is not played anymore (changed the file)
when the third boss dies, sound is not played
when cows spawn (the normal ones) no sound is played...

i will put this into the forum maybe someone has the solution :D
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: therocode on March 23, 2014, 02:42:40 pm
Haha that is awesome!

I like the cow boss graphics, and the part when it starts spinning around. :D

The sound effects also give a nice retro feel. Keep it up!
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on March 23, 2014, 03:25:56 pm
thanks :D

i will make more :P
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on March 23, 2014, 04:01:46 pm
Sound should work now. Updated everything ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on June 14, 2014, 10:32:54 pm
hi,

it's been a while :D i had just no time left to keep my project going :/

today, as i saw my code i wanted to structure it right up from the beginning, because even i had problems with finding back into it.

This got me to a problem and i can't find the mistake :( maybe someone can help me :D

first i will post some code and then tell you what exactly happens.

//main.cpp

#include "Game.h"

int main()
{
        Game pew;
        pew.ChangeState(Game::gameStates::MAINMENU);

        pew.Run();

        return 0;
}
 

//Game.h

#ifndef GAME_H
#define GAME_H

#include <iostream>
#include <memory>

#include "GameState.h"
#include "MainMenuState.h"
#include "PlayState.h"
#include "Intro.h"

class Game
{
public:
         Game();
        ~Game();

        enum class gameStates{ MAINMENU, INTRO, SETTINGS, PLAY, GRAPHICSET, SOUNDSET, DIFFSET, COOPSET, HIGHSCORE };

        void Run();
        void ChangeState(gameStates newState);
        bool isRunning(){ return running; };
        void setRunning(bool mRunning);
       
        sf::RenderWindow window;

private:

        void Quit();
        void Update();
        void HandleEvents();
        void Render();

        std::unique_ptr<GameState> CurrentState;
       
        bool running;
};

#endif
 

//Game.cpp

#include "Game.h"

Game::Game()
{
        running = true;

        window.create(sf::VideoMode(800, 600), "Pew");
        window.setFramerateLimit(60);
        window.setVerticalSyncEnabled(true);
}

Game::~Game()
{
        CurrentState = nullptr;
}

void Game::Run()
{
        while (running)
        {
                Update();
                HandleEvents();
                Render();
                Quit();        
        }
}

void Game::ChangeState(gameStates newState)
{
        switch (newState)
        {
        case gameStates::MAINMENU:
                CurrentState = std::move(std::unique_ptr<MainMenuState>(new MainMenuState));
                break;
        case gameStates::PLAY:
                CurrentState = std::move(std::unique_ptr<PlayState>(new PlayState));
                break;
        case gameStates::INTRO:
                CurrentState = std::move(std::unique_ptr<Intro>(new Intro));
                break;
        }
}

void Game::setRunning(bool mRunning)
{
        running = mRunning;
}

void Game::Quit()
{
        if (!running)
                window.close();
}
void Game::Update()
{
        CurrentState->Update(*this);
}
void Game::HandleEvents()
{
        CurrentState->HandleEvents(*this);
}
void Game::Render()
{
        window.clear();
        CurrentState->Render(*this);
        window.display();
}
 

//MainMenuState.h

#ifndef MAINMENUSTATE_H
#define MAINMENUSTATE_H

#include "Game.h"
#include "MenuSfx.h"
#include "IOstuff.h"

class MainMenuState : public GameState
{
public:
        MainMenuState();
        ~MainMenuState();
        void HandleEvents(Game &game);
        void Update(Game &game);
        void Render(Game &game);
private:
        IOsound iosound;
        MenuSound sound;

        bool  playing;
        float speed;
        float elapsedTime;
        float x_movement;
        float y_movement;
        float x, y;
        short int   debauch;
        short int   selection;
        int   volume;

        sf::Event   *pEvent;
        sf::Clock   *pClock;
        sf::Texture *texture;
        sf::Sprite  *sprite;

        Background bg;
        Text play, again, settings, close;
};

#endif
 

//MainMenuState.cpp

#define PI 3.14159
#include "MainMenuState.h"
#include <cmath>

MainMenuState::MainMenuState()
{
        bg.setFilePath("graphics//core//menu.png");
       
        //sound & music
        sound.LoadSoundBuffer();
        sound.setBuffer(volume);

        playing = false;
        speed = 0.5;
        selection = 0;
        iosound.ReadSoundSettings(volume);

        pEvent = new sf::Event;
        pClock = new sf::Clock;
        texture = new sf::Texture;
        sprite = new sf::Sprite;

        //Enemy
        elapsedTime = 0;
        x_movement = 0;
        y_movement = 0;
        debauch = 200;
        texture->loadFromFile("graphics//enemies//enemy.png");
        texture->setSmooth(false);
        sprite->setTexture(*texture);
        sprite->setOrigin(36.5, 35);

        //buttons

        play.setStringAndSize("play", 70);
        again.setStringAndSize("again", 70);
        settings.setStringAndSize("settings", 70);
        close.setStringAndSize("close", 70);

        play.setPosition(270, 150);
        again.setPosition(270, 150);
        settings.setPosition(270, 250);
        close.setPosition(270, 350);
}

MainMenuState::~MainMenuState()
{
        delete pEvent;
        delete pClock;
        delete sprite;
        delete texture;

        pEvent =  nullptr;
        pClock =  nullptr;
        sprite = nullptr;
        texture = nullptr;

}

void MainMenuState::HandleEvents(Game &game)
{
        while (game.window.pollEvent(*pEvent))
        {
                if (pEvent->type == sf::Event::Closed)
                        game.setRunning(false);

                //Keyboard selection
                if (pEvent->type == sf::Event::KeyPressed)
                {
                        switch (pEvent->key.code)
                        {
                        case sf::Keyboard::Up:
                                if (selection > 0)
                                {
                                        selection -= 1;
                                        sound.PlaySound("select");
                                }
                                else
                                        selection = 0;
                                break;

                        case sf::Keyboard::Down:
                                if (selection < 2)
                                {
                                        selection += 1;
                                        sound.PlaySound("select");
                                }
                                else
                                        selection = 2;
                                break;

                        case sf::Keyboard::Return:
                                if (selection == 0)
                                {
                                        if (playing)
                                                game.ChangeState(Game::gameStates::PLAY);
                                        else
                                                playing = true;
                                                game.ChangeState(Game::gameStates::INTRO);
                                }
                                else if (selection == 1)
                                        game.ChangeState(Game::gameStates::SETTINGS);
                                else
                                        game.setRunning(false);
                                break;
                        default:
                                break;
                        }
                }
        }
}

void MainMenuState::Update(Game &game)
{
        if (selection == 0)//Spielen
        {
                play.setColor(sf::Color(255, 128, 0));
                again.setColor(sf::Color(255, 128, 0));
                settings.setColor(sf::Color(255, 255, 255));
                close.setColor(sf::Color(255, 255, 255));
        }
        else if (selection == 1)//Settings
        {
                play.setColor(sf::Color(255, 255, 255));
                again.setColor(sf::Color(255, 255, 255));
                settings.setColor(sf::Color(255, 128, 0));
                close.setColor(sf::Color(255, 255, 255));
        }
        else//Beenden
        {
                play.setColor(sf::Color(255, 255, 255));
                again.setColor(sf::Color(255, 255, 255));
                settings.setColor(sf::Color(255, 255, 255));
                close.setColor(sf::Color(255, 128, 0));
        }

        //moving enemy
        elapsedTime = pClock->restart().asMilliseconds();
        x_movement += elapsedTime;
        y_movement += elapsedTime;
        y = sprite->getPosition().y;
        x = sprite->getPosition().x;
        y = 300 + std::sin((y_movement * PI) / 180) * debauch;
        x = 400 + std::cos((x_movement * PI) / 180) * debauch;

        if (x_movement > 360)
                x_movement = 0;

        if (y_movement > 360)
                y_movement = 0;

        sprite->setPosition(x, y);
}

void MainMenuState::Render(Game &game)
{
        bg.Render(game.window);
        game.window.draw(*sprite);

        if (playing)
                again.Render(game.window);
        else
                play.Render(game.window);

        settings.Render(game.window);
        close.Render(game.window);
}
 



Soooooo, this is a lot code, but i wanted to make sure you got everything you need :D
the error accures, if i want to change the gamestate. here is a screenshot of the debug output:

(http://img0.www.suckmypic.net/img/V/8/zgEByn4H/err-png_thumb.jpg) (http://www.suckmypic.net/zgEByn4H.png)


thank you for your help
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: AlexAUT on June 14, 2014, 11:07:28 pm
Just quickly overlooked the code and saw in the game.cpp in changeState one error

this line:
CurrentState = std::move(std::unique_ptr<MainMenuState>(new MainMenuState));

should be

CurrentState = std::move(std::unique_ptr<MainMenuState>(new MainMenuState()));

you forgot the ()


AlexAUT
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on June 14, 2014, 11:15:07 pm
Just quickly overlooked the code and saw in the game.cpp in changeState one error

this line:
CurrentState = std::move(std::unique_ptr<MainMenuState>(new MainMenuState));

should be

CurrentState = std::move(std::unique_ptr<MainMenuState>(new MainMenuState()));

you forgot the ()


AlexAUT

thanks for your reply ;)
i changed it, but sadly this does not solve the problem :'(
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: Laurent on June 14, 2014, 11:19:41 pm
new X and new X() are perfectly equivalent. This was not an error.

To the OP: you should have opened a new thread. Now you're requesting help, you're not adding to your project's presentation. And you should show the call stack, so that we know exactly where it crashes.
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on June 14, 2014, 11:40:07 pm
new X and new X() are perfectly equivalent. This was not an error.

To the OP: you should have opened a new thread. Now you're requesting help, you're not adding to your project's presentation. And you should show the call stack, so that we know exactly where it crashes.

sorry for that, i opened a new thread ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: Veritas on June 15, 2014, 01:09:43 am
new X and new X() are perfectly equivalent. This was not an error.

To the OP: you should have opened a new thread. Now you're requesting help, you're not adding to your project's presentation. And you should show the call stack, so that we know exactly where it crashes.

Just nitpicking here but they are not necessarily the same depending on whether X is a POD or not.
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on July 19, 2014, 05:13:36 pm
Soooo,

i managed to get a better state handling running, for the end user this mainly just brings 3 improvements:
1. intro starts when it should,
2. if you play, go to the menu and go back to play, nothing from the game before is there
3. sound is now changed correctly when you change it in the settings, so you can hear how loud it is without having to go back to control it.

further the pause function is now on escape, and not on "P" as it was.

You can get the release at the mainpage as always.
By the way. i have holiday soon and will bring some improvements to the game like more content and functionalities.

See ya ;)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 09, 2015, 04:35:53 am
Hello,

after a long time (i think nearly a year) i could finally work again on my little project.
Got really buisy  ;D

Found out that my code is more than just spaghetti :D it is horrible.
But i enhanced my understanding of Computers a bit and learned a little about how it should be.

The App thing is something that probably will never be done because i just dont have the energy for that :(

So i did not do much, but here is it:

Coop will be shut down. That is because i changed the controls of the game.
You can now use the mouse in most of the menu and you will need it to play the game.

Projectiles are now shot in the direction the mouse is in relation to the player.
The player now moves with WASD and is always heading towards the mouse cursor.

I think that this makes the controls more dynamic.

As always, the code is uploaded to github. https://github.com/nebula2/Pew/tree/master/src%20Visual%20Studio%202013/Pew-Rework (https://github.com/nebula2/Pew/tree/master/src%20Visual%20Studio%202013/Pew-Rework)

Here is the Release:
http://www.xup.in/dl,32149673/Release.rar/ (http://www.xup.in/dl,32149673/Release.rar/)

Maybe i will make an extra video for the new controls for you to see how it behaves.
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 09, 2015, 01:13:03 pm
A quick update:

i fixed a bug where the select sound is played too often in the menu.
And the mouse now sticks to the window.
Furthermore the player-texture was upside down :'D

For some reason github has some issues uploading the changes. so here is just the fixed release:

http://www.xup.in/dl,68075662/Release.rar/ (http://www.xup.in/dl,68075662/Release.rar/)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 09, 2015, 08:08:27 pm
Hey Guys,

i tried to implement a highscore :D #game crashes

Made a new gameState, added it to the main menu bla bla bla.

The constructor should load data from the highscore file. Which looks like this:
Quote
Points 0,Enemy Missed 0,Enemy Killed 0,Monkey Killed 0,Shots Fired 0,Shots Got 0
Points 0,Enemy Missed 0,Enemy Killed 0,Monkey Killed 0,Shots Fired 0,Shots Got 0
Points 370,Enemy Missed 18,Enemy Killed 28,Monkey Killed 1,Shots Fired 129,Shots Got 78

and my class looks like this:

public:
        HighscoreList();
        ~HighscoreList();

        void HandleEvents(Game &game);
        void Update(Game &game);
        void Render(Game &game);

private:
        static bool sortScoreDesc(const sf::Vector3<int>& a, const sf::Vector3<int>& b);
        //mystuff
        HighscoreManager _mng;
        IOHighscore _ioHighscore;
        Background _bg;
        Text _score, _back, _highscore;

        //streams
        std::vector<sf::Vector3i> _numInput; ///< trägt die 3 wichtigen zahlen
        std::vector<std::string> _highScoreDataV;

        std::stringstream _scoreStream;
};

#endif //__HIGHSCORELIST_H__

//HighscoreList.cpp

#include "HighscoreList.h"
#include <fstream>
#include <iostream>
#include <algorithm>

HighscoreList::HighscoreList(){

        //set the background
        _bg.setFilePath("graphics//core//menu.png");

        //show something
        _back.setStringAndSize("BACK", 50);
        _back.setPosition(325, 500);

        _highscore.setStringAndSize("HIGHSCORE", 50);
        _highscore.setPosition(275, 10);

        //init highscorelist+++++++++++++++++++++++++++++++++

        //first get a vector that has the exact size of lines as the file
        std::fstream file;
        file.open("highscore.txt");
        if (file.fail()){
                perror("could not load highscore.txt file\n");
        }

        //create some stuff for temp save
        std::string tmp;       
        int tmpNumPoints, tmpNumFired, tmpNumGot, tmpint;

        //now extract the integer we need (points, shots fired, shots got)
        while (!file.eof()){
                std::getline(file, tmp, '\n');
                //IN-(1)STRING--POINTS--------(2)--------------(3)---------------(4)--------------(5)----Shots fired----(6)----Shots got
                file >> tmp >> tmpNumPoints >> tmp >> tmpint >> tmp >> tmpint >> tmp >> tmpint >> tmp >> tmpNumFired >> tmp >> tmpNumGot;
                //and store it into the integer
                //------------------------X--------------Y----------Z-------
                _numInput.emplace_back(tmpNumPoints, tmpNumFired, tmpNumGot);
        }
        file.close();

        //convert the values of Vector3i to what we need (Points, Accuracy, Score)
        for (unsigned int i = 0; i < _numInput.size(); i++){
                int tmpY, tmpZ;
                tmpY = _numInput[i].z * 100 / _numInput[i].z; //get Accuracy
                tmpZ = _numInput[i].x / tmpY; //get Score (Points / Accuracy)

                //set new values
                _numInput[i].y = tmpY;
                _numInput[i].z = tmpZ;
        }

        //sort the Vec for Score (Z) descending
        std::stable_sort(_numInput.begin(), _numInput.end(), sortScoreDesc);
        //std::sort(_numInput.begin(),_numInput.end());

        //erase all entries that are not in the top ten
        for (auto it = _numInput.begin() + 10; it != _numInput.end();it++){
                it = _numInput.erase(it);
        }

        //now we have a vector of integer, sorted by score which holds the TOP 10 plays
        //we need to print it out now
        for (unsigned int i = 0; i < _numInput.size(); i++){
                std::cout << "Points: " << _numInput[i].x << " Accuracy: " << _numInput[i].y << " Score: " << _numInput[i].z << std::endl;
        }

        _score.setStringAndSize("", 20);
        _score.setPosition(150, 195);

}

HighscoreList::~HighscoreList(){
        _numInput.clear();
}

void HighscoreList::HandleEvents(Game &game){
        sf::Event pEvent;

        while (game.window.pollEvent(pEvent)){
                //close
                if (pEvent.type == sf::Event::Closed)
                        game.setRunning(false);
                //menu
                if (pEvent.type == sf::Event::KeyPressed){
                        if (pEvent.key.code == sf::Keyboard::Return)
                                game.ChangeState(Game::gameStates::MAINMENU);
                }
        }
}
void HighscoreList::Update(Game &game){
        _mng = game.highscore;

        //Update stuff (there is the convertion from int to stringstream)
        //_score.Update(_scoreStream, _mng.getPoints());
}
void HighscoreList::Render(Game &game){
        _bg.Render(game.window);

        //Render stuff
        _score.Render(game.window);
        _back.Render(game.window);
        _highscore.Render(game.window);
}

//if the first integer is greater than the second, this returns true
bool HighscoreList::sortScoreDesc(const sf::Vector3<int>& a, const sf::Vector3<int>& b){
        return (a.z > b.z);
}


If i enter the highscore overview in the game, it simply does nothing more.
only thing i could get was this:
Quote
Ausnahme (erste Chance) bei 0x77BA604C (ntdll.dll) in Pew ReWork.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xFEEEFEF6
Ausnahmefehler bei 0x77BA604C (ntdll.dll) in Pew ReWork.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xFEEEFEF6

Ausnahme (erste Chance) bei 0x77BA604C (ntdll.dll) in Pew ReWork.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xFEEEFEF6
Ausnahmefehler bei 0x77BA604C (ntdll.dll) in Pew ReWork.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xFEEEFEF6

Ausnahme (erste Chance) bei 0x77BA604C (ntdll.dll) in Pew ReWork.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xFEEEFEF6
Ausnahmefehler bei 0x77BA604C (ntdll.dll) in Pew ReWork.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xFEEEFEF6

Das Programm "[11728] Pew ReWork.exe" wurde mit Code -1073741510 (0xc000013a) beendet.

I will keep you updated guys :D
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: AlexAUT on September 09, 2015, 08:35:19 pm
You should learn how to debug, most of the time you find the root of an access violation in under 10seconds if you know how to use your debug tools.

Some suggestions:

1) iirc variablenames beginning with an underscore are reserverd for compilers/implementation
2) Just use a forward slash in your include paths ( / ), they are the only way supported by all compilers ( \\ might not work with gcc)
3) You can use while(std::getline(file, tmp)) {...} Instead of the two liner (eof and then getline)
4) You can check if file.bad() if one of the output operations failed
5) Are you sure this line is correct? Because tmpY will always be 100
tmpY = _numInput[i].z * 100 / _numInput[i].z; //get Accuracy
 
6)Your deconstructor isn't needed, you do not have to clear it yourself, the deconstructor of a container will delete it's elements (you have to delete the content of pointers if you have something like std::vector<sf::Vector3i*> and the pointers are the owner of the memory, which should be avoided anyways)
7) This loop should cause the access violation if your highscore contains less than 10entries
    //erase all entries that are not in the top ten
    for (auto it = _numInput.begin() + 10; it != _numInput.end();it++){
        it = _numInput.erase(it);
    }
(but i'm not quite sure, try a indices loop (for(int i = 10; i < _numInput.size(); i++)) and look if it solves your problem or even better just call _numInput.resize(10);

AlexAUT
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 09, 2015, 09:09:42 pm
Hello AlexAUT,

first of all thank you for your input.

Quote
1) iirc variablenames beginning with an underscore are reserverd for compilers/implementation
Ok, from now on i will declare member variables with this "m_VariableName"

Quote
2) Just use a forward slash in your include paths ( / ), they are the only way supported by all compilers ( \\ might not work with gcc)
I did not know that. I will change this ;-)

Quote
3) You can use while(std::getline(file, tmp)) {...} Instead of the two liner (eof and then getline)
Thanks. That acutally stopped the game.
Quote
4) You can check if file.bad() if one of the output operations failed
I will keep that in memory.

Quote
5) Are you sure this line is correct? Because tmpY will always be 100
No, absolutely not :D thanks. It should be:
tmpY = m_numInput[i].y * 100 / m_numInput[i].z; //get Accuracy

Quote
6)Your deconstructor isn't needed, you do not have to clear it yourself, the deconstructor of a container will delete it's elements (you have to delete the content of pointers if you have something like std::vector<sf::Vector3i*> and the pointers are the owner of the memory, which should be avoided anyways)
Yes, my bad.

Quote
7) This loop should cause the access violation if your highscore contains less than 10entries
... i am an idiot :'D

I changed it and came to some other issues that i have solved now (stuff like division by 0 - so terrible)

now the only problem is that i have only one row of data in my vector :'D

my changed c++ file:
        //set the background
        m_bg.setFilePath("graphics/core/menu.png");

        //show something
        m_back.setStringAndSize("BACK", 50);
        m_back.setPosition(325, 500);

        m_highscore.setStringAndSize("HIGHSCORE", 50);
        m_highscore.setPosition(275, 10);

        //init highscorelist+++++++++++++++++++++++++++++++++

        //first open the file
        std::fstream file;
        file.open("highscore.txt");
        if (file.fail()){
                perror("could not load highscore.txt file\n");
        }

        //create some stuff for temp save
        std::string tmp;       
        int tmpNumPoints, tmpNumFired, tmpNumGot, tmpint;

        //now extract the integer we need (points, shots fired, shots got)
        while (std::getline(file, tmp, '\n')){
                //IN-(1)STRING--POINTS--------(2)--------------(3)---------------(4)--------------(5)----Shots fired----(6)----Shots got
                file >> tmp >> tmpNumPoints >> tmp >> tmpint >> tmp >> tmpint >> tmp >> tmpint >> tmp >> tmpNumFired >> tmp >> tmpNumGot;
                //and store it into the integer
                //------------------------X--------------Y----------Z-------
                m_numInput.emplace_back(tmpNumPoints, tmpNumFired, tmpNumGot);
        }

        file.close();

        //convert the values of Vector3i to what we need (Points, Accuracy, Score)
        for (unsigned int i = 0; i < m_numInput.size(); i++){
                int tmpY, tmpZ;
                if (m_numInput[i].y != 0 && m_numInput[i].z != 0){
                        tmpY = m_numInput[i].y * 100 / m_numInput[i].z; //get Accuracy
                }
                else{
                        tmpY = 0;
                }
                if (m_numInput[i].x != 0 && tmpY != 0){
                        tmpZ = m_numInput[i].x / tmpY; //get Score (Points / Accuracy)
                }
                else{
                        tmpZ = 0;
                }
               
                //set new values
                m_numInput[i].y = tmpY;
                m_numInput[i].z = tmpZ;
        }

        //sort the Vec for Score (Z) descending
        std::stable_sort(m_numInput.begin(), m_numInput.end(), sortScoreDesc);

        //erase all entries that are not in the top ten
        //but only if there are more than ten!
        if (m_numInput.size() > 10){
                for (auto it = m_numInput.begin() + 10; it != m_numInput.end(); it++){
                        it = m_numInput.erase(it);
                }
        }

        //now we have a vector of integer, sorted by score which holds the TOP 10 plays
        //we need to print it out now
        for (unsigned int i = 0; i < m_numInput.size(); i++){
                std::cout << "Points: " << m_numInput[i].x << " Accuracy: " << m_numInput[i].y << " Score: " << m_numInput[i].z << std::endl;
                std::cout << " Vector size: " << m_numInput.size() << std::endl;
        }
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 09, 2015, 09:51:13 pm
i changed the highscore txt file to the following:

Quote
370 18 28 1 129 120
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
370 18 28 1 129 78
0 0 0 0 0 0

Furthermore i changed the code to read from file to the following:
        //now extract the integer we need (points, shots fired, shots got)
        while (std::getline(file, tmp,'\n')){
                //IN-(1)STRING--POINTS--------(2)--------------(3)---------------(4)--------------(5)----Shots fired----(6)----Shots got
                file  >> tmpNumPoints >> tmp >> tmpint >> tmp >> tmpint >> tmp >> tmpint >> tmp >> tmpNumFired >> tmp >> tmpNumGot;

                std::cout << tmp << " <-das ist tmp " << tmpNumPoints << " <-das ist points \n" << tmpNumFired << " <-das ist fired" << tmpNumFired << " <- das ist got\n";
                //and store it into the integer
                //------------------------X--------------Y----------Z-------
                m_numInput.emplace_back(tmpNumPoints, tmpNumFired, tmpNumGot);
               
                std::cout << " Vector size at filling point: " << m_numInput.size() << std::endl;
        }

now i can read in 5 lines... with shitty output :D
(https://img0.suckmypic.net/img/E/9/Qn2wyAvD/neu-1-png_thumb.jpg) (https://suckmypic.net/Qn2wyAvD.png)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 09, 2015, 10:31:54 pm
LoL

(https://img0.suckmypic.net/img/L/b/01WXvvol/lol-png_thumb.jpg) (https://suckmypic.net/01WXvvol.png)

Think i need to figure out how to read in like the following:

int char int char int char int char int char int char(\n)
...
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 10, 2015, 12:28:05 am
Okay, I fixed it

Highscore - Check :D
not really beautiful but hey, its something.
The accuracy and Score are also wrong :D

Main Menu:
(https://img0.suckmypic.net/img/m/j/iWkXE1f6/mainmenu-png_thumb.jpg) (https://suckmypic.net/iWkXE1f6.png)

Highscore:
(https://img0.suckmypic.net/img/7/O/4rmTohib/highscore-png_thumb.jpg) (https://suckmypic.net/4rmTohib.png)

here is the new release. Today in a .zip file :D
http://www.xup.in/dl,83314044/Release.zip/

PS: The Solution for my problem was really simple. Here is a snipped:
        //first open the file
        std::fstream file;
        file.open("highscore.txt", std::ios::in);
        if (file.fail()){
                perror("could not load highscore.txt file\n");
        }

        //create some stuff for temp save
        std::string tmp; ///< to display in game later
        int tmpNumPoints, tmpNumFired, tmpNumGot, tmpint;

        //now extract the integer we need (points, shots fired, shots got)
        while (file >> tmpNumPoints >> tmpint >> tmpint >> tmpint >> tmpNumFired >> tmpNumGot){
               
                //and store it into the integer
                //------------------------X--------------Y----------Z-------
                m_numInput.emplace_back(tmpNumPoints, tmpNumFired, tmpNumGot);
        }

        //won't need file anymore
        file.close();
 

Special Thanks to AlexAUT for his help ;-)
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: AlexAUT on September 10, 2015, 08:41:32 am
Looks nice!

You could still simply replace this
if (m_numInput.size() > 10){
        for (auto it = m_numInput.begin() + 10; it != m_numInput.end(); it++){
            it = m_numInput.erase(it);
        }
    }
 

with this

 m_numInput.resize(10);

looks cleaner  :P



You could also use 3 different sf::Text for each highscore value (Points, Accuracy, Score) so you can align them in a vertical line



AlexAUT

Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 10, 2015, 03:36:58 pm
Thank you AlexAUT,

now I have this:

(https://img0.suckmypic.net/img/J/z/hpHyL4sq/highscore-png_thumb.jpg) (https://suckmypic.net/hpHyL4sq.png)

As you can see - now the stuff should be correct :D
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 10, 2015, 06:34:44 pm
Reworked the Mainpage.
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: Jesper Juhl on September 11, 2015, 09:05:30 pm
1) iirc variablenames beginning with an underscore are reserverd for compilers/implementation
Not quite.
Symbols starting with underscore are reserved for the implementation in global scope. Names that start with underscore+uppercase letter or names that contain double underscore are reserved in any scope.
See section 2.10 of the standard (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf).
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 11, 2015, 11:44:34 pm
Hey Guys,

added healthbar for the normal enemy.

(http://fs1.directupload.net/images/150911/anezw5ls.png) (http://www.directupload.net)

Will update this for the others later. Just wanted to show something :D

And here is what i plan to do in the future:


If you have suggestions or something, let me know  :P
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 12, 2015, 07:41:08 pm
Hi Guys,

All Enemies (except for the Formation - temp) got healthbars now.

Latest Release on Mainpage - Code on Github

UPDATE:
Quote
All Enemies (except for the Formation - temp) got healthbars now.
Fixed that

Also fixed other things quickly

New: Player can now only move in window - I think he got enough freedom
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 12, 2015, 08:35:50 pm
INFO:

There is currently a bug in the Highscore:

HighscoreList.cpp
        //erase all entries that are not in the top ten
        //but only if there are more than ten!
        if (m_numInput.size() > 10){
                for (auto it = m_numInput.begin() + 10; it != m_numInput.end();){
                        it = m_numInput.erase(it);
                        it++;
                }
        }

I will fix this soon
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: santiaboy on September 13, 2015, 12:25:54 am
Hey man, if you are erasing, don't increment the variable. The "erase" erases the one pointing and then it goes to the next one.

Example:
You want to erase top 11 and 12. So you have 1,2,...,10,11,12.
You are pointing at top 11. Erase it and then you have 1,2,...,10,12 are pointing at 12. If you increment it, you will go past it.

    //erase all entries that are not in the top ten
    //but only if there are more than ten!
    if (m_numInput.size() > 10){
        for (auto it = m_numInput.begin() + 10; it != m_numInput.end();){
            it = m_numInput.erase(it);
            //it++; Don't increment it!
        }
    }
 

Besides that, I think you are trying to resize the vector. Simply use resize (http://en.cppreference.com/w/cpp/container/vector/resize)! It also works with lists (http://en.cppreference.com/w/cpp/container/list/resize).

So the final extract will be
    if (m_numInput.size() > 10){
        m_numInput.resize(10);
    }
 
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 13, 2015, 02:12:00 pm
Quote
    if (m_numInput.size() > 10){
        m_numInput.resize(10);
    }
@santiaboy - U sir deserve a cookie :D Thank you.

__________________________________________

Edit: Uploaded the changes to github and the new release is at the main post
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: santiaboy on September 13, 2015, 06:01:49 pm
Thanks, but re-reading the thread Alex said it first :P

You could still simply replace this
if (m_numInput.size() > 10){
        for (auto it = m_numInput.begin() + 10; it != m_numInput.end(); it++){
            it = m_numInput.erase(it);
        }
    }
 

with this

 m_numInput.resize(10);

looks cleaner  :P


The "erase" bit is important, though. C++ sometimes doesn't do what you expect it to do. Erase always throws me off.
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 13, 2015, 07:33:56 pm
Quote
Thanks, but re-reading the thread Alex said it first :P
Damn - you are right :D Should listen to ppl.
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 13, 2015, 07:35:53 pm
Hello Guys,

today i have managed to get full support for the mouse in menu-related GameStates.
In Addition every menu-related GameState now has a transition.

New Release  and GitHub updated
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 13, 2015, 10:18:12 pm
Hey,

Added a SplashScreen to give Credits:

(http://fs2.directupload.net/images/150913/e537phwh.png) (http://www.directupload.net)

(http://fs2.directupload.net/images/150913/87hoxfoe.png) (http://www.directupload.net)

(http://fs2.directupload.net/images/150913/8g3995ox.png) (http://www.directupload.net)

Everything updated bla bla -> as usual :'D
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 14, 2015, 07:03:38 pm
Heeeeellloooooo :D

+Core enemies now have a death animation. It is not much, but gives the whole thing a bit more life :P
+New weapon textures-> so that they look round, was too lazy to give them direction
+Fixed that music was played in the splashscreen

I will record a new video for the mainpage, because the look of the game changed quite a bit ;-)

Everything updated
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: nebula on September 14, 2015, 08:12:58 pm
So, there is the video:


http://youtu.be/Lz6h8L5a3ls

Also avaliable on the main post
Title: Re: [SFML 2.1 and C++] 2D Shooter - Pew (Open Source)
Post by: SeriousITGuy on October 01, 2015, 04:08:14 pm
You got me with "Einschetellüngen"
This looks funny as hell, will try it out :D