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.

Entities.pde 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. int i_interactableAmount = 10;
  2. //entitiy-subklassen: papier .. computer .. mobiles ... books ... lamps ... tables ...
  3. Interactable[] interactables = new Interactable[10];
  4. void initInteractables() {
  5. for (int i = 0; i < interactables.length; i++) {
  6. interactables[i] = new Interactable("Interactable", "Content");
  7. }
  8. for (int i = 0; i < interactables.length; i++) {
  9. interactables[i].spawn(citizen[int(random(0, citizen.length))].i_home);
  10. }
  11. }
  12. class Entity {
  13. String s_name;
  14. boolean b_linked;
  15. int i(int x) {
  16. return (x);
  17. };
  18. boolean b_selected;
  19. boolean b_moving;
  20. boolean b_turning;
  21. PVector v2_turnBuffer = new PVector(0, 0);
  22. float f_turnSpeed;
  23. int i_turning;
  24. float f_xPos, f_yPos, f_xSpawn, f_ySpawn;
  25. float f_angle;
  26. int i_diameter = 10;
  27. int i_nameSize = 12;
  28. color c_selected = color(128, 50, 50);
  29. color c_color = color(50, 200, 80);
  30. color c_stroke = color(255, 255, 255);
  31. PVector v2_direction = new PVector(0, 0);
  32. void spawn(int house) { //generic spawn
  33. PVector v2_spawnPoint = houses.get(house).v2_randomSpawnPoint();
  34. f_xSpawn = v2_spawnPoint.x;
  35. f_ySpawn = v2_spawnPoint.y;
  36. f_xPos = f_xSpawn;
  37. f_yPos = f_ySpawn;
  38. turnTo(0, 10, 0);
  39. f_angle = 0;
  40. b_linked = true;
  41. }
  42. void spawn(int x, int y) { //specific spawn
  43. f_xSpawn = x;
  44. f_ySpawn = y;
  45. f_xPos = f_xSpawn;
  46. f_yPos = f_ySpawn;
  47. turnTo(0, 10, 0);
  48. b_linked = true;
  49. }
  50. void despawn() {
  51. b_linked = false;
  52. }
  53. void turnTo(float x, float y, float speed) {
  54. f_turnSpeed = speed;
  55. if (f_turnSpeed > 0) {
  56. b_turning = true;
  57. v2_turnBuffer.x = x;
  58. v2_turnBuffer.y = y;
  59. float difference = v2_direction.heading() - v2_turnBuffer.heading();
  60. if (difference < -PI) difference += TWO_PI;
  61. if (difference > PI) difference -= TWO_PI;
  62. if (difference > 0.0) i_turning = -1;
  63. if (difference < 0.0) i_turning = 1;
  64. f_turnSpeed*=4*abs(difference);
  65. } else {
  66. v2_direction.x = x;
  67. v2_direction.y = y;
  68. }
  69. }
  70. void turn() {
  71. if (!(abs(int(v2_direction.heading() * 1000) - int(v2_turnBuffer.heading()*1000)) < 100)) {
  72. v2_direction = v2_direction.rotate(i_turning*PI/180*f_turnSpeed);
  73. } else {
  74. b_turning = false;
  75. }
  76. }
  77. void display() {
  78. pg_map.stroke(c_stroke);
  79. pg_map.fill(c_color);
  80. if (b_selected) pg_map.fill(c_selected);
  81. pg_map.ellipse(f_xPos, f_yPos, i_diameter, i_diameter);
  82. pg_map.fill(c_stroke);
  83. pg_map.textAlign(CENTER);
  84. pg_map.textSize(i_nameSize);
  85. pg_map.text(s_name, f_xPos, f_yPos-10);
  86. }
  87. }
  88. class Interactable extends Entity {
  89. Interactable(String name, String description) {
  90. s_name = name;
  91. }
  92. void update() {
  93. }
  94. }