Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="windowBounds"></param>
        /// <param name="renderTarget"></param>
        public override void Render(Size2F windowBounds, WindowRenderTarget renderTarget)
        {
            viewCenterX += (destinationViewCenterX - viewCenterX) / 5f;
            viewCenterY += (destinationViewCenterY - viewCenterY) / 5f;

            RectangleF sourceRect;

            Map map = null;
            PlayerShipMapUnit shipUnit = null;

            if (currentShip != null && currentShip.IsAlive && mapManager.TryGetPlayerUnit(currentShip.Universe.Name, currentShip.Name, out map, out shipUnit))
            {
                sourceRect = getSourceRectangleF(shipUnit.Position.X, shipUnit.Position.Y, scale, windowBounds.Width, windowBounds.Height);
            }
            else
            {
                sourceRect = getSourceRectangleF(viewCenterX, viewCenterY, scale, windowBounds.Width, windowBounds.Height);
            }

            X = new Transformator(sourceRect.Left, sourceRect.Right, 0, windowBounds.Width);
            Y = new Transformator(sourceRect.Top, sourceRect.Bottom, 0, windowBounds.Height);

            // TODO: Default Universe muss gesetzt werden falls ein Schiff nicht am Leben ist

            List <MapUnit> unitList;

            if (((map != null && mapManager.TryGetUnits(map, sourceRect, out unitList)) ||
                 mapManager.TryGetUnits(currentShip.Universe.Name, sourceRect, out unitList)) &&
                unitList.Count > 0)
            {
                drawUnits(renderTarget, unitList);

                // TODO: Draw HUD
                //if (shipUnit != null)
                //{
                //    renderTarget.DrawRectangle(
                //        new SharpDX.Mathematics.Interop.RawRectangleF(
                //            windowBounds.Width / 2f - 50f,
                //            windowBounds.Height - 20f,
                //            windowBounds.Width / 2f + 50f,
                //            windowBounds.Height),
                //        Brushes.SolidColorBrushes.White);

                //    renderTarget.FillRectangle(
                //        new SharpDX.Mathematics.Interop.RawRectangleF(
                //            windowBounds.Width / 2f - 49f,
                //            windowBounds.Height - 19f,
                //            (windowBounds.Width / 2f - 49f) + 98f * shipUnit.Energy,
                //            windowBounds.Height - 1f),
                //        Brushes.SolidColorBrushes.Violet);
                //}

                // TODO: Temp Klick Position
                if (currentShip != null && currentShip.IsAlive)
                {
                    Flattiverse.Vector pos = currentShip.DesiredPosition;

                    if (pos != null)
                    {
                        Primitives.Circle.Fill(renderTarget, Brushes.SolidColorBrushes.White, new SharpDX.Vector2(X[pos.X], Y[pos.Y]), 2f);
                    }
                }

                if (showScoreBoard)
                {
                    scoreBoard.Draw(SCOREBOARD_PADDING, SCOREBOARD_PADDING, windowBounds.Width - SCOREBOARD_PADDING * 2f, windowBounds.Height - SCOREBOARD_PADDING * 2f, renderTarget);
                }

                //MapPathfinder mapPathfinder = ship.MapPathfinder;

                //if (mapPathfinder != null)
                //{
                //    MapSectionRaster[] rasters = ship.MapPathfinder.Rasters;

                //    for (int i = 0; i < rasters.Length; i++)
                //    {
                //        MapSectionRasterTile[] tiles = rasters[i].Tiles;

                //        for (int t = 0; t < tiles.Length; t++)
                //        {
                //            var tile = tiles[t];

                //            if ((tile.Status & MapSectionRasterTileStatus.Blocked) == MapSectionRasterTileStatus.Blocked)
                //            {
                //                SharpDX.Mathematics.Interop.RawRectangleF rectangleF = new SharpDX.Mathematics.Interop.RawRectangleF(
                //                X[tile.X - rasters[i].TileSize / 2f],
                //                Y[tile.Y - rasters[i].TileSize / 2f],
                //                X[tile.X + rasters[i].TileSize / 2f],
                //                Y[tile.Y + rasters[i].TileSize / 2f]);

                //                renderTarget.DrawRectangle(rectangleF, Brushes.SolidColorBrushes.White);

                //                renderTarget.DrawRectangle(rectangleF, Brushes.SolidColorBrushes.RedHalfTransparent);
                //            }
                //        }
                //    }
                //}
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the searched player ship unit and the map containing it
        /// </summary>
        /// <param name="universeName">The universe to search the unit in</param>
        /// <param name="unitName">Unit name</param>
        /// <param name="map">The map the unit is in</param>
        /// <param name="playerShipMapUnit">The searched unit</param>
        /// <returns></returns>
        public bool TryGetPlayerUnit(string universeName, string unitName, out Map map, out PlayerShipMapUnit playerShipMapUnit)
        {
            map = null;
            playerShipMapUnit = null;

            Map tempMainMap;

            if (TryGetMap(universeName, out tempMainMap) && tempMainMap != null)
            {
                tempMainMap.BeginLock();

                if (!tempMainMap.TryGetPlayerShip(unitName, out playerShipMapUnit))
                {
                    List <Map> universeMaps = universeSortedMaps[universeName];

                    if (universeMaps.Count > 1)
                    {
                        for (int i = 1; i < universeMaps.Count; i++)
                        {
                            Map tempMap = universeMaps[i];

                            try
                            {
                                tempMap.BeginLock();

                                if (tempMap.TryGetPlayerShip(unitName, out playerShipMapUnit))
                                {
                                    map = tempMap;
                                    break;
                                }
                            }
                            finally
                            {
                                tempMap.EndLock();
                            }
                        }
                    }
                }
                else
                {
                    map = tempMainMap;
                }

                tempMainMap.EndLock();
            }

            return(playerShipMapUnit != null);
        }