Example #1
0
        public Entity(Texture2D image, Vector2 position, float maxAcc, float maxSpe)
        {
            boundingCircle = new Circle(position.X, position.Y, 50);
            debugCircle    = new PrimitiveLine(position, Color.White);
            debugCircle.CreateCircle(50, 20);

            velocity = new Vector2();

            this.image           = image;
            this.position        = position;
            this.maxAcceleration = maxAcc;
            this.maxSpeed        = maxSpe;
            rotation             = orientation = wanderOrientation = 0;
            offsetToCenter       = new Vector2(image.Width / 2, image.Height / 2);
            position            += offsetToCenter;

            //for now, make max angular rotation and rotation statndard
            this.maxRotation            = 0.2f;
            this.maxAngularAcceleration = 1;

            maxSpeedSq = maxSpeed * maxSpeed;

            neighbors = new List <Entity>();

            wanderSpeed = 0.5f;
        }
Example #2
0
        public void DrawExplosion(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            if (explosionTime > 0.3f)
            {
                CurrentState = State.DEAD;
            }

            float circleRadius;
            float f = 1f - explosionTime * 3.33f;
            float k;

            if (explosionTime < 0.1f)
            {
                circleRadius = (sprite.Width / 2f) * 1.3f - explosionTime * explosionTime * 50f + 5 + 50 * explosionTime;
                k            = 1;
            }
            else
            {
                circleRadius = (sprite.Width / 2f) * 1.3f - explosionTime * explosionTime * 200f;
                k            = f + 0.3f;
            }
            // 0.1 = 5
            float blastRadius = (sprite.Width / 2f) * 1.3f + 50f * (float)(Math.Sqrt(explosionTime * 4f));

            Color blastColor = new Color(Constans.MAIN_EXPLOSION_COLOR.R / 255f * f * 1.5f,
                                         Constans.MAIN_EXPLOSION_COLOR.G / 255f * f * 1.5f,
                                         Constans.MAIN_EXPLOSION_COLOR.B / 255f * f * 1.5f, f * 1.5f);

            line.ClearVectors();
            line.CreateCircle(blastRadius, 20);

            Vector2 corner = CalculateScreenPosition();

            float blastX = corner.X + sprite.Width / 2f;
            float blastY = corner.Y + sprite.Height / 2f;

            line.Colour = blastColor;
            line.Render(spriteBatch, new Vector2((int)blastX, (int)blastY));

            if (circleRadius >= 0)
            {
                corner.X += sprite.Width / 2f;
                corner.Y += sprite.Height / 2f;

                corner.X -= circleRadius;
                corner.Y -= circleRadius;

                Color color = new Color(Constans.MAIN_EXPLOSION_COLOR.R / 255f * k,
                                        Constans.MAIN_EXPLOSION_COLOR.G * k / 255f,
                                        Constans.MAIN_EXPLOSION_COLOR.B * k / 255f, k);

                spriteBatch.Draw(circle,
                                 new Rectangle((int)corner.X, (int)corner.Y, (int)circleRadius * 2, (int)circleRadius * 2),
                                 color);
            }
        }
Example #3
0
        public void OnLoadContentEvent(GameScreenManager.LoadContentEventArgs eventArgs)
        {
            List <string> enemies = new List <string> {
                "alien1", "alien2", "alien3"
            };
            int index = row % enemies.Count;

            sprite = eventArgs.contentManager.Load <Texture2D>(enemies[index]);
            circle = eventArgs.contentManager.Load <Texture2D>("circle");
            line   = new PrimitiveLine();
            line.CreateCircle(200, 40);
        }
Example #4
0
        public void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            if (explosionTime < 0)
            {
                return;
            }

            if (shouldPlaySound)
            {
                SoundPlayer.Instance.PlaySound("explosion1");
                shouldPlaySound = false;
            }

            if (explosionTime > 0.3f || CurrentState.Equals(State.EXPLODED))
            {
                CurrentState = State.EXPLODED;
                return;
            }

            float circleRadius;
            float f = 1f - explosionTime * 3.33f;
            float k;

            if (explosionTime < 0.1f)
            {
                circleRadius = (spriteWidth / 2f) * 1.3f - explosionTime * explosionTime * 50f + 5 + 50 * explosionTime;
                k            = 1;
            }
            else
            {
                circleRadius = (spriteWidth / 2f) * 1.3f - explosionTime * explosionTime * 200f;
                k            = f + 0.3f;
            }
            // 0.1 = 5
            float blastRadius = (spriteWidth / 2f) * 1.3f + 50f * (float)(Math.Sqrt(explosionTime * 4f));
            Color blastColor  = new Color(Constans.MAIN_PLAYER_EXPLOSION_COLOR.R / 255f * f * 1.5f,
                                          Constans.MAIN_PLAYER_EXPLOSION_COLOR.G / 255f * f * 1.5f,
                                          Constans.MAIN_PLAYER_EXPLOSION_COLOR.B / 255f * f * 1.5f, f * 1.5f);

            line.ClearVectors();
            line.CreateCircle(blastRadius, 100);

            Vector2 corner = ScreenUtils.TranslateToScreenCoordinates(position);

            float blastX = corner.X /*- spriteWidth / 2f*/;
            float blastY = corner.Y /* - spriteWidth / 2f*/;

            line.Colour = blastColor;
            line.Render(spriteBatch, new Vector2((int)blastX, (int)blastY));

            if (circleRadius >= 0)
            {
                corner.X -= circleRadius;
                corner.Y -= circleRadius;

                Color color = new Color(Constans.MAIN_PLAYER_EXPLOSION_COLOR.R / 255f * k,
                                        Constans.MAIN_PLAYER_EXPLOSION_COLOR.G / 255f * k,
                                        Constans.MAIN_PLAYER_EXPLOSION_COLOR.B / 255f * k, k);
                spriteBatch.Draw(circle,
                                 new Rectangle((int)corner.X, (int)corner.Y, (int)circleRadius * 2, (int)circleRadius * 2),
                                 color);
            }
        }
Example #5
0
 private void OnLoadContentEvent(GameScreenManager.LoadContentEventArgs eventArgs)
 {
     circle = eventArgs.contentManager.Load <Texture2D>("circle");
     line   = new PrimitiveLine();
     line.CreateCircle(200, 1000);
 }