-
Notifications
You must be signed in to change notification settings - Fork 2
/
map.h
133 lines (120 loc) · 3.63 KB
/
map.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once
#include "Clock.h"
#include <array>
#include "macro.h"
#include "sprite.h"
#include "block.h"
#include "tank.h"
#include "bullet.h"
#include "explosion.h"
#include <iostream>
const int blockSIZE{ 30 };
typedef std::array < Block, blockSIZE > Blocks;
// BlockTab = typedef std::array < Blocks, blockSIZE > an array with size blockSIZE
//2D array
typedef std::array < Blocks, blockSIZE > BlockTab;
struct Window{
int topBot; // empty space at the top and bottom of the screen
int sides; // blank field on the left and right of the screen
int blockSize; // block size after reduction
int sideMenu; // width of the side panel
float scale; // scale of the block relative to its base dimension
int widthInBlocks; // the width of the map in blocks
};
struct Level{
enum class NewTankPos{ left, mid, right } actualPos;
std::list<TankPtr> tanks;
std::list<Bullet> bullets;
std::list<Explosion> explosions;
int levelCount;
int actualLevel{ 0 };
int tanksID{ 2 };
int enemyTanks;
int playerTanks{ 3 };
int enemyDestroyed{ 0 };
sf::Clock timerPlayer1;
sf::Clock timerPlayer2;
sf::Clock timerEnemy;
Level(int levelCount = 1) : levelCount{ levelCount }{}
};
class Map : public sf::Drawable{
public:
Map(Sprite &, Timer & FPSclock ,sf::RenderWindow &);
enum class Sett { left, up, right, down, corner1, corner2, corner3, corner4, cornerBig1, cornerBig2, cornerBig3, cornerBig4, full };
enum class GameState{ game, nextLevel, gameOver, exit };
Window pr;
BlockTab tab;
Sprite & spr;
Timer &GameClock;
sf::RenderWindow & wndow;
Level lvl;
int destroyedEnemey{ 0 };
void setProperties(sf::RenderWindow & wndow){
pr.blockSize = int(wndow.getSize().y / 30);
pr.topBot = (wndow.getSize().y - pr.blockSize * 30) / 2;
pr.sideMenu = int((wndow.getSize().x - pr.blockSize * 30) / pr.blockSize) * pr.blockSize;
pr.sides = (wndow.getSize().x - pr.blockSize * 30 - pr.sideMenu) / 2;
pr.scale = float(pr.blockSize / 50.0);
pr.widthInBlocks = 30 + pr.sideMenu / pr.blockSize;
}
void setSpritesProperties(){
for (int y = 0; y < blockSIZE; y++){
for (int x = 0; x < blockSIZE; x++){
tab[y][x].setImg(spr);
tab[y][x].img.setPosition(float(x * pr.blockSize + pr.sides), float(y * pr.blockSize + pr.topBot));
tab[y][x].img.setScale(pr.scale, pr.scale);
tab[y][x].setHardness();
tab[y][x].setMoveMode();
}
}
}
void setInformationProperties();
int loadMap();
void addEnemyTank();
void addPlayer1Tank();
void addPlayer2Tank();
void events(Timer &);
bool gameGood();
bool checkGameStatus();
void initiateGame(bool);
void endGame();
void setEagle(){
for (int x = 0; x < 2; x++){
for (int y = 0; y < 2; y++){
sf::Vector2f position = tab[26 + y][14 + x].img.getPosition();
tab[26 + y][14 + x].img = spr.Eagle;
tab[26 + y][14 + x].img.setTextureRect(sf::IntRect(x * 50,
y * 50, 100, 100));
tab[26 + y][14 + x].img.setPosition(position);
tab[26 + y][14 + x].img.setScale(pr.scale, pr.scale);
tab[26 + y][14 + x].move = Block::Move::notMoveAble;
tab[26 + y][14 + x].type = Block::Type::Eagle;
tab[26 + y][14 + x].setHardness();
}
}
}
bool checkEagleIsLive(){
if (tab[26][14].type == Block::Type::EagleDEAD) return 0;
else return 1;
}
void nextLevel();
void gameOver();
void Won();
void Exit();
private:
GameState state;
sf::Font font;
sf::Text txt1, txt2 ,enmeisStr ,livesStr, level_;
bool SecRoundPlus = false;
int AliveEnemyTank;
sf::Sprite sprPlayerTank;
sf::Sprite sprEnemyTank;
virtual void draw(sf::RenderTarget & wndow, sf::RenderStates) const{
for (auto y : tab){
for (auto x : y){
if (x.hide) continue;
wndow.draw(x.img);
}
}
}
};