예제 #1
0
        public void DragObject(ScreenObject so)
        {
            Vector2 currentMouse = so.parent.getRelativeMouse();

            so.position += currentMouse - prevMouse;
            prevMouse    = so.parent.getRelativeMouse();
        }
예제 #2
0
        public virtual void LoadCopy(ScreenObject so)
        {
            state = so.state;

            origin              = so.origin;
            relativePosition    = so.relativePosition;
            position            = so.position;
            velocity            = so.velocity;
            acceleration        = so.acceleration;
            angularAcceleration = so.angularAcceleration;
            angularVelocity     = so.angularVelocity;
            angle    = so.angle;
            mass     = so.mass;
            friction = so.friction;
            fCritVel = so.fCritVel;

            scale           = so.scale;
            relativeScale   = so.relativeScale;
            radius          = so.radius;
            Width           = Height = so.Width;
            rectangle       = so.rectangle;
            parent          = so.parent;
            layer           = so.layer;
            color           = so.color;
            hitWall         = so.hitWall;
            spriteEffects   = so.spriteEffects;
            CollisionMethod = so.CollisionMethod;
        }
예제 #3
0
        //functions
        public virtual void LoadContent()
        {
            state = STATE_INACTIVE;

            origin              = Vector2.Zero;
            relativePosition    = Vector2.Zero;
            position            = Vector2.Zero;
            velocity            = Vector2.Zero;
            acceleration        = Vector2.Zero;
            angularAcceleration = 0;
            angularVelocity     = 0;
            angle    = 0;
            mass     = 1f;
            friction = 1f;
            fCritVel = 0f;

            scale           = 1f;
            relativeScale   = 1f;
            radius          = 100f;
            Width           = Height = (int)radius;
            rectangle       = new Rectangle(0, 0, Width, Height);
            parent          = null;
            layer           = 0.5f;
            color           = Color.White;
            hitWall         = false;
            spriteEffects   = SpriteEffects.None;
            CollisionMethod = ObjectsCollideByRectangle;
        }
예제 #4
0
        public void renderExplosion(ScreenObject parent, Vector2 pos, int numParticles, float size, float maxAge, GameTime gameTime)
        {
            //stopwatch.Reset();  //++++++++++ Test 1 ++++++++++++++++++
            //stopwatch.Start();  //++++++++++ Test 1 ++++++++++++++++++
            for (int i = 0; i < numParticles; i++)
            {
                Particle p = (Particle)GetNextObject();
                p.parent    = parent;
                p.position  = pos;
                p.birthTime = (float)gameTime.TotalGameTime.TotalMilliseconds;
                p.maxAge    = maxAge;
                p.scale     = size * .25f;
                p.color     = Color.White;
                p.state     = Particle.STATE_FADE;

                float   particleDistance = (float)Global.random.NextDouble() * size;
                Vector2 displacement     = new Vector2(particleDistance, 0);
                float   ang   = MathHelper.ToRadians(Global.random.Next(360));
                float   ang2  = MathHelper.ToRadians(Global.random.Next(360));
                float   ang3  = (float)Global.random.NextDouble() * .01f;
                float   ang3d = Global.random.Next(-1, 2);
                displacement      = Vector2.Transform(displacement, Matrix.CreateRotationZ(ang2));
                p.angularVelocity = ang3d * ang3;
                p.angle           = ang;
                p.velocity        = displacement;
                p.friction        = 0.97f;
            }
            //stopwatch.Stop();   //---------- Test 1 ------------------
            //test1 = stopwatch.Elapsed;  //-- Test 1 ------------------
        }
예제 #5
0
        public override void Add(ScreenObject so)
        {
            ScreenObject parentt = so.parent;

            base.Add(so);
            so.parent = parentt;
        }
예제 #6
0
 static public void ObjectsCollideByRectangle(ScreenObject ob1, ScreenObject ob2)
 {
     //use bool collision to determine if there was a collision
     if (ob1.rectangle.Intersects(ob2.rectangle))
     {
         collision = true;
         return;
     }
     collision = false;
 }
예제 #7
0
 static public void ObjectsCollide(ScreenObject so1, ScreenObject so2)
 {
     if (so1 is SpriteObject && so2 is SpriteObject)
     {
         ObjectsCollide((SpriteObject)so1, (SpriteObject)so2);
     }
     else
     {
         ObjectsCollideByRectangle(so1, so2);
     }
 }
예제 #8
0
        static public void ObjectsCollideByRadius(ScreenObject ob1, ScreenObject ob2)
        {
            //use bool collision to determine if there was a collision
            float dist = Vector2.Distance(ob1.position, ob2.position) - ob1.radius - ob2.radius;

            if (dist < 0)
            {
                collision = true;
                return;
            }
            collision = false;
        }
예제 #9
0
        private void setScreenLayer()
        {
            //The actual layer for this object will be an amalgamation of its parents layers.
            //An object with layer .2 with a parent with layer .4 with a parent with layer .3
            //will have the layer .342
            ScreenObject pa = parent;

            relativeLayer = layer;
            do
            {
                relativeLayer = pa.layer + relativeLayer * .1f;
                pa            = pa.parent;
            } while (pa != null);
        }
예제 #10
0
        public override void LoadCopy(ScreenObject so)
        {
            base.LoadCopy(so);
            SpriteObject spo = (SpriteObject)so;

            texture      = spo.texture;
            textureData  = spo.textureData;
            matrix       = spo.matrix;
            origin       = spo.origin;
            _TR          = spo._TR;
            _BL          = spo._BL;
            _BR          = spo._BR;
            hlColor      = spo.hlColor;
            hlOverColor  = spo.hlOverColor;
            hlTexture    = spo.hlTexture;
            hlClickColor = spo.hlClickColor;
            hlSetColor   = spo.hlSetColor;
            radius       = spo.radius;
        }
예제 #11
0
        public override bool Equals(object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            ScreenObject so = obj as ScreenObject;

            if ((System.Object)so == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return(ID == so.ID);
        }
예제 #12
0
 public bool cursorOverObject(ScreenObject so)
 {
     //use the ScreenObject's variable method CollisionMethod
     so.CollisionMethod(cursor, so);
     return(ScreenObject.collision);
 }