Esempio n. 1
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            if (SelectedGameObjects.Count > 0)
            {
                foreach (var selectedGameObject in SelectedGameObjects)
                {
                    if (SimulationGame.VisibleArea.Contains(selectedGameObject.Position))
                    {
                        var worldDrawPosition = Rectangle.Empty;

                        if (selectedGameObject is AmbientObject)
                        {
                            var gameObject = (AmbientObject)selectedGameObject;

                            worldDrawPosition = new Rectangle((int)(gameObject.Position.X - gameObject.GetObjectType().SpriteOrigin.X), (int)(gameObject.Position.Y - gameObject.GetObjectType().SpriteOrigin.Y), gameObject.GetObjectType().SpriteBounds.X, gameObject.GetObjectType().SpriteBounds.Y);
                        }
                        else if (selectedGameObject is AmbientHitableObject)
                        {
                            var gameObject = (AmbientHitableObject)selectedGameObject;

                            worldDrawPosition = new Rectangle((int)(gameObject.Position.X - gameObject.GetObjectType().SpriteOrigin.X), (int)(gameObject.Position.Y - gameObject.GetObjectType().SpriteOrigin.Y), gameObject.GetObjectType().SpriteBounds.X, gameObject.GetObjectType().SpriteBounds.Y);
                        }
                        else if (selectedGameObject is LivingEntity)
                        {
                            var gameObject = (LivingEntity)selectedGameObject;

                            worldDrawPosition = new Rectangle((int)(gameObject.Position.X - gameObject.GetObjectType().SpriteOrigin.X), (int)(gameObject.Position.Y - gameObject.GetObjectType().SpriteOrigin.Y), gameObject.GetObjectType().SpriteBounds.X, gameObject.GetObjectType().SpriteBounds.Y);
                        }

                        var uiPosition = SimulationGame.ConvertWorldPositionToUIPosition(worldDrawPosition.X, worldDrawPosition.Y);
                        SimulationGame.PrimitiveDrawer.Rectangle(new Rectangle((int)uiPosition.X, (int)uiPosition.Y, worldDrawPosition.Width, worldDrawPosition.Height), Color.Yellow);
                    }
                }
            }
            else if (SelectedBlockType != null)
            {
                var uiPosition = SimulationGame.ConvertWorldPositionToUIPosition(SelectedBlockPosition.X * WorldGrid.BlockSize.X, SelectedBlockPosition.Y * WorldGrid.BlockSize.Y);

                SimulationGame.PrimitiveDrawer.Rectangle(new Rectangle((int)uiPosition.X, (int)uiPosition.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y), Color.Blue);
            }
            else if (SelectedWorldLink != null)
            {
                var uiPosition = SimulationGame.ConvertWorldPositionToUIPosition(SelectedWorldLink.FromBlock.X * WorldGrid.BlockSize.X, SelectedWorldLink.FromBlock.Y * WorldGrid.BlockSize.Y);

                SimulationGame.PrimitiveDrawer.Rectangle(new Rectangle((int)uiPosition.X, (int)uiPosition.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y), Color.Orange);
            }

            if (startDragPosition != null)
            {
                var _startDragPosition  = startDragPosition ?? Point.Zero;
                var uiStartDragPosition = SimulationGame.ConvertWorldPositionToUIPosition(_startDragPosition.X, _startDragPosition.Y).ToPoint();
                var selectionRect       = ShapeCollision.ConvertLineToRect(uiStartDragPosition, SimulationGame.MouseState.Position);

                if (selectionRect.Width > 20 || selectionRect.Height > 20)
                {
                    SimulationGame.PrimitiveDrawer.Rectangle(selectionRect.ToXnaRectangle(), Color.White);
                }
            }
        }
Esempio n. 2
0
        public static void PlayMatch(Dictionary <string, Tester> testers)
        {
            if (testers.Count < 2 || testers.Count > 4)
            {
                throw new ArgumentOutOfRangeException("Game only supports 2 - 4 players");
            }

            SimulationGame game = new SimulationGame(testers.Count);

            // create players
            List <IPlayer> players = new List <IPlayer>();
            AIPlayer       player;

            foreach (Tester tester in testers.Values.ToList())
            {
                player = new AIPlayer(
                    tester.name,
                    GameSettings.Places.OfType <IDigSite>().ToList(),
                    GameSettings.StartingPlace,
                    GameSettings.Places,
                    Console.WriteLine,
                    game.AvailableCards.ChangeDisplayedCards,
                    game.AvailableCards.GiveCard,
                    game.Deck.Discard,
                    game.ActiveExhibitions.GiveExhibition,
                    game.DrawTokens,
                    game.PlayersOnWeek
                    );;

                player.Init(tester.ai);
                players.Add(player);
            }

            game.Initialize(players);

            game.Play();

            players.Sort((x, y) => y.Points.CompareTo(x.Points));

            // save results
            for (int i = 0; i < players.Count; i++)
            {
                testers[players[i].Name].AddScore(players[i].Points);
                testers[players[i].Name].AddRank(i + 1);
                testers[players[i].Name].players.Add(players[i]);
            }
        }
Esempio n. 3
0
        public static void Draw(SpriteBatch spriteBatch, GameTime gameTime, SimulationGame simulationGame)
        {
            simulationGame.GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin(SimulationGame.Camera, SpriteSortMode.FrontToBack);

            WorldRenderer.Draw(spriteBatch, gameTime);

            if (SimulationGame.IsGodMode)
            {
                MovingEntityRenderer.Draw(spriteBatch, gameTime, SimulationGame.Player);
            }

            spriteBatch.End();

            LightningRenderer.Draw(spriteBatch, gameTime);

            // Hud
            spriteBatch.Begin();

            SimulationGame.Hud.Draw(spriteBatch, gameTime);

            spriteBatch.End();
        }
