Browse Source

Mouvements et couleurs random

master
DemiSel 3 years ago
parent
commit
4147041ecd

+ 2
- 0
lib/Environment/PictureEnvironment.hpp View File

27
 	void makeAgents(int iNumber);
27
 	void makeAgents(int iNumber);
28
 	void paint(int iX, int iY, const sf::Color Color);
28
 	void paint(int iX, int iY, const sf::Color Color);
29
 
29
 
30
+	int getWidth();
31
+	int getHeight();
30
 	bool loop();
32
 	bool loop();
31
 	void displayLockInput();
33
 	void displayLockInput();
32
 
34
 

+ 10
- 7
src/Agents/Agent.cpp View File

7
 
7
 
8
 Agent::Agent(PictureEnvironment* iEnvironment)
8
 Agent::Agent(PictureEnvironment* iEnvironment)
9
 {
9
 {
10
-	long WHITE = 0xFFFFFFFF;
10
+	//uint32_t WHITE = 0xFFFFFFFF;
11
 	fEnvironment = iEnvironment;
11
 	fEnvironment = iEnvironment;
12
 
12
 
13
 	//fColor = sf::Color(rand() % 0xFFFFFFFFFFFF);
13
 	//fColor = sf::Color(rand() % 0xFFFFFFFFFFFF);
14
-	fColor = sf::Color(((rand() % WHITE) << 16) + 0xFF);
15
-	fXPos = 100;
16
-	fYPos = 100;
14
+	uint32_t vRand = (((double)rand() / RAND_MAX) * 0xFFFFFFFFU);
15
+
16
+	fColor = sf::Color(vRand);
17
+	//fColor = sf::Color(((rand() % fColor.Red.toInteger())));
18
+	fXPos = iEnvironment->getWidth() / 2;
19
+	fYPos = iEnvironment->getHeight() / 2;
17
 }
20
 }
18
 
21
 
19
 void Agent::loop()
22
 void Agent::loop()
22
 	move();
25
 	move();
23
 }
26
 }
24
 
27
 
25
-int MOVESIZE = 10;
28
+int MOVESIZE = 5;
26
 
29
 
27
 void Agent::move()
30
 void Agent::move()
28
 {
31
 {
29
-	fXPos += (fXPos > MOVESIZE) ? rand() % MOVESIZE - 5 : MOVESIZE;
30
-	fYPos += (fYPos > MOVESIZE) ? rand() % MOVESIZE - 5 : MOVESIZE;
32
+	fXPos += (fXPos > MOVESIZE) ? (rand() % MOVESIZE) - (MOVESIZE / 2) : MOVESIZE;
33
+	fYPos += (fYPos > MOVESIZE) ? (rand() % MOVESIZE) - (MOVESIZE / 2) : MOVESIZE;
31
 	fEnvironment->paint(fXPos, fYPos, fColor);
34
 	fEnvironment->paint(fXPos, fYPos, fColor);
32
 }
35
 }

+ 39
- 19
src/Environment/PictureEnvironment.cpp View File

23
 	fImage = fTextureImage.copyToImage();
23
 	fImage = fTextureImage.copyToImage();
24
 
24
 
25
 	//memccpy(&fFilePath, &iFilePath, *iFilePath., 10);
25
 	//memccpy(&fFilePath, &iFilePath, *iFilePath., 10);
26
-	std::cout << "Environement pour " << fFilePath;
27
 	fPlatform = iPlatform;
26
 	fPlatform = iPlatform;
28
 	fWindow = iWindow;
27
 	fWindow = iWindow;
29
 	float screenScalingFactor = fPlatform->getScreenScalingFactor(fWindow->getSystemHandle());
28
 	float screenScalingFactor = fPlatform->getScreenScalingFactor(fWindow->getSystemHandle());
47
 	return vPerception;
46
 	return vPerception;
48
 }
47
 }
49
 
48
 
