Ejemplo n.º 1
0
    public override void Up(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        if (target.BlockedAngleDetector)
        {
            return;
        }
        float contactX = contactPoint.position.x;
        float contactY = contactPoint.position.y;
        float bx       = GetX(x, l);
        float by       = GetY(y, l);

        if (contactX < bx + x1)
        {
            if (contactY <= by + y1)
            {
                base.Up(target, contactPoint, x, y, l);
            }
        }
        else if (contactX > bx + x2)
        {
            if (contactY <= by + y2)
            {
                base.AngleDetector(target, contactPoint, x, y, l);
            }
        }
    }
Ejemplo n.º 2
0
    public override void AngleDetector(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        float contactX = contactPoint.position.x;
        float contactY = contactPoint.position.y;
        float bx       = GetX(x, l);
        float by       = GetY(y, l);

        if (contactX < bx + x1)
        {
            if (contactY <= by + y1)
            {
                base.AngleDetector(target, contactPoint, x, y, l);
            }
        }
        else if (contactX > bx + x2)
        {
            if (contactY <= by + y2)
            {
                base.AngleDetector(target, contactPoint, x, y, l);
            }
        }
        else
        {
            float dy = m * (contactX - (bx + x1)) + (by + y1) - contactY;

            if (dy > 0 || target.GuidedByTerrain)
            {
                target.Y += dy;
                target.BlockedAngleDetector = true;
                target.TerrainAngle         = angle;
                target.BlockedFromBelow     = true;
            }
        }
    }