Esempio n. 4
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            if (SimulationGame.IsWorldBuilderOpen)
            {
                spriteBatch.Draw(backgroundOverlay, Bounds.ToXnaRectangle(), backgroundColor);
                base.Draw(spriteBatch, gameTime);

                if (placementType != PlacementType.NoType && placementType != PlacementType.Inspect && placementType != PlacementType.WorldPartDetails)
                {
                    switch (placementMode)
                    {
                    case PlacementMode.Manage:
                        manageObjectList.Draw(spriteBatch, gameTime);

                        if (manageObjectList.SelectedElement != null)
                        {
                            editBtn.Draw(spriteBatch, gameTime);
                            createNewFromBtn.Draw(spriteBatch, gameTime);
                            removeBtn.Draw(spriteBatch, gameTime);
                        }
                        break;

                    case PlacementMode.ChooseTileset:
                        tilesetSelectionList.Draw(spriteBatch, gameTime);
                        break;

                    case PlacementMode.CreateFromTileset:
                        tileSetSelectionView.Draw(spriteBatch, gameTime);

                        if (tileSetSelectionView.SelectedSpritePosition != null)
                        {
                            createBtn.Draw(spriteBatch, gameTime);
                            createIfNotExistBtn.Draw(spriteBatch, gameTime);
                        }

                        break;
                    }

                    manageBtn.Draw(spriteBatch, gameTime);
                    createFromJsonBtn.Draw(spriteBatch, gameTime);

                    if (placementType != PlacementType.LivingEntityPlacement)
                    {
                        createFromTilesetBtn.Draw(spriteBatch, gameTime);
                    }
                }
                else if (placementType == PlacementType.WorldPartDetails)
                {
                    changePersistencyBtn.Draw(spriteBatch, gameTime);
                    createWorldLinkBtn.Draw(spriteBatch, gameTime);
                    createInteriorBtn.Draw(spriteBatch, gameTime);

                    if (SimulationGame.Player.InteriorID != Interior.Outside)
                    {
                        changeInteriorDimensionsBtn.Draw(spriteBatch, gameTime);
                        removeInteriorBtn.Draw(spriteBatch, gameTime);
                    }

                    worldPartDetailsTextView.Draw(spriteBatch, gameTime);
                }
                else if (placementType == PlacementType.Inspect)
                {
                    if (inspectView.SelectedGameObjects.Count > 0)
                    {
                        editInstanceBtn.Draw(spriteBatch, gameTime);
                        removeInstanceBtn.Draw(spriteBatch, gameTime);
                        showInstanceTypeBtn.Draw(spriteBatch, gameTime);
                        selectedObjectDetailTextView.Draw(spriteBatch, gameTime);
                    }
                    else if (inspectView.SelectedWorldLink != null)
                    {
                        editInstanceBtn.Draw(spriteBatch, gameTime);
                        removeInstanceBtn.Draw(spriteBatch, gameTime);

                        selectedObjectDetailTextView.Draw(spriteBatch, gameTime);
                    }
                }

                if ((placementMode == PlacementMode.Manage && manageObjectList.SelectedElement != null) ||
                    (placementMode == PlacementMode.CreateFromTileset && tileSetSelectionView.SelectedObject != null))
                {
                    placeView.Draw(spriteBatch, gameTime);

                    if (placeView.Bounds.Contains(SimulationGame.MouseState.Position))
                    {
                        if (SimulationGame.KeyboardState.IsKeyDown(Keys.LeftControl) || SimulationGame.KeyboardState.IsKeyDown(Keys.RightControl))
                        {
                            WorldBuilderUtils.DrawPreview(spriteBatch, SimulationGame.MouseState.Position.ToVector2(), (placementMode == PlacementMode.Manage) ? ((ObjectListItem)manageObjectList.SelectedElement).GetObject() : tileSetSelectionView.SelectedObject);
                        }
                        else
                        {
                            var isBlockSelected = false;

                            if (placementMode == PlacementMode.Manage)
                            {
                                if (((ObjectListItem)manageObjectList.SelectedElement) is BlockListItem)
                                {
                                    isBlockSelected = true;
                                }
                            }
                            else if (placementMode == PlacementMode.CreateFromTileset)
                            {
                                if (tileSetSelectionView.SelectedObject is BlockType)
                                {
                                    isBlockSelected = true;
                                }
                            }

                            if (isBlockSelected)
                            {
                                var worldBlockPosition = GeometryUtils.GetBlockFromReal((int)SimulationGame.RealWorldMousePosition.X, (int)SimulationGame.RealWorldMousePosition.Y);

                                WorldBuilderUtils.DrawPreview(spriteBatch, SimulationGame.ConvertWorldPositionToUIPosition(worldBlockPosition.X * WorldGrid.BlockSize.X, worldBlockPosition.Y * WorldGrid.BlockSize.Y), (placementMode == PlacementMode.Manage) ? ((ObjectListItem)manageObjectList.SelectedElement).GetObject() : tileSetSelectionView.SelectedObject);
                            }
                            else
                            {
                                var worldBlockPosition = GeometryUtils.GetChunkPosition((int)SimulationGame.RealWorldMousePosition.X, (int)SimulationGame.RealWorldMousePosition.Y, 16, 16);

                                WorldBuilderUtils.DrawPreview(spriteBatch, SimulationGame.ConvertWorldPositionToUIPosition(worldBlockPosition.X * 16, worldBlockPosition.Y * 16), (placementMode == PlacementMode.Manage) ? ((ObjectListItem)manageObjectList.SelectedElement).GetObject() : tileSetSelectionView.SelectedObject);
                            }
                        }
                    }
                }
                else
                {
                    inspectView.Draw(spriteBatch, gameTime);
                }
            }
        }