50
-void PictureEnvironment::makeAgents(int iNumber)
51
-{
52
-	Agent vTmpAgent;
53
-	fAgents = std::list<Agent>(iNumber);
54
-	fAgentsIterator = fAgents.begin();
55
-
56
-	for (int i = 0; i < iNumber; i++)
57
-	{
58
-		vTmpAgent = Agent(this);
59
-		fAgents.insert(fAgentsIterator, vTmpAgent);
60
-	}
61
-}
62
-
63
 bool PictureEnvironment::loop()
49
 bool PictureEnvironment::loop()
64
 {
50
 {
65
 	if (fWindow->isOpen())
51
 	if (fWindow->isOpen())
69
 			if (fEvent.type == sf::Event::Closed)
55
 			if (fEvent.type == sf::Event::Closed)
70
 				fWindow->close();
56
 				fWindow->close();
71
 		}
57
 		}
72
-
73
-		fAgentsIterator = fAgents.begin();
74
-		for (uint i = 0; i < fAgents.size(); i++)
58
+		// fAgentsIterator = fAgents.begin();
59
+		std::list<Agent>::iterator vAgentsIterator = fAgents.begin();
60
+		fAgents.begin();
61
+		while (vAgentsIterator != fAgents.end())
75
 		{
62
 		{
76
-			fAgentsIterator->loop();
77
-		}
78
 
63
 
64
+			//std::cout << "loop" << vAgentsIterator->fColor->toInteger() << " at " << &vAgentsIterator << "\n";
65
+			vAgentsIterator->loop();
66
+			vAgentsIterator++;
67
+		}
79
 		fTextureImage.loadFromImage(fImage);
68
 		fTextureImage.loadFromImage(fImage);
80
 		fShape.setTexture(&fTextureImage);
69
 		fShape.setTexture(&fTextureImage);
81
 		fWindow->clear();
70
 		fWindow->clear();
90
 	return true;
79
 	return true;
91
 }
80
 }
92
 
81
 
82
+int PictureEnvironment::getHeight()
83
+{
84
+	return fImage.getSize().y;
85
+}
86
+
87
+int PictureEnvironment::getWidth()
88
+{
89
+	return fImage.getSize().x;
90
+}
91
+
92
+void PictureEnvironment::makeAgents(int iNumber)
93
+{
94
+
95
+	fAgents = std::list<Agent>();
96
+
97
+	for (int i = 0; i < iNumber; i++)
98
+	{
99
+		Agent vTmpAgent = Agent(this);
100
+		fAgents.push_back(vTmpAgent);
101
+		//std::cout << "pushback" << vTmpAgent.fColor.toInteger() << " at " << &vTmpAgent << "\n"
102
+		//		  << " size : " << fAgents.size() << "\n";
103
+	}
104
+	std::list<Agent>::iterator vAgentsIterator = fAgents.begin();
105
+	while (vAgentsIterator != fAgents.end())
106
+	{
107
+
108
+		//std::cout << "loop" << vAgentsIterator->fColor->toInteger() << " at " << &vAgentsIterator << "\n";
109
+		vAgentsIterator++;
110
+	}
111
+}
112
+
93
 void PictureEnvironment::displayLockInput()
113
 void PictureEnvironment::displayLockInput()
94
 {
114
 {
95
 	fWindow->create(sf::VideoMode(fInitialSize.x, fInitialSize.y), "Last peek");
115
 	fWindow->create(sf::VideoMode(fInitialSize.x, fInitialSize.y), "Last peek");

+ 4
- 4
src/Main.cpp View File

22
 
22
 
23
 	PictureEnvironment vEnvironment(filepath, &window, &platform);
23
 	PictureEnvironment vEnvironment(filepath, &window, &platform);
24
 
24
 
25
-	vEnvironment.makeAgents(100);
26
-	int i = 0;
27
-	while (i++ < 10000)
25
+	vEnvironment.makeAgents(1000);
26
+	//int i = 0;
27
+	while (vEnvironment.loop())
28
 	{
28
 	{
29
-		vEnvironment.loop();
29
+		;
30
 		usleep(30);
30
 		usleep(30);
31
 	}
31
 	}
32
 
32
 

Loading…
Cancel
Save