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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. void initUI() {
  2. i_uiX = 0;
  3. i_uiY = 420;
  4. i_uiW = width;
  5. i_uiH = height - i_uiY;
  6. }
  7. int i_uiX, i_uiY, i_uiW, i_uiH;
  8. int i_uiOffsetX, i_uiOffsetY, i_uiOffsetStartX, i_uiOffsetStartY, i_initUiY;
  9. void drawUI() {
  10. strokeWeight(1);
  11. line(i_uiX, i_uiY, i_uiX+i_uiW, i_uiY);
  12. strokeWeight(0);
  13. fill(255, 230);
  14. rect(i_uiX, i_uiY, i_uiW, i_uiH);
  15. fill(0);
  16. textSize(30);
  17. textAlign(LEFT);
  18. text(String.format("%02d", hour()) + ":" + String.format("%02d", minute()) + ":" + String.format("%02d", second()), 10, 30);
  19. textSize(15);
  20. text("FPS: " + int(frameRate), 10, i_uiY + 15);
  21. }
  22. boolean b_mouseChangeMapOffset, b_mouseChangeUiHeight;
  23. boolean b_hoverUI;
  24. void mousePressed() {
  25. if (mouseButton == LEFT) {
  26. if (mouseX >= i_uiX && mouseX <= i_uiX+i_uiW && mouseY >= i_uiY-10 && mouseY <= i_uiY+10) {
  27. b_mouseChangeUiHeight = true;
  28. i_uiOffsetStartY = mouseY;
  29. i_initUiY = i_uiY;
  30. } else {
  31. }
  32. }
  33. if (mouseButton == CENTER) {
  34. b_mouseChangeMapOffset = true;
  35. i_mapOffsetStartX = mouseX - i_mapOffsetX;
  36. i_mapOffsetStartY = mouseY - i_mapOffsetY;
  37. }
  38. if (mouseButton == RIGHT) {
  39. if (b_mapZoom)
  40. citizen[0].goTo(constrain((mouseX-i_mapOffsetX)*2, 0, pg_map.width), constrain((mouseY-i_mapOffsetY)*2, 0, pg_map.height));
  41. else
  42. citizen[0].goTo(constrain(mouseX-i_mapOffsetX, 0, pg_map.width), constrain(mouseY-i_mapOffsetY, 0, pg_map.height));
  43. }
  44. }
  45. void mouseDragged() {
  46. if (b_mouseChangeMapOffset) {
  47. i_mapOffsetX = (mouseX - i_mapOffsetStartX);
  48. i_mapOffsetY = (mouseY - i_mapOffsetStartY);
  49. }
  50. if (b_mouseChangeUiHeight) {
  51. i_uiY = mouseY - i_uiOffsetStartY + i_initUiY;
  52. if (i_uiY > height) i_uiY = height;
  53. i_uiH = height - i_uiY;
  54. }
  55. }
  56. void mouseReleased() {
  57. b_mouseChangeMapOffset = false;
  58. b_mouseChangeUiHeight = false;
  59. }
  60. //bad
  61. //int maxScale = 5;
  62. //float zoomFactor = 0.4;
  63. //int i_imgCenterX;
  64. //int i_imgCenterY;
  65. int i_mapScale = 1;
  66. boolean b_mapZoom;
  67. float e;
  68. void mouseWheel(MouseEvent event) {
  69. e = event.getAmount();
  70. if (e == -1) {
  71. i_mapScale+=1;
  72. }
  73. if (e == 1) {
  74. i_mapScale-=1;
  75. }
  76. constrain(i_mapScale, 0, 2);
  77. switch(int(e)) {
  78. case 1:
  79. if (!b_mapZoom) {
  80. i_mapW = pg_map.width/2;
  81. i_mapH = pg_map.height/2;
  82. i_mapOffsetX -= 3*i_mapOffsetX/4;
  83. i_mapOffsetY -= 3*i_mapOffsetY/4;
  84. b_mapZoom = true;
  85. }
  86. break;
  87. case -1:
  88. i_mapW = pg_map.width;
  89. i_mapH = pg_map.height;
  90. b_mapZoom = false;
  91. break;
  92. }
  93. }