Exemple #1
0
        public Game(Registry registry, AssetSrc assets)
        {
            this.registry = registry;
            this.assets   = assets;
            // TODO: initialization order is getting wonky
            registry.LoadTypes(this);

            idleJobs = new MinionIdle(this);

            gameContainer  = new GameObject("Game").transform;
            itemContainer  = CreateContainer("Items");
            agentContainer = CreateContainer("Agents");
            workOverlays   = CreateContainer("Work Overlays");

            map = new Map(this);
            map.InitDebug(new Vec2I(128, 128));

            for (int i = 0; i < 10; ++i)
            {
                minions.AddLast(new Minion(this, new Vec2I(1 + i, 1)));
            }
            agents.AddRange(minions);

            lightGlobal = Camera.main.gameObject.GetComponent <Light2D>();

            var benchProto = (IBuildable)registry.D_GetProto <BldgWorkbenchDef>("BB:Woodcutter");

            AddBuilding(benchProto.CreateBuilding(Tile(new Vec2I(9, 3)), Dir.Down));
        }
Exemple #2
0
        public MetaAtlas(AssetSrc assets)
        {
            #region Caches
            keys = new CacheNonNullable <AnimKey, Atlas.Rect>(
                animKey =>
            {
                var origin = new Vec2I(
                    OffsetFrame(animKey.frame),
                    20 - (OriginAnim(animKey.anim) + OffsetDir(animKey.dir)));

                return(new Atlas.Rect(
                           origin * 2,
                           new Vec2I(2, 2),
                           new Vec2I(1, 0)));
            });

            atlases = new Cache <string, Atlas>(
                path =>
            {
                var tex = assets.textures.Get(path);
                return(new Atlas(tex, 32, 64));
            });

            paletteMats = new Cache <int, Material>(
                index =>
            {
                var mat = new Material(assets.spriteShader);
                mat.EnableKeyword("_ISPALETTED");
                mat.SetFloat("_PaletteOffset", 1 - (index + .5f) / 64f);
                mat.SetTexture("_PaletteTex", assets.textures.Get("character/palette"));
                return(mat);
            });
            #endregion
        }
Exemple #3
0
        public void Init(AssetSrc assets)
        {
            if (atlas == null)
            {
                atlas = new MetaAtlas(assets);
            }

            cam             = Camera.main;
            spriteContainer = new GameObject("Sprite Container").transform;
            spriteContainer.SetParent(transform, false);
            spriteContainer.localPosition = new Vec2(.5f, 0);
            spriteContainer.localScale    = Vec3.one * 1.75f;

            spriteLayers = new Dictionary <string, SpriteRenderer>();
            int subLayer = 0;

            foreach (string layer in layers)
            {
                var sprite = assets.CreateSpriteObject(
                    spriteContainer, Vec2.zero,
                    layer, null, Color.white, RenderLayer.Minion);

                sprite.transform.localPosition -= new Vec3(0, 0, .001f * subLayer);
                spriteLayers.Add(layer, sprite);
                ++subLayer;
            }

            K_SetSkin(MinionSkinColor.Light);
            K_SetHair(MinionHairColor.Purple);
            K_SetOutfit(0);
            state.SetAnim(MinionAnim.Idle, true);
        }
Exemple #4
0
 private void SplitSprite(AssetSrc assets, SpriteDef def,
                          int size, out Sprite sprite, out Sprite spriteOver)
 {
     if (Tiling.SplitSprite(def, size, out var defLower, out var defUpper))
     {
         sprite     = assets.sprites.Get(defLower);
         spriteOver = assets.sprites.Get(defUpper);
     }
        private static Line CreateLine(AssetSrc assets, Transform parent, Vec2[] pts)
        {
            var line = assets.CreateLine(
                parent, "<corner>",
                RenderLayer.Highlight.Layer(10000),
                Color.white, 1 / 32f, false, false);

            line.SetPts(pts);
            return(line);
        }
        public SelectionHighlight(AssetSrc assets, Transform parent)
        {
            this.parent    = parent;
            this.container = new GameObject("<highlight>").transform;
            container.SetParent(parent, false);

            this.scaler = new GameObject("<scaler>").transform;
            scaler.SetParent(container, false);

            bl = CreateLine(assets, scaler, ptsBL);
            br = CreateLine(assets, scaler, ptsBR);
            tl = CreateLine(assets, scaler, ptsTL);
            tr = CreateLine(assets, scaler, ptsTR);
        }
Exemple #7
0
        public GameController()
        {
            registry = new Registry();
            assets   = new AssetSrc();
            cam      = Camera.main;
            game     = new Game(registry, assets);
            gui      = new GameUI(this);

            builds    = new ToolBuildSelect(this);
            orders    = new ToolOrdersSelect(this);
            selection = new ToolSelection(this);

            speed = PlaySpeed.Normal;
            OnSpeedChange(speed);
        }