added double jump and sitting state
This commit is contained in:
		
							parent
							
								
									2e5c5a8dde
								
							
						
					
					
						commit
						90d07dde3f
					
				
					 148 changed files with 13050 additions and 0 deletions
				
			
		
							
								
								
									
										2
									
								
								term1/seminar09_libraries/02_thor/Makefile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								term1/seminar09_libraries/02_thor/Makefile
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | |||
| balls: | ||||
| 	g++ ./balls.cpp -std=c++11 -o balls.exe -I../../../3rdparty/SFML-2.5.1/include -L ../../../3rdparty/SFML-2.5.1/lib/ -lsfml-graphics -lsfml-window -lsfml-system  | ||||
							
								
								
									
										93
									
								
								term1/seminar09_libraries/02_thor/balls.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								term1/seminar09_libraries/02_thor/balls.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,93 @@ | |||
| #include <SFML/Graphics.hpp> | ||||
| #include <iostream> | ||||
| #include <vector> | ||||
| #include <cstdlib> | ||||
| #include <ctime> | ||||
| 
 | ||||
| using namespace std; | ||||
| 
 | ||||
| 
 | ||||
| struct Ball | ||||
| { | ||||
|     float radius; | ||||
|     sf::Vector2f position; | ||||
|     sf::Vector2f velocity; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| int main() | ||||
| { | ||||
|     srand(time(0)); | ||||
|      | ||||
|     const int width = 1000; | ||||
|     const int height = 800; | ||||
|     const int n_balls = 100; | ||||
|     // Шаг по времени
 | ||||
|     const float delta_t = 0.1; | ||||
| 
 | ||||
|     // Создаём экземпляр класса окно
 | ||||
|     sf::RenderWindow window(sf::VideoMode(width, height), "My window"); | ||||
|     // Задаём максимальное количество кадров в секунду
 | ||||
|     window.setFramerateLimit(60); | ||||
| 
 | ||||
|     // Так как sf::CircleShape занимает много памяти, создаём всего 1 экземпляр
 | ||||
|     sf::CircleShape circle(50.0f); | ||||
|     circle.setFillColor({200, 216, 200}); | ||||
| 
 | ||||
|     std::vector<Ball> balls; | ||||
|     balls.resize(n_balls); | ||||
|     for (int i = 0; i < n_balls; i++) | ||||
|     { | ||||
|         balls[i].radius = 4 + rand() % 8; | ||||
|         balls[i].position = {(float)(rand() % width), (float)(rand() % height)}; | ||||
|         balls[i].velocity = {(float)(rand() % 100 - 50), (float)(rand() % 100 - 50)}; | ||||
|     } | ||||
| 
 | ||||
|     while (window.isOpen()) | ||||
|     { | ||||
|         sf::Event event; | ||||
|         while (window.pollEvent(event)) | ||||
|         { | ||||
|             // В данном примере проверяем окно на закрытие
 | ||||
|             if (event.type == sf::Event::Closed) | ||||
|                 window.close(); | ||||
|         } | ||||
| 
 | ||||
|         // очистить скрытый холст черным цветом
 | ||||
|         window.clear(sf::Color::Black); | ||||
| 
 | ||||
|         for (int i = 0; i < n_balls; i++) | ||||
|         { | ||||
|             balls[i].position += balls[i].velocity * delta_t; | ||||
| 
 | ||||
|              | ||||
|             if (balls[i].position.x < 0) | ||||
|                 balls[i].position.x += width; | ||||
|             if (balls[i].position.x > width) | ||||
|                 balls[i].position.x -= width; | ||||
| 
 | ||||
|             if (balls[i].position.y < 0) | ||||
|                 balls[i].position.y += height; | ||||
|             if (balls[i].position.y > height) | ||||
|                 balls[i].position.y -= height; | ||||
|              | ||||
| 
 | ||||
|             // Используем 1 sf::CircleShape, чтобы нарисовать все шары
 | ||||
|             circle.setRadius(balls[i].radius); | ||||
|             // setOrigin - задаёт центр объекта
 | ||||
|             // По умолчанию центр - в левом верхнем угле объекта
 | ||||
|             // Строка ниже устанавливает центр в центре шарика
 | ||||
|             // В дальнейшем функция, setPosition устанавливает положение шарика так, 
 | ||||
|             // чтобы его центр был в точке balls[i].position
 | ||||
|             circle.setOrigin(balls[i].radius, balls[i].radius); | ||||
|             circle.setPosition(balls[i].position); | ||||
|              | ||||
|             window.draw(circle); | ||||
|         } | ||||
| 
 | ||||
|         // отображаем содержимое скрытого холста на экран
 | ||||
|         window.display(); | ||||
|     } | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
		Reference in a new issue