Loading Enemies.cpp +19 −32 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ Enemy Enemies::get_enemy(int idx) return enemy[idx]; } void Enemies::add_enemy() { Enemy e(mode); Loading Loading @@ -54,13 +53,14 @@ void Enemies::move_back_to_screen(int idx) int new_pos_y = set_rand_position_on_the_screen().position_y; sf::Time time = clock.getElapsedTime(); sf::Time time1 = clock1.getElapsedTime(); if (time.asMicroseconds() > 0.4) { last_pos_x = enemy[idx].get_position().position_x; last_pos_y = enemy[idx].get_position().position_y; clock.restart(); } sf::Time time1 = clock1.getElapsedTime(); if (time1.asMicroseconds() > 0.1) { if (new_pos_x < last_pos_x) Loading @@ -76,36 +76,23 @@ void Enemies::move_back_to_screen(int idx) } } //void Enemies::move_enemies() //{ // for (int i = 0; i < enemy.size(); ++i) // { // Unit new_pos = set_rand_position_on_the_screen(); // Unit pos_now = enemy[i].get_position(); // // sf::Time time2 = clock2.getElapsedTime(); // if (time2.asSeconds() > 0.5) // { // while (new_pos.position_x != pos_now.position_x && // new_pos.position_y != pos_now.position_y) // { // sf::Time time1 = clock1.getElapsedTime(); // if (time1.asSeconds() > 0.5) { // if (pos_now.position_x < new_pos.position_x) // ++pos_now.position_x; // if (pos_now.position_x > new_pos.position_x) // --pos_now.position_x; // if (pos_now.position_y < new_pos.position_y) // ++pos_now.position_y; // if (pos_now.position_y > new_pos.position_y) // --pos_now.position_x; // enemy[i].set_position(pos_now.position_x, pos_now.position_y, "equel"); // clock1.restart(); // } // } // } // } //} int Enemies::attack(sf::RenderWindow &win) { int en = rand() % enemy.size(); sf::Time cool_dawn = cool_dawn_attack.getElapsedTime(); if (cool_dawn.asSeconds() > 5) { // std::cout << "Hit!\n"; cool_dawn_attack.restart(); enemy[en].attack_animations(win); return enemy[en].get_attack(); } return 0; } Loading Enemies.h +7 −6 Original line number Diff line number Diff line Loading @@ -13,19 +13,20 @@ class Enemies : public Enemy{ int last_pos_y; sf::Clock clock; sf::Clock clock1; sf::Clock clock2; sf::Time current_time; sf::Clock cool_dawn_attack; public: Enemies(GameMode m); void add_enemy(); void remove_enemy(int &idx); void move_back_to_screen(int idx); void check_health(int idx); void set_position(int n, int pos_x, int pos_y); void move_enemies(); int get_enemies_count() const; Enemy get_enemy(int idx); void add_enemy(); void remove_enemy(int &idx); int attack(sf::RenderWindow &win); void draw_enemys(sf::RenderWindow &win); }; Loading Enemy.cpp +37 −15 Original line number Diff line number Diff line Loading @@ -16,14 +16,17 @@ Enemy::Enemy(GameMode mode) case NORMAL: health = 10; speed = 5; attack = 10; break; case HERO: health = 15; speed = 6; attack = 15; break; case GOD: health = 20; speed = 7; attack = 20; break; } } Loading @@ -33,11 +36,6 @@ void Enemy::hit(int h) health -= h; } void Enemy::set_speed(int s) { health = s; } void Enemy::set_health(int h) { health = h; Loading @@ -48,11 +46,6 @@ int Enemy::get_health() const return health; } int Enemy::get_speed() const { return speed; } void Enemy::set_rand_position() { if(rand() % 2) Loading Loading @@ -98,22 +91,51 @@ void Enemy::set_position(int pos_x, int pos_y, std::string str) enemy_sprite.setPosition(unit.position_x,unit.position_y); } Unit Enemy::get_position() Position Enemy::get_position() const { return unit; } Unit Enemy::set_rand_position_on_the_screen() Position Enemy::set_rand_position_on_the_screen() { Unit position; Position position; position.position_x = rand() % 960 + 160; position.position_y = rand() % 540; return position; } bool Enemy::need_or_not_move_enemy() int Enemy::get_attack() const { return attack; } void Enemy::attack_animations(sf::RenderWindow &win) { return false; sf::VertexArray laser1(sf::Triangles,3); sf::VertexArray laser2(sf::Triangles,3); int x_rand = rand() % 580 + 350; int y_rand = rand() % 440 + 100; laser1[0].position = sf::Vector2f (unit.position_x + 40,unit.position_y + 55); laser1[1].position = sf::Vector2f (unit.position_x + 54,unit.position_y + 65); laser1[2].position = sf::Vector2f (x_rand,y_rand); laser1[0].color = sf::Color::Red; laser1[1].color = sf::Color::Red; laser1[2].color = sf::Color(137, 19, 145); laser2[0].position = sf::Vector2f (unit.position_x + 120,unit.position_y + 51); laser2[1].position = sf::Vector2f (unit.position_x + 110,unit.position_y + 61); laser2[2].position = sf::Vector2f (x_rand,y_rand); laser2[0].color = sf::Color::Red; laser2[1].color = sf::Color::Red; laser2[2].color = sf::Color(137, 19, 145); win.draw(laser1); win.draw(laser2); } Enemy.h +9 −8 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ enum GameMode: int {NORMAL, HERO, GOD}; struct Unit struct Position { int position_x; int position_y; Loading @@ -16,23 +16,24 @@ struct Unit class Enemy { int health; int speed; int attack; sf::Texture enemy_texture; sf::Sprite enemy_sprite; Unit unit; Position unit; public: explicit Enemy(GameMode mode); void hit(int h); void attack_animations(sf::RenderWindow &win); void set_health(int h); void set_speed(int s); void set_rand_position(); Unit set_rand_position_on_the_screen(); Position set_rand_position_on_the_screen(); void set_position(int pos_x, int pos_y, std::string str = "increase"); Unit get_position(); bool need_or_not_move_enemy(); void draw_enemy(sf::RenderWindow &win); Position get_position() const; int get_health() const; int get_speed() const; int get_attack() const; void draw_enemy(sf::RenderWindow &win); }; Loading Falcon_9.cpp +23 −18 Original line number Diff line number Diff line Loading @@ -45,24 +45,6 @@ Falcon_9::Falcon_9() } void Falcon_9::draw_falcon(sf::RenderWindow &win) { sf::Time time = clock.getElapsedTime(); current_time = time; set_health_bar(); win.draw(sprite_scope); win.draw(sprite_cabine); for (int i = 0; i < health; ++i) { win.draw(health_bar[i]); } } int Falcon_9::get_speed() { return speed; } void Falcon_9::lasers(sf::RenderWindow &win) { sf::VertexArray laser1(sf::Quads,4); Loading Loading @@ -182,4 +164,27 @@ void Falcon_9::set_health_bar() } } bool Falcon_9::hit(int damage) { if (health >= damage) { health -= damage; return true; } return false; } void Falcon_9::draw_falcon(sf::RenderWindow &win) { sf::Time time = clock.getElapsedTime(); current_time = time; set_health_bar(); win.draw(sprite_scope); win.draw(sprite_cabine); for (int i = 0; i < health; ++i) { win.draw(health_bar[i]); } } Loading
Enemies.cpp +19 −32 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ Enemy Enemies::get_enemy(int idx) return enemy[idx]; } void Enemies::add_enemy() { Enemy e(mode); Loading Loading @@ -54,13 +53,14 @@ void Enemies::move_back_to_screen(int idx) int new_pos_y = set_rand_position_on_the_screen().position_y; sf::Time time = clock.getElapsedTime(); sf::Time time1 = clock1.getElapsedTime(); if (time.asMicroseconds() > 0.4) { last_pos_x = enemy[idx].get_position().position_x; last_pos_y = enemy[idx].get_position().position_y; clock.restart(); } sf::Time time1 = clock1.getElapsedTime(); if (time1.asMicroseconds() > 0.1) { if (new_pos_x < last_pos_x) Loading @@ -76,36 +76,23 @@ void Enemies::move_back_to_screen(int idx) } } //void Enemies::move_enemies() //{ // for (int i = 0; i < enemy.size(); ++i) // { // Unit new_pos = set_rand_position_on_the_screen(); // Unit pos_now = enemy[i].get_position(); // // sf::Time time2 = clock2.getElapsedTime(); // if (time2.asSeconds() > 0.5) // { // while (new_pos.position_x != pos_now.position_x && // new_pos.position_y != pos_now.position_y) // { // sf::Time time1 = clock1.getElapsedTime(); // if (time1.asSeconds() > 0.5) { // if (pos_now.position_x < new_pos.position_x) // ++pos_now.position_x; // if (pos_now.position_x > new_pos.position_x) // --pos_now.position_x; // if (pos_now.position_y < new_pos.position_y) // ++pos_now.position_y; // if (pos_now.position_y > new_pos.position_y) // --pos_now.position_x; // enemy[i].set_position(pos_now.position_x, pos_now.position_y, "equel"); // clock1.restart(); // } // } // } // } //} int Enemies::attack(sf::RenderWindow &win) { int en = rand() % enemy.size(); sf::Time cool_dawn = cool_dawn_attack.getElapsedTime(); if (cool_dawn.asSeconds() > 5) { // std::cout << "Hit!\n"; cool_dawn_attack.restart(); enemy[en].attack_animations(win); return enemy[en].get_attack(); } return 0; } Loading
Enemies.h +7 −6 Original line number Diff line number Diff line Loading @@ -13,19 +13,20 @@ class Enemies : public Enemy{ int last_pos_y; sf::Clock clock; sf::Clock clock1; sf::Clock clock2; sf::Time current_time; sf::Clock cool_dawn_attack; public: Enemies(GameMode m); void add_enemy(); void remove_enemy(int &idx); void move_back_to_screen(int idx); void check_health(int idx); void set_position(int n, int pos_x, int pos_y); void move_enemies(); int get_enemies_count() const; Enemy get_enemy(int idx); void add_enemy(); void remove_enemy(int &idx); int attack(sf::RenderWindow &win); void draw_enemys(sf::RenderWindow &win); }; Loading
Enemy.cpp +37 −15 Original line number Diff line number Diff line Loading @@ -16,14 +16,17 @@ Enemy::Enemy(GameMode mode) case NORMAL: health = 10; speed = 5; attack = 10; break; case HERO: health = 15; speed = 6; attack = 15; break; case GOD: health = 20; speed = 7; attack = 20; break; } } Loading @@ -33,11 +36,6 @@ void Enemy::hit(int h) health -= h; } void Enemy::set_speed(int s) { health = s; } void Enemy::set_health(int h) { health = h; Loading @@ -48,11 +46,6 @@ int Enemy::get_health() const return health; } int Enemy::get_speed() const { return speed; } void Enemy::set_rand_position() { if(rand() % 2) Loading Loading @@ -98,22 +91,51 @@ void Enemy::set_position(int pos_x, int pos_y, std::string str) enemy_sprite.setPosition(unit.position_x,unit.position_y); } Unit Enemy::get_position() Position Enemy::get_position() const { return unit; } Unit Enemy::set_rand_position_on_the_screen() Position Enemy::set_rand_position_on_the_screen() { Unit position; Position position; position.position_x = rand() % 960 + 160; position.position_y = rand() % 540; return position; } bool Enemy::need_or_not_move_enemy() int Enemy::get_attack() const { return attack; } void Enemy::attack_animations(sf::RenderWindow &win) { return false; sf::VertexArray laser1(sf::Triangles,3); sf::VertexArray laser2(sf::Triangles,3); int x_rand = rand() % 580 + 350; int y_rand = rand() % 440 + 100; laser1[0].position = sf::Vector2f (unit.position_x + 40,unit.position_y + 55); laser1[1].position = sf::Vector2f (unit.position_x + 54,unit.position_y + 65); laser1[2].position = sf::Vector2f (x_rand,y_rand); laser1[0].color = sf::Color::Red; laser1[1].color = sf::Color::Red; laser1[2].color = sf::Color(137, 19, 145); laser2[0].position = sf::Vector2f (unit.position_x + 120,unit.position_y + 51); laser2[1].position = sf::Vector2f (unit.position_x + 110,unit.position_y + 61); laser2[2].position = sf::Vector2f (x_rand,y_rand); laser2[0].color = sf::Color::Red; laser2[1].color = sf::Color::Red; laser2[2].color = sf::Color(137, 19, 145); win.draw(laser1); win.draw(laser2); }
Enemy.h +9 −8 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ enum GameMode: int {NORMAL, HERO, GOD}; struct Unit struct Position { int position_x; int position_y; Loading @@ -16,23 +16,24 @@ struct Unit class Enemy { int health; int speed; int attack; sf::Texture enemy_texture; sf::Sprite enemy_sprite; Unit unit; Position unit; public: explicit Enemy(GameMode mode); void hit(int h); void attack_animations(sf::RenderWindow &win); void set_health(int h); void set_speed(int s); void set_rand_position(); Unit set_rand_position_on_the_screen(); Position set_rand_position_on_the_screen(); void set_position(int pos_x, int pos_y, std::string str = "increase"); Unit get_position(); bool need_or_not_move_enemy(); void draw_enemy(sf::RenderWindow &win); Position get_position() const; int get_health() const; int get_speed() const; int get_attack() const; void draw_enemy(sf::RenderWindow &win); }; Loading
Falcon_9.cpp +23 −18 Original line number Diff line number Diff line Loading @@ -45,24 +45,6 @@ Falcon_9::Falcon_9() } void Falcon_9::draw_falcon(sf::RenderWindow &win) { sf::Time time = clock.getElapsedTime(); current_time = time; set_health_bar(); win.draw(sprite_scope); win.draw(sprite_cabine); for (int i = 0; i < health; ++i) { win.draw(health_bar[i]); } } int Falcon_9::get_speed() { return speed; } void Falcon_9::lasers(sf::RenderWindow &win) { sf::VertexArray laser1(sf::Quads,4); Loading Loading @@ -182,4 +164,27 @@ void Falcon_9::set_health_bar() } } bool Falcon_9::hit(int damage) { if (health >= damage) { health -= damage; return true; } return false; } void Falcon_9::draw_falcon(sf::RenderWindow &win) { sf::Time time = clock.getElapsedTime(); current_time = time; set_health_bar(); win.draw(sprite_scope); win.draw(sprite_cabine); for (int i = 0; i < health; ++i) { win.draw(health_bar[i]); } }