-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava.js
More file actions
7860 lines (7483 loc) · 227 KB
/
java.js
File metadata and controls
7860 lines (7483 loc) · 227 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const TypePage = document.body.dataset.page;
const table = document.getElementById("screen")
const eraser = document.getElementById("eraser")
const hand = document.getElementById("hand")
const Gotero = document.getElementById("gotita")
const flag = document.getElementById("banderin")
const but2 = document.getElementById("saved")
const but4 = document.getElementById("start")
const depot = document.getElementById("depot")
const CutS = document.getElementById("colideS")
const CutF = document.getElementById("colideF")
const RC1 = document.getElementById("color1")
const RC2 = document.getElementById("color2")
const RC3 = document.getElementById("color3")
const loadbut = document.getElementById("load")
const savebut = document.getElementById("save")
const chekbox = document.querySelectorAll(".chek")
const time = document.getElementById("p")
const mid = document.getElementById("blockC4")
const butup = document.getElementById("up")
const butdw = document.getElementById("down")
const butleft = document.getElementById("derecha")
const butrigth = document.getElementById("izquierda")
const controladores = document.getElementById("controladores")
const pestana = document.getElementById("controladores3")
const ancho = table.style.width
const largo = table.style.height
const LVselector = document.getElementById("selector-nivel")
flag.addEventListener("click",() =>{
DrawMode = 7
DrawsModes[7].Started()
})
eraser.addEventListener("click",() =>{
DrawMode = 1
DrawsModes[1].Started()
})
Gotero.addEventListener("click",() =>{
DrawMode = 6
DrawsModes[6].Started()
})
hand.addEventListener("click",() =>{
DrawMode = 5
DrawsModes[5].Started()
})
let TouchControls = {
Left: false,
Right: false,
Abuton: false,
Bbuton: false,
};
var WaterTexture = new Texture("texturas/Water.png",0,0,96,96)
var ShadowTexture = new Texture("texturas/Shadow.png",0,0,96,96)
var NoTexture = new Texture("texturas/ASCII.png",0,0,30,30)
var LavaTexture = new Texture("texturas/Lava.png",0,0,96,96)
var PaleteTexture = new Texture("texturas/character.png",0,0,256,256)
var Wellcome = new Texture("texturas/Wellcome.png",0,0,80,20)
var TexturesArray = {WaterTexture, ShadowTexture, NoTexture, LavaTexture, PaleteTexture};
const isTouchDevice =
'ontouchstart' in window ||
navigator.maxTouchPoints > 0;
var LeftButon = undefined
var RightButon = undefined
var Abuton = undefined
var Bbuton = undefined
function createTouchButtons(){
if(isTouchDevice){
var LeftButon = document.getElementById("LeftButon")
var RightButon = document.getElementById("RightButon")
var Abuton = document.getElementById("Abuton")
var Bbuton = document.getElementById("Bbuton")
LeftButon.style.display = "block";
LeftButon.addEventListener("touchstart", () => TouchControls.Left = true );
LeftButon.addEventListener("touchend", () => TouchControls.Left = false);
RightButon.style.display = "block";
RightButon.addEventListener("touchstart", () => TouchControls.Right = true );
RightButon.addEventListener("touchend", () => TouchControls.Right = false);
Abuton.style.display = "block";
Abuton.addEventListener("touchstart", () => TouchControls.Abuton = true );
Abuton.addEventListener("touchend", () => TouchControls.Abuton = false);
Bbuton.style.display = "block";
Bbuton.addEventListener("touchstart", () => TouchControls.Bbuton = true );
Bbuton.addEventListener("touchend", () => TouchControls.Bbuton = false);
}
}
const Selection = document.getElementById('selection')
function toggleTopMenu() {
Selection.classList.toggle('active');
}
const Level_name = document.getElementById("Level_name");
const inputArchivo = document.getElementById("archivoJson");
const cargarJsonBtn = document.getElementById("cargarJson");
cargarJsonBtn.addEventListener("click", () => {
const archivo = inputArchivo.files[0];
if (archivo) {
const lector = new FileReader();
lector.onload = function(e) {
try {
// Parsear el contenido del archivo y reemplazar el array
SAVE = JSON.parse(e.target.result);
chargeLevelNoTiles()
Level_name.value = inputArchivo.files[0].name.slice(0,-5)
console.log("Después de cargar el archivo:" );
} catch (error) {
console.error("Error al cargar el archivo JSON:", error);
}
};
lector.readAsText(archivo);
} else {
alert("Selecciona un archivo primero.");
}
});
function cargarJSON(Json) {
fetch(Json)
.then(response => {
if (!response.ok) throw new Error("No se pudo cargar el archivo JSON");
return response.json();
})
.then(data => {
SAVE = data
chargeLevelNoTiles()
let Name = Json.slice(0,-5)
Name = Name.slice(13)
Level_name.value = Name
})
}
window.addEventListener("beforeunload", function (e) {
e.preventDefault(); // Requerido para algunos navegadores
e.returnValue = ""; // Necesario para que aparezca el diálogo en otros
});
var Target = ""
const CharacterSelector2 = document.getElementById("Character-selector2")
const chalkboard = document.getElementById("characters")
var SkinSelector = document.getElementById("Skin-selector")
var chalkboard2;
var SkinSelector2;
var Skins_for_players = [
{
PlayerID : 0,
characterSelect : 0 ,
SkinSelect : 0 ,
},
{
PlayerID : 1,
characterSelect : 0 ,
SkinSelect : 1 ,
}
]
function DrawSelectionsSkins(object,Number) {
object.innerHTML = ""
for(let i = 0; i < characters[Number].Img.length ; i++){
object.innerHTML += "<canvas class = Skins id = Skin"+i+" onclick=ChangeSkin("+Number+","+i+") ></canvas>"
}
for(let i = 0; i < characters[Number].Img.length ; i++){
let SkinToPrint = document.getElementById("Skin"+i)
PrinCharacter(SkinToPrint,Number,i)
}
}
function DrawSelectionsSkins2(object,Number) {
object.innerHTML = ""
for(let i = 10; i < characters[Number].Img.length+10 ; i++){
let Skin = i -10
object.innerHTML += "<canvas class = Skins id = Skin"+i+" onclick=ChangeSkin2("+Number+","+Skin+") ></canvas>"
}
for(let i = 10; i < characters[Number].Img.length+10 ; i++){
let SkinToPrint = document.getElementById("Skin"+i)
PrinCharacter(SkinToPrint,Number,i-10)
}
}
function ChangeSkin(characterSelect,SkinSelect){
Skins_for_players[0].SkinSelect = SkinSelect
PrinCharacter(chalkboard,characterSelect,SkinSelect)
}
function ChangeSkin2(characterSelect,SkinSelect){
Skins_for_players[1].SkinSelect = SkinSelect
PrinCharacter(chalkboard2,characterSelect,SkinSelect)
}
document.getElementById("arrowRight").addEventListener('click', function() {
arrowRight_forSkins(0)
PrinCharacter(chalkboard,Skins_for_players[0].characterSelect,0)
DrawSelectionsSkins(SkinSelector,Skins_for_players[0].characterSelect)
})
document.getElementById("arrowLeft").addEventListener('click', function() {
arrowLeft_forSkins(0)
PrinCharacter(chalkboard,Skins_for_players[0].characterSelect,0)
DrawSelectionsSkins(SkinSelector,Skins_for_players[0].characterSelect)
})
function Star_Multiplayer(){
Multiplayer = true
CharacterSelector2.innerHTML =
"<div class=arrow id=arrowRight2></div><canvas id=characters2 ></canvas><div class=arrow id=arrowLeft2></div><div id=Skin-selector2 style= width:64em;height:32em;float:left; > </div>"
chalkboard2 = document.getElementById("characters2")
SkinSelector2 = document.getElementById("Skin-selector2")
PrinCharacter(chalkboard2,Skins_for_players[1].characterSelect,Skins_for_players[1].SkinSelect)
DrawSelectionsSkins2(SkinSelector2,Skins_for_players[1].characterSelect)
document.getElementById("arrowRight2").addEventListener('click', function() {
arrowRight_forSkins(1)
PrinCharacter(chalkboard2,Skins_for_players[1].characterSelect,0)
DrawSelectionsSkins2(SkinSelector2,Skins_for_players[1].characterSelect)
})
document.getElementById("arrowLeft2").addEventListener('click', function() {
arrowLeft_forSkins(1)
PrinCharacter(chalkboard2,Skins_for_players[1].characterSelect,0)
DrawSelectionsSkins2(SkinSelector2,Skins_for_players[1].characterSelect)
})
}
function arrowRight_forSkins(PlayerID){
let Player = Skins_for_players[PlayerID]
Player.characterSelect += -1
Player.SkinSelect = 0
if(Player.characterSelect < 0){Player.characterSelect = characters.length -1 }
}
function arrowLeft_forSkins(PlayerID){
let Player = Skins_for_players[PlayerID]
Player.characterSelect += 1
Player.SkinSelect = 0
if(Player.characterSelect >= characters.length ){Player.characterSelect = 0}
}
function PrinCharacter(Canva,Number,Character,){
let Grid = characters[Number].Grid
let ctx = Canva.getContext("2d");
let image = new Image();
image.src = characters[Number].Img[Character];
let Whit = Math.max(Grid[0],Grid[1])
let X = (Whit - Grid[0]) * 0.5
let Y = (Whit - Grid[1]) * 0.5
Canva.width = Whit
Canva.height = Whit
image.addEventListener("load", (e) => {
let ctx = Canva.getContext("2d")
ctx.drawImage(
image,
0,
0,
Grid[0],
Grid[1],
X,
Y,
Grid[0],
Grid[1],
)
}
)
}
const salvarJsonBtn = document.getElementById("SalvarJson");
salvarJsonBtn.addEventListener("click", () => {
if (Level_name.value.startsWith("(-<= ")) {
console.log("codes Active")
let Value = Level_name.value.slice(5)
Boregito(Value)
}else{
Save_Level_NoTiles()
}
})
PrinCharacter(chalkboard,Skins_for_players[0].characterSelect,Skins_for_players[0].SkinSelect)
DrawSelectionsSkins(SkinSelector,Skins_for_players[0].characterSelect)
let margin_v = '0'
const LLY = document.getElementsByClassName("flecha")
var Xmouse = 0
var Ymouse = 0
var camX = 0
var camY = 0
var bck = []
var CBC = [[255,255,255],[0,0,0]]
RC1.value = CBC[1][0]
RC2.value = CBC[1][1]
RC3.value = CBC[1][2]
let PT = document.getElementById("sprites")
let SelectCB = 1
var ALLCB = document.querySelectorAll(".colorR");
ALLCB[1].style.borderColor = "rgb(256,125,0)"
for(let i = 0; i < ALLCB.length ; i++){
ALLCB[i].addEventListener("click", () => {
SelectCB = i
ALLCB[0].style.borderColor = "rgb(0,0,0)"
ALLCB[1].style.borderColor = "rgb(0,0,0)"
ALLCB[i].style.borderColor = "rgb(256,125,0)"
RC1.value = CBC[i][0]
RC2.value = CBC[i][1]
RC3.value = CBC[i][2]
});
};
ALLCB[0].style.backgroundColor = "#FFF"
ALLCB[1].style.backgroundColor = "#000"
var drawNum = 0
function CS (range,N){
CBC[SelectCB][N] = range.value
ALLCB[SelectCB].style.backgroundColor = "rgb("+ CBC[SelectCB][0] +","+ CBC[SelectCB][1] +","+ CBC[SelectCB][2] +")"
DRAWS[drawNum](PT)
}
const DRAWS = [
function (b){
b.style.backgroundImage = "linear-gradient(180deg,"+ ALLCB[0].style.backgroundColor+","+ALLCB[1].style.backgroundColor+")"
},
function (b){
b.style.backgroundImage = "linear-gradient(90deg,"+ ALLCB[0].style.backgroundColor+","+ALLCB[1].style.backgroundColor+")"
},
function (b){
b.style.backgroundImage = "linear-gradient(45deg,"+ ALLCB[0].style.backgroundColor+","+ALLCB[1].style.backgroundColor+")"
},
function (b){
b.style.backgroundImage = "radial-gradient(circle,"+ ALLCB[0].style.backgroundColor+","+ALLCB[1].style.backgroundColor+")"
},
function (b){
b.style.backgroundImage = "repeating-linear-gradient("+ ALLCB[0].style.backgroundColor+" ,"+ALLCB[1].style.backgroundColor+"50%)"
},
function (b){
b.style.backgroundImage = "repeating-linear-gradient("+ ALLCB[0].style.backgroundColor+" ,"+ALLCB[1].style.backgroundColor+"25%)"
},
function (b){
b.style.backgroundImage = "linear-gradient(180deg,"+ ALLCB[0].style.backgroundColor+"50%,"+ALLCB[1].style.backgroundColor+"50%,"+ALLCB[0].style.backgroundColor+")"
},
]
let ALLDRAWS = document.getElementById("Draw-selector")
function Draw_star (){
for(let i = 0; i < DRAWS.length ; i++){
ALLDRAWS.innerHTML += "<canvas class=DRAWING id=draw"+i+"></canvas>"
DRAWS[i](document.getElementById("draw"+i))
}
for(let i = 0; i < DRAWS.length ; i++){
let x = document.getElementById("draw"+i)
DRAWS[i](x)
x.addEventListener("click", () =>{
drawNum = i
DRAWS[drawNum](PT)
})
}
}
DRAWS[0](PT)
const songSelector = document.getElementById("songSelector");
MusicList.forEach(opcion => {
let opt = document.createElement("option");
opt.className = "Text"
opt.value = opcion.Crs;
opt.textContent = opcion.Name;
songSelector.appendChild(opt);
});
const audioPlayer = document.getElementById("audioPlayer");
var LevelSelected = 'Niveles JSON/LEVELNULL.json'
songSelector.addEventListener("change", function() {
let selectedSong = this.value;
if (selectedSong) {
audioPlayer.src = selectedSong;
backgroundMusic.src = selectedSong;
backgroundMusicSrc = selectedSong
} else {
audioPlayer.pause();
audioPlayer.src = "";
backgroundMusic.src = ""
}
});
const LevelSelector = document.getElementById("LevelSelector");
LevelSelector.addEventListener("change", function() {
LevelSelected = this.value;
})
function test (A){
var fileName = "myfile.txt";
js = JSON.stringify(A)
var fileContent = js
var myFile = new Blob([fileContent], {type: 'text/plain'});
window.URL = window.URL || window.webkitURL;
var dlBtn = document.getElementById("download");
dlBtn.setAttribute("href", window.URL.createObjectURL(myFile));
dlBtn.setAttribute("download", fileName);
}
const jN =document.querySelectorAll("canvas");
let sidesX = false
let sidesY = false
let r4 = document.getElementById("r4")
let r5 = document.getElementById("r5")
const k1B = document.getElementById("blockC1");
const k2B = document.getElementById("blockC2");
function transform_to_image (A){
var imageURL = A.toDataURL('image/png'); // Convertir canvas a Data URL
var link = document.createElement('a'); // Crear un enlace <a>
link.href = imageURL;
link.download = 'canvas-image.png'; // Nombre del archivo de descarga
link.click(); // Activar la descarga
}
Draw_star()
const tablestyle = getComputedStyle(table)
var PLUSRight = document.getElementById("PLUSRight")
var PLUSLeft = document.getElementById("PLUSLeft")
PLUSRight.addEventListener("click", () => {
BlockResolutionState --
if(BlockResolutionState < 0){
BlockResolutionState = 0
}else{
BlockResolutionStates[BlockResolutionState]()
}
})
PLUSLeft.addEventListener("click", () => {
BlockResolutionState ++
if(BlockResolutionState > BlockResolutionStates.length -1){
BlockResolutionState = BlockResolutionStates.length -1
}else{
BlockResolutionStates[BlockResolutionState]()
}
})
var BlockResolutionStates = [
function (){
PLUSRight.style.backgroundPosition = "-64px -16px"
PLUSLeft.style.backgroundPosition = "-96px -16px"
change_BlockResolution(8)
},
function (){
PLUSRight.style.backgroundPosition = "-80px -16px"
PLUSLeft.style.backgroundPosition = "-96px -16px"
change_BlockResolution(12)
},
function (){
PLUSRight.style.backgroundPosition = "-80px -16px"
PLUSLeft.style.backgroundPosition = "-96px -16px"
change_BlockResolution(16)
},
function (){
PLUSRight.style.backgroundPosition = "-80px -16px"
PLUSLeft.style.backgroundPosition = "-96px -16px"
change_BlockResolution(24)
},
function (){
PLUSRight.style.backgroundPosition = "-80px -16px"
PLUSLeft.style.backgroundPosition = "-64px -16px"
change_BlockResolution(32)
},
]
function CreateWidth(){
let screenView = 0
if(100 >= (extratNumbers(tablestyle.width))*1 || 1000 <= (extratNumbers(tablestyle.width))*1){
screenView = window.innerWidth
}else{
screenView = (extratNumbers(tablestyle.width))*1
}
return screenView;
}
function CreateHeight(){
let screenView = 0
if(100 >= (extratNumbers(tablestyle.height))*1 || 1000 <= (extratNumbers(tablestyle.height))*1){
screenView = window.innerHeight
}else{
screenView = (extratNumbers(tablestyle.height))*1
}
return screenView;
}
var BlockInGame = 32
var BlockResolution = 16
var BlockResolutionState = 2
if(TypePage === 'UniversalScreen'){
var screenWidth = 512
var screenHeigth = 512
var ShowScreenWidth = (extratNumbers(tablestyle.width))*1
var ShowScreenHeigth = (extratNumbers(tablestyle.height))*1
}else{
var screenWidth = CreateWidth()
var screenHeigth = CreateHeight()
var ShowScreenWidth = screenWidth
var ShowScreenHeigth = screenHeigth
}
var GridWidth = (SAVE.X * BlockResolution)
var GridHeight = (SAVE.Y * BlockResolution)
const screenWidthHalf = Math.round(screenWidth/2)
const screenHeigthHalf = Math.round(screenHeigth/2)
var screen_resoltion = 16 * BlockResolution
var scale_sprites = 32 / BlockResolution
var limitXGird = Math.round((GridWidth / BlockResolution)+0.4)
var limitYGird = Math.round((GridHeight / BlockResolution)+0.4)
const limitX = Math.round((screenWidth / 32)+1.4)
const limitY = Math.round((screenHeigth / 32)+1.4)
const limitXHalf = Math.round((limitX / 2)+0)
const limitYHalf = Math.round((limitY / 2)-0.4)
var margin_screen = GridHeight - screen_resoltion
var SAVE = window.SAVE
var Tiles = SAVE.tiles
var color_palete = window.Palete
var backgroundMusicTrack = SAVE.backgroundMusicTrack
var LC = SAVE.LevelCol.slice()
var LevelEfects = []
var Level_Sprites = SAVE.Levelsprites.slice()
var BackgroundsInLevel = []
var backgroundMusicCollection = []
var TilesCollection = []
var ColorSelected = "#FFF"
var Tileselect = 0
var image_collection = []
var image_collection_offSet = []
var imageCords = [0]
var SoundEffectsCollection = []
var SoundEffectsCords = []
var functions_collection = []
var functionsCords = [1]
var Scrips_collection = []
var ScripsCords = [1]
var backgroundBase = SAVE.StyleBackground
var Limit_Rigth = (32 * limitXGird)*-1
var Limit_Up = (32 * limitYGird)
var Limit_Left = 0
var Limit_Down = 0
var totalprizes = SAVE.totalPrizes
var startX = SAVE.StartX
var startY = SAVE.StartY
var topScreen = (extratNumbers(tablestyle.top))*1
var leftScreen = (extratNumbers(tablestyle.left))*1
// cambia de tamaño la pagina
if(TypePage === 'UniversalScreen'){
window.addEventListener("resize", () => {
ShowScreenWidth = (extratNumbers(tablestyle.width))*1
ShowScreenHeigth = (extratNumbers(tablestyle.height))*1
});
}
document.addEventListener('mousemove', (event) => {
Xmouse = event.clientX - leftScreen
Ymouse = event.clientY - topScreen
});
reset_functions_and_scrips()
var LevelScript = undefined
function chargeLevelNoTiles(){
if(LevelScript != undefined){
AntiBoregito(LevelScript)
LevelScript = undefined
}
DegenerateValue = 128
TileTeleportType = SAVE.scroll_configuration
AZAR = false
backgroundMusic.pause(); // Pausa el audio
backgroundMusic.currentTime = 0; // Reinicia al inicio
audioPlayer.pause();
audioPlayer.src = "";
if(SAVE.StyleBackground != undefined && SAVE.StyleBackground != ''){
backgroundBase = SAVE.StyleBackground
}else{
backgroundBase = 'linear-gradient(0deg, rgb(0, 0, 255), rgb(0, 255, 255))'
}
changeBackground(backgroundBase)
color_palete = window.Palete
backgroundMusicTrack = SAVE.backgroundMusicTrack
if(SAVE.totalPrizes != null){
totalprizes = SAVE.totalPrizes
}else{
totalprizes = 0
}
if(SAVE.StartX != undefined){
startX = SAVE.StartX
}else{
startX = 8
}
if(SAVE.StartY != undefined){
startY = SAVE.StartY
}else{
startY = 8
}
Xsize.value = SAVE.X
Ysize.value = SAVE.Y
LC = SAVE.LevelCol.slice()
effects_in_game = []
if(SAVE.LevelEfects != undefined){
for(let i = 0; i < SAVE.LevelEfects.length ; i++){
effe = SAVE.LevelEfects[i]
effects_in_game.push(new effect(effe[0],TexturesArray[effe[1]],effe[2],effe[3],effe[4],effe[5],effe[6],effe[7],effe[8],effe[9]))
}
}
SpritesInGrid = []
createSpritesInGrid ()
BackgroundsInLevel = []
backgroundMusicCollection = []
for(let i = 0; i < SAVE.backgroundMusic.length ; i++){
backgroundMusicCollection.push(new Audio(SAVE.backgroundMusic[i]))
}
backgroundMusicSrc = SAVE.backgroundMusic[0]
backgroundMusic = backgroundMusicCollection[backgroundMusicTrack]
backgroundMusic.loop = true; // Activar reproducción en bucle
for(let i = 0; i < SAVE.backgroundImages.length ; i++){
BCC = SAVE.backgroundImages[i]
BackgroundsInLevel.push(new Background(BCC[0],BCC[1],BCC[2],BCC[3],BCC[4],BCC[5],BCC[6],BCC[7],BCC[8],BCC[9],BCC[10]))
}
change_BlockResolution(BlockResolution)
limits_and_alture()
buton[1](0)
if(SAVE.Script != undefined){
Boregito(SAVE.Script)
LevelScript = SAVE.Script
}
}
function Save_Level_NoTiles(){
const {tiles, ... SAVEcopy} = SAVE
SAVEcopy.backgroundMusic =[ backgroundMusicSrc]
SAVEcopy.StartX = startX
SAVEcopy.StartY = startY
SAVEcopy.totalPrizes = totalprizes
SAVEcopy.StyleBackground = backgroundBase
SAVEcopy.LevelCol = LC
SAVEcopy.Levelsprites = SpritesInGrid
Array_to_JSON(SAVEcopy)
}
function Push_effect(type,texture,Width,Height,sideX,altureX,sideY,altureY,growX,growY){
effects_in_game.push(new effect(type,TexturesArray[texture],Width,Height,sideX,altureX,sideY,altureY,growX,growY))
if(SAVE.LevelEfects == undefined){SAVE.LevelEfects = []}
SAVE.LevelEfects.push([type,texture,Width,Height,sideX,altureX,sideY,altureY,growX,growY])
}
function limits_and_alture(){
if(SAVE.limit_rigth == false){
Limit_Rigth = (32 * limitXGird)*-1
}else{
if(SAVE.limit_rigth*-32 > screenWidth*-1 ){
SAVE.CameraX_frese = 1
Limit_Rigth = (32 * limitXGird)*-1
}else{
Limit_Rigth = SAVE.limit_rigth*-32
}
}
if(SAVE.limit_up == false){
Limit_Up = (32 * limitYGird)
}else{
if(SAVE.limit_up*32 < screenHeigth ){
SAVE.CameraY_frese = 1
Limit_Up = (32 * limitYGird)
}else{
Limit_Up = SAVE.limit_up*32
}
}
if(SAVE.X == undefined || SAVE.X == 0 ){
SAVE.X = limitXGird
}
if(SAVE.Y == undefined || SAVE.Y == 0 ){
SAVE.Y = limitYGird
}
}
function reset_functions_and_scrips(){
functions_collection = [
{
Action: function Action(Tile,player) {},
Loop: function Loop (Tile,player) {"nothing"},
},
]
functionsCords = [1]
Scrips_collection = [
{
Action: function Action(sprite,i) {
sprite.live = 0
if(sprite.col[7] == 8){sprite.Xvelocity = 0}
if(sprite.col[8] == 8){sprite.Xvelocity = 0}
},
Loop: function Loop (sprite,player1,player2,tiles,i){
PreProgramedMode(sprite,player1)
},
RenderMode: function RenderMode (ctx,Sprite) {
PreRenderMode(ctx,Sprite)
}
},
]
ScripsCords = [1]
}
Xsize = document.getElementById("Xsize")
Ysize = document.getElementById("Ysize")
function change_Size(X,Y){
SAVE.X = X*1
SAVE.Y = Y*1
SAVE.limit_rigth = X *1;
SAVE.limit_up = Y *1;
Limit_Up = Y *32
Limit_Rigth = X*32
limits_and_alture()
change_BlockResolution(BlockResolution)
}
function change_BlockResolution(Number){
BlockResolution = Number
scale_sprites = 32 / BlockResolution
GridWidth = SAVE.X * BlockResolution
GridHeight = SAVE.Y * BlockResolution
limitXGird = Math.round((GridWidth / BlockResolution)+0.4)
limitYGird = Math.round((GridHeight / BlockResolution)+0.4)
screen_resoltion = 16 * BlockResolution
margin_screen = GridHeight - screen_resoltion
createSpritesInGrid()
DrawGirdTiles(Grid)
DrawGirdSprites(GridSprites)
}
function Array_to_JSON(Array){
// Convertir el array de objetos a JSON
let datosJSON = JSON.stringify(Array, null, 2);
// Crear un Blob con el contenido JSON
let blob = new Blob([datosJSON], { type: "application/json" });
// Crear enlace para descargar el archivo
let enlace = document.createElement("a");
enlace.href = URL.createObjectURL(blob);
enlace.download = Level_name.value;
// Simular clic en el enlace para iniciar descarga
enlace.click();
// Liberar memoria
URL.revokeObjectURL(enlace.href);
}
const palete = document.getElementById("colors")
function create_palete() {
for(let i = 0; i < color_palete.length ; i++){
palete.innerHTML += "<div class=MBLOCK style=background-color:"+color_palete[i]+" > </div>"
}
const ColorBlocks = document.querySelectorAll('.MBLOCK')
ColorBlocks.forEach(ColorBlock => {
ColorBlock.addEventListener('click', () => {
ColorSelected = ColorBlock.style.backgroundColor
if(DrawMode != 3){
DrawMode = 0
}
DrawsModes[0].Started()
});
});
}
function code(){
let code = ""
for(let i = 0; i < 256 ; i++){
code += RandomNumber(0,1)
}
return binarioALetras(code)
}
function RandomNumber(Min,Max){
let MaxNumber = Max - Min
return (Math.round(Math.random()*MaxNumber)) + Min
}
function binarioALetras(binario) {
let bloques = binario.match(/.{1,8}/g);
let texto = bloques.map(bloque => String.fromCharCode(parseInt(bloque, 2))).join('');
return texto;
}
const Tileset = document.getElementById("tiles")
function CreateTiles (){
for(let i = 0; i < Tiles.length ; i++ ){
let innerHTML = ""
let heigth = Math.round((Tiles[i].objects.length / 8)+0.4) + 1
for(let I = 0; I < Tiles[i].objects.length ; I++ ){
innerHTML += "<canvas class=TBLOCK id = "+ i +" accessKey="+I+"></canvas>"
}
Tileset.innerHTML +=
"<div style= font-size:32px;height:"+heigth+"em;width:8em;>"+
"<p style= font-size:32px;height:1em;width:8em;margin:0em;>"+Tiles[i].Name+"</p>"
+innerHTML+
"</div>"
}
let object = []
XG = 0
YG = 0
const TilesBlocks = document.querySelectorAll('.TBLOCK')
TilesBlocks.forEach(TilesBlock => {
object = Tiles[TilesBlock.id].objects[TilesBlock.accessKey]
if(object[0] == "Tile"){
TilesBlock.addEventListener('click', () => {
Tileselect = Tiles[TilesBlock.id].objects[TilesBlock.accessKey].slice()
Tileselect[2] += imageCords[TilesBlock.id]
if(Tileselect[4] == undefined){
Tileselect[4] == 0
}else{
Tileselect[4] += functionsCords[TilesBlock.id]
}
DrawMode = 2
DrawsModes[2].Started()
});
TilesBlock.width = 32
TilesBlock.height = 32
XG = ( "0x"+object[3][5])* 32
YG = ( "0x"+object[3][6])* 32
let ctx = TilesBlock.getContext("2d");
ctx.drawImage(image_collection[object[2] + imageCords[TilesBlock.id]],XG,YG,32,32, 0,0,32,32)
}else{
TilesBlock.addEventListener('click', () => {
Tileselect = Tiles[TilesBlock.id].objects[TilesBlock.accessKey].slice()
if(Tileselect[3] == "#"){
Tileselect[3] = 0
}else{
Tileselect[3] += ScripsCords[TilesBlock.id]
}
Tileselect[5] += imageCords[TilesBlock.id]
DrawMode = 4
DrawsModes[4].Started()
});
TilesBlock.width = object[1]
TilesBlock.height = object[2]
XG = ( "0x"+object[6][1])* object[1]
YG = ( "0x"+object[6][2])* object[2]
let ctx = TilesBlock.getContext("2d");
ctx.drawImage(image_collection[object[5] + imageCords[TilesBlock.id]],XG,YG,object[1],object[2], 0,0,object[1],object[2])
}
});
}
const Skins_3x3 =
[
{
X_Grid:0,
Y_Grid:1,
Grid:
[
[1,"rgba(0,0,0,0)","11111200",0,0],
[1,"rgba(0,0,0,0)","11111210",0,0],
]
},
{
X_Grid:0,
Y_Grid:1,
Grid:
[
[1,"rgba(0,0,0,0)","10002220",0,0],
[1,"rgba(0,0,0,0)","00000230",0,0],
]
}
]
function Randomblocks(X,Y,N,Xcoordinate,Ycoordinate) {
let Xp = Xcoordinate
if(Xp == undefined){Xp = 0}
let Yp = Ycoordinate
if(Yp == undefined){Yp = 0}
for(let i = 0; i < N ; i++){
LC.push({
X : Math.round((Math.random())*X) + Xp,
Y : Math.round((Math.random())*Y) + Yp,
col : "11111000",
color: "rgb("+Math.round((Math.random())*255)+","+Math.round((Math.random())*255)+","+Math.round((Math.random())*255)+")",
IN : 0})
}
}
function fillblock(X,Y,Xcoordinate,Ycoordinate,color,colision,ImageNumber,Script) {
let Xp = Xcoordinate
let InicialXp = Xcoordinate
if(Xp == undefined){Xp = 0}
let Yp = Ycoordinate
if(Yp == undefined){Yp = 0}
let col = "#fff"
let colisione = "11111000"
let ImgN = 0
let script = 0
if(colision != undefined){
colisione = colision
}
if(ImageNumber != undefined){
ImgN = ImageNumber
}
if(Script != undefined){
script = Script
}
for(let iy = 0; iy < Y ; iy++){
for(let ix = 0; ix < X ; ix++){
if(color == undefined){
col = "rgb("+Math.round((Math.random())*255)+","+Math.round((Math.random())*255)+","+Math.round((Math.random())*255)+")"
}else{
col = color
}
replaceTilePriority(Xp,Yp,true,Yp,colisione,col,ImgN,0)
Xp ++
}
Yp--
Xp = InicialXp
}
}
function fillblockImg_3x3(X,Y,Xcoordinate,Ycoordinate,Img,color,colision,XGirdLimit,YGirdLimit,Script) {
let Xp = Xcoordinate
let Yp = Ycoordinate
let StarYp = Yp
let animation = colision[7]
var XG = parseInt(colision[5], 32)
let XLimit = XGirdLimit + XG
var YG = parseInt(colision[6], 32)
let YLimit = YGirdLimit + YG
let starYG = YG
let col = colision.slice(0,5)
let type = true
let alture = Yp
let downCol = col
if(colision[4] == 2){
downCol = "00000"
type = false
}
function Yblocks(){
Yp = StarYp
YG = starYG
replaceTilePriority(Xp,Yp,type,alture,col + XG.toString(32) +YG.toString(32)+animation,color,Img,Script)
Yp--
YG++
if(YGirdLimit == 0 && !type){return true;}
if(YG > YLimit){YG = YLimit}
for(let i = 0; i < Y-1 ; i++){
replaceTilePriority(Xp,Yp,type,alture,downCol + XG.toString(32) +YG.toString(32)+animation,color,Img,Script)
Yp --
}
YG ++
if(YG > YLimit){YG = YLimit}
replaceTilePriority(Xp,Yp,type,alture,downCol + XG.toString(32) +YG.toString(32)+animation,color,Img,Script)
}
Yblocks()
Xp ++
XG++
if(XG > XLimit){XG = XLimit}
for(let i = 0; i < X-2 ; i++){
Yblocks()
Xp ++
}
XG++
if(XG > XLimit){XG = XLimit}
Yblocks()
}
function createBlocks(Number,Gplus,minX,maxX,minY,maxY,x,y,Xcoordinate,Ycoordinate,Img,color,colision,XGirdLimit,YGirdLimit,animation,Script){
let Xp = Xcoordinate
if(Xp == undefined){Xp = 0}
let Yp = Ycoordinate
if(Yp == undefined){Yp = 0}
let Xmult = x
if(Xmult == undefined || Xmult == false ){Xmult = limitXGird}
let Ymult = y
if(Ymult == undefined || Ymult == false ){Ymult = limitYGird}
for(let i = 0; i < Number ; i++){
let X = RandomNumber(minX,maxX)
let Y = RandomNumber(minY,maxY)
if(Gplus == undefined || Gplus ){
fillblockImg_3x3(X,Y,(Math.round(Math.random()*Xmult)) + Xp,(Math.round(Math.random()*Ymult)) + Yp,Img,color,colision,XGirdLimit,YGirdLimit,animation,Script)
}else{
fillblock(X,Y,(Math.round(Math.random()*Xmult)) + Xp,(Math.round(Math.random()*Ymult)) + Yp,color,colision,animation,Img,Script)
}
}
}
function createBlocksPerlin(Number,Gplus,minX,maxX,minY,maxY,x,y,Xcoordinate,Ycoordinate,Img,color,colision,XG,YG,animation,Script){
let Xp = Xcoordinate
if(Xp == undefined){Xp = 0}
let Yp = Ycoordinate
if(Yp == undefined){Yp = 0}
let Xmult = x
if(Xmult == undefined || Xmult == false ){Xmult = limitXGird}
let Ymult = y
if(Ymult == undefined || Ymult == false ){Ymult = limitYGird}
var List = Random_Perlin(Number,Xmult)
for(let i = 0; i < List.length ; i++){
let X = 1
let Y = 1
if(Gplus == undefined || Gplus ){