-
(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.
menu | game | settings | game over | highscore |
(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
OLD - Here a quick video (i could not record more :/)
http://youtu.be/XRYQD-meRDI
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
-
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
-
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
-
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.
-
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)
-
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...
-
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.
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
-
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 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
-
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
-
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
-
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
-
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
-
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 ;)
-
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.
-
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 ;)
-
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
-
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 ;)
-
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
-
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
-
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
-
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
-
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 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 ;)
-
may i ask what you mean with unpolished? i really want to improve this so every hint counts to me, thanks
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
-
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
-
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:
- Added an enemy to the main screen so that it is not that boring :D (for now it is just one and it is way to fast)
- in the graphics menu you now see the active settings (selection is on true or false)
- the sound can now be set in 5% steps as wished ;)
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
-
Update
- vector.clear() when leaving game has now a method
- reduced damage of the cow (30->25)
- Pew is now faster (0.8->0.9)
- Enemy formation added
- text "New Weapon" repositioned
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)
-
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)
-
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. ;)
-
oops :D
well i am working with visual studio 2013 :P
-
added Coop mode:
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
-
a quick info:
i think it may be important to mention some things
- http://www.microsoft.com/en-us/download/details.aspx?id=40784 (http://www.microsoft.com/en-us/download/details.aspx?id=40784) if you cannot start the game because dll files are missing (now the 2013 link)
- if you want to help me with the code posted on github, please write it here, else i maybe wont see it
- the second boss can only be hit by the third weapon, try to change weapon or fly from left to right (or the other way around) to escape the apples
- the coop can be buggy at the moment, because i did not have the time to test it
- i am currently working on adding the boss for the cows, which will be a machine
- after this boss i will implement buffs, which appear after a monkey is killed (picked random)
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 ;)
-
Nice improvements :)
Some ideas:
- Pause
- Something like a progress bar to show the reload time. So you know when you can shoot again, especially for the thrid weapon
- Maybe stop the normal enemies to spawn during a bossfight (on crazy its crazy ;) )
- Please show the close button in the window. It's annoying to press escape and navigate through the menu just to close the game
AlexAUT
-
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 ;)
-
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.
- You could create a new state for the pause menu. The pause screen then changes, after a user input, the current state to menu or to game back again.
- Other option (easier and imo better) (thats how I implemented it in kroniax) you have a bool in the game class like mPaused, and if this is true, do not update all the game objects (player, enemies etc) so they do not move but you draw them with a overlay on top of it (Here you can see an example in C# http://msdn.microsoft.com/en-us/library/bb195026.aspx you don't need to track the pause key :)
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
-
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
-
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 ;)
-
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 ;)
-
Okay, I uploaded todays changes.
cl14:
- some fixes
->first boss will now be cleared as intended
->after respawn the revieved player should have 100 life
->window style is on default again
- added pause menu (just press P)
furthermore i added a readme.txt to the release, where the controls are shown and some information ;)
-
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.
-
thank you ;) i will edit my code like you say. it seems logic
-
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 ;)
-
Looks like an funny shooter, made just 4fun. Like it! :)
-
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 ;)
-
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
-
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
______________________________________________________
-
(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.)
- some nonesence flying
- shooting heads of cows
- only attackable at left or right "spawner"
2.)
- still shitty movement :D
- mid "spawner" shows up to shoot with some crazy cows
- only mid "spawner" is attackable (the first ones are now away)
3.)
- some really nonsence movement
- mid spawner is broken
- mashine is attackable
- mashine tries to hit player with collision
well, that is how i imagined it... kinda :D you'll see
__________________________________________
after that enemy, the following will happen
- ending for game will be made (for a feeling of success :P)
- highscore
- pool of buffs (one you get after you finished the game successfully)
- credits
- More enemies
- and more
-
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 ;)
-
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
-
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!
-
thanks :D
i will make more :P
-
Sound should work now. Updated everything ;)
-
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
-
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
-
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 :'(
-
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.
-
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 ;)
-
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.
-
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 ;)
-
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.
-
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/)
-
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:
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:
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
-
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
-
Hello AlexAUT,
first of all thank you for your input.
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"
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 ;-)
3) You can use while(std::getline(file, tmp)) {...} Instead of the two liner (eof and then getline)
Thanks. That acutally stopped the game.
4) You can check if file.bad() if one of the output operations failed
I will keep that in memory.
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
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.
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;
}
-
i changed the highscore txt file to the following:
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)
-
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)
...
-
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 ;-)
-
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
-
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
-
Reworked the Mainpage.
- Now with a video which shows the game with the new controls
(could not find out how to show it like the old one). - Pictures updated
- Textual updates
- Links updated
-
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).
-
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:
- Sprites of Weapons should have the rotation according to their direction
- An Intro before the main menu is entered - to give credits to SFML and some guys that helped me
- Some kind of transition between the Gamestates, because as you may have noticed the present solution causes some issues
- Countdown before the game starts
- Some animated Sprites / better Sprites in general
- Maybe a Reward System (for example speed buff, faster shooting, a shield)
If you have suggestions or something, let me know :P
-
Hi Guys,
All Enemies (except for the Formation - temp) got healthbars now.
Latest Release on Mainpage - Code on Github
UPDATE:
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
-
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
-
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);
}
-
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
-
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.
-
Thanks, but re-reading the thread Alex said it first :P
Damn - you are right :D Should listen to ppl.
-
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
-
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
-
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
-
So, there is the video:
http://youtu.be/Lz6h8L5a3ls
Also avaliable on the main post
-
You got me with "Einschetellüngen"
This looks funny as hell, will try it out :D