123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import processing.net.*;
-
-
- //settings
- boolean b_smallerImage = false; //use a cropped, smaller version of the 1920x1080 image for faster development
- 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...
-
- int i_sMapReso = 8; //the higher the smaller the reso, 2 is best quality but takes some time to download
-
- float f_walkSpeedMin = .05;
- float f_walkSpeedMax = .1;
-
- boolean b_cameraFollow = true;
- boolean b_autoPlayAfterSelect = false;
-
-
- boolean b_controlEyeWithMouse;
-
-
- boolean b_debug = true;
- boolean b_drawNodes = false;
-
- float f_nodeResolution = 0.2; //defines density of path-finding nodes, multiplied with resolution
- int i_pathAlgorithm = 3;
- int i_debugTextSize = 10;
- int i_mapW, i_mapH;
- int i_windowW, i_windowH;
- int i_viewportW, i_viewportH;
-
- Server server;
- Client client;
-
-
- void setup() {
- size(700, 600);
- server = new Server(this, 5210);
- //blendMode(MULTIPLY);
- i_windowW = width;
- i_windowH = height;
- img_map = loadImage(dataPath("map/map.png"));
- if (b_smallerImage) img_houses = loadImage(dataPath("map/houses_with_borders_small.png"));
- else img_houses = loadImage(dataPath("map/houses_with_borders.png"));
- img_streets = loadImage(dataPath("map/streets.png"));
-
- pg_map = createGraphics(img_houses.width, img_houses.height);
-
- surface.setResizable(true);
- registerMethod("pre", this);
-
- i_mapW = pg_map.width;
- i_mapH = pg_map.height;
-
- initHouses();
- initPathFinding();
- initWeather();
- initCitizen();
- initInteractables();
- initUI();
- }
-
- void pre() {
- if (i_windowW != width || i_windowH != height) {
- // Sketch window has resized
- i_windowW = width;
- i_windowH = height;
- i_uiY = height - i_uiH;
- i_uiW = width;
- i_uiH = height - i_uiY;
- }
- }
- String s_fromClient;
- int i_mapLevelTransferC;
- void draw() {
- background(127);
-
- clientCommunication();
-
- pg_map.beginDraw();
- pg_map.background(127);
-
- if (b_debug) pg_map.image(img_houses, 0, 0, img_houses.width, img_houses.height);
- else pg_map.image(img_map, 0, 0, img_houses.width, img_houses.height);
-
- pg_map.fill(0);
- pg_map.textSize(7);
- pg_map.textAlign(CENTER);
-
- if (b_debug) {
- for (House house : houses) {
- house.display();
- }
- }
- if (b_drawNodes) drawNodes();
-
- for (int i = 0; i < interactables.length; i++) {
- interactables[i].update();
- interactables[i].display();
- }
-
- for (int i = 0; i < citizen.length; i++) {
- if (citizen[i].b_linked) {
- citizen[i].update();
- if (i != i_selectedCitizen)
- citizen[i].display();
- if (b_debug)
- citizen[i].debug();
- }
- }
-
- if (b_controlEyeWithMouse) {
- 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) ;
- }
- citizen[i_selectedCitizen].display();
-
- pg_map.endDraw();
- image(pg_map, i_mapOffsetX, i_mapOffsetY, i_mapW, i_mapH);
- drawUI();
- }
|