World.cs 1.03 KB
Newer Older
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
using UnityEngine;
using System.Collections;

public static class World
{
    private static Tile[][] map;
    private static int width, height;

    public static int Width
    {
        get
        {
            return width;
        }
    }

    public static int Height
    {
        get
        {
            return height;
        }
    }

    static World()
    { }

    public static void setup(int w, int h)
    {
        width = w;
        height = h;

        instantiateMap();
    }

    private static void instantiateMap()
    {
        map = new Tile[width][];
        for (int i = 0; i < width; i++)
        {
            map[i] = new Tile[height];
        }
    }

    public static void giveMap(Tile[][] newMap) { map = newMap; }

    public static void set(int x, int y, Tile t)
    {
        t.x = x;
        t.y = y;
        map[x][y] = t;
    }

    public static Tile get(int x, int y)
    {
        if (x < 0 || x >= width || y < 0 || y >= width)
        {
            return null;
        }
        return map[x][y];
    }
}