Beispiel #1
0
        public static void Draw(SpriteBatch sprites, Camera camera)
        {
            Rectangle frustum = new Rectangle((int)(camera.Position.X - camera.Size.X / 2), (int)(camera.Position.Y - camera.Size.Y / 2), (int)camera.Size.X, (int)camera.Size.Y);

            for (int i = 1; i <= 8; i++)
            {
                int    systemRadius       = (int)Math.Pow(2, 16);
                int    starMovementFactor = i * 32;
                Camera starCamera         = new Camera();
                starCamera.Size     = camera.Size;
                starCamera.Position = new Vector2((camera.Position.X / starMovementFactor) % 1024, (camera.Position.Y / starMovementFactor) % 1024);

                sprites.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearClamp, null, null, null, starCamera.GetTransformation());

                for (int x = -(int)Math.Ceiling(camera.Size.X / 1024) * 1024; x < Math.Ceiling(camera.Size.X / 1024) * 1024; x += 1024)
                {
                    for (int y = -(int)Math.Ceiling(camera.Size.Y / 1024) * 1024; y < Math.Ceiling(camera.Size.Y / 1024) * 1024; y += 1024)
                    {
                        sprites.Draw(GameContent.Texture("environment\\background\\stars" + i), (new Vector2(x, y)).Round(), Color.White);
                    }
                }

                sprites.End();
            }
        }
Beispiel #2
0
        protected override void Draw(GameTime time)
        {
            GraphicsDevice.Clear(Color.Black);

            if (State == GameState.AtMenu)
            {
                sprites.Begin();

                for (int i = 0; i < ScreenBounds.X / 100; i++)
                {
                    Utility.DrawDottedCircle(sprites, Color.Gray, ScreenBounds / 2, i * 100, 16);
                }

                for (int x = 0; x < Math.Ceiling(ScreenBounds.X / 1024); x++)
                {
                    for (int y = 0; y < Math.Ceiling(ScreenBounds.Y / 1024); y++)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            sprites.Draw(GameContent.Texture("environment\\background\\stars" + (i + 1)), new Vector2(x * 1024, y * 1024), Color.White);
                        }
                    }
                }

                sprites.End();
            }
            else if (State == GameState.Connecting)
            {
                ConnectingScreen.Draw(this, sprites, time);
            }
            else if (State == GameState.InGame)
            {
                Backdrop.Draw(sprites, MainCamera);

                if (NetworkHelper.LocalPlayer != null)
                {
                    MainCamera.Position = NetworkHelper.LocalPlayer.RenderPosition;
                    //Camera.Position = new Vector2((int)Math.Round(MathHelper.Lerp(Camera.Position.X, NetworkHelper.LocalPlayer.RenderPosition.X, 0.05f)), (int)Math.Round(MathHelper.Lerp(Camera.Position.Y, NetworkHelper.LocalPlayer.RenderPosition.Y, 0.5f)));
                }
                else
                {
                    MainCamera.Position = Vector2.Zero;
                }

                sprites.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearClamp, null, null, null, MainCamera.GetTransformation());

                Particles.Draw(sprites);
                DrawSystem();
                Entities.EntityManager.Draw(sprites);

                sprites.End();

                HUD.Draw(sprites, this);
            }

            Interface.InterfaceManager.Draw(sprites);

            base.Draw(time);
        }
Beispiel #3
0
        public static void DrawCircle(SpriteBatch sprites, Color color, Vector2 pos, int radius)
        {
            pos = pos.Round();

            for (float i = 0; i < Math.PI * 2; i += 1.0f / radius)
            {
                sprites.Draw(GameContent.Texture("pixel"), pos + new Vector2((float)Math.Sin(i) * radius, (float)Math.Cos(i) * radius), color);
            }
        }
Beispiel #4
0
        public static void DrawLine(SpriteBatch sprites, Color color, Vector2 start, Vector2 end)
        {
            start = start.Round();
            end   = end.Round();

            Vector2 line  = end - start;
            float   angle = (float)Math.Atan2(line.Y, line.X);

            sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)start.X, (int)start.Y, (int)line.Length(), 1), null, color, angle, new Vector2(0, 0), SpriteEffects.None, 0);
        }
Beispiel #5
0
 public static void Draw(SpriteBatch sprites)
 {
     foreach (Particle particle in particles)
     {
         if (particle.Life > 0) // I don't even know anymore
         {
             sprites.Draw(GameContent.Texture("pixel"), particle.Position, particle.Color);
         }
     }
 }
Beispiel #6
0
        public static void DrawDottedCircle(SpriteBatch sprites, Color color, Vector2 pos, int radius, int sparsity)
        {
            pos = pos.Round();

            for (float i = 0; i < (Math.PI * 2); i += (1.0f / radius) * sparsity)
            {
                if (i + (1.0f / radius) * sparsity < (Math.PI * 2))
                {
                    sprites.Draw(GameContent.Texture("pixel"), pos + new Vector2((float)Math.Sin(i) * radius, (float)Math.Cos(i) * radius), color);
                }
            }
        }