Ejemplo n.º 3
0
 public override void Down(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
 {
     if (angle != 0)
     {
         return;
     }
     base.Down(target, contactPoint, x, y, l);
 }
Ejemplo n.º 4
0
    public override void OnInspectorGUI()
    {
        MobileObject mo = (MobileObject)target;

        base.OnInspectorGUI();

        EditorGUILayout.LabelField("Physics");

        EditorGUI.indentLevel++;

        mo.Solid = EditorGUILayout.Toggle("Interact With Layers", mo.Solid);
        EditorGUILayout.Toggle("Blocked Below", mo.BlockedFromBelow);
        EditorGUILayout.Toggle("Blocked Above", mo.BlockedFromAbove);
        EditorGUILayout.Toggle("Blocked Right", mo.BlockedFromRight);
        EditorGUILayout.Toggle("Blocked Left", mo.BlockedFromLeft);

        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Terrain Angle: " + mo.TerrainAngle);

        EditorGUILayout.Separator();

        mo.XSpeed = EditorGUILayout.FloatField("X Speed", mo.XSpeed);
        mo.YSpeed = EditorGUILayout.FloatField("Y Speed", mo.YSpeed);

        EditorGUILayout.Separator();

        mo.XAccel = EditorGUILayout.FloatField("X Acceleration", mo.XAccel);
        mo.YAccel = EditorGUILayout.FloatField("Y Acceleration", mo.YAccel);

        EditorGUILayout.Separator();

        mo.MinXSpeed = EditorGUILayout.FloatField("Min X Speed", mo.MinXSpeed);
        mo.MinYSpeed = EditorGUILayout.FloatField("Min Y Speed", mo.MinYSpeed);

        EditorGUILayout.Separator();

        mo.MaxXSpeed = EditorGUILayout.FloatField("Max X Speed", mo.MaxXSpeed);
        mo.MaxYSpeed = EditorGUILayout.FloatField("Max Y Speed", mo.MaxYSpeed);

        EditorGUILayout.Separator();

        mo.XGravity = EditorGUILayout.FloatField("X Gravity", mo.XGravity);
        mo.YGravity = EditorGUILayout.FloatField("Y Gravity", mo.YGravity);

        EditorGUILayout.Separator();

        mo.XFriction = EditorGUILayout.FloatField("X Friction", mo.XFriction);
        mo.YFriction = EditorGUILayout.FloatField("Y Friction", mo.YFriction);

        EditorGUILayout.Separator();

        mo.Mass = EditorGUILayout.IntField("Mass", mo.Mass);

        EditorGUI.indentLevel--;

        EditorUtility.SetDirty(target);
    }
Ejemplo n.º 5
0
 public Acting(MobileObject mobileObject, Interfaces.IActions.IAction action, Point destination, IEnumerable<GameObject> objects)
 {
     // TODO: Complete member initialization
     this.mobileObject = mobileObject;
     this.action = action;
     this.destination = destination;
     this.objects = objects;
     this.timestamp = maxTimeStamp;
 }
Ejemplo n.º 6
0
 public Acting(MobileObject mobileObject, IAction action, Point destination, IList <GameObject> objects)
 {
     // TODO: Complete member initialization
     _mobileObject = mobileObject;
     _action       = action;
     _destination  = destination;
     _objects      = objects;
     _timestamp    = MAX_TIME_STAMP;
 }
Ejemplo n.º 7
0
    public override void up(MobileObject target, Transform contactPoint, float x, float y, int blockSize, layer l)
    {
        if (!target.Solid) return;

        float contactY = contactPoint.position.y;
        if ((target.YSpeed <= 0 && contactY - y <= 7) || target.GuidedByTerrain)
        {
            target.BlockedFromBelow = true;
        }
    }
Ejemplo n.º 8
0
    public override void Right(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        float nx = GetY(x, l) + BlockLayer.BlockSize;

        int b = l.getBlock(nx, contactPoint.position.y);

        if (b >= 0)
        {
            BlockLayer.AllBlocks[b].AngleDetector(target, contactPoint, l.getXPos(nx), y, l);
        }
    }
Ejemplo n.º 9
0
 private void Ani_Tick(int ticks)
 {
     for (int i = 0; i < Board.Items.Count; ++i)
     {
         MobileObject obj = Board.Items[i];
         if (!obj.Animate(Animations, ticks))
         {
             Board.Items.RemoveAt(i--);
         }
     }
 }
Ejemplo n.º 10
0
    public override void Up(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        float ny = GetY(y, l) + BlockLayer.BlockSize;

        int b = l.getBlock(contactPoint.position.x, ny);

        if (b >= 0)
        {
            BlockLayer.AllBlocks[b].Up(target, contactPoint, x, l.getYPos(ny), l);
        }
    }
Ejemplo n.º 11
0
    // Grows the list as needed
    private void Grow()
    {
        // Create a new array twice the size of the old one
        MobileObject[] newList = new MobileObject[list.Length + 1];

        // Copy all of the values into the new list, and reassign the old list
        for (int i = 0; i < list.Length; ++i)
        {
            newList[i] = list[i];
        }
        list = newList;
    }
Ejemplo n.º 12
0
Archivo: Combat.cs Proyecto: crybx/mud
 public IBaseObject Opponet(MobileObject mobileObject)
 {
     CombatPair.CombatPair pair;
     if (combatants.TryGetValue(mobileObject, out pair))
     {
         return(pair.Defender);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 13
0
    public override void up(MobileObject target, Transform contactPoint, float x, float y, int blockSize, layer l)
    {
        if (!target.Solid)
        {
            return;
        }

        if (target.YSpeed <= 0 || target.GuidedByTerrain)
        {
            target.BlockedFromBelow = true;
        }
    }
Ejemplo n.º 14
0
    public override void right(MobileObject target, Transform contactPoint, float x, float y, int blockSize, layer l)
    {
        if (!target.Solid || (target.TerrainAngle < 0 && target.BlockedFromBelow)) return;

        float contactY = contactPoint.position.y;
        if (target.YSpeed <= 0 && contactY - y <= 7 && target.XSpeed < 0 && contactPoint.position.x < (x + 15))
        {
            target.BlockedFromLeft = true;
            target.x += (x + 15) - contactPoint.position.x;
            target.XSpeed = 0;
        }
    }
Ejemplo n.º 15
0
    public override void angleDetector(MobileObject target, Transform contactPoint, float x, float y, int blockSize, layer l)
    {
        if (!target.Solid) return;

        float contactY = contactPoint.position.y;
        if ((target.YSpeed <= 0 && contactY - y <= 7) || target.GuidedByTerrain)
        {
            target.y += (y + 7) - contactY;
            target.TerrainAngle = 0;
            target.BlockedAngleDetector = true;
        }
    }
Ejemplo n.º 16
0
    private void Awake () {

        GameObject go = GameObject.Find ("MobileObject");

        if (go == null) { Debug.Log ("GameControl: Can't find MobileObject."); return; }

        phase       = Phases.Ended;
        mObject     = go.AddComponent<MobileObject> ();

        cam         = Camera.main;

        moveInfo    = new List<MotionInfo> ();
    }
Ejemplo n.º 17
0
    public override void down(MobileObject target, Transform contactPoint, float x, float y, int blockSize, layer l)
    {
        if (!target.Solid)
        {
            return;
        }
        float contactY = contactPoint.position.y;

        if (target.YSpeed > 0 && contactY < y + (blockSize / 2))
        {
            target.y -= contactY - y;
            target.BlockedFromAbove = true;
        }
    }
Ejemplo n.º 18
0
    public override void left(MobileObject target, Transform contactPoint, float x, float y, int blockSize, layer l)
    {
        if (!target.Solid)
        {
            return;
        }

        if (target.XSpeed > 0 && contactPoint.position.x > x + 1)
        {
            target.BlockedFromRight = true;
            target.x     += x + 1 - contactPoint.position.x;
            target.XSpeed = 0;
        }
    }
Ejemplo n.º 19
0
    public static void AddToCell(MobileObject toAdd)
    {
        // Required variables
        string       id = toAdd.CellID;
        float        min, max;
        int          sentinel = 0;
        MobileObject one, two;

        MobileObject[] sort;

        // Add object to the list, create an array to sort, and delete the list
        cellGrid[(int)toAdd.Pos.X / 10, (int)toAdd.Pos.Y / 10].Obj.Add(toAdd);
        sort = cellGrid[(int)toAdd.Pos.X / 10, (int)toAdd.Pos.Y / 10].Obj.ToArray();
        cellGrid[(int)toAdd.Pos.X / 10, (int)toAdd.Pos.Y / 10].Obj = null;


        // A Bubble Sort Algorithm I had written for 2300H (Assignment Four - Merge Two Arrays)
        // I had already written it and found it on my machine... repurposed it for this
        // Sorts the array
        if (sort.Length != 0)
        {
            while (sentinel != sort.Length - 1)
            {
                sentinel = 0;
                for (int i = 0; i < sort.Length - 1; ++i)
                {
                    // Get the data to sort and the z-index
                    min = sort[i].Pos.Z;
                    max = sort[i + 1].Pos.Z;
                    one = sort[i];
                    two = sort[i + 1];
                    ++sentinel;
                    if (min > max)
                    {
                        // If the one term is larger, swap them out
                        sort[i]     = two;
                        sort[i + 1] = one;
                        sentinel    = 0;
                    }
                }
            }
        }

        // Create a new list, and add the sorted elements back to it
        cellGrid[(int)toAdd.Pos.X / 10, (int)toAdd.Pos.Y / 10].Obj = new List <MobileObject>();
        foreach (var element in sort)
        {
            cellGrid[(int)toAdd.Pos.X / 10, (int)toAdd.Pos.Y / 10].Obj.Add(element);
        }
    }
Ejemplo n.º 20
0
    public static void RemoveFromCell(MobileObject toRemove)
    {
        // Required variables
        string       id = toRemove.CellID;
        float        min, max;
        int          sentinel = 0;
        MobileObject one, two;

        MobileObject[] sort;

        // Remove object from the list, create an array to sort, then delete the list
        cellGrid[(int)toRemove.Pos.X / 10, (int)toRemove.Pos.Y / 10].Obj.Remove(toRemove);
        sort = cellGrid[(int)toRemove.Pos.X / 10, (int)toRemove.Pos.Y / 10].Obj.ToArray();
        cellGrid[(int)toRemove.Pos.X / 10, (int)toRemove.Pos.Y / 10].Obj = null;

        // A Bubble Sort Algorithm I had written for 2300H... I had already written it
        // and found it on my machine... repurposed it for this
        // Sorts the list
        if (sort.Length != 0)
        {
            while (sentinel != sort.Length - 1)
            {
                sentinel = 0;
                for (int i = 0; i < sort.Length - 1; ++i)
                {
                    // Get the data to sort and the z-index
                    min = sort[i].Pos.Z;
                    max = sort[i + 1].Pos.Z;
                    one = sort[i];
                    two = sort[i + 1];
                    ++sentinel;
                    if (min > max)
                    {
                        // If the one z-index is larger, swap out the objects
                        sort[i]     = two;
                        sort[i + 1] = one;
                        sentinel    = 0;
                    }
                }
            }
        }

        // Create a new list and add elements back to it
        cellGrid[(int)toRemove.Pos.X / 10, (int)toRemove.Pos.Y / 10].Obj = new List <MobileObject>();
        foreach (var element in sort)
        {
            cellGrid[(int)toRemove.Pos.X / 10, (int)toRemove.Pos.Y / 10].Obj.Add(element);
        }
    }
Ejemplo n.º 21
0
    public override void right(MobileObject target, Transform contactPoint, float x, float y, int blockSize, layer l)
    {
        if (!target.Solid)
        {
            return;
        }


        if (target.XSpeed < 0 && contactPoint.position.x < (x + 15))
        {
            target.BlockedFromLeft = true;
            target.x     += (x + 15) - contactPoint.position.x;
            target.XSpeed = 0;
        }
    }
Ejemplo n.º 22
0
        public override void up(MobileObject target, Transform contactPoint, float x, float y, int blockSize, layer l)
        {
            float ny = (l.y - blockSize * l.height);

            ny += y + blockSize;

            int b = l.getBlock(contactPoint.position.x, ny);

            if (b >= 0)
            {
                float X = l.getXPos(contactPoint.position.x) * l.blockSize;
                float Y = l.getYPos(ny) * l.blockSize;

                layer.AllBlocks[b].up(target, contactPoint, X, Y, l.blockSize, l);
            }
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            MobileObject[] mobileObjects = new MobileObject[3];
            // insert MobileObject
            MobileObject mob1 = new MobileObject()
            {
                Name     = "Jawahara",
                Position = (12, 15),
                Id       = 123456
            };

            mobileObjects[0] = mob1;

            //Insert Vehicle
            Vehicle veh = new Vehicle()
            {
                Name     = "Willow",
                Position = (14, 13),
                Id       = 6549879,
                Length   = 23
            };

            mobileObjects[1] = veh;

            //Insert another vehicle
            mobileObjects[2] = new Vehicle()
            {
                Name     = "Indira",
                Position = (14, 13),
                Id       = 885298451,
                Length   = 12
            };

            foreach (var mobileObject in mobileObjects)
            {
                Console.WriteLine($"Name: {mobileObject.Name}, " +
                                  $"Position: {mobileObject.Position.X };{mobileObject.Position.Y}, " +
                                  $"Id: {mobileObject.Id}");

                if (mobileObject is Vehicle)
                {
                    Console.WriteLine($"Length: {((Vehicle)mobileObject).Length}");
                }
            }
        }
    }
Ejemplo n.º 24
0
        private void CreateBullet(MobileObject obj)
        {
            // Если у объекта еще перезарядка, то не стреляем
            if ((obj as IShooter).Reload > 0)
            {
                return;
            }

            float x = obj.X + obj.Width / 2 - 2;
            float y = obj.Y + obj.Height / 2 - 2;

            int w = obj.IsHorizontal() ? 8 : 4;
            int h = obj.IsVertical() ? 8 : 4;

            _objects.Bullets.Add(new BulletView(x, y, obj.Direction, w, h, obj));
            (obj as IShooter).Reload = 0.3f;
        }
Ejemplo n.º 25
0
    public override void up(MobileObject target, Transform contactPoint, float x, float y, int blockSize, layer l)
    {
        if (!target.Solid)
        {
            return;
        }

        float contactX = contactPoint.position.x;
        float contactY = contactPoint.position.y;

        float deltaX = contactX - (x + xAdder);
        float deltaY = contactY - (y + yAdder);

        if (deltaY <= m * deltaX || (target.BlockedFromBelow && target.GuidedByTerrain))
        {
            target.BlockedFromBelow = true;
        }
    }
Ejemplo n.º 26
0
    public override void Down(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        if (target.YSpeed - l.YSpeed <= 0)
        {
            return;
        }

        float by = GetY(y, l);

        float cy = contactPoint.position.y;

        float dy = by - cy;

        target.BlockedFromAbove = true;

        target.Y     += dy;
        target.YSpeed = 0;
    }
Ejemplo n.º 27
0
    public override void Right(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        if (angle <= 0 && target.XSpeed >= 0)
        {
            return;
        }
        if (angle >= 0 && target.XSpeed <= 0)
        {
            return;
        }
        float by       = GetY(y, l);
        float contactY = contactPoint.position.y;

        if (contactY < by + y2)
        {
            base.Right(target, contactPoint, x, y, l);
        }
    }
Ejemplo n.º 28
0
    public override void Left(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        if (target.XSpeed - l.XSpeed <= 0)
        {
            return;
        }

        float bx = GetX(x, l);

        float cx = contactPoint.position.x;

        float dx = cx - bx;

        target.X -= dx;

        target.BlockedFromRight = true;

        target.XSpeed = 0;
    }
Ejemplo n.º 29
0
    public override void AngleDetector(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        if (target.YSpeed - l.YSpeed >= 0)
        {
            return;
        }

        float by = GetY(y, l);

        float cy = contactPoint.position.y;

        float dy = cy - (by + BlockLayer.BlockSize);

        target.Y -= dy;

        target.BlockedAngleDetector = true;
        target.BlockedFromBelow     = true;
        target.TerrainAngle         = 0;
    }
Ejemplo n.º 30
0
    public override void Right(MobileObject target, Transform contactPoint, int x, int y, BlockLayer l)
    {
        if (target.XSpeed - l.XSpeed >= 0)
        {
            return;
        }

        float bx = GetX(x, l);

        float cx = contactPoint.position.x;

        float dx = bx + BlockLayer.BlockSize - cx;

        target.X += dx;

        target.BlockedFromLeft = true;

        target.XSpeed = 0;
    }
Ejemplo n.º 31
0
    // Adds a piece of data to the end of the list
    public void Append(MobileObject data)
    {
        if (list != null)
        {
            // Boolean flag for use in the loops
            bool added = false;

            // If the last position of the list is empty, add some data
            for (int i = list.Length - 1; i >= 0 && !added; --i)
            {
                if (list[i] == null)
                {
                    list[i] = data;
                    added   = true;
                }
            }

            // If nothing was added, we need to grow the list
            if (added == false)
            {
                // Grow the list and reset the flag
                added = false;
                Grow();

                // Find the first empty position and add the data
                for (int i = list.Length - 1; i >= 0 && !added; --i)
                {
                    if (list[i] == null)
                    {
                        list[i] = data;
                        added   = true;
                    }
                }
            }
        }
        else
        {
            // Create a new list, then add something to it
            list    = new MobileObject[2];
            list[0] = data;
        }
    }
Ejemplo n.º 32
0
    public override void OnInspectorGUI()
    {
        MobileObject t = (MobileObject)target;

        EditorGUILayout.LabelField("Options");

        t.Solid                  = EditorGUILayout.Toggle("Solid:", t.Solid);
        t.GuidedByTerrain        = EditorGUILayout.Toggle("Guided By Terrain:", t.GuidedByTerrain);
        t.AffectedByTerrain      = EditorGUILayout.Toggle("Affected By Terrain:", t.AffectedByTerrain);
        t.IgnoreBelowInteraction = EditorGUILayout.Toggle("Ignore Below Interaction:", t.IgnoreBelowInteraction);
        t.XDirection             = EditorGUILayout.Toggle("H. Direction:", t.XDirection);
        t.YDirection             = EditorGUILayout.Toggle("V. Direction:", t.YDirection);
        t.BlockedAngleDetector   = EditorGUILayout.Toggle("Blocked Angle Detector:", t.BlockedAngleDetector);
        t.BlockedFromBelow       = EditorGUILayout.Toggle("Blocked From Below:", t.BlockedFromBelow);
        t.BlockedFromLeft        = EditorGUILayout.Toggle("Blocked From Left:", t.BlockedFromLeft);
        t.BlockedFromRight       = EditorGUILayout.Toggle("Blocked From Right:", t.BlockedFromRight);
        t.BlockedFromAbove       = EditorGUILayout.Toggle("Blocked From Above:", t.BlockedFromAbove);

        EditorGUILayout.LabelField("Physics Variables");

        t.Mass          = EditorGUILayout.IntField("Mass:", t.Mass);
        t.TerrainAngle  = EditorGUILayout.FloatField("Terrain Angle:", t.TerrainAngle);
        t.MinXSpeed     = EditorGUILayout.FloatField("Min X Speed:", t.MinXSpeed);
        t.MinYSpeed     = EditorGUILayout.FloatField("Min Y Speed:", t.MinYSpeed);
        t.MaxXSpeed     = EditorGUILayout.FloatField("Max X Speed:", t.MaxXSpeed);
        t.MaxYSpeed     = EditorGUILayout.FloatField("Max Y Speed:", t.MaxYSpeed);
        t.XSpeed        = EditorGUILayout.FloatField("X Speed:", t.XSpeed);
        t.YSpeed        = EditorGUILayout.FloatField("Y Speed:", t.YSpeed);
        t.XAcceleration = EditorGUILayout.FloatField("X Acceleration:", t.XAcceleration);
        t.YAcceleration = EditorGUILayout.FloatField("Y Acceleration:", t.YAcceleration);
        t.XFriction     = EditorGUILayout.FloatField("X Friction:", t.XFriction);
        t.YFriction     = EditorGUILayout.FloatField("Y Friction:", t.YFriction);
        t.XGravity      = EditorGUILayout.FloatField("X Gravity:", t.XGravity);
        t.YGravity      = EditorGUILayout.FloatField("Y Gravity:", t.YGravity);

        EditorGUILayout.LabelField("Detectors");

        base.OnInspectorGUI();

        EditorUtility.SetDirty(target);
    }
Ejemplo n.º 33
0
 public Wondering(MobileObject mobileObject, Size viewPort)
     : base(mobileObject, null)
 {
     _viewPort = viewPort;
 }
Ejemplo n.º 34
0
 public Doing(MobileObject mobileObject, Action action)
 {
     _action = action;
     _mobileObject = mobileObject;
 }
Ejemplo n.º 35
0
 public ShakingTree(MobileObject mobileObject, IHasSmthToCollect<Berry> tree)
 {
     _mobileObject = mobileObject;
     _maxRestingTicks = Game.Random.Next(MAX_MAXSHAKINGTICK);
     Tree = tree;
 }
Ejemplo n.º 36
0
 public Resting(MobileObject mobileObject)
 {
     _mobileObject = mobileObject;
     _maxRestingTicks = Game.Random.Next(MAX_MAXRESTINGTICK);
 }