-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel1.cpp
More file actions
54 lines (43 loc) · 1.63 KB
/
Copy pathLevel1.cpp
File metadata and controls
54 lines (43 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "Level1.h"
#include "GameEngine.h"
#include "Enemies.h"
#include "EnemiesFactory.h"
#include "AudioManager.h"
#include "HUD.h"
#include "Background.h"
#include "Player.h"
#include <string>
Level1::Level1() {
sf::RenderWindow& window = GameEngine::getInstance().getWindow();
this->HUD = HUD::getInstance();
this->background = new Background("Blue_Nebula_01.png");
this->player = Player::getInstance();
float startX = window.getSize().x / 9.0f;
float startY = window.getSize().y / 8.0f;
float spacingX = (window.getSize().x - 2 * window.getSize().x / 9.0f) / 9.0f;
float spacingY = (window.getSize().x - 2 * window.getSize().x / 9.0f) / 9.0f;
for (int row = 0; row < 3; ++row) {
for (int col = 0; col < 10; ++col) {
std::string enemiesList[] = { Enemies::BIG, Enemies::MEDIUM, Enemies::SMALL };
Enemy* enemy = EnemiesFactory::createEnemy(enemiesList[row]);
enemy->setPosition(sf::Vector2f(startX + col * spacingX, startY + row * spacingY));
enemies.push_back(enemy);
}
}
}
Level1::~Level1() {
}
void Level1::update() {
Level::update();
GameEngine::getInstance().showCursor(false);
float deltaTime = GameEngine::getInstance().getDeltaTime();
sf::RenderWindow& window = GameEngine::getInstance().getWindow();
float speed = 70.f;
for (int i = 0; i < enemies.size(); i++) {
sf::Vector2f pos = enemies[i]->getPosition();
if (pos.x <= 0 + 40.f) direction = 1;
if (pos.x >= window.getSize().x - 40.f) direction = -1;
pos.x += speed * deltaTime * direction;
enemies[i]->setPosition(pos);
}
}