Созданные ответы форума
Просмотр 9 сообщений - с 1 по 9 (из 9 всего)
-
АвторСообщения
-
а в конце что то эксепшн выскакивает, теперь
о чет не подумал, спасибо, все воркс)))
не помню доделал процедурное программирование или нет
результаты работы. без коммента и что должно быть
Вложения:
You must be logged in to view attached files.C++12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849void main(){LoadTrack();Clock clock;RenderWindow window(sf::VideoMode(640, 480), "2D Racing");view.reset(sf::FloatRect(0, 0, 640, 480));Player p("car.png", 25, 50, 206, 142, 1, 0, 0, 0, 0, 0, 0);p.sprite.setPosition(p.x, p.y);p.sprite.setOrigin(p.w / 3, p.h / 2);Image map_image;map_image.loadFromFile("images/map.png");Texture map;map.loadFromImage(map_image);Sprite s_map;s_map.setTexture(map);while (window.isOpen()){float time = clock.getElapsedTime().asMicroseconds();clock.restart();time = time / 800;sf::Event event;while (window.pollEvent(event)){if (event.type == sf::Event::Closed)window.close();}if (Keyboard::isKeyPressed(Keyboard::Up)) { p.sprite.move(cos(PI / 180 * p.ang)*0.3*time, sin(PI / 180 * p.ang)*0.3*time); }if (Keyboard::isKeyPressed(Keyboard::Down)) { p.sprite.move(cos(PI / 180 * p.ang)*-0.1*time, sin(PI / 180 * p.ang)*-0.1*time); }if (Keyboard::isKeyPressed(Keyboard::Left)) { p.ang = p.ang - 0.2; p.sprite.setRotation(p.ang); }if (Keyboard::isKeyPressed(Keyboard::Right)) { p.ang = p.ang + 0.2; p.sprite.setRotation(p.ang); }view.setCenter(p.sprite.getPosition());window.setView(view);window.clear(Color(100,20,250));for (int i = 0; i < WIDTH_MAP; i++)for (int j = 0; j < HEIGHT_MAP; j++){if (trackMaxrix[i][j] == 0) s_map.setTextureRect(IntRect(0, 0, 32, 32));if (trackMaxrix[i][j] == 1) s_map.setTextureRect(IntRect(32, 0, 32, 32));if ((trackMaxrix[i][j] == 2)) s_map.setTextureRect(IntRect(64, 0, 32, 32));if ((trackMaxrix[i][j] == 3)) s_map.setTextureRect(IntRect(96, 0, 96, 96));if ((trackMaxrix[i][j] == 4)) s_map.setTextureRect(IntRect(128, 0, 128, 128));s_map.setPosition(j * 32, i * 32);window.draw(s_map);}window.draw(p.sprite);window.display();}}Вложения:
You must be logged in to view attached files.или вы имели ввиду другой цикл какой то. но если я правильно скобки посчитал, то вот он цикл. инициализация окна выше. так куда его пихать то?
C++12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273while (window.isOpen()){float time = clock.getElapsedTime().asMicroseconds();clock.restart();time = time / 800;sf::Event event;while (window.pollEvent(event)){if (event.type == sf::Event::Closed)window.close();}///////////////////////////////////////////Управление персонажем с анимацией////////////////////////////////////////////////////////////////////////if (Keyboard::isKeyPressed(Keyboard::Left)) {p.dir = 1; p.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;p.sprite.setTextureRect(IntRect(96 * int(CurrentFrame), 96, 96, 96));getplayercoordinateforview(p.getplayercoordinateX(), p.getplayercoordinateY());//передаем координаты игрока в функцию управления камерой}if (Keyboard::isKeyPressed(Keyboard::Right)) {p.dir = 0; p.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;p.sprite.setTextureRect(IntRect(96 * int(CurrentFrame), 192, 96, 96));getplayercoordinateforview(p.getplayercoordinateX(), p.getplayercoordinateY());//передаем координаты игрока в функцию управления камерой}if (Keyboard::isKeyPressed(Keyboard::Up)) {p.dir = 3; p.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;p.sprite.setTextureRect(IntRect(96 * int(CurrentFrame), 288, 96, 96));getplayercoordinateforview(p.getplayercoordinateX(), p.getplayercoordinateY());//передаем координаты игрока в функцию управления камерой}if (Keyboard::isKeyPressed(Keyboard::Down)) {p.dir = 2; p.speed = 0.1;CurrentFrame += 0.005*time;if (CurrentFrame > 3) CurrentFrame -= 3;p.sprite.setTextureRect(IntRect(96 * int(CurrentFrame), 0, 96, 96));getplayercoordinateforview(p.getplayercoordinateX(), p.getplayercoordinateY());//передаем координаты игрока в функцию управления камерой}p.update(time);viewmap(time);//функция скроллинга карты, передаем ей время sfmlchangeview();//прикалываемся с камерой вида<strong>setView(view)</strong>;//"оживляем" камеру в окне sfml ЦИКЛ ЕСЛИ Я ПРАВИЛЬНО ПОСЧИТАЛ СКОБКИ{})))window.clear();/////////////////////////////Рисуем карту/////////////////////for (int i = 0; i < HEIGHT_MAP; i++)for (int j = 0; j < WIDTH_MAP; j++){if (TileMap[i][j] == ' ') s_map.setTextureRect(IntRect(0, 0, 32, 32));if (TileMap[i][j] == 's') s_map.setTextureRect(IntRect(32, 0, 32, 32));if ((TileMap[i][j] == '0')) s_map.setTextureRect(IntRect(64, 0, 32, 32));s_map.setPosition(j * 32, i * 32);window.draw(s_map);}window.draw(p.sprite);window.display();}то есть window.setView() задается не в цикле? в уроке было сказано перед очисткой экрана его делать.
-
АвторСообщения
Просмотр 9 сообщений - с 1 по 9 (из 9 всего)