130 lines
3.4 KiB
Plaintext
130 lines
3.4 KiB
Plaintext
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 = 1;
|
|
float f_walkSpeedMax = 2;
|
|
|
|
boolean b_cameraLock = false;
|
|
boolean b_autoPlay = false;
|
|
|
|
|
|
boolean b_controlEyeWithMouse;
|
|
|
|
|
|
boolean b_debug = true;
|
|
boolean b_drawNodes = false;
|
|
boolean b_housesTexts = false;
|
|
|
|
float f_nodeResolution = 0.2; //defines density of path-finding nodes, multiplied with resolution
|
|
int i_pathAlgorithm = 4;
|
|
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;
|
|
int i_makeThemGoC;
|
|
void draw() {
|
|
background(127);
|
|
|
|
clientCommunication();
|
|
|
|
if (b_makeThemGo) {
|
|
citizen[i_makeThemGoC].goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)), 10);
|
|
i_makeThemGoC ++;
|
|
if (i_makeThemGoC >= citizen.length) {
|
|
b_makeThemGo = false;
|
|
i_makeThemGoC = 0;
|
|
}
|
|
println(i_makeThemGoC);
|
|
}
|
|
|
|
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 && b_housesTexts) {
|
|
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();
|
|
}
|