VTI-ES

Game in onderhoud

Tegare 8-bit prototype

made by Dante Deketele

debug

animations

No info found!

instructions

move with arrow keys
switch character by pressing 'space'
select with space
restart with R

script

var canvas = document.getElementById("Tegare");

			var play_levels = true;
			var selectedlevel = 1;

			document.addEventListener('keydown', function (event) {

                if (event.keyCode == 82) {
                    window.location.reload();
                }

				if (movable) {
					if (event.keyCode == 37) {
                        if (map[playerY[playerId]][playerX[playerId] - 1] == 1 || map[playerY[playerId]][playerX[playerId] - 1] == 13) {
							prevPlayerX[playerId] = playerX[playerId];
							prevPlayerY[playerId] = playerY[playerId];
							playerX[playerId]--;

							MoveEnemies();
							lerp(-1, 0);
						}
					}
					else if (event.keyCode == 38) {
                        if (map[playerY[playerId] - 1][playerX[playerId]] == 1 || map[playerY[playerId] - 1][playerX[playerId]] == 13) {
							prevPlayerY[playerId] = playerY[playerId];
							prevPlayerX[playerId] = playerX[playerId];
							playerY[playerId]--;

							MoveEnemies();
							lerp(0, -1);
						}
					}
					else if (event.keyCode == 39) {
                        if (map[playerY[playerId]][playerX[playerId] + 1] == 1 || map[playerY[playerId]][playerX[playerId] + 1] == 13 ) {
							prevPlayerX[playerId] = playerX[playerId];
							prevPlayerY[playerId] = playerY[playerId];
							playerX[playerId]++;

							MoveEnemies();
							lerp(1, 0);
						}
					}
					else if (event.keyCode == 40) {
                        if (map[playerY[playerId] + 1][playerX[playerId]] == 1 || map[playerY[playerId] + 1][playerX[playerId]] == 13 ) {
							prevPlayerY[playerId] = playerY[playerId];
							prevPlayerX[playerId] = playerX[playerId];
							playerY[playerId]++;

							MoveEnemies();
							lerp(0, 1);
						}
					}
					else if (event.keyCode == 32 && playerActive[inactivePlayerId] == 1) {//space
						playerId = inactivePlayerId;
						getInactivePlayerId();
						drawBG();
						sprite(Tileap, playerX[playerId], playerY[playerId], 0, 0);
						drawEnemies();
						draw();
					}
				}

                if (levelId == 1) {
					if (event.keyCode == 38) {
						play_levels = true;
                        drawBG();
                        sprite(Tile8, 0, 4, 0, 0);
						draw();
						
					}
					if (event.keyCode == 40) {
						play_levels = false;
                        drawBG();
                        sprite(Tile8, 0, 5, 0, 0);
                        draw();
					}
                    if (event.keyCode == 32) {
                        if (play_levels) {
                            changeLevelId(3);
                        } else {
                            changeLevelId(2);
						}
                        play_levels = true;
                    }
				}

                if (levelId == 2) {
                    if (event.keyCode == 38 && selectedlevel > 1) {
						selectedlevel--;
                        drawBG();
                        switch (selectedlevel) {

							case 1:
								sprite(Tile9, 7, 5, 0, 0);
								break;
                            case 2:
                                sprite(Tile10, 7, 5, 0, 0);
								break;
                            case 3:
                                sprite(Tile11, 7, 5, 0, 0);
								break;
                            case 4:
                                sprite(Tile12, 7, 5, 0, 0);
								break;
                            case 5:
                                sprite(Tile13, 7, 5, 0, 0);
								break;
                            case 6:
                                sprite(Tile14, 7, 5, 0, 0);
                                break;

                            default:

                        }
                        draw();

                    }
					if (event.keyCode == 40 && selectedlevel <16) {
														selectedlevel++;
														drawBG();
														switch (selectedlevel) {
														case 1:
														sprite(Tile9, 7, 5, 0, 0);
														break;
														case 2:
														sprite(Tile10, 7, 5, 0, 0);
														break;
														case 3:
														sprite(Tile11, 7, 5, 0, 0);
														break;
														case 4:
														sprite(Tile12, 7, 5, 0, 0);
														break;
														case 5:
														sprite(Tile13, 7, 5, 0, 0);
														break;
														case 6:
														sprite(Tile14, 7, 5, 0, 0);
														break;
														default:
														}
														draw();
														}
														if (event.keyCode= =32) {
														if (play_levels) {
														changeLevelId(selectedlevel + 1);
														} else {
														changeLevelId(selectedlevel + 1);
														}
														}
														}
														});
														setTimeout(function () {
														changeLevelId(1);
														drawBG();
														sprite(Tile8, 0, 4, 0, 0);
														draw();
														}, 300);
														window.addEventListener("keydown", function (e) {
														if (["Space", "ArrowUp" , "ArrowDown" , "ArrowLeft" , "ArrowRight" ].indexOf(e.code)> -1) {
					e.preventDefault();
				}
			}, false);

			var ctx = canvas.getContext("2d");
			var esw = Math.round(canvas.width / 4);
			var esh = Math.round(canvas.height / 4);

			var screen = Array.from(Array(esw), () => new Array(esh));

			var animations = false;

			function toggleAnim() {
				// Get the checkbox
				var checkBox = document.getElementById("animations");

				// If the checkbox is checked, display the output text
				if (checkBox.checked == true) {
					animations = true;
				} else {
					animations = false;
				}
			}

			var movable = true;

			var playerActive = [0, 0];
			var playerX = [0, 0];
			var playerY = [0, 0];
			var prevPlayerX = [0, 0];
			var prevPlayerY = [0, 0];
			var playerId = 0;
			var inactivePlayerId = 1;

			var enemyPos = [[0, 0], [0, 0], [0, 0]];
			var enemyAm = 0;
			var enemyDir = [0, 0, 0];

			var levelId = 0;

			function changeLevelId(id) {
				levelId = id;
				reloadMap();
                if (levelId == 0) {
                    setTimeout(function () {
                        changeLevelId(1);
					}, 2500);
				}
                if (levelId == 3) {
                    sprite(Tile9, 7, 5, 0, 0);
                }
			}

			var Tile1 =
				[[0, 0, 0, 0, 0, 0, 0, 0],
				[0, 0, 0, 0, 0, 0, 0, 0],
				[0, 0, 0, 0, 0, 0, 0, 0],
				[0, 0, 0, 0, 0, 0, 0, 0],
				[0, 0, 0, 0, 0, 0, 0, 0],
				[0, 0, 0, 0, 0, 0, 0, 0],
				[0, 0, 0, 0, 0, 0, 0, 0],
				[0, 0, 0, 0, 0, 0, 0, 0]];

			var Tile2 =
				[[1, 1, 1, 1, 1, 1, 1, 1],
				[1, 1, 1, 1, 1, 1, 1, 1],
				[1, 1, 1, 1, 1, 1, 1, 1],
				[1, 1, 1, 1, 1, 1, 1, 1],
				[1, 1, 1, 1, 1, 1, 1, 1],
				[1, 1, 1, 1, 1, 1, 1, 1],
				[1, 1, 1, 1, 1, 1, 1, 1],
				[1, 1, 1, 1, 1, 1, 1, 1]];

			var Tile3 =
				[[0, 1, 1, 1, 1, 1, 1, 1],
				[0, 0, 0, 1, 1, 1, 0, 0],
				[0, 0, 0, 1, 1, 1, 0, 0],
				[0, 0, 0, 1, 1, 1, 0, 0],
				[0, 0, 0, 1, 1, 1, 0, 0],
				[0, 0, 0, 1, 1, 1, 0, 0],
				[0, 0, 0, 1, 1, 1, 0, 0],
				[0, 0, 0, 0, 0, 0, 0, 0]];

			var Tile4 =
				[[0, 1, 1, 1, 1, 1, 1, 1],
				[0, 1, 1, 1, 0, 0, 0, 0],
				[0, 1, 1, 1, 0, 0, 0, 0],
				[0, 1, 1, 1, 1, 1, 0, 0],
				[0, 1, 1, 1, 0, 0, 0, 0],
				[0, 1, 1, 1, 0, 0, 0, 0],
				[0, 1, 1, 1, 1, 1, 1, 1],
				[0, 0, 0, 0, 0, 0, 0, 0]];

			var Tile5 =
				[[0, 0, 1, 1, 1, 1, 1, 0],
				[0, 1, 1, 1, 1, 0, 0, 1],
				[0, 1, 1, 1, 0, 0, 0, 0],
				[0, 1, 1, 1, 0, 0, 1, 1],
				[0, 1, 1, 1, 0, 0, 0, 1],
				[0, 1, 1, 1, 1, 0, 0, 1],
				[0, 0, 1, 1, 1, 1, 1, 0],
				[0, 0, 0, 0, 0, 0, 0, 0]];

			var Tile6 =
				[[0, 0, 1, 1, 1, 1, 1, 0],
				[0, 1, 1, 1, 0, 0, 1, 1],
				[0, 1, 1, 1, 0, 0, 1, 1],
				[0, 1, 1, 1, 1, 1, 1, 1],
				[0, 1, 1, 1, 0, 0, 1, 1],
				[0, 1, 1, 1, 0, 0, 1, 1],
				[0, 1, 1, 1, 0, 0, 1, 1],
				[0, 0, 0, 0, 0, 0, 0, 0]];

			var Tile7 =
				[[0, 1, 1, 1, 1, 1, 1, 0],
				[0, 1, 1, 1, 0, 0, 1, 1],
				[0, 1, 1, 1, 0, 0, 1, 1],
				[0, 1, 1, 1, 1, 1, 1, 0],
				[0, 1, 1, 1, 0, 0, 1, 1],
				[0, 1, 1, 1, 0, 0, 1, 1],
				[0, 1, 1, 1, 0, 0, 1, 1],
					[0, 0, 0, 0, 0, 0, 0, 0]];

            var Tile8 =
                [[0, 0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 1, 0, 0, 0, 0],
                    [0, 0, 0, 1, 1, 0, 0, 0],
                    [0, 0, 0, 1, 1, 1, 0, 0],
                    [0, 0, 0, 1, 1, 0, 0, 0],
                    [0, 0, 0, 1, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0]];

            var Tile9 =
                [[0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
					[0, 0, 0, 0, 0, 0, 0, 0]];

            var Tile10 =
                [[0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
					[0, 0, 0, 0, 0, 0, 0, 0]];

            var Tile11 =
                [[0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
					[0, 0, 0, 0, 0, 0, 0, 0]];

            var Tile12 =
                [[0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 1, 0],
                [0, 0, 0, 0, 0, 0, 0, 0]];

			var Tile20 =
				[[0, 0, 1, 1, 1, 1, 1, 0],
				[0, 1, 1, 1, 0, 0, 0, 1],
				[0, 1, 1, 1, 1, 0, 0, 0],
				[0, 0, 1, 1, 1, 1, 1, 0],
				[0, 0, 0, 0, 1, 1, 1, 1],
				[0, 1, 0, 0, 0, 1, 1, 1],
				[0, 0, 1, 1, 1, 1, 1, 0],
				[0, 0, 0, 0, 0, 0, 0, 0]];

			var Tile21 =
				[[0, 1, 1, 1, 0, 0, 0, 0],
				[0, 1, 1, 1, 0, 0, 0, 0],
				[0, 1, 1, 1, 0, 0, 0, 0],
				[0, 1, 1, 1, 0, 0, 0, 0],
				[0, 1, 1, 1, 0, 0, 0, 0],
				[0, 1, 1, 1, 0, 0, 0, 0],
				[0, 1, 1, 1, 1, 1, 1, 1],
				[0, 0, 0, 0, 0, 0, 0, 0]];

			var Tile22 =
				[[0, 1, 1, 1, 0, 0, 0, 1],
				[0, 1, 1, 1, 0, 0, 0, 1],
				[0, 1, 1, 1, 0, 0, 0, 1],
				[0, 0, 1, 1, 0, 0, 0, 1],
				[0, 0, 0, 1, 1, 0, 1, 0],
				[0, 0, 0, 0, 1, 0, 1, 0],
				[0, 0, 0, 0, 0, 1, 0, 0],
					[0, 0, 0, 0, 0, 0, 0, 0]];

            var Tile25 =
                [[0, 1, 1, 1, 0, 0, 0, 1],
                [0, 1, 1, 1, 0, 0, 0, 1],
                [0, 1, 1, 1, 0, 0, 0, 1],
                [0, 0, 1, 1, 0, 0, 0, 1],
                [0, 0, 0, 1, 1, 0, 1, 0],
                [0, 0, 0, 0, 1, 0, 1, 0],
                [0, 0, 0, 0, 0, 1, 0, 0],
					[0, 0, 0, 0, 0, 0, 0, 0]];

            var Tileap =
                [[1, 1, 1, 1, 1, 1, 1, 1],
                    [1, 1, 1, 1, 1, 1, 1, 1],
                    [1, 1, 1, 1, 1, 1, 1, 1],
                    [1, 1, 1, 2, 2, 1, 1, 1],
                    [1, 1, 2, 1, 1, 2, 1, 1],
                    [1, 1, 1, 2, 2, 1, 1, 1],
                    [1, 1, 2, 2, 2, 2, 1, 1],
					[1, 1, 1, 1, 1, 1, 1, 1]];
            var Tilep =
                [[1, 1, 1, 1, 1, 1, 1, 1],
                [1, 1, 1, 1, 1, 1, 1, 1],
                [1, 1, 1, 1, 1, 1, 1, 1],
                [1, 1, 1, 2, 2, 1, 1, 1],
                [1, 1, 2, 2, 2, 2, 1, 1],
                [1, 1, 1, 2, 2, 1, 1, 1],
                [1, 1, 2, 2, 2, 2, 1, 1],
					[1, 1, 1, 1, 1, 1, 1, 1]];

            var Tileenemy =
                [[1, 1, 1, 1, 1, 1, 1, 1],
                [1, 1, 1, 1, 1, 1, 1, 1],
                [1, 1, 1, 1, 1, 1, 1, 1],
                [1, 1, 1, 3, 3, 1, 1, 1],
                [1, 1, 3, 3, 3, 3, 1, 1],
                [1, 1, 1, 3, 3, 1, 1, 1],
                [1, 1, 3, 3, 3, 3, 1, 1],
                [1, 1, 1, 1, 1, 1, 1, 1]];

            var Tileend =
                [[1, 1, 1, 1, 1, 1, 1, 1],
                [1, 0, 0, 0, 0, 0, 0, 1],
                [1, 0, 1, 1, 1, 1, 0, 1],
                [1, 0, 1, 1, 1, 1, 0, 1],
                [1, 0, 1, 1, 1, 1, 0, 1],
                [1, 0, 1, 1, 1, 1, 0, 1],
                [1, 0, 0, 0, 0, 0, 0, 1],
                [1, 1, 1, 1, 1, 1, 1, 1]];

            var maps =
                [[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 3, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],

                    [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
                    [2, 3, 4, 5, 6, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
                    [0, 19, 2, 5, 6, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
                    [0, 20, 3, 21, 3, 20, 19, 0, 0, 0, 0, 0, 0, 0, 1, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]],

                    [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    [2, 3, 4, 5, 6, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, 20, 3, 21, 3, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],

                    [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 13, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
						[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],

                    [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0],
                        [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 13, 0, 0, 0],
                        [0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],

                    [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 13, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 13, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
						[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],

                    [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 1, 13, 0, 1, 1, 1, 1, 1, 13, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
						[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],

                    [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]

];

            var PX = [[2, 2], [2, 2], [0, 0], [5, 5], [3, 3], [5, 5], [6,3]];
            var PY = [[2, 4], [2, 4], [0, 0], [5, 5], [4, 4], [2, 5], [4, 4]];
            var PA = [[0, 0], [0, 0], [0, 0], [1, 0], [1, 0], [1, 1], [1, 1]];

            var EP = [[[14, 0], [0, 0], [0, 0]], [[0, 14], [0, 0], [0, 0]], [[9, 4], [0, 0], [0, 0]], [[9, 4], [0, 0], [0, 0]], [[10, 4], [0, 0], [0, 0]], [[9, 4], [0, 0], [0, 0]], [[10, 4], [0, 0], [0, 0]], [[10, 4], [0, 0], [0, 0]]];
			var EA = [0, 0, 0, 0,1,0,1,1];

			var map = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
			[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
			[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
			[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
			[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
			[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
			[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
			[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];

			function tile(tileMatrix, x, y) {
				for (let i = 0; i < 8; i++) {
					for (let j = 0; j < 8; j++) {
						screen[i + x * 8][j + y * 8] = tileMatrix[j][i];
					}
				}
			}

			function sprite(tileMatrix, x, y, xoff, yoff) {
				for (let i = 0; i < 8; i++) {
					for (let j = 0; j < 8; j++) {
						if (tileMatrix[j][i])
							screen[i + x * 8 + xoff][j + y * 8 + yoff] = tileMatrix[j][i];
					}
				}
			}


			function lerp(x, y) {
				if (animations) {
					movable = false;
					for (let i = 0; i < 8; i++) {
						setTimeout(() => {
							drawBG();
							sprite(Tile1, prevPlayerX[playerId], prevPlayerY[playerId], i * x, i * y);
							draw();
						}, i / 4);
					}
					setTimeout(() => {
						drawBG();
						sprite(sTile1, playerX[playerId], playerY[playerId], 0, 0);
						drawEnemies();
						draw();
						movable = true;
					}, 8 / 4);
				} else {
					drawBG();
                    sprite(Tileap, playerX[playerId], playerY[playerId], 0, 0);
					drawEnemies();
					draw();
				}
			}

			function drawEnemies() {
				for (let i = 0; i < enemyAm; i++) {
					sprite(Tileenemy, enemyPos[i][0], enemyPos[i][1], 0, 0);
				}
			}

			function reloadMap() {
				map = maps[levelId];
				playerX = PX[levelId];
				playerY = PY[levelId];
				playerActive = PA[levelId];

				enemyPos = EP[levelId];
				enemyAm = EA[levelId];

				drawBG();
				drawEnemies();
				if (playerActive[playerId] == 1)
                    sprite(Tileap, playerX[playerId], playerY[playerId], 0, 0);
				draw();
			}


			function drawBG() {


				for (let i = 0; i < 16; i++) {
					for (let j = 0; j < 8; j++) {
						if (map[j][i] == 0)
							tile(Tile1, i, j);
						if (map[j][i] == 1)
							tile(Tile2, i, j);
						if (map[j][i] == 2)
							tile(Tile3, i, j);
						if (map[j][i] == 3)
							tile(Tile4, i, j);
						if (map[j][i] == 4)
							tile(Tile5, i, j);
						if (map[j][i] == 5)
							tile(Tile6, i, j);
						if (map[j][i] == 6)
							tile(Tile7, i, j);
						if (map[j][i] == 7)
							tile(Tile8, i, j);
						if (map[j][i] == 8)
							tile(Tile9, i, j);
						if (map[j][i] == 9)
							tile(Tile10, i, j);
						if (map[j][i] == 10)
							tile(Tile11, i, j);
						if (map[j][i] == 11)
							tile(Tile12, i, j);
						if (map[j][i] == 12)
							tile(Tile13, i, j);
						if (map[j][i] == 13)
							tile(Tileend, i, j);
						if (map[j][i] == 14)
							tile(Tile1, i, j);
						if (map[j][i] == 15)
							tile(Tile1, i, j);
						if (map[j][i] == 16)
							tile(Tile1, i, j);
						if (map[j][i] == 17)
							tile(Tile1, i, j);
						if (map[j][i] == 18)
							tile(Tile1, i, j);
						if (map[j][i] == 19)
							tile(Tile20, i, j);
						if (map[j][i] == 20)
							tile(Tile21, i, j);
						if (map[j][i] == 21)
							tile(Tile22, i, j);
						if (map[j][i] == 22)
							tile(Tile1, i, j);
						if (map[j][i] == 23)
							tile(Tile1, i, j);
						if (map[j][i] == 24)
							tile(Tile25, i, j);
						if (map[j][i] == 25)
							tile(Tile1, i, j);
						if (map[j][i] == 26)
							tile(Tile1, i, j);
						if (map[j][i] == 27)
							tile(Tile1, i, j);
						if (map[j][i] == 28)
							tile(Tile1, i, j);
						if (map[j][i] == 29)
							tile(Tile1, i, j);
						if (map[j][i] == 30)
							tile(Tile1, i, j);
						if (map[j][i] == 31)
							tile(Tile1, i, j);
						if (map[j][i] == 32)
							tile(Tile1, i, j);
						if (map[j][i] == 33)
							tile(Tile1, i, j);
						if (map[j][i] == 34)
							tile(Tile1, i, j);
						if (map[j][i] == 35)
							tile(Tile1, i, j);
						if (map[j][i] == 36)
							tile(Tile1, i, j);
					}
				}
			}

			function MoveEnemies() {

				if (maps[levelId][playerY[0]][playerX[0]] == 13 && maps[levelId][playerY[1]][playerX[1]] == 13) {
					console.log("ree");
					changeLevelId(levelId+1);
					return;
                }
                    
				if ((playerActive[0] == 0 || playerActive[1] == 0) && (maps[levelId][playerY[0]][playerX[0]] == 13 || maps[levelId][playerY[1]][playerX[1]] == 13)) {
					changeLevelId(levelId+1);
					return;
                }
					
				
				console.log(maps[levelId][playerY[0]][playerX[0]] == 13);
                console.log(maps[levelId][playerY[1]][playerX[1]] == 13);
				console.log(maps[levelId][playerY[0]][playerX[0]] == 13 && maps[levelId][playerY[1]][playerX[1]] == 13);


				for (let i = 0; i < enemyAm; i++) {
					var closest = 10000;
					var clId = 0;
					if (map[enemyPos[i][1] + 1][enemyPos[i][0]] == 1 && enemyDir[i] != 3) {
						closest = Math.abs(enemyPos[i][0] - playerX[playerId]) + Math.abs(enemyPos[i][1] - playerY[playerId] + 1);
						clId = 1;
					}
					if (map[enemyPos[i][1]][enemyPos[i][0] + 1] == 1 && enemyDir[i] != 4) {
						var newcl = Math.abs(enemyPos[i][0] - playerX[playerId] + 1) + Math.abs(enemyPos[i][1] - playerY[playerId]);
						if (newcl < closest) {
							closest = newcl;
							clId = 2;
						}
					}
					if (map[enemyPos[i][1] - 1][enemyPos[i][0]] == 1 && enemyDir[i] != 1) {
						var newcl = Math.abs(enemyPos[i][0] - playerX[playerId]) + Math.abs(enemyPos[i][1] - playerY[playerId] - 1);
						if (newcl < closest) {
							closest = newcl;
							clId = 3;
						}
					}
					if (map[enemyPos[i][1]][enemyPos[i][0] - 1] == 1 && enemyDir[i] != 2) {
						var newcl = Math.abs(enemyPos[i][0] - playerX[playerId] - 1) + Math.abs(enemyPos[i][1] - playerY[playerId]);

						if (newcl < closest) {
							closest = newcl;
							clId = 4;
						}
					}

					if (clId == 1) {
						enemyPos[i][1]++;
						lerpEnemy(0, 1, i);
						enemyDir[i] = 1;
					}
					if (clId == 2) {
						enemyPos[i][0]++;
						lerpEnemy(1, 0, i);
						enemyDir[i] = 2;
					}
					if (clId == 3) {
						enemyPos[i][1]--;
						lerpEnemy(0, -1, i);
						enemyDir[i] = 3;
					}
					if (clId == 4) {
						enemyPos[i][0]--;
						lerpEnemy(-1, 0, i);
						enemyDir[i] = 4;
					}
					if (animations) {
						setTimeout(() => {
							checkColl(i);
						}, 1);
					} else {
						setTimeout(() => {
							checkColl(i);
						}, 9);
					}
                    
				}
			}

			function checkColl(i) {
                if ((enemyPos[i][0] == playerX[0] && enemyPos[i][1] == playerY[0]) && playerActive[0] == 1)
                    location.reload();
                if ((enemyPos[i][0] == playerX[1] && enemyPos[i][1] == playerY[1]) && playerActive[1] == 1)
                    location.reload();

				if (enemyDir[i] == 1 && enemyPos[i][0] == playerX[playerId] && enemyPos[i][1] - 1 == playerY[playerId])
                    location.reload();
				if (enemyDir[i] == 2 && enemyPos[i][0] - 1 == playerX[playerId] && enemyPos[i][1] == playerY[playerId])
                    location.reload();
				if (enemyDir[i] == 3 && enemyPos[i][0] == playerX[playerId] && enemyPos[i][1] + 1 == playerY[playerId])
                    location.reload();
				if (enemyDir[i] == 4 && enemyPos[i][0] + 1 == playerX[playerId] && enemyPos[i][1] == playerY[playerId])
                    location.reload();
				
				
			}

			function lerpEnemy(x, y, j) {
				if (animations) {
					for (let i = 0; i < 8; i++) {
						setTimeout(() => {
							drawBG();
							sprite(Tile1, enemyPos[j][0] - x, enemyPos[j][1] - y, i * x, i * y);
							draw();
						}, i / 4);
					}
					setTimeout(() => {
						drawBG();
						sprite(Tile1, enemyPos[j][0], enemyPos[j][1], 0, 0);
						draw();
					}, 8 / 4);
				} else {
					sprite(Tile1, enemyPos[j][0], enemyPos[j][1], 0, 0);
				}
			}

			function getInactivePlayerId() {
				if (playerId == 0)
					inactivePlayerId = 1;
				if (playerId == 1)
					inactivePlayerId = 0;
			}

			function drawInactivePlayer() {
				if (playerActive[inactivePlayerId] == 1)
                    sprite(Tilep, playerX[(inactivePlayerId)], playerY[inactivePlayerId], 0, 0);
			}

			function draw() {
				drawInactivePlayer();

				for (let i = 0; i < esw; i++) {
					for (let j = 0; j < esh; j++) {
						if (screen[i][j] == 3)
							ctx.fillStyle = '#152D35';
						if (screen[i][j] == 2)
							ctx.fillStyle = '#345B63';
						if (screen[i][j] == 1)
							ctx.fillStyle = '#D4ECDD';
						if (screen[i][j] == 0)
							ctx.fillStyle = '#112031';
						ctx.fillRect(i * 10, j * 10, 10, 10);
					}
				}
				document.getElementById("debugInfo").innerHTML =
					"map-matrix: " + map +
					"
player-position: xPos[" + playerX + "], yPos[" + playerY + "]" + "
selected-player-id: " + playerId + "
enemy-position: " + enemyPos; } reloadMap();