-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
79 lines (61 loc) · 1.46 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Std lib
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctime>
// For Linux/Mac
#include <unistd.h>
// For Windows
// #include <windows.h>
// You also need to replace "sleep()" by "Sleep()"
// Graphic lib
#include "bwindow.h"
// Constants
#include "DefVal.h"
// Boid struct
#include "Obstacle.h"
// Boid classes
#include "Border.h"
#include "Agent.h"
#include "Prey.h"
#include "Hunter.h"
#include "Scene.h"
int main()
{
// Seed for the random variables
srand (time (NULL));
// Window set-up
bwindow win(DefVal::WINDOW_WIDTH,DefVal::WINDOW_HEIGHT);
printf("%d\n",win.init());
win.map();
// Scene declaration
Scene* s1 = new Scene ();
// Add borders
s1->addBorder(0,20,20,(DefVal::WINDOW_WIDTH)-20);
s1->addBorder(1,20,(DefVal::WINDOW_HEIGHT)-20,(DefVal::WINDOW_WIDTH)-20);
s1->addBorder(2,(DefVal::WINDOW_WIDTH)-20,(DefVal::WINDOW_HEIGHT)-20,20);
s1->addBorder(3,20,(DefVal::WINDOW_HEIGHT)-20,20);
// Add obstacle
s1->addObstacle(DefVal::NB_OBST);
// Add agents
s1->addAgent(20,20);
// Paint loop
for(;;)
{
int ev = win.parse_event();
usleep(DefVal::TIME_STEP); // time step in microseconds
// Comment to see trajectories
win.draw_fsquare(0,0,DefVal::WINDOW_WIDTH,DefVal::WINDOW_HEIGHT,0xE2BD40);
s1->draw(win);
//must be >10ms (depending on the system)
switch(ev)
{
case BKPRESS :
if(!strcmp(win.get_lastkey(), "space"))
// Sleep for 1s
usleep(1000000);
break;
}
}
return 0;
}