more stuff
This commit is contained in:
parent
1f32f44626
commit
f5c6d6101b
14
rts/Map.cpp
14
rts/Map.cpp
|
@ -70,9 +70,11 @@ void rts::Map::changeView(long x, long y) {
|
||||||
viewy = (viewy+y<0)?0:h;
|
viewy = (viewy+y<0)?0:h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rts::Map::Render(sf::RenderWindow *rw) {
|
void rts::Map::Render(sf::RenderWindow *rw, int offset) {
|
||||||
int cw = rw->getSize().x;
|
//int cw = rw->getSize().x;
|
||||||
int ch = rw->getSize().y;
|
int cw = 400;
|
||||||
|
//int ch = rw->getSize().y;
|
||||||
|
int ch = 400;
|
||||||
|
|
||||||
for(int y = 0; y < tileCount; y++) {
|
for(int y = 0; y < tileCount; y++) {
|
||||||
for(int x = 0; x < tileCount; x++) {
|
for(int x = 0; x < tileCount; x++) {
|
||||||
|
@ -82,10 +84,10 @@ void rts::Map::Render(sf::RenderWindow *rw) {
|
||||||
tx1 = tx0 + TILE_W,
|
tx1 = tx0 + TILE_W,
|
||||||
ty1 = tx1 + TILE_H;
|
ty1 = tx1 + TILE_H;
|
||||||
|
|
||||||
//if((ty0 >= viewy && ty1 <= viewy+ch) && (tx1 >= viewx && tx0 <= viewx+cw)) {
|
if((ty1-viewy >= 0 && ty0-viewy <= ch) && (tx1-viewx >= 0 && tx0-viewx <= cw)) {
|
||||||
grass.setPosition(tx0-viewx, ty0-viewy);
|
grass.setPosition(tx0-viewx+offset, ty0-viewy+offset);
|
||||||
rw->draw(grass);
|
rw->draw(grass);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -45,7 +45,7 @@ namespace rts {
|
||||||
void setView(long,long);
|
void setView(long,long);
|
||||||
void changeView(long,long);
|
void changeView(long,long);
|
||||||
|
|
||||||
void Render(sf::RenderWindow*);
|
void Render(sf::RenderWindow*,int=0);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
15
rts/main.cpp
15
rts/main.cpp
|
@ -9,10 +9,10 @@
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
//sf::RenderWindow rw(sf::VideoMode::getDesktopMode(), "test", sf::Style::Fullscreen);
|
//sf::RenderWindow rw(sf::VideoMode::getDesktopMode(), "test", sf::Style::Fullscreen);
|
||||||
sf::RenderWindow rw(sf::VideoMode(800, 600), "test");
|
sf::RenderWindow rw(sf::VideoMode(800, 800), "test");
|
||||||
rw.setFramerateLimit(60);
|
rw.setFramerateLimit(60);
|
||||||
|
|
||||||
rts::Map gameMap(24);
|
rts::Map gameMap(32);
|
||||||
|
|
||||||
long mclk = 0;
|
long mclk = 0;
|
||||||
sf::Clock uclk;
|
sf::Clock uclk;
|
||||||
|
@ -22,6 +22,8 @@ int main() {
|
||||||
while (rw.pollEvent(event)) {
|
while (rw.pollEvent(event)) {
|
||||||
if (event.type == sf::Event::Closed)
|
if (event.type == sf::Event::Closed)
|
||||||
rw.close();
|
rw.close();
|
||||||
|
if (event.type == sf::Event::Resized)
|
||||||
|
rw.setSize(sf::Vector2u(event.size.width,event.size.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
rw.clear();
|
rw.clear();
|
||||||
|
@ -40,7 +42,14 @@ int main() {
|
||||||
gameMap.changeView(4,0);
|
gameMap.changeView(4,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
gameMap.Render(&rw);
|
sf::RectangleShape test(sf::Vector2f(400,400));
|
||||||
|
test.setFillColor(sf::Color(0,0,0,0));
|
||||||
|
test.setOutlineColor(sf::Color(255,255,255));
|
||||||
|
test.setOutlineThickness(4);
|
||||||
|
test.setPosition(200,200);
|
||||||
|
|
||||||
|
gameMap.Render(&rw,200);
|
||||||
|
rw.draw(test);
|
||||||
|
|
||||||
rw.display();
|
rw.display();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue