-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmundo.js
More file actions
219 lines (157 loc) · 4.75 KB
/
mundo.js
File metadata and controls
219 lines (157 loc) · 4.75 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
p5.disableFriendlyErrors = true
/*
coisas relativas a criação do mundo salas e os escambau
TODOS:
-refazer a geração de mundo para que faça uma matriz e plote essa matriz
os movimentos e colisoes todas feitas usando a matriz ao inves dessa merda de .play
-portas
-perfumarias
-montar um sistema de enxaixe de uma sala na outra
DONE:
-criar paredes
-overlays com efeitos de luz (UI)
*/
let gsala
let imgchao
let gparedes
let gcolisor
let imgCSE
let imgCSD
let imgCIE
let imgCID
let imgE
let imgD
let imgC
let imgB
function colide (a, b){
console.log(a.nome+" colidiu com "+ b.nome)
}
function initMundo ()
{
console.log("initmundo")
imgchao = loadImage ("Arte/Paredes/17.png")
imgCSE= loadImage ("Arte/Paredes/00.png") //alterar pra usar um so mirror h e w
imgCC= loadImage ("Arte/Paredes/08.png")
imgCSE2= loadImage ("Arte/Paredes/07.png")
// imgCID= loadImage ("Arte/Paredes/00.png")
imgE= loadImage ("Arte/Paredes/14.png")
// imgD= loadImage ("Arte/Paredes/14.png")
imgC= loadImage ("Arte/Paredes/02.png")
// imgB= loadImage ("Arte/Paredes/02.png")
gsala = new Group()
gparedes = new Group()
// gparedes.overlaps(gcolisor, colide)
// gcolisor.overlaps(gparedes, colide)
let spr
const tsala = 4
const ttile = 64
const woffset = width/2 - ((ttile*tsala)/2)
const hoffset = height/2 - ((ttile*tsala)/2)
const tsalapxw = woffset + (ttile*tsala)
const tsalapxh = hoffset + (ttile*tsala)
for (let ax = woffset; ax<=tsalapxw; ax += ttile){
for (let ay = hoffset; ay<=tsalapxh; ay += ttile){
//primeira coluna
let xx = (ax - woffset)/ttile
let yy = (ay - hoffset)/ttile
if(ay==hoffset)
{
//canto superior esquerdo
if (ax==woffset)
{
plotaTile (imgCSE, ax, ay, true, "CSE")
//console.log ((ax - woffset)/ttile)
}
//canto inferior esquerdo
if (ax==tsalapxw)
{
plotaTile (imgCSE, ax, ay, true, "CIE")
//console.log ((ax - woffset)/ttile)
}
//coloca toda a parte superior que faltou
if ((ax>woffset) && (ax <tsalapxw))
{
plotaTile (imgC, ax, ay, true, "C")
}
}
if (ay==tsalapxh)
{
//canto inferior esquerdo
if (ax==woffset)
{
plotaTile (imgCSE, ax, ay, true, "CIE")
}
//canto inferior direito
if (ax==tsalapxw)
{
plotaTile (imgCSE, ax, ay, true,"CID")
}
//coloca toda a parte superior que faltou
if ((ax>woffset) && (ax <tsalapxw))
{
plotaTile (imgC, ax, ay, true, "B")
}
}
if (ay > hoffset)
{
//parede esquerda
if (ax == woffset)
{
plotaTile (imgE, ax, ay, true, "E")
}
//parede direita
if (ax == tsalapxw)
{
plotaTile (imgE, ax, ay, true), "D"
}
}
//aqui plota o chao
if ( (ay>hoffset) && (ay < tsalapxh) && (ax>woffset) && (ax<tsalapxw) )
{
if (yy == 1 && xx>0 ){
plotaTile(imgCC,ax,ay)
}
if (yy == 1 && xx ==0)
{
plotaTile(imgCSE2,ax,ay)
}else if (xx > 0 ){
plotaTile(imgchao,ax,ay)
}
}
}
}
}
function getIndex()
{
const tsala = 4
const ttile = 64
const woffset = personagem.x - ((ttile*tsala)/2)
const hoffset = personagem.y - ((ttile*tsala)/2)
console.log(woffset+ " "+ hoffset)
}
function plotaTile (imagem, ax, ay, parede = false, nome = "chao")
{
const tsala = 4
const ttile = 64
const woffset = width/2 - ((ttile*tsala)/2)
const hoffset = height/2 - ((ttile*tsala)/2)
let spr = new Sprite (imagem);
spr.static = true
spr.x = ax+64
spr.y = ay+64
spr.height = 64
spr.width = 64
spr.xx = (ax - woffset)/ttile
spr.yy = (ay - hoffset)/ttile
spr.parede = false
spr.nome = nome
if (parede){
spr.parede = true
gparedes.push(spr);
}
gsala.push (spr)
}
function drawMundo ()
{
gsala.draw()
}