JSFiddle - React, Tailwind, and code Playground

by szivak009

JavaScript

/* Let's have some fun with tiles */

/*
 * Specification
 *
 * I'm developing a 2D game and the game is created from 2D graphics. Map will also based on 2D
 * graphics, so it means I will implement a 2D tile based multilayer map.
 * Objects (tables, desks, houses) are seperated from map generation.
 * 
 * Tiles are multilayered. Bottom layer is for example sand, and the second layer is dust on it.
 *
 * Tile texture ids:
 * 0 - empty
 *
 *
 *
 *
 *
 * String representing a map:
 * var map = '2,3:2:2:2,3,1:2,3,1:2,3,1:2:3:3';
 * It is a
 * 
 */


var map = (function(){

    var mapSys = function(){
    
        var types = [
            /* empty tile */
            {
                tex: null,
                callback : function(entity) {};
            },
            
            /* special object: hurt*/
            {
                tex: null,
                callback : function(entity) { entity.health--;}
            },
            
            /* grass */
            {
                tex: 'grass',
                callback : null
            },
            
            /* road */
            {
                tex : 'road',
                callback : null
            }
            
        ];
        
        var typesMap = {
            empty : 0,
            hurt : 1,
            grass : 2,
            road : 3
        };
    
        var tile = function(obj) {
            /* stores texture id: grass, sand, stone, water, lava, hurt, shake, shock, etc.... */
            var typeId = [];
            var x = obj.x === undefined ? 0 : obj.x;
            var y = obj.y === undefined ? 0 : obj.y;
            var w = obj.w === undefined ? 0 : obj.w;
            var h = obj.h === undefined ? 0 : obj.h;
        };
        
        /* Name of the map */
        var mapName = '';
        
        /* The actual map. It is one dimensional array containing tiles */
        var _tiles = [];
    
        this.loadMap = function(name) {
            mapName = name;
        };
...