Exemplo n.º 1
0
        //Called to set what StellarObject the player has selected.
        public static void SetSelectedStellarObject(Vector3 worldMousePos)
        {
            //The player might accidentally click what would be a null position in the system's array, so we need to handle that.
            try
            {
                //Sets the selected StellarObject to the nearest StellarObject in the star system's array, accounting for the offset in the drawn screen as well.
                selectedStellarObject = renderStarSystem.systemObjects[Mathf.RoundToInt(worldMousePos.x - drawXOffset) + Settings.systemRadius,
                                                                       Mathf.RoundToInt(worldMousePos.y - drawYOffset) + Settings.systemRadius];

                //Check to see if there are ships present in the StellarObject.
                if (selectedStellarObject.ShipsPresent())
                {
                    //If there are, set the player's selected ship to the displayed ship, allowing it to be given move orders and so on.
                    UnitManager.SetSelectedShip(selectedStellarObject.GetDisplayedShip());
                }
                else
                {
                    //Otherwise, make it so no ship is selected.
                    UnitManager.SetSelectedShip(null);
                }
            }
            catch
            {
                //Do nothing, this is an honest mistake that isn't an issue.
            }
        }
Exemplo n.º 2
0
        //Called every frame to tell the GPU what meshes to render with what textures and where, essentially.
        public static void DrawPlayScreen()
        {
            //Currently, we're setting the star system to render to the only star system available in the galaxy right now,
            //later, the player will be able to move from system to system.
            renderStarSystem = Galaxy.galaxyArray[0, 0];

            //Once the game knows what system to render, we loop through every possible position in the array.
            //While this might not be the fastest possible way, it's fast enough for now at least.
            for (int x = 0; x < Settings.systemRadius * 2 + 1; x++)
            {
                for (int y = 0; y < Settings.systemRadius * 2 + 1; y++)
                {
                    //Is the position in the array null? If it is, it's meant to be that way, so do nothing.
                    if (renderStarSystem.systemObjects[x, y] != null)
                    {
                        //Grab a temporary reference to the StellarObject contained at x, y position in the system.
                        workStellarObject = renderStarSystem.systemObjects[x, y];

                        //If this StellarObject is the same as the one currently selected by the player...
                        if (workStellarObject == selectedStellarObject)
                        {
                            //...draw the selection icon at the foremost z layer at its position.
                            InternalDrawMesh(x - Settings.systemRadius + drawXOffset, y - Settings.systemRadius + drawYOffset, 0, MatDict.GetMaterial("Selection"));
                        }

                        //Check if ships are present.
                        if (workStellarObject.ShipsPresent())
                        {
                            //If they are, grab a reference to the top-most ship for display purposes, and order it to be rendered.
                            workShip = workStellarObject.GetDisplayedShip();
                            InternalDrawMesh(x - Settings.systemRadius + drawXOffset, y - Settings.systemRadius + drawYOffset, 1, workShip.rotation, MatDict.GetMaterial(workShip.rootTemplate.graphicName));
                        }

                        //Finally, draw whatever texture the StellarObject has, with an EmptySpace background behind it. Eventually, I'll use a single background image
                        //spread across the whole screen instead of an ugly repeating texture.
                        InternalDrawMesh(x - Settings.systemRadius + drawXOffset, y - Settings.systemRadius + drawYOffset, 2, MatDict.GetMaterial(renderStarSystem.systemObjects[x, y].rootTemplate.graphicName));
                        InternalDrawMesh(x - Settings.systemRadius + drawXOffset, y - Settings.systemRadius + drawYOffset, 3, MatDict.GetMaterial("StellarObject_EmptySpace"));
                    }
                }
            }
        }