Explorar el Código

Mouvements et couleurs random

master
DemiSel hace 3 años
padre
commit
4147041ecd

+ 2
- 0
lib/Environment/PictureEnvironment.hpp Ver fichero

@@ -27,6 +27,8 @@ public: // Access specifier
27 27
 	void makeAgents(int iNumber);
28 28
 	void paint(int iX, int iY, const sf::Color Color);
29 29
 
30
+	int getWidth();
31
+	int getHeight();
30 32
 	bool loop();
31 33
 	void displayLockInput();
32 34
 

+ 10
- 7
src/Agents/Agent.cpp Ver fichero

@@ -7,13 +7,16 @@ Agent::Agent()
7 7
 
8 8
 Agent::Agent(PictureEnvironment* iEnvironment)
9 9
 {
10
-	long WHITE = 0xFFFFFFFF;
10
+	//uint32_t WHITE = 0xFFFFFFFF;
11 11
 	fEnvironment = iEnvironment;
12 12
 
13 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 22
 void Agent::loop()
@@ -22,11 +25,11 @@ void Agent::loop()
22 25
 	move();
23 26
 }
24 27
 
25
-int MOVESIZE = 10;
28
+int MOVESIZE = 5;
26 29
 
27 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 34
 	fEnvironment->paint(fXPos, fYPos, fColor);
32 35
 }

+ 39
- 19
src/Environment/PictureEnvironment.cpp Ver fichero

@@ -23,7 +23,6 @@ PictureEnvironment::PictureEnvironment(std::string& iFilePath, sf::RenderWindow*
23 23
 	fImage = fTextureImage.copyToImage();
24 24
 
25 25
 	//memccpy(&fFilePath, &iFilePath, *iFilePath., 10);
26
-	std::cout << "Environement pour " << fFilePath;
27 26
 	fPlatform = iPlatform;
28 27
 	fWindow = iWindow;
29 28
 	float screenScalingFactor = fPlatform->getScreenScalingFactor(fWindow->getSystemHandle());
@@ -47,19 +46,6 @@ Perception PictureEnvironment::getPerception(int iX, int iY)
47 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 49
 bool PictureEnvironment::loop()
64 50
 {
65 51
 	if (fWindow->isOpen())
@@ -69,13 +55,16 @@ bool PictureEnvironment::loop()
69 55
 			if (fEvent.type == sf::Event::Closed)
70 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 68
 		fTextureImage.loadFromImage(fImage);
80 69
 		fShape.setTexture(&fTextureImage);
81 70
 		fWindow->clear();
@@ -90,6 +79,37 @@ bool PictureEnvironment::loop()
90 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 113
 void PictureEnvironment::displayLockInput()
94 114
 {
95 115
 	fWindow->create(sf::VideoMode(fInitialSize.x, fInitialSize.y), "Last peek");

+ 4
- 4
src/Main.cpp Ver fichero

@@ -22,11 +22,11 @@ int main()
22 22
 
23 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 30
 		usleep(30);
31 31
 	}
32 32
 

Loading…
Cancelar
Guardar