-
Notifications
You must be signed in to change notification settings - Fork 0
/
Map_maker.js
101 lines (69 loc) · 1.76 KB
/
Map_maker.js
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
let sclX = 10;
let sclY = 10;
let row;
let col;
let mat;
let mapa;
/*
function preload (){
mapa = loadBytes ('https://drive.google.com/file/d/17I1W6G6JvnPK8C9YxalNdUFJ8b9t3fcM/view?usp=sharing');
print (mapa);
}*/
function setup() {
createCanvas(280, 360);
background(255);
mat = Array.from(Array(36), _ => Array(28).fill(0));
}
function draw() {
gridLines();
//row = floor(mouseY / sclY);
//col = floor(mouseX / sclX);
if (mouseIsPressed) {
if (mouseButton === LEFT) {
row = floor(mouseY / sclY);
col = floor(mouseX / sclX);
fill(0);
square (col * sclX, row * sclY, 10);
mat[row][col] = 1; //PREENCHENDO AS PAREDES
print (row, col);
}
/*
if (mouseButton === RIGHT) {
rect(25, 25, 50, 50);
}
*/
if (mouseButton === CENTER) { //caso vc tenha desenhado errado
row = floor(mouseY / sclY);
col = floor(mouseX / sclX);
fill (255);
square (col * sclX, row * sclY, 10);
mat[row][col] = 0; //coloca 0 pq eh caminho livre
print (row, col);
}
}
//print (row, col);
}
// ******************* CORPO DE FUNCOES DO CODIGO ******************* //
function gridLines(){
stroke(0);
for(let i = 0; i <= width + sclX; i += sclX){
line(i,0, i, height);
}
for(let i = 0; i <= height + sclY; i += sclY){
line(0,i, width, i);
}
}
function keyPressed () {
if (keyCode == 32){
console.clear();
print (mat);
}
if (keyCode == ENTER){
let json = {};
//json.m = mat;
var arrayToString = JSON.stringify(Object.assign({}, mat)); // convert array to string
json = JSON.parse(arrayToString); // convert string to json object
saveJSON(json, 'Official_map.json');
//save(mat, "Mapa_Pac_man.txt");
}
}