-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel.h
More file actions
145 lines (119 loc) · 4.26 KB
/
Level.h
File metadata and controls
145 lines (119 loc) · 4.26 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
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
134
135
136
137
138
139
140
141
142
143
144
145
#pragma once
#include <iostream>
#include <SFML/Graphics.hpp>
#include "FontManager.h"
#include <fstream>
#include "SoundManager.h"
#include "Scoreboard.h"
#include "PlantFactory.h"
#include "ZombieFactory.h"
#include "Background.h"
#include "Inventory.h"
using namespace std;
using namespace sf;
class Level {
protected:
Text levelText;
Text levelTextS;
float levelPosition[2];
const float middle1 = 450, middle2 = 620;
float speed;
bool midWay;
Clock levelClock;
bool exists;
SoundManager* SMptr;
FontManager* FMptr;
TextureManager* TMptr;
Scoreboard* SBptr;
int round;
public:
Level(TextureManager* TM, FontManager* FM, SoundManager* SM, Scoreboard* scoreboard) {
this->SMptr = SM;
this->FMptr = FM;
this->TMptr = TM;
this->SBptr = scoreboard;
this->levelText.setFont(FM->get(2));
this->levelText.setCharacterSize(150);
this->levelText.setString("LEVEL 1");
this->levelText.setFillColor(Color::White);
this->levelPosition[0] = -250, levelPosition[1] = 210;
this->levelText.setPosition(levelPosition[0], levelPosition[1]);
this->levelTextS.setFont(FM->get(2));
this->levelTextS.setCharacterSize(151);
this->levelTextS.setString("LEVEL 1");
this->levelTextS.setFillColor(Color(89, 46, 12));
this->levelTextS.setPosition(levelPosition[0], levelPosition[1] + 8);
this->speed = 50;
this->midWay = false;
this->exists = true;
//this->SMptr->playSound("round1");
}
void saveEverything(ofstream& file) {
file.write(reinterpret_cast<char*>(&levelPosition[0]), sizeof(float));
file.write(reinterpret_cast<char*>(&levelPosition[1]), sizeof(float));
file.write(reinterpret_cast<char*>(&speed), sizeof(float));
file.write(reinterpret_cast<char*>(&midWay), sizeof(bool));
file.write(reinterpret_cast<char*>(&exists), sizeof(bool));
}
void readEverything(ifstream& file) {
file.read(reinterpret_cast<char*>(&levelPosition[0]), sizeof(float));
file.read(reinterpret_cast<char*>(&levelPosition[1]), sizeof(float));
this->levelText.setPosition(levelPosition[0], levelPosition[1]);
file.read(reinterpret_cast<char*>(&speed), sizeof(float));
file.read(reinterpret_cast<char*>(&midWay), sizeof(bool));
file.read(reinterpret_cast<char*>(&exists), sizeof(bool));
}
void reset() {
this->levelPosition[0] = -250, levelPosition[1] = 250;
this->levelText.setPosition(levelPosition[0], levelPosition[1]);
this->levelTextS.setPosition(levelPosition[0], levelPosition[1]);
this->levelClock.restart();
this->midWay = false;
this->exists = true;
}
void increaseLevel() {
this->levelText.setString("LEVEL " + to_string(round));
this->levelTextS.setString("LEVEL " + to_string(round));
}
virtual void drawEverything(RenderWindow& window, Background& background,
Inventory* Inv, int& sunCount, PlantFactory* PF, ZombieFactory* ZF, LawnMower** lawnmowers, Life& lives,
FallingSun* sun, Text& sunCountText) = 0;
void updateEverything(PlantFactory* PF, ZombieFactory* ZF, LawnMower** lawnmowers, Life& lives, FallingSun& sun) {
// Update everything here
// check for collisions, animation, shooting, everything
PF->updateEverything(ZF->getZombies(), ZF->getZombiesArrayIndex(), this->SBptr);
ZF->updateEverything(PF->getPlants(), PF->getPlantsArrayIndex(), lawnmowers, &lives, this->round);
// call all functions of sun
sun.generate();
sun.moveSun();
for (int i = 0; i < 5; i++) {
lawnmowers[i]->move(ZF->getZombies(), ZF->getZombiesArrayIndex(), this->SBptr);
lawnmowers[i]->animate();
}
}
void resetEverything(PlantFactory* PF, ZombieFactory* ZF) {
PF->reset();
ZF->reset();
}
void move_draw(RenderWindow& window) {
if (this->exists) {
if (this->levelClock.getElapsedTime().asMilliseconds() > 15) {
this->levelPosition[0] += speed;
if (this->levelPosition[0] >= this->middle1 && this->levelPosition[1] <= this->middle2 && !this->midWay) {
this->speed = 1.5;
}
if (this->levelText.getPosition().x > this->middle2 && !this->midWay) {
this->midWay = true;
this->speed = 50;
}
this->levelClock.restart();
}
this->levelTextS.setPosition(levelPosition[0], levelPosition[1] + 8);
this->levelText.setPosition(levelPosition[0], levelPosition[1]);
if (this->levelPosition[0] >= 1400) exists = false;
window.draw(levelTextS);
window.draw(levelText);
}
}
virtual ~Level() {}
};