-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.h
138 lines (101 loc) · 3.43 KB
/
graphics.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
134
135
136
137
138
//
// Created by Herman Karlsson on 2017-02-11.
//
#ifndef POKEMON_SIMULATION_GRAPHICS_H
#define POKEMON_SIMULATION_GRAPHICS_H
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Font.hpp>
#include <vector>
#include <string>
#include "state.h"
class graphics {
private:
sf::RenderWindow statwin;
sf::RenderWindow window;
std::vector<std::vector<sf::Uint8 >> colors;
//sf::Text text;
int width, height;
public:
graphics(int,int);
bool draw(state &);
};
graphics::graphics(int _height, int _width): window(sf::VideoMode((unsigned int) _width, (unsigned int) _height), "Simulation"),
statwin(sf::VideoMode(80,303),"Data"){
std::vector<sf::Uint8> nor = {104,100,80,255};
std::vector<sf::Uint8> fir = {213,75,15,255};
std::vector<sf::Uint8> wat = {15,35,213,255};
std::vector<sf::Uint8> ele = {219,194,30,255};
std::vector<sf::Uint8> gra = {68,186,72,255};
std::vector<sf::Uint8> ice = {98,220,216,255};
std::vector<sf::Uint8> fig = {164,0,0,255};
std::vector<sf::Uint8> poi = {125,11,166,255};
std::vector<sf::Uint8> gro = {195,158,57,255};
std::vector<sf::Uint8> fly = {177,148,229,255};
std::vector<sf::Uint8> psy = {255,38,176,255};
std::vector<sf::Uint8> bug = {120,156,58,255};
std::vector<sf::Uint8> roc = {151,132,36,255};
std::vector<sf::Uint8> gho = {75,57,81,255};
std::vector<sf::Uint8> dra = {79,12,235,255};
std::vector<sf::Uint8> dar = {41,32,5,255};
std::vector<sf::Uint8> ste = {112,112,112,255};
std::vector<sf::Uint8> fai = {240,62,246,255};
colors = {nor,fir,wat,ele,gra,ice,fig,poi,gro,fly,psy,bug,roc,gho,dra,dar,ste,fai};
this->width = _width;
this->height = _height;
this->window.setPosition(sf::Vector2i(120,30));
this->statwin.setPosition(sf::Vector2i(20,30));
this->statwin.clear(sf::Color::White);
this->window.clear(sf::Color::Black);
this->statwin.display();
this->window.display();
}
bool graphics::draw(state & st) {
static int frame = 0;
static std::vector<std::string> types = {"nor","fir","wat","ele","gra","ice","fig","poi","gro","fly","psy","bug","roc","gho","dra","dar","ste","fai"};
sf::Event event;
while(this->window.pollEvent(event))
if(event.type == sf::Event::Closed){
this->window.close();
this->statwin.close();
return 0;
}
while(this->statwin.pollEvent(event))
if(event.type == sf::Event::Closed){
this->window.close();
this->statwin.close();
return 0;
}
int cnt = 0;
for(int i = 0; i < 18; ++i) cnt += st.get_count(i) != 0;
if(cnt == 1) --frame;
sf::Texture texture;
texture.create(this->width,this->height);
sf::Uint8 * pixels = new sf::Uint8[this->width * this->height * 4];
for(int i = 0; i < this->height; ++i)
for(int j = 0; j < this->width; ++j)
for(int k = 0; k < 4; ++k)
pixels[4 * (i * this->width + j) + k] = this->colors[st.type(i, j)][k];
texture.update(pixels);
texture.setSmooth(true);
sf::Sprite sprite;
sprite.setTexture(texture);
std::string str = "Frame " + std::to_string(frame)+"\n";
for(int i = 0; i < 18; ++i)
str += types[i]+": "+std::to_string(st.get_count(i))+"\n";
sf::Font font;
sf::Text text;
font.loadFromFile("alef/Alef-Regular.ttf");
text.setFont(font);
text.setString(str);
text.setCharacterSize(12);
text.setFillColor(sf::Color::Black);
this->statwin.clear(sf::Color::White);
this->window.clear(sf::Color::Black);
this->statwin.draw(text);
this->window.draw(sprite);
this->statwin.display();
this->window.display();
++frame;
return 1;
}
#endif //POKEMON_SIMULATION_GRAPHICS_H