Beispiel #7
0
        public static void DrawCircleOptimized(SpriteBatch sprites, Camera camera, Color color, Vector2 pos, int radius)
        {
            pos = pos.Round();

            for (float i = 0; i < Math.PI * 2; i += 1.0f / radius)
            {
                Vector2   pixelPos = pos + new Vector2((float)Math.Sin(i) * radius, (float)Math.Cos(i) * radius);
                Rectangle frustum  = new Rectangle((int)(camera.Position.X - camera.Size.X / 2), (int)(camera.Position.Y - camera.Size.Y / 2), (int)camera.Size.X, (int)camera.Size.Y);

                if (frustum.Contains(new Point((int)pixelPos.X, (int)pixelPos.Y)))
                {
                    sprites.Draw(GameContent.Texture("pixel"), pixelPos, color);
                }
            }
        }
Beispiel #8
0
        protected override void LoadContent()
        {
            MainCamera.Size = ScreenBounds;

            Window.AllowUserResizing  = true;
            Window.ClientSizeChanged += new EventHandler <EventArgs>((sender, e) =>
            {
                float snap   = 10.0f;
                ScreenBounds = new Vector2((float)Math.Round(Window.ClientBounds.Width / snap) * snap, (float)Math.Round(Window.ClientBounds.Height / snap) * snap);
                Window.Title = "Aphelion - X:" + ScreenBounds.X + ", Y:" + ScreenBounds.Y;

                graphics.PreferredBackBufferWidth  = (int)ScreenBounds.X;
                graphics.PreferredBackBufferHeight = (int)ScreenBounds.Y;
                graphics.ApplyChanges();

                // TO DO: Decide if I should turn this into a switch statement
                if (State == GameState.AtMenu)
                {
                    Interface.InterfaceManager.RemoveAllWithTag("Title Menu");
                    Interface.InterfaceManager.RemoveAllWithTag("Prompt");

                    CreateTitleMenu();
                }
                else
                {
                    Interface.TextButton debugButton = (Interface.TextButton)Interface.InterfaceManager.GetAllElementsWithTag("Debug Button")[0];
                    debugButton.Position             = new Vector2(8, ScreenBounds.Y - 8 - debugButton.CalculateDimensions().Y);
                }

                MainCamera.Size = ScreenBounds;
            });

            sprites = new SpriteBatch(GraphicsDevice);
            GameContent.SetContentManager(Content);

            TextRenderer.SetSpriteBatch(sprites);
            TextRenderer.SetFont(GameContent.Texture(@"interface\fonts\default"));

            CreateTitleMenu();
        }
        public static void Draw(Aphelion aphelion, SpriteBatch sprites, GameTime time)
        {
            sprites.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, RasterizerState.CullNone);

            sprites.Draw(GameContent.Texture("pixel"), new Rectangle(0, 0, (int)aphelion.ScreenBounds.X, (int)aphelion.ScreenBounds.Y), Color.Black);

            CurrentColor = Color.Lerp(CurrentColor, DestColor, 0.05f);

            TextRenderer.SaveState();
            TextRenderer.SetScale(2);
            TextRenderer.SetColor(Color.FromNonPremultiplied(CurrentColor.R, CurrentColor.G, CurrentColor.B, 155 - (int)(Math.Cos(time.TotalGameTime.TotalSeconds) * 100)));

            Vector2 textSize = TextRenderer.MeasureString(Text);

            TextRenderer.DrawString(Text, aphelion.ScreenBounds / 2 - textSize / 2);
            TextRenderer.RestoreState();

            for (int i = 0; i < 4; i++)
            {
                Utility.DrawCircle(sprites, Color.FromNonPremultiplied(CurrentColor.R, CurrentColor.G, CurrentColor.B, 155 - (int)(Math.Cos(time.TotalGameTime.TotalSeconds + i) * 100)), aphelion.ScreenBounds / 2, (int)textSize.X / 2 + 64 + (int)(Math.Cos(time.TotalGameTime.TotalSeconds + i) * 32));
            }

            sprites.End();
        }
