Simulation von Bürgern
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

citizen.pde 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import processing.net.*;
  2. //settings
  3. boolean b_smallerImage = false; //use a cropped, smaller version of the 1920x1080 image for faster development
  4. boolean b_loadSun = false; //load sun from web-api instead of local json file (local file is adressed to january 4th 2019. might implement a check that downloads today's information only once...
  5. int i_sMapReso = 8; //the higher the smaller the reso, 2 is best quality but takes some time to download
  6. float f_walkSpeedMin = .05;
  7. float f_walkSpeedMax = .1;
  8. boolean b_cameraFollow = true;
  9. boolean b_autoPlayAfterSelect = false;
  10. boolean b_controlEyeWithMouse;
  11. boolean b_debug = true;
  12. boolean b_drawNodes = false;
  13. float f_nodeResolution = 0.2; //defines density of path-finding nodes, multiplied with resolution
  14. int i_pathAlgorithm = 3;
  15. int i_debugTextSize = 10;
  16. int i_mapW, i_mapH;
  17. int i_windowW, i_windowH;
  18. int i_viewportW, i_viewportH;
  19. Server server;
  20. Client client;
  21. void setup() {
  22. size(700, 600);
  23. server = new Server(this, 5210);
  24. //blendMode(MULTIPLY);
  25. i_windowW = width;
  26. i_windowH = height;
  27. img_map = loadImage(dataPath("map/map.png"));
  28. if (b_smallerImage) img_houses = loadImage(dataPath("map/houses_with_borders_small.png"));
  29. else img_houses = loadImage(dataPath("map/houses_with_borders.png"));
  30. img_streets = loadImage(dataPath("map/streets.png"));
  31. pg_map = createGraphics(img_houses.width, img_houses.height);
  32. surface.setResizable(true);
  33. registerMethod("pre", this);
  34. i_mapW = pg_map.width;
  35. i_mapH = pg_map.height;
  36. initHouses();
  37. initPathFinding();
  38. initWeather();
  39. initCitizen();
  40. initInteractables();
  41. initUI();
  42. }
  43. void pre() {
  44. if (i_windowW != width || i_windowH != height) {
  45. // Sketch window has resized
  46. i_windowW = width;
  47. i_windowH = height;
  48. i_uiY = height - i_uiH;
  49. i_uiW = width;
  50. i_uiH = height - i_uiY;
  51. }
  52. }
  53. String s_fromClient;
  54. int i_mapLevelTransferC;
  55. void draw() {
  56. background(127);
  57. clientCommunication();
  58. pg_map.beginDraw();
  59. pg_map.background(127);
  60. if (b_debug) pg_map.image(img_houses, 0, 0, img_houses.width, img_houses.height);
  61. else pg_map.image(img_map, 0, 0, img_houses.width, img_houses.height);
  62. pg_map.fill(0);
  63. pg_map.textSize(7);
  64. pg_map.textAlign(CENTER);
  65. if (b_debug) {
  66. for (House house : houses) {
  67. house.display();
  68. }
  69. }
  70. if (b_drawNodes) drawNodes();
  71. for (int i = 0; i < interactables.length; i++) {
  72. interactables[i].update();
  73. interactables[i].display();
  74. }
  75. for (int i = 0; i < citizen.length; i++) {
  76. if (citizen[i].b_linked) {
  77. citizen[i].update();
  78. if (i != i_selectedCitizen)
  79. citizen[i].display();
  80. if (b_debug)
  81. citizen[i].debug();
  82. }
  83. }
  84. if (b_controlEyeWithMouse) {
  85. citizen[i_selectedCitizen].turnTo(citizen[i_selectedCitizen].f_xPos-(float)constrain(i_mapViewToMap(mouseX, i_mapOffsetX), 0, pg_map.width), citizen[i_selectedCitizen].f_yPos-(float)constrain(i_mapViewToMap(mouseY, i_mapOffsetY), 0, pg_map.height), 0) ;
  86. }
  87. citizen[i_selectedCitizen].display();
  88. pg_map.endDraw();
  89. image(pg_map, i_mapOffsetX, i_mapOffsetY, i_mapW, i_mapH);
  90. drawUI();
  91. }