예제 #1
0
        public void StartRoute(ModCity city, ModCity homeCity, IsoGrid isogrid, Path path)
        {
            // calculate a path for movement

            running = true;
            drawPath = path.PathList(homeCity.gridposition + new Vector2(2, 2), city.gridposition + new Vector2(2, 2), isogrid);
            pathStep = 1;
            walkingTarget = drawPath[pathStep];

            gridPosition = drawPath[0];
            position = isogrid.gridCoords( homeCity.position);
        }
예제 #2
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // grid & camera
            isoGrid = new IsoGrid(GraphicsDevice,Math.PI/6.0,30,new Vector2(100,100));
            cameraPosition = isoGrid.cameraCentre(new Vector2(11,12),graphics); // initial camera position!
            scrollSpeed = 10.0f;

            // fonts
            font = Content.Load<SpriteFont>("font");

            // cursor
            cursor = new Cursor(Content.Load<Texture2D>("cursor"));

            // HUD
            buttons = new List<Button> { };

            // random seed
            random = new Random();

            // spacescape
            tiles = new GridTileRegion(Content.Load<Texture2D>("starTiles"), new Vector2(-1, 0),new Vector2(100,100), isoGrid,random);

            // --- game objects ----------

            // ships
            trader = new Ship("Trading Ship", Content.Load<Texture2D>("cargoShip"));
            transport = new Ship("Transport Ship", Content.Load<Texture2D>("cargoShip"));

            // materials
            metal = new Material("Metal");
            rock = new Material("Rock");
            gems = new Material("Gemstones");

            // buildings
            dwellBlock = new Building("Dwelling Block",Content.Load<Texture2D>("building2"),3,new Vector2(0,0),new Vector2(1,1));
            dwellBlockLarge = new Building("Large Dwelling Block",Content.Load<Texture2D>("building5"), 3, new Vector2(0, 0), new Vector2(1, 1));
            govTower = new Building("Goverment Central Tower",Content.Load<Texture2D>("building3"), 1, new Vector2(0, 0), new Vector2(3, 3));
            hugeGovTower = new Building("Huge Governemnt Central Tower", Content.Load<Texture2D>("hugeGovernmentTower"), 1, new Vector2(0, 0), new Vector2(12, 12));
            Factory = new Building("Factory",Content.Load<Texture2D>("building4"), 2, new Vector2(0, 0), new Vector2(2, 1));
            Arena = new Building("Entertainment Arena",Content.Load<Texture2D>("building1"), 1, new Vector2(0, 0), new Vector2(2, 2));

            // cities

            modCity = new ModCity("Customisable City", Content.Load<Texture2D>("smallcity"), Content.Load<Texture2D>("smallcityHigh"), Content.Load<Texture2D>("smallcityClick"), new Vector2(20, 3),new Vector2(20, 85),8, isoGrid, new Tuple<float, float, float>(0.33f, 0.33f, 0.34f), new List<Ship> { trader }, new List<Material> { metal }, new List<Tuple<Building, int>> { new Tuple<Building, int>(dwellBlock, 4), new Tuple<Building, int>(dwellBlockLarge, 4), new Tuple<Building, int>(govTower, 1), new Tuple<Building, int>(Arena, 1),new Tuple<Building,int>(Factory,3) }, GraphicsDevice, random);
            modCity2 = new ModCity("Another Customisable City", Content.Load<Texture2D>("smallcity"), Content.Load<Texture2D>("smallcityHigh"), Content.Load<Texture2D>("smallcityClick"), new Vector2(30, 5),new Vector2(20, 85),8, isoGrid, new Tuple<float, float, float>(0.33f, 0.33f, 0.34f), new List<Ship> { trader }, new List<Material> { metal }, new List<Tuple<Building, int>> { new Tuple<Building, int>(dwellBlock, 4), new Tuple<Building, int>(dwellBlockLarge, 4), new Tuple<Building, int>(govTower, 1), new Tuple<Building, int>(Arena, 1), new Tuple<Building, int>(Factory, 3) }, GraphicsDevice, random);
            homeModCity = new ModCity("Home Customisable City", Content.Load<Texture2D>("smallcity"), Content.Load<Texture2D>("smallcityHigh"), Content.Load<Texture2D>("smallcityClick"), new Vector2(10, 10),new Vector2(20, 85),8, isoGrid, new Tuple<float, float, float>(0.33f, 0.33f, 0.34f), new List<Ship> { trader }, new List<Material> { metal }, new List<Tuple<Building, int>> { new Tuple<Building, int>(dwellBlock, 4), new Tuple<Building, int>(dwellBlockLarge, 4), new Tuple<Building, int>(govTower, 1), new Tuple<Building, int>(Arena, 1), new Tuple<Building, int>(Factory, 3) }, GraphicsDevice, random, true);
            hugeCity = new ModCity("Huge City", Content.Load<Texture2D>("hugecity"), Content.Load<Texture2D>("hugecityHigh"), Content.Load<Texture2D>("hugecityClick"), new Vector2(30, 30), new Vector2(-100,280), 90, isoGrid, new Tuple<float, float, float>(0.30f, 0.30f, 0.4f), new List<Ship> { trader }, new List<Material> { metal }, new List<Tuple<Building, int>> {new Tuple<Building, int>(hugeGovTower,1), new Tuple<Building, int>(dwellBlock, 1000), new Tuple<Building, int>(dwellBlockLarge, 400), new Tuple<Building, int>(govTower, 1), new Tuple<Building, int>(Arena, 50), new Tuple<Building, int>(Factory, 300) }, GraphicsDevice, random);
            fullCity = new ModCity("A Full City", Content.Load<Texture2D>("smallcity"), Content.Load<Texture2D>("smallcityHigh"), Content.Load<Texture2D>("smallcityClick"), new Vector2(10, 15), new Vector2(7, 90), 9, isoGrid, new Tuple<float, float, float>(0.33f, 0.33f, 0.34f), new List<Ship> { trader }, new List<Material> { metal }, new List<Tuple<Building, int>> { new Tuple<Building, int>(dwellBlock, 64)}, GraphicsDevice, random);

            modCities = new List<ModCity> { modCity, modCity2,homeModCity,hugeCity,fullCity };

            universe = new DeadObject(Content.Load<Texture2D>("universe"), new Vector2(90, 94), isoGrid);
            uiball = new DeadUIObject(Content.Load<Texture2D>("rball"), new Vector2(10, 10));

            // accesible region and paths
            reach = new ReachableArea(isoGrid, modCities);
            path = new Path(reach);
        }
