JSFiddle - React, Tailwind, and code Playground

by gerdonabbink

HTML

<!DOCTYPE html>
<html>

    <head>
        <style type="text/css">
            body {
                padding: 0px;
                margin: 0px;
            }

        </style>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.2/phaser.min.js"></script>
    </head>

    <body>
    </body>

</html>

JavaScript

var game;
var maze = [];
var mazeWidth = 50;
var mazeHeight = 50;
var tileSize = 10;
var mazeGraphics;

var playGame = function(game) {};

playGame.prototype = {
    create: function() {
        mazeGraphics = game.add.graphics(0, 0);
        var moves = [];
        for (var i = 0; i < mazeHeight; i++) {
            maze[i] = [];
            for (var j = 0; j < mazeWidth; j++) {
                maze[i][j] = 1;
            }
        }
        var posX = Math.floor(mazeWidth / 2);
        var posY = Math.floor(mazeHeight / 2);
        maze[posX][posY] = 0
        moves.push(posY + posY * mazeWidth);
        game.time.events.loop(0, function() {
            if (moves.length) {
                var possibleDirections = "";

                var a = Math.floor(mazeWidth / 2) - posX;
                var b = Math.floor(mazeHeight / 2) - posY;

                var c = Math.sqrt(a * a + b * b);
				
				let distance = 40


                if (posX + 2 > 0 && posX + 2 < mazeHeight - 1 && maze[posX + 2][posY] == 1 && c < distance) {
                    possibleDirections += "S";
                }
                if (posX - 2 > 0 && posX - 2 < mazeHeight - 1 && maze[posX - 2][posY] == 1 && c < distance) {
                    possibleDirections += "N";
                }
                if (posY - 2 > 0 && posY - 2 < mazeWidth - 1 && maze[posX][posY - 2] == 1 && c < distance) {
                    possibleDirections += "W";
                }
                if (posY + 2 > 0 && posY + 2 < mazeWidth - 1 && maze[posX][posY + 2] == 1 && c < distance) {
                    possibleDirections += "E";
                }
                if (possibleDirections) {
                    var move = game.rnd.between(0, possibleDirections.length - 1);
                    switch (possibleDirections[move]) {
                        case "N":
                            maze[posX - 2][posY] = 0;
                            maze[posX - 1][posY] = 0;
                            posX -= 2;
           ...