fixed a seg fault on add weapon
This commit is contained in:
parent
065d543d4d
commit
d1a7053149
3 changed files with 123 additions and 157 deletions
|
|
@ -3,10 +3,10 @@ project(SFML_Template)
|
|||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
include_directories("D:/Program Files/mingw64/include")
|
||||
include_directories("D:/Program Files/mingw-w64/mingw64/x86_64-w64-mingw32/include")
|
||||
|
||||
add_executable(SFML_Template main.cpp Game.cpp Game.h GameSprite.cpp GameSprite.h Ship.cpp Ship.h System.cpp System.h Planet.cpp Planet.h Collision.cpp Collision.h Menu.cpp Menu.h)
|
||||
|
||||
target_link_directories(SFML_Template PUBLIC "D:/Program Files/mingw64/lib")
|
||||
target_link_directories(SFML_Template PUBLIC "D:/Program Files/mingw-w64/mingw64/x86_64-w64-mingw32/lib")
|
||||
|
||||
target_link_libraries(SFML_Template sfml-graphics sfml-system sfml-window sfml-audio)
|
||||
|
|
|
|||
57
Game.cpp
57
Game.cpp
|
|
@ -354,7 +354,8 @@ void Game::init() {
|
|||
iss = std::istringstream(input);
|
||||
results = std::vector<std::string>((std::istream_iterator<std::string>(iss)),
|
||||
std::istream_iterator<std::string>());
|
||||
if (results.size() <= 5) systems[systems.size() - 1]->addPlanet(
|
||||
if (results.size() <= 5)
|
||||
systems[systems.size() - 1]->addPlanet(
|
||||
new Planet(*planets[stoi(results[0])], stof(results[1]), window.getSize().x * stof(results[2]),
|
||||
window.getSize().y * stof(results[3]), stof(results[4])));
|
||||
else {
|
||||
|
|
@ -444,10 +445,8 @@ void Game::init() {
|
|||
sf::Vector2f oldPos;
|
||||
sf::Vector2f currentPos;
|
||||
|
||||
Ship *player = new Ship(ship, 50, window.getSize().x / (float) 2.0, window.getSize().y / (float) 2.0, 0, 10, -45, 2,
|
||||
3, 500, 100, 5);
|
||||
player->addWeapon(new ProjectileWeapon(
|
||||
Projectile(laser, sf::IntRect(29, 207, 651, 91), 10, 4, 3, 676, 513, 3, 15, 25, 1500), 40));
|
||||
Ship *player = new Ship(ship, 50, window.getSize().x / (float) 2.0, window.getSize().y / (float) 2.0, 0, 10, -45, 2,3, 500, 100, 5);
|
||||
player->addWeapon(new BeamWeapon(Beam(beam, sf::IntRect(0, 207, 535, 91), 10, 12, 1, 0, 513, 3, 1, 1500), 25, 40));
|
||||
int playerMoney = 100000;
|
||||
|
||||
System *currentSystem = systems[0];
|
||||
|
|
@ -568,13 +567,8 @@ void Game::init() {
|
|||
int randXpos = roll(gen);
|
||||
int randYpos = roll(gen);
|
||||
|
||||
ships.push_back(new COMShip(*shipTextures[n], shipTextureScales[n],
|
||||
currentSystem->getPlanets()[1]->getXPos() + randXpos,
|
||||
currentSystem->getPlanets()[1]->getYPos() + randYpos, 0, 0.1, 10, 0, 2, 0, 500, 0,
|
||||
0, wordWrap(generateName(gen), targetWindow.getGlobalBounds().width, monkirta, 15),
|
||||
currentSystem->getSysRep()));
|
||||
ships[ships.size() - 1]->addWeapon(new ProjectileWeapon(
|
||||
Projectile(laser, sf::IntRect(29, 207, 651, 91), 10, 4, 3, 676, 513, 3, 15, 25, 1500), 40));
|
||||
ships.push_back(new COMShip(*shipTextures[n], shipTextureScales[n],currentSystem->getPlanets()[1]->getXPos() + randXpos,currentSystem->getPlanets()[1]->getYPos() + randYpos, 0, 0.1, 10, 0, 2, 0, 500, 0,0, wordWrap(generateName(gen), targetWindow.getGlobalBounds().width, monkirta, 15),currentSystem->getSysRep()));
|
||||
ships[ships.size() - 1]->addWeapon(new ProjectileWeapon(Projectile(laser, sf::IntRect(29, 207, 651, 91), 10, 4, 3, 676, 513, 3, 15, 25, 1500), 40));
|
||||
}
|
||||
|
||||
//planet pointer
|
||||
|
|
@ -938,12 +932,7 @@ void Game::init() {
|
|||
|
||||
if (res == COMShip::WARPING) {
|
||||
sound.setBuffer(warp);
|
||||
sound.setVolume((GameSprite::distance(player->getPosition(), s->getPosition()) > 2000) ? 0 : 100 *
|
||||
(2000 -
|
||||
GameSprite::distance(
|
||||
player->getPosition(),
|
||||
s->getPosition())) /
|
||||
2000);
|
||||
sound.setVolume((GameSprite::distance(player->getPosition(), s->getPosition()) > 2000) ? 0 : 100 *(2000 -GameSprite::distance(player->getPosition(),s->getPosition())) /2000);
|
||||
sound.play();
|
||||
|
||||
if (player->getTarget() == s) {
|
||||
|
|
@ -965,23 +954,11 @@ void Game::init() {
|
|||
int randXpos = roll(gen);
|
||||
int randYpos = roll(gen);
|
||||
|
||||
ships.push_back(new COMShip(*shipTextures[n], shipTextureScales[n],
|
||||
currentSystem->getPlanets()[1]->getXPos() + randXpos,
|
||||
currentSystem->getPlanets()[1]->getYPos() + randYpos, 0, 0.1, 10, 0, 2, 0,
|
||||
500, 0, 0,
|
||||
wordWrap(generateName(gen), targetWindow.getGlobalBounds().width, monkirta,
|
||||
15),
|
||||
currentSystem->getSysRep()));
|
||||
ships[ships.size() - 1]->addWeapon(new ProjectileWeapon(
|
||||
Projectile(laser, sf::IntRect(29, 207, 651, 91), 10, 4, 3, 676, 513, 3, 15, 25, 1500), 40));
|
||||
ships.push_back(new COMShip(*shipTextures[n], shipTextureScales[n],currentSystem->getPlanets()[1]->getXPos() + randXpos,currentSystem->getPlanets()[1]->getYPos() + randYpos, 0, 0.1, 10, 0, 2, 0,500, 0, 0,wordWrap(generateName(gen), targetWindow.getGlobalBounds().width, monkirta,15),currentSystem->getSysRep()));
|
||||
ships[ships.size() - 1]->addWeapon(new ProjectileWeapon(Projectile(laser, sf::IntRect(29, 207, 651, 91), 10, 4, 3, 676, 513, 3, 15, 25, 1500), 40));
|
||||
|
||||
sound.setBuffer(warp);
|
||||
sound.setVolume(
|
||||
(GameSprite::distance(player->getPosition(), ships[ships.size() - 1]->getPosition()) > 2000) ? 0
|
||||
:
|
||||
100 *
|
||||
(2000 - GameSprite::distance(player->getPosition(), ships[ships.size() - 1]->getPosition())) /
|
||||
2000);
|
||||
sound.setVolume((GameSprite::distance(player->getPosition(), ships[ships.size() - 1]->getPosition()) > 2000) ? 0 : 100 * (2000 - GameSprite::distance(player->getPosition(), ships[ships.size() - 1]->getPosition())) / 2000);
|
||||
sound.play();
|
||||
|
||||
messageLog.push_front(new sf::Text("A ship entered the system.", oxan, 18));
|
||||
|
|
@ -1152,15 +1129,8 @@ void Game::init() {
|
|||
int randXpos = roll(gen);
|
||||
int randYpos = roll(gen);
|
||||
|
||||
ships.push_back(new COMShip(*shipTextures[n], shipTextureScales[n],
|
||||
currentSystem->getPlanets()[1]->getXPos() + randXpos,
|
||||
currentSystem->getPlanets()[1]->getYPos() + randYpos, 0, 0.1, 10, 0, 2,
|
||||
0, 500, 0, 0,
|
||||
wordWrap(generateName(gen), targetWindow.getGlobalBounds().width,
|
||||
monkirta, 15),
|
||||
currentSystem->getSysRep()));
|
||||
ships[ships.size() - 1]->addWeapon(new ProjectileWeapon(
|
||||
Projectile(laser, sf::IntRect(29, 207, 651, 91), 10, 4, 3, 676, 513, 3, 15, 25, 1500), 40));
|
||||
ships.push_back(new COMShip(*shipTextures[n], shipTextureScales[n],currentSystem->getPlanets()[1]->getXPos() + randXpos,currentSystem->getPlanets()[1]->getYPos() + randYpos, 0, 0.1, 10, 0, 2,0, 500, 0, 0,wordWrap(generateName(gen), targetWindow.getGlobalBounds().width,monkirta, 15),currentSystem->getSysRep()));
|
||||
ships[ships.size() - 1]->addWeapon(new ProjectileWeapon(Projectile(laser, sf::IntRect(29, 207, 651, 91), 10, 4, 3, 676, 513, 3, 15, 25, 1500), 40));
|
||||
}
|
||||
|
||||
mainView.setCenter(player->getXPos(), player->getYPos());
|
||||
|
|
@ -1824,8 +1794,7 @@ void Game::init() {
|
|||
}
|
||||
sysPopText.setString(std::to_string(systems[i]->getPop()) + " billion");
|
||||
sysStrenText.setString(std::to_string(systems[i]->getStren()));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sysInfoTitle.setString("???");
|
||||
sysStatusText.setString("Unexplored");
|
||||
sysStatusText.setFillColor(sf::Color::White);
|
||||
|
|
|
|||
5
Ship.cpp
5
Ship.cpp
|
|
@ -105,8 +105,5 @@ void Ship::setTarget(Ship *_target) {
|
|||
}
|
||||
|
||||
void Ship::addWeapon(Weapon *w) {
|
||||
Weapon *copiedWeapon;
|
||||
*copiedWeapon = *w;
|
||||
|
||||
weapons.push_back(copiedWeapon);
|
||||
weapons.push_back(w);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue