コード例 #1
0
ファイル: Panel.cs プロジェクト: dylanbienenstock/Aphelion
 public Panel()
 {
     Position    = Vector2.Zero;
     BorderScale = 1;
     BorderColor = Color.Gray;
     Color       = Color.FromNonPremultiplied(new Vector4(1, 1, 1, 0.25f));
     Texture     = GameContent.Texture("pixel");
 }
コード例 #2
0
        public ImageButton()
        {
            Position = Vector2.Zero;
            Image    = GameContent.Texture(@"icons\accept");
            State    = ButtonState.Idle;

            lastMouseState = Mouse.GetState();
        }
コード例 #3
0
ファイル: TextBox.cs プロジェクト: dylanbienenstock/Aphelion
 public TextBox()
 {
     Text              = string.Empty;
     Mode              = TextBoxInputMode.Anything;
     Position          = Vector2.Zero;
     BorderScale       = 1;
     Scale             = 1;
     MaxLength         = 8;
     BorderColor       = Color.Gray;
     BackgroundColor   = Color.FromNonPremultiplied(new Vector4(0, 0, 0, 0.25f));
     Color             = Color.White;
     Texture           = GameContent.Texture("pixel");
     Font              = TextRenderer.GetFont();
     Shadow            = true;
     Enabled           = true;
     State             = ButtonState.Idle;
     cursor            = false;
     lastMouseState    = Mouse.GetState();
     lastKeyboardState = Keyboard.GetState();
 }
コード例 #4
0
ファイル: CheckBox.cs プロジェクト: dylanbienenstock/Aphelion
        public override void Draw(SpriteBatch sprites)
        {
            Color drawColor = Color;

            if (State == ButtonState.Hovered)
            {
                drawColor = Color.FromNonPremultiplied(drawColor.ToVector4() - new Vector4(0.2f, 0.2f, 0.2f, 0));
            }
            else if (State == ButtonState.Pressed)
            {
                drawColor = Color.FromNonPremultiplied(drawColor.ToVector4() - new Vector4(0.45f, 0.45f, 0.45f, 0));
            }

            if (Shadow)
            {
                Color shadowColor = Color.FromNonPremultiplied(89, 89, 89, 255); // TO DO: Fix this

                sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)CalculatedPosition.X + Scale, (int)CalculatedPosition.Y + Scale, Scale * 7, Scale), shadowColor);
                sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)CalculatedPosition.X + Scale, (int)CalculatedPosition.Y + Scale, Scale, Scale * 7), shadowColor);
                sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)CalculatedPosition.X + Scale, (int)CalculatedPosition.Y + Scale + Scale * 7 - Scale, Scale * 7, Scale), shadowColor);
                sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)CalculatedPosition.X + Scale + Scale * 7 - Scale, (int)CalculatedPosition.Y + Scale, Scale, Scale * 7), shadowColor);

                if (Checked)
                {
                    sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)CalculatedPosition.X + Scale + Scale * 2, (int)CalculatedPosition.Y + Scale + Scale * 2, Scale * 7 - Scale * 4, Scale * 7 - Scale * 4), shadowColor);
                }
            }

            sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)CalculatedPosition.X, (int)CalculatedPosition.Y, Scale * 7, Scale), drawColor);
            sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)CalculatedPosition.X, (int)CalculatedPosition.Y, Scale, Scale * 7), drawColor);
            sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)CalculatedPosition.X, (int)CalculatedPosition.Y + Scale * 7 - Scale, Scale * 7, Scale), drawColor);
            sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)CalculatedPosition.X + Scale * 7 - Scale, (int)CalculatedPosition.Y, Scale, Scale * 7), drawColor);

            if (Checked)
            {
                sprites.Draw(GameContent.Texture("pixel"), new Rectangle((int)CalculatedPosition.X + Scale * 2, (int)CalculatedPosition.Y + Scale * 2, Scale * 7 - Scale * 4, Scale * 7 - Scale * 4), drawColor);
            }
        }
コード例 #5
0
ファイル: Player.cs プロジェクト: dylanbienenstock/Aphelion
        public override void Draw(SpriteBatch sprites)
        {
            Texture2D     defaultShip   = GameContent.Texture("ships\\default\\base");
            Texture2D     thrust        = GameContent.Texture("ships\\default\\forward");
            KeyboardState keyboardState = Keyboard.GetState();

            sprites.Draw(defaultShip, new Rectangle((int)RenderPosition.X, (int)RenderPosition.Y, defaultShip.Width, defaultShip.Height), null, Color.White, RenderAngle + MathHelper.ToRadians(90), new Vector2(defaultShip.Width / 2, defaultShip.Height / 2), SpriteEffects.None, 0);

            if (IsLocalPlayer)
            {
                if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W) && !keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S))
                {
                    sprites.Draw(thrust, new Rectangle((int)RenderPosition.X, (int)RenderPosition.Y, thrust.Width, thrust.Height), null, Color.White, RenderAngle + MathHelper.ToRadians(90), new Vector2(thrust.Width / 2, thrust.Height / 2), SpriteEffects.None, 0);

                    if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift))
                    {
                        Vector2 direction = new Vector2((float)Math.Cos(RenderAngle), (float)Math.Sin(RenderAngle));
                        Color[] colors    = new Color[] { Color.Red, Color.Orange };
                        Random  random    = new Random();

                        for (int i = 0; i < 3; i++)
                        {
                            Particle particle = new Particle();
                            particle.Life     = random.Next(500, 1250);
                            particle.Color    = colors[random.Next(colors.Length)];
                            particle.Position = RenderPosition - (defaultShip.Height / 2) * direction + new Vector2(random.Next(-2, 2), random.Next(-2, 2));
                            particle.Velocity = Velocity - direction * 0.05f + new Vector2(((float)random.NextDouble() - 0.5f) * 2.0f, ((float)random.NextDouble() - 0.5f) * 2.0f);
                            Particles.Add(particle);
                        }
                    }
                }
                else if (!keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W) && keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S))
                {
                    sprites.Draw(GameContent.Texture("ships\\default\\backward"), new Rectangle((int)RenderPosition.X, (int)RenderPosition.Y, thrust.Width, thrust.Height), null, Color.White, RenderAngle + MathHelper.ToRadians(90), new Vector2(thrust.Width / 2, thrust.Height / 2), SpriteEffects.None, 0);
                }

                if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A) && !keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D))
                {
                    sprites.Draw(GameContent.Texture("ships\\default\\left"), new Rectangle((int)RenderPosition.X, (int)RenderPosition.Y, thrust.Width, thrust.Height), null, Color.White, RenderAngle + MathHelper.ToRadians(90), new Vector2(thrust.Width / 2, thrust.Height / 2), SpriteEffects.None, 0);
                }
                else if (!keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A) && keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D))
                {
                    sprites.Draw(GameContent.Texture("ships\\default\\right"), new Rectangle((int)RenderPosition.X, (int)RenderPosition.Y, thrust.Width, thrust.Height), null, Color.White, RenderAngle + MathHelper.ToRadians(90), new Vector2(thrust.Width / 2, thrust.Height / 2), SpriteEffects.None, 0);
                }
            }
            else
            {
                Utility.DrawCircle(sprites, Color.LawnGreen, RenderPosition, 25);

                TextRenderer.SaveState();
                TextRenderer.SetScale(1);
                TextRenderer.SetColor(Color.White);
                TextRenderer.DrawString(Name, RenderPosition.Round() + new Vector2(16, -3));
                TextRenderer.RestoreState();

                if (MovingForward && !MovingBackward)
                {
                    sprites.Draw(thrust, new Rectangle((int)RenderPosition.X, (int)RenderPosition.Y, thrust.Width, thrust.Height), null, Color.White, RenderAngle + MathHelper.ToRadians(90), new Vector2(thrust.Width / 2, thrust.Height / 2), SpriteEffects.None, 0);

                    if (Boosting)
                    {
                        Vector2 direction = new Vector2((float)Math.Cos(RenderAngle), (float)Math.Sin(RenderAngle));
                        Color[] colors    = new Color[] { Color.Red, Color.Orange };
                        Random  random    = new Random();

                        for (int i = 0; i < 3; i++)
                        {
                            Particle particle = new Particle();
                            particle.Life     = random.Next(500, 1250);
                            particle.Color    = colors[random.Next(colors.Length)];
                            particle.Position = RenderPosition - (defaultShip.Height / 2) * direction + new Vector2(random.Next(-2, 2), random.Next(-2, 2));
                            particle.Velocity = Velocity - direction * 0.05f + new Vector2(((float)random.NextDouble() - 0.5f) * 2.0f, ((float)random.NextDouble() - 0.5f) * 2.0f);
                            Particles.Add(particle);
                        }
                    }
                }
                else if (!MovingForward && MovingBackward)
                {
                    sprites.Draw(GameContent.Texture("ships\\default\\backward"), new Rectangle((int)RenderPosition.X, (int)RenderPosition.Y, thrust.Width, thrust.Height), null, Color.White, RenderAngle + MathHelper.ToRadians(90), new Vector2(thrust.Width / 2, thrust.Height / 2), SpriteEffects.None, 0);
                }

                if (TurningLeft && !TurningRight)
                {
                    sprites.Draw(GameContent.Texture("ships\\default\\left"), new Rectangle((int)RenderPosition.X, (int)RenderPosition.Y, thrust.Width, thrust.Height), null, Color.White, RenderAngle + MathHelper.ToRadians(90), new Vector2(thrust.Width / 2, thrust.Height / 2), SpriteEffects.None, 0);
                }
                else if (!TurningLeft && TurningRight)
                {
                    sprites.Draw(GameContent.Texture("ships\\default\\right"), new Rectangle((int)RenderPosition.X, (int)RenderPosition.Y, thrust.Width, thrust.Height), null, Color.White, RenderAngle + MathHelper.ToRadians(90), new Vector2(thrust.Width / 2, thrust.Height / 2), SpriteEffects.None, 0);
                }
            }
        }