more stuff

This commit is contained in:
Alec Obradovich 2013-03-06 22:28:41 -06:00
parent 1f32f44626
commit f5c6d6101b
3 changed files with 21 additions and 10 deletions

View file

@ -70,9 +70,11 @@ void rts::Map::changeView(long x, long y) {
viewy = (viewy+y<0)?0:h;
}
void rts::Map::Render(sf::RenderWindow *rw) {
int cw = rw->getSize().x;
int ch = rw->getSize().y;
void rts::Map::Render(sf::RenderWindow *rw, int offset) {
//int cw = rw->getSize().x;
int cw = 400;
//int ch = rw->getSize().y;
int ch = 400;
for(int y = 0; y < tileCount; y++) {
for(int x = 0; x < tileCount; x++) {
@ -82,10 +84,10 @@ void rts::Map::Render(sf::RenderWindow *rw) {
tx1 = tx0 + TILE_W,
ty1 = tx1 + TILE_H;
//if((ty0 >= viewy && ty1 <= viewy+ch) && (tx1 >= viewx && tx0 <= viewx+cw)) {
grass.setPosition(tx0-viewx, ty0-viewy);
if((ty1-viewy >= 0 && ty0-viewy <= ch) && (tx1-viewx >= 0 && tx0-viewx <= cw)) {
grass.setPosition(tx0-viewx+offset, ty0-viewy+offset);
rw->draw(grass);
//}
}
}
}
}

View file

@ -45,7 +45,7 @@ namespace rts {
void setView(long,long);
void changeView(long,long);
void Render(sf::RenderWindow*);
void Render(sf::RenderWindow*,int=0);
};
};

View file

@ -9,10 +9,10 @@
int main() {
//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);
rts::Map gameMap(24);
rts::Map gameMap(32);
long mclk = 0;
sf::Clock uclk;
@ -22,6 +22,8 @@ int main() {
while (rw.pollEvent(event)) {
if (event.type == sf::Event::Closed)
rw.close();
if (event.type == sf::Event::Resized)
rw.setSize(sf::Vector2u(event.size.width,event.size.height));
}
rw.clear();
@ -40,7 +42,14 @@ int main() {
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();
}