예제 #3
0
        public void Update(Cursor cursor, Matrix cameraTransform, List<Button> buttons, GraphicsDevice graphicsDevice, Path path, IsoGrid isogrid, ModCity homeCity)
        {
            Vector2 translation = new Vector2(cameraTransform.Translation.X, cameraTransform.Translation.Y);

            screenPosition = position + translation;

            if (cursor.position.X >= screenPosition.X && cursor.position.X <= screenPosition.X + rect.Width
                && cursor.position.Y >= screenPosition.Y && cursor.position.Y <= screenPosition.Y + rect.Height)
            {
                tex = highTex;

                if (cursor.mstate.LeftButton == ButtonState.Pressed)
                {
                    if (cursor.click == false)
                    {
                        cursor.click = true;
                        clicked = true;

                        if (player == false && tradeDeal == false)
                        {
                            tradeButton = new Button(new Vector2(10, 750), 150, 40, "Trade", graphicsDevice);
                            buttons.Add(tradeButton);
                        }
                    }
                }

            }

            else
            {
                tex = lowTex;

                if (tradeButton != null)
                {
                    if (tradeButton.pressed == true)
                    {
                        buttons.Clear();
                        tradeDeal = true;
                        tradeButton = null;

                        ships[0].StartRoute(this, homeCity, isogrid, path);
                    }

                    else if (cursor.mstate.LeftButton == ButtonState.Pressed)
                    {
                        if (cursor.click == false)
                        {
                            cursor.click = true;

                            if (clicked == true)
                            {
                                clicked = false;
                                buttons.Clear();
                            }
                        }
                    }
                }

                else if (cursor.mstate.LeftButton == ButtonState.Pressed)
                {
                    if (cursor.click == false)
                    {

                        if (clicked == true)
                        {
                            cursor.click = true;
                            clicked = false;
                            buttons.Clear();
                        }
                    }
                }
            }

            if (clicked == true)
            {
                tex = clickTex;
            }
        }
예제 #4
0
        public void Update(ModCity homeCity, IsoGrid isogrid, GameTime gametime)
        {
            // continuous movement
            if (running == true)
            {
                direction = (isogrid.gridCoords(walkingTarget) - isogrid.gridCoords(gridPosition));

                targetDistance = direction.Length();
                direction.Normalize();

                walkingOffset += direction * gametime.ElapsedGameTime.Milliseconds * 0.02f;
                distanceGone = walkingOffset.Length();

                if (distanceGone < targetDistance)
                {
                    position = isogrid.gridCoords(gridPosition) + walkingOffset;
                }

                else
                {
                    pathStep += 1;

                    if (pathStep < drawPath.Count)
                    {
                        gridPosition = drawPath[pathStep - 1];
                        walkingTarget = drawPath[pathStep];
                        position = isogrid.gridCoords(gridPosition);
                    }

                    else
                    {
                        drawPath.Reverse();
                        pathStep = 1;
                        walkingTarget = drawPath[pathStep];
                        gridPosition = drawPath[pathStep - 1];
                        position = isogrid.gridCoords(gridPosition);
                    }

                    walkingOffset = Vector2.Zero;
                    targetDistance = 0;
                    distanceGone = 0;
                }

            }

            // set direction anim (8 directions!)

            double dot = Vector2.Dot(new Vector2(0, -1), direction); // dot product of direction with vertical

            double angle = Math.Acos(dot); // angle from vertical

            if (angle == 0) { dir = 0; }
            else if (0 < angle && angle < Math.PI / 2 && direction.X > 0) { dir = 1; }
            else if (angle == Math.PI / 2 && direction.X > 0) { dir = 2; }
            else if (Math.PI / 2 < angle && angle < Math.PI && direction.X > 0) { dir = 3; }
            else if (angle == Math.PI) { dir = 4; }
            else if (Math.PI / 2 < angle && angle < Math.PI && direction.X < 0) { dir = 5; }
            else if (angle == Math.PI / 2 && direction.X < 0) { dir = 6; }
            else if (0 < angle && angle < Math.PI/2 && direction.X < 0) { dir = 7; }

            if (dir != 0)
            {
            }

            // update animation
            timer += gametime.ElapsedGameTime.Milliseconds;

            if (timer >= msecsTweenFrames)
            {
                timer = 0;

                if (currentFrame++ == numberOfFrames - 1)
                {
                    currentFrame = 0;
                }
            }

            rect.X = currentFrame * rect.Width;
            rect.Y = dir * rect.Height;
        }