-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
276 lines (253 loc) · 6.88 KB
/
Copy pathscript.js
File metadata and controls
276 lines (253 loc) · 6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
//Drag n drop imagez
var green;
var blue;
var brown;
var apt1;
var apt2;
var house;
var transparent;
//Backgrounds
var farmBg;
var cityBg;
var suburbBg;
//Displaymode stuff
var officialMap;
var pinImage;
//Set up some arrays!
var imageArr;
var imageIndex = 0;
var bgArr;
var bgIndex = 0;
var newTree;
var newTrees = [];
var pins = [];
//Drag n drop specific weirdness
var currentSprite;
var stationaryCurrentSprite;
var bx;
var by;
var treeWidth = 64;
var treeHeight = 73;
var overTree = false;
var locked = false;
var xOffset = 0.0;
var yOffset = 0.0;
var createMode = false;
var placeMap = false;
function preload(){
green = loadImage("images/greenspace.png");
blue = loadImage("images/bluespace.png");
brown = loadImage("images/brownspace.png");
apt1 = loadImage("images/buildingish.png");
apt2 = loadImage("images/buildingish2.png");
house = loadImage("images/house.png");
transparent = loadImage("images/transparent.png");
farmBg = loadImage("images/farmtemp.png");
suburbBg = loadImage("images/streettemp.png");
cityBg = loadImage("images/citytemp.png");
officialMap = loadImage("images/officialmap.png");
pinImage = loadImage("images/pin.png");
}
function setup() {
document.getElementById("userInput").style.display = "none";
var canvas1 = createCanvas(1425, 780);
canvas1.parent("canvasHolder");
bx = 50;
by = 50;
imageArr = [green, blue, brown, apt1, apt2, house, transparent];
bgArr = [farmBg, suburbBg, cityBg, transparent];
}
function draw() {
//Split the draw function into two modes, create mode and display mode
if(createMode){
if(bgIndex == 0 || bgIndex % 1 == 0){
background("white");
background(bgArr[bgIndex]);
}
drawSprites();
// Test if the cursor is over the box
if (
mouseX > bx - treeWidth &&
mouseX < bx + treeWidth &&
mouseY > by - treeHeight &&
mouseY < by + treeHeight
) {
overTree = true;
currentSprite.position.x = bx;
currentSprite.position.y = by;
}
else{
overTree = false;
}
//Press enter to delete the most recently dropped item
if(keyIsDown(13) && newTree){
newTree.remove();
}
}
//displayMode
else{
background(officialMap);
drawSprites();
}
}
//Key press function
function keyPressed(){
if(createMode){
if(keyCode == RIGHT_ARROW){
if(imageIndex < imageArr.length - 1){
imageIndex+=0.5;
}
else{
imageIndex = -0.5;
}
if(imageIndex == 0 || imageIndex%1 == 0){
currentSprite.remove();
currentSprite = createSprite(50, 50, 64, 73);
currentSprite.addImage(imageArr[imageIndex]);
stationaryCurrentSprite.remove();
stationaryCurrentSprite = createSprite(50, 50, 64, 73);
stationaryCurrentSprite.addImage(imageArr[imageIndex]);
}
}
else if(keyCode == LEFT_ARROW){
if(imageIndex > 0){
imageIndex-=0.5;
}
else{
imageIndex = imageArr.length - 0.5;
}
if(imageIndex == 0 || imageIndex%1 == 0){
currentSprite.remove();
currentSprite = createSprite(50, 50, 64, 73);
currentSprite.addImage(imageArr[imageIndex]);
stationaryCurrentSprite.remove();
stationaryCurrentSprite = createSprite(50, 50, 64, 73);
stationaryCurrentSprite.addImage(imageArr[imageIndex]);
}
}
//this is for A
else if(keyCode == DOWN_ARROW){
if(bgIndex > 0){
bgIndex-=0.5;
}
else{
bgIndex = bgArr.length - 0.5;
}
}
//this is for D
else if(keyCode == UP_ARROW){
if(bgIndex < bgArr.length - 1){
bgIndex+=0.5;
}
else{
bgIndex = -0.5;
}
}
}
//displayMode
else{
}
}
var viewingImage = false;
//Mouse functions
function mousePressed() {
if (overTree) {
locked = true;
} else {
locked = false;
}
xOffset = mouseX - bx;
yOffset = mouseY - by;
//If a user clicks on a pin, open the map assigned to said pin
if(!createMode && !placeMap && !viewingImage){
for(var i = 0; i < pins.length; i++){
var ohD = dist(mouseX, mouseY, pins[i].position.x, pins[i].position.y);
if(ohD <= 5){
viewingImage = true;
window.open("images/map" + i + ".jpeg");
var delayInMilliseconds = 1000; //1 second
setTimeout(function() {
viewingImage = false;
}, delayInMilliseconds);
}
}
}
}
//Continue adjusting position of image
function mouseDragged() {
if (locked) {
bx = mouseX - xOffset;
by = mouseY - yOffset;
}
}
function mouseReleased() {
//Drop and place image
if(locked){
newTree = createSprite(bx, by, 64, 73);
newTree.addImage(imageArr[imageIndex]);
append(newTrees, newTree);
bx = 50;
by = 50;
currentSprite.position.x = bx;
currentSprite.position.y = by;
}
locked = false;
//Drop a pin!
if(!createMode && placeMap){
var pinSprite = createSprite(mouseX, mouseY, 32, 32);
pinSprite.addImage("images/transparent.png", transparent);
pinSprite.addImage("images/pin.png", pinImage);
pinSprite.changeAnimation("images/pin.png");
append(pins, pinSprite);
placeMap = false;
document.getElementById("createMapButton").style.display = "inline";
}
}
var pinIndex = 0;
//This function is called when the create map button is clicked, and automatically switches the mode from create to display
function createMap(){
//createMode to displayMode
if(createMode){
textSize(30);
text("Map by: " + document.getElementById("userInput").value, 625, 30);
saveCanvas('map' + pinIndex, 'jpeg');
pinIndex++;
createMode = false;
placeMap = true;
document.getElementById("userInput").style.display = "none";
document.getElementById("createMapButton").style.display = "none";
currentSprite.remove();
stationaryCurrentSprite.remove();
document.getElementById("userInput").value = "";
//Remove drag n dropped images
for(var i = 0; i < newTrees.length; i++){
newTrees[i].remove();
}
newTrees = [];
//Display pins
for(var i = 0; i < pins.length; i++){
pins[i].changeAnimation("images/pin.png");
}
}
//displayMode to createMode
else{
createMode = true;
document.getElementById("userInput").style.display = "inline";
var canvas1 = createCanvas(1425, 780);
canvas1.parent("canvasHolder");
bx = 50;
by = 50;
currentSprite = createSprite(50, 50, 64, 73);
currentSprite.addImage(green);
stationaryCurrentSprite = createSprite(50, 50, 64, 73);
stationaryCurrentSprite.addImage(green);
imageArr = [green, blue, brown, apt1, apt2, house, transparent];
bgArr = [farmBg, suburbBg, cityBg, transparent];
imageIndex = 0;
bgIndex = 0;
//Hide the pins!
for(var i = 0; i < pins.length; i++){
pins[i].changeAnimation("images/transparent.png");
}
}
}