-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
257 lines (156 loc) · 5.38 KB
/
main.cpp
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <list>
#include <iostream>
#include "Collision.h"
void events_controller(sf::RenderWindow &window ,bool &band , sf::Sprite &cursor, sf::Sprite &select , sf::Vector2i &aux,sf::Vector2i &cell );
int main()
{
std::list<int> tiles;
std::list<int>::iterator i;
std::list< std::list<int> > matriz;
std::list< std::list<int> >::iterator m_iterator;
sf::Vector2f origen;//varibles del pitado del mapa
sf::Vector2f origen_punto;
sf::Vector2f posicion;
sf::Vector2i select_position;
// sf::Texture select_texture;
// select_texture.loadFromFile("assets/tile2.png");
// select.setTexture(&select_texture);
// select.setOrigin({0,0});
//
bool band=false;
for(int i=0;i<20;i++){
tiles.push_back(1);
}
for(int i=0;i<20;i++){
matriz.push_back(tiles);
}
std::cout<<matriz.size()<<std::endl;
m_iterator=matriz.begin();
// Load a sprite to display
sf::Texture texture;
if (!texture.loadFromFile("assets/tile.png"))
return EXIT_FAILURE;
sf::Sprite sprite(texture);
sprite.scale(10,10);
sf::Sprite sprite2(texture);
sprite2.setColor(sf::Color::Red);
sprite2.scale(10,10);
// sprite.setOrigin({20,10});
// Create a graphical text to display
origen.x=(matriz.size())*((texture.getSize().x)/2);
if(matriz.size()%2==0){
origen_punto.x= matriz.size()/2;
}else{
origen_punto.x= 1 + (matriz.size()/2);
}
origen_punto.y=0;
// Create the main window
sf::RenderWindow window(sf::VideoMode(1600, 800), "SFML window");
window.setFramerateLimit(10);
sf::Texture triangulox;
triangulox.loadFromFile("assets/prueba.png");
sf::Image img;
img.loadFromFile("assets/prueba.png");
sf::Sprite triangulo_s;
triangulo_s.setTexture(triangulox);
triangulo_s.scale(10,10);
sf::Texture cursor;
cursor.loadFromFile("assets/cursor.png");
sf::Sprite cursor_s(cursor);
sf::Vector2i mouse_pos;
window.display();
sf::Vector2f r_size;
r_size.x=400;
r_size.y=200;
sf::RectangleShape select(r_size);
select.setFillColor(sf::Color(0,0,0,0));
select.setOutlineColor(sf::Color(255,0,0));
select.setOutlineThickness(-1);
sf::Vector2i select_cell(0,0);
while (window.isOpen())
{
//
window.clear();
events_controller(window,band,cursor_s,triangulo_s, mouse_pos, select_cell);
for(int i=0;i<4;i++){
//cada linea siempre tendra el mismo pos en y
posicion.y = ( ( 100 * i ) );
posicion.x = origen.x - ( i*200 )- 200;
for(int y=0;y<4;y++){
posicion.x += ( 200 );
sprite.setPosition(posicion);
posicion.y += ( 100 );
window.draw(sprite);
}
}
//
// select.setPosition( mouse_pos.x*400 , mouse_pos.y*200);
// triangulo_s.setPosition( mouse_pos.x*400 , mouse_pos.y*200);
// window.draw(select);
// window.draw(triangulo_s);
if(Collision::PixelPerfectTest(triangulo_s,cursor_s)){
// std::cout<<"colision " << mouse_pos.x%400 <<" : " <<mouse_pos.y%200<<std::endl;
if(mouse_pos.x%400<200 && mouse_pos.y%200<100){
std::cout<<"Esquina superior\n";
sprite2.setPosition(triangulo_s.getPosition().x-200 ,triangulo_s.getPosition().y-100 );
}
if(mouse_pos.x%400>200 && mouse_pos.y%200<100){
std::cout<<"Esquina superior der \n";
sprite2.setPosition(triangulo_s.getPosition().x+200 ,triangulo_s.getPosition().y-100 );
}
if(mouse_pos.x%400<200 && mouse_pos.y%200>100){
std::cout<<"Esquina inferior\n";
sprite2.setPosition(triangulo_s.getPosition().x-200 ,triangulo_s.getPosition().y+100 );
}
if(mouse_pos.x%400>200 && mouse_pos.y%200>100){
std::cout<<"Esquina inferior der\n";
sprite2.setPosition(triangulo_s.getPosition().x+200 ,triangulo_s.getPosition().y+100 );
}
}else{
sprite2.setPosition(triangulo_s.getPosition().x ,triangulo_s.getPosition().y );
}
window.draw(sprite2);
window.display();
}
std::cin.get();
return EXIT_SUCCESS;
}
void events_controller(sf::RenderWindow &window , bool &band ,sf::Sprite &cursor , sf::Sprite &select ,sf::Vector2i &aux,sf::Vector2i &cell ){
sf::Event event;
sf::Vector2i mouse_position;
sf::Vector2i origen(sf::Vector2f(10,0));
while(window.pollEvent(event)){
switch(event.type){
case sf::Event::Closed:
window.close();exit(1);
break;
case sf::Event::MouseEntered:
band=true;
break;
case sf::Event::MouseLeft:
band=false;
break;
case sf::Event::MouseMoved:
if(band){
mouse_position = sf::Mouse::getPosition(window);
mouse_position= (sf::Vector2i)window.mapPixelToCoords(mouse_position);
// std::cout<<(mouse_position.x / 400 ) <<":"<<mouse_position.y / 200<<std::endl;
// std::cout<<(mouse_position.x % 256) <<":"<<mouse_position.y % 128<<std::endl;
cursor.setPosition((sf::Vector2f)mouse_position);
//
// if( (mouse_position.x < 200 && mouse_position.y < 100 )){
//
// std::cout<<"Esquina superior "<<std::endl;
//
// }
aux.x=mouse_position.x/400;
aux.y=mouse_position.y/200;
select.setPosition(sf::Vector2f(aux.x*400, aux.y*200));
aux= mouse_position;
}
break;
}
}
}