Beispiel #10
0
        private static void DrawRadar(SpriteBatch sprites, Aphelion aphelion) // TO DO: Give the radar it's own file (Radar.cs)
        {
            int     ratio       = (int)Math.Pow(2, 9);
            Vector2 radarOrigin = aphelion.ScreenBounds - new Vector2(128, 128) - new Vector2(16, 16);

            Utility.DrawDottedCircle(sprites, Color.White, radarOrigin, 128, 16);

            #region Sun & Planets

            int     sunRadius = 6958;
            Vector2 sunPos    = Vector2.Zero;

            int     mercuryRadius   = 24;
            int     mercuryDistance = 8368;
            Vector2 mercuryPos      = new Vector2(sunRadius + mercuryDistance, 0);

            int     venusRadius   = 60;
            int     venusDistance = 8368;
            Vector2 venusPos      = new Vector2(mercuryPos.X + venusDistance, 0);

            Vector2 center = radarOrigin - new Vector2(2, 3);
            TextRenderer.SaveState();
            TextRenderer.SetScale(1);
            TextRenderer.SetColor(Color.Red);
            Utility.DrawCircle(sprites, Color.Red, radarOrigin, sunRadius / ratio);
            Utility.DrawCircle(sprites, Color.Orange, radarOrigin, sunRadius / ratio - 2);
            TextRenderer.DrawString("S", center);
            TextRenderer.SetColor(Color.Gray);
            TextRenderer.DrawString("M", center + mercuryPos / ratio);
            TextRenderer.SetColor(Color.DarkOrange);
            TextRenderer.DrawString("V", center + venusPos / ratio);
            TextRenderer.RestoreState();

            #endregion

            if (NetworkHelper.LocalPlayer != null)
            {
                Vector2 localPlayerPos = radarOrigin + NetworkHelper.LocalPlayer.Position / ratio;

                sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)localPlayerPos.X - 1, (int)localPlayerPos.Y - 1, 3, 3), Color.White);
            }

            foreach (Player player in NetworkHelper.Players)
            {
                Vector2 playerPos = radarOrigin + player.Position / ratio;

                sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)playerPos.X - 1, (int)playerPos.Y - 1, 3, 3), Color.LawnGreen);
            }

            // TargetPos System

            MouseState mouseState = Mouse.GetState();
            Vector2    mousePos   = new Vector2(mouseState.X, mouseState.Y);

            if (Vector2.Distance(radarOrigin, mousePos) <= 128)
            {
                aphelion.IsMouseVisible = false;

                Utility.DrawLine(sprites, Color.White, mousePos + new Vector2(0, 4), mousePos + new Vector2(0, 4 + 16));
                Utility.DrawLine(sprites, Color.White, mousePos - new Vector2(0, 4), mousePos - new Vector2(0, 4 + 16));
                Utility.DrawLine(sprites, Color.White, mousePos + new Vector2(4, 0), mousePos + new Vector2(4 + 16, 0));
                Utility.DrawLine(sprites, Color.White, mousePos - new Vector2(4, 0), mousePos - new Vector2(4 + 16, 0));

                if (mouseState.LeftButton == ButtonState.Pressed /* && lastMouseState.LeftButton == ButtonState.Released*/)
                {
                    targetPos  = ((aphelion.ScreenBounds - new Vector2(128, 128) - new Vector2(16, 16)) - new Vector2(mouseState.X, mouseState.Y)) * -ratio;
                    drawTarget = true;
                }
                else if (mouseState.RightButton == ButtonState.Pressed && lastMouseState.RightButton == ButtonState.Released)
                {
                    drawTarget = false;
                }
            }
            else
            {
                aphelion.IsMouseVisible = true;
            }

            lastMouseState = mouseState;

            if (targetPos != null && drawTarget)
            {
                Vector2 targetDrawPos = radarOrigin + targetPos / ratio;

                Utility.DrawLine(sprites, Color.White, targetDrawPos + new Vector2(0, 2), targetDrawPos + new Vector2(0, 5));
                Utility.DrawLine(sprites, Color.White, targetDrawPos - new Vector2(0, 2), targetDrawPos - new Vector2(0, 5));
                Utility.DrawLine(sprites, Color.White, targetDrawPos + new Vector2(2, 0), targetDrawPos + new Vector2(5, 0));
                Utility.DrawLine(sprites, Color.White, targetDrawPos - new Vector2(2, 0), targetDrawPos - new Vector2(5, 0));

                if (NetworkHelper.LocalPlayer != null)
                {
                    Vector2 localPlayerPos = radarOrigin + NetworkHelper.LocalPlayer.Position / ratio;

                    if (Vector2.Distance(NetworkHelper.LocalPlayer.Position, targetPos) > 64)
                    {
                        Vector2 tangent = (targetDrawPos - localPlayerPos); // TO DO: Figure out if this is actually what a tangent is. I'm only in Algebra 2 ¯\_(ツ)_/¯
                        tangent.Normalize();
                        Utility.DrawLine(sprites, Color.White, targetDrawPos - tangent * 5, localPlayerPos + tangent * 3);
                    }

                    // SHADY CODE
                    sprites.End();

                    sprites.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearClamp, null, null, null, aphelion.MainCamera.GetTransformation());

                    if (Vector2.Distance(NetworkHelper.LocalPlayer.Position, targetPos) > 64)
                    {
                        Vector2 tangent2 = (targetPos - NetworkHelper.LocalPlayer.Position);
                        tangent2.Normalize();
                        Utility.DrawLine(sprites, Color.White, NetworkHelper.LocalPlayer.Position + tangent2 * 25, targetPos - tangent2 * 30);
                    }

                    Utility.DrawLine(sprites, Color.White, targetPos + new Vector2(0, 4), targetPos + new Vector2(0, 4 + 16));
                    Utility.DrawLine(sprites, Color.White, targetPos - new Vector2(0, 4), targetPos - new Vector2(0, 4 + 16));
                    Utility.DrawLine(sprites, Color.White, targetPos + new Vector2(4, 0), targetPos + new Vector2(4 + 16, 0));
                    Utility.DrawLine(sprites, Color.White, targetPos - new Vector2(4, 0), targetPos - new Vector2(4 + 16, 0));

                    sprites.End();

                    sprites.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null);
                    // END SHADY CODE
                }
            }
        }