added zoom, sketch resize and ui panel
This commit is contained in:
@@ -38,7 +38,7 @@ class Citizen {
|
||||
f_yPos = i_ySpawn;
|
||||
rNodes = pathFinder.getRoute();
|
||||
|
||||
if (b_randomRun) goTo(int(random(0, width)), int(random(0, height)));
|
||||
if (b_randomRun) goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)));
|
||||
b_linked = true;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class Citizen {
|
||||
} else {
|
||||
b_moving = false;
|
||||
nextNode = 0;
|
||||
if (b_randomRun)goTo(int(random(0, width)), int(random(0, height)));
|
||||
if (b_randomRun)goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ class Citizen {
|
||||
rNodesList.add(rNodes[i]);
|
||||
}
|
||||
} else {
|
||||
if (b_randomRun) goTo(int(random(0, width)), int(random(0, height)));
|
||||
if (b_randomRun) goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import pathfinder.*;
|
||||
PImage img_houses;
|
||||
PImage img_streets;
|
||||
PGraphics pg_map;
|
||||
int i_mapOffsetX, i_mapOffsetY, i_offsetStartX, i_offsetStartY;
|
||||
int i_mapOffsetX, i_mapOffsetY, i_mapOffsetStartX, i_mapOffsetStartY;
|
||||
int i_biggestHouseSize;
|
||||
|
||||
ArrayList<House> houses = new ArrayList<House>();
|
||||
|
||||
@@ -1,39 +1,102 @@
|
||||
int i_uiX = 0, i_uiY = 280, i_uiW = width, i_uiH = height - i_uiY;
|
||||
void initUI() {
|
||||
i_uiX = 0;
|
||||
i_uiY = 420;
|
||||
i_uiW = width;
|
||||
i_uiH = height - i_uiY;
|
||||
}
|
||||
|
||||
int i_uiX, i_uiY, i_uiW, i_uiH;
|
||||
int i_uiOffsetX, i_uiOffsetY, i_uiOffsetStartX, i_uiOffsetStartY, i_initUiY;
|
||||
void drawUI() {
|
||||
strokeWeight(1);
|
||||
line(i_uiX, i_uiY, i_uiX+i_uiW, i_uiY);
|
||||
strokeWeight(0);
|
||||
fill(255, 230);
|
||||
rect(i_uiX, i_uiY, i_uiW, i_uiH);
|
||||
|
||||
|
||||
void UI() {
|
||||
fill(0);
|
||||
textSize(30);
|
||||
textAlign(LEFT);
|
||||
text(String.format("%02d", hour()) + ":" + String.format("%02d", minute()) + ":" + String.format("%02d", second()), 10, 30);
|
||||
|
||||
text(String.format("%02d",hour()) + ":" + String.format("%02d",minute()) + ":" + String.format("%02d",second()), 10, 30);
|
||||
textSize(15);
|
||||
text("FPS: " + int(frameRate), 10, 45);
|
||||
|
||||
|
||||
line(i_uiX,i_uiY,i_uiX+i_uiW, i_uiY);
|
||||
fill(255);
|
||||
rect(i_uiX, i_uiY, i_uiW, i_uiH);
|
||||
|
||||
|
||||
text("FPS: " + int(frameRate), 10, i_uiY + 15);
|
||||
}
|
||||
|
||||
boolean b_changeOffset;
|
||||
boolean b_mouseChangeMapOffset, b_mouseChangeUiHeight;
|
||||
boolean b_hoverUI;
|
||||
|
||||
void mousePressed() {
|
||||
if (mouseButton == RIGHT){
|
||||
b_changeOffset = true;
|
||||
i_offsetStartX = mouseX - i_mapOffsetX;
|
||||
i_offsetStartY = mouseY - i_mapOffsetY;
|
||||
if (mouseButton == LEFT) {
|
||||
if (mouseX >= i_uiX && mouseX <= i_uiX+i_uiW && mouseY >= i_uiY-10 && mouseY <= i_uiY+10) {
|
||||
b_mouseChangeUiHeight = true;
|
||||
i_uiOffsetStartY = mouseY;
|
||||
i_initUiY = i_uiY;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
if (mouseButton == CENTER) {
|
||||
b_mouseChangeMapOffset = true;
|
||||
i_mapOffsetStartX = mouseX - i_mapOffsetX;
|
||||
i_mapOffsetStartY = mouseY - i_mapOffsetY;
|
||||
}
|
||||
if (mouseButton == RIGHT) {
|
||||
if (b_mapZoom)
|
||||
citizen[0].goTo(constrain((mouseX-i_mapOffsetX)*2, 0, pg_map.width), constrain((mouseY-i_mapOffsetY)*2, 0, pg_map.height));
|
||||
else
|
||||
citizen[0].goTo(constrain(mouseX-i_mapOffsetX, 0, pg_map.width), constrain(mouseY-i_mapOffsetY, 0, pg_map.height));
|
||||
}
|
||||
if (mouseButton == LEFT) citizen[0].goTo(constrain(mouseX-i_mapOffsetX, 0, pg_map.width), constrain(mouseY-i_mapOffsetY, 0, pg_map.height));
|
||||
}
|
||||
void mouseDragged() {
|
||||
if (b_changeOffset) {
|
||||
i_mapOffsetX = (mouseX - i_offsetStartX);
|
||||
i_mapOffsetY = (mouseY - i_offsetStartY);
|
||||
if (b_mouseChangeMapOffset) {
|
||||
i_mapOffsetX = (mouseX - i_mapOffsetStartX);
|
||||
i_mapOffsetY = (mouseY - i_mapOffsetStartY);
|
||||
}
|
||||
if (b_mouseChangeUiHeight) {
|
||||
i_uiY = mouseY - i_uiOffsetStartY + i_initUiY;
|
||||
if (i_uiY > height) i_uiY = height;
|
||||
i_uiH = height - i_uiY;
|
||||
}
|
||||
}
|
||||
void mouseReleased() {
|
||||
b_changeOffset = false;
|
||||
b_mouseChangeMapOffset = false;
|
||||
b_mouseChangeUiHeight = false;
|
||||
}
|
||||
|
||||
|
||||
//bad
|
||||
//int maxScale = 5;
|
||||
//float zoomFactor = 0.4;
|
||||
//int i_imgCenterX;
|
||||
//int i_imgCenterY;
|
||||
int i_mapScale = 1;
|
||||
boolean b_mapZoom;
|
||||
float e;
|
||||
void mouseWheel(MouseEvent event) {
|
||||
e = event.getAmount();
|
||||
|
||||
if (e == -1) {
|
||||
i_mapScale+=1;
|
||||
}
|
||||
if (e == 1) {
|
||||
i_mapScale-=1;
|
||||
}
|
||||
constrain(i_mapScale, 0, 2);
|
||||
switch(int(e)) {
|
||||
case 1:
|
||||
if (!b_mapZoom) {
|
||||
i_mapW = pg_map.width/2;
|
||||
i_mapH = pg_map.height/2;
|
||||
i_mapOffsetX -= 3*i_mapOffsetX/4;
|
||||
i_mapOffsetY -= 3*i_mapOffsetY/4;
|
||||
b_mapZoom = true;
|
||||
}
|
||||
break;
|
||||
case -1:
|
||||
i_mapW = pg_map.width;
|
||||
i_mapH = pg_map.height;
|
||||
b_mapZoom = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,29 +9,41 @@ boolean b_drawPathDestination = true;
|
||||
boolean b_randomRun = false;
|
||||
float f_nodeResolution = 0.2; //defines density of path-finding nodes, multiplied with resolution
|
||||
int i_pathAlgorithm = 3;
|
||||
|
||||
int i_selectedCitizen = 0;
|
||||
int i_mapW, i_mapH;
|
||||
int i_windowW, i_windowH;
|
||||
int i_viewportW, i_viewportH;
|
||||
//void mousePressed() {
|
||||
// citizen[0].goTo(constrain(mouseX, 0, img_houses.width), constrain(mouseY, 0, img_houses.height));
|
||||
//}
|
||||
|
||||
|
||||
void setup() {
|
||||
size(400,400);
|
||||
size(700,600);
|
||||
//blendMode(MULTIPLY);
|
||||
|
||||
i_windowW = width;
|
||||
i_windowH = height;
|
||||
|
||||
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.setSize(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();
|
||||
initUI();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void initCitizen(){
|
||||
|
||||
|
||||
@@ -55,8 +67,18 @@ void initCitizen(){
|
||||
}
|
||||
|
||||
|
||||
void pre() {
|
||||
if (i_windowW != width || i_windowH != height) {
|
||||
// Sketch window has resized
|
||||
i_windowW = width;
|
||||
i_windowH = height;
|
||||
i_uiW = width;
|
||||
i_uiH = height - i_uiY;
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
background(127);
|
||||
|
||||
pg_map.beginDraw();
|
||||
|
||||
@@ -80,9 +102,6 @@ void draw() {
|
||||
}
|
||||
|
||||
pg_map.endDraw();
|
||||
image(pg_map, i_mapOffsetX, i_mapOffsetY);
|
||||
UI();
|
||||
|
||||
|
||||
|
||||
image(pg_map, i_mapOffsetX, i_mapOffsetY, i_mapW, i_mapH);
|
||||
drawUI();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user