コード例 #1
0
        public void Update(float dT)
        {
            WM.Update(dT);
            foreach (Components.Stockpile p in this.Map.Stockpiles)
            {
                this.Map.AvailableTasks.AddRange(p.GenerateTasks());
                p.Update(dT);
            }

            for (int i = 0; i < Map.Objects.Count; i++)
            {
                Interfaces.IActor o = Map.Objects[i] as Interfaces.IActor;
                if (o != null)
                {
                    o.DoStuff(dT);
                }
            }

            if (this.State == GameState.Designate && this.dragState.IsActive && this.dragState.Complete)
            {
                this.dragState.IsActive = false;
                foreach (Point p in this.dragState.GetCells())
                {
                    Components.WallTest wt = new Components.WallTest();
                    wt.X            = p.X;
                    wt.Y            = p.Y;
                    wt.WorkRequired = 34;
                    wt.ParentMap    = this.Map;
                    Components.Tasks.Build b = new Components.Tasks.Build(wt);
                    b.Description = "Build wall";
                    this.Map.Objects.Add(wt);
                    this.Map.AvailableTasks.Add(b);
                }
            }
        }
コード例 #2
0
        public void Click(int X, int Y)
        {
            int MapX, MapY, RealMapX, RealMapY;

            RealMapX = (int)(Math.Floor((X + Viewport.X) / this.ZoomLevel));
            RealMapY = (int)(Math.Floor((Y + Viewport.Y) / this.ZoomLevel));
            MapX     = (int)(Math.Floor((X + Viewport.X) / (float)Components.Map.Tile.TileStride / this.ZoomLevel));
            MapY     = (int)(Math.Floor((Y + Viewport.Y) / (float)Components.Map.Tile.TileStride / this.ZoomLevel));
            // Console.Write(GUI.Renderer.ColourToCode(Color.Blue) + " " + MapX + "," + MapY);
            Interfaces.ISelectable m;
            Point p, mp;
            bool  sel = false;

            p  = new Point(RealMapX, RealMapY);
            mp = new Point(MapX, MapY);
            List <Interfaces.ISelectable> selection = new List <Interfaces.ISelectable>();

            foreach (Interfaces.IMapObject o in this.Map.Objects)
            {
                m = o as Interfaces.ISelectable;
                if (m != null && m.Bound.Contains(p))
                {
                    //m.MaterialColor = Color.Red;

                    /*
                     * Components.Tasks.WalkTo t = new Components.Tasks.WalkTo((o as Components.MapItem).X, (o as Components.MapItem).Y);
                     * t.Actor = player;
                     * player.Tasks.Enqueue(t);
                     * //*/
                    selection.Add(m);
                    sel = true;
                }
            }
            if (sel)
            {
                if (LastClick.Equals(mp))
                {
                    SelectionIndex++;
                    if (SelectionIndex >= selection.Count)
                    {
                        SelectionIndex = 0;
                    }
                }
                else
                {
                    SelectionIndex = 0;
                }
                LastClick = mp;
                Select(selection[SelectionIndex]);
            }
            else
            {
                if (State != GameState.Build)
                {
                    Select(Map.MakeSelectable(MapX, MapY));
                }
                else
                {
                    Components.WallTest wt = new Components.WallTest();
                    wt.X            = MapX;
                    wt.Y            = MapY;
                    wt.WorkRequired = 34;
                    wt.ParentMap    = this.Map;
                    Components.Tasks.Build b = new Components.Tasks.Build(wt);
                    b.Description = "Build wall";
                    this.Map.AvailableTasks.Add(b);
                }
            }
        }