Example #1
0
        internal static bool CollideCircleCircle(ICollidible circleCollidible1, CollisionTypeCircle cTypeCircle1, ICollidible circleCollidible2, CollisionTypeCircle cTypeCircle2)
        {
            CCPoint pos1    = ((CCNode)circleCollidible1).PositionWorldspace;
            CCPoint pos2    = ((CCNode)circleCollidible2).PositionWorldspace;
            float   radius1 = CorrectRadius(circleCollidible1, cTypeCircle1);
            float   radius2 = CorrectRadius(circleCollidible2, cTypeCircle2);

            return(pos1.IsNear(pos2, radius1 + radius2));
        }
Example #2
0
 public void Activity(float frameTimeInSeconds)
 {
     if (desiredLocation.IsNear(this.Position, 20))
     {
         shield.Visible = false;
     }
     else
     {
         if (shield.Visible)
         {
             shield.Visible = false;
         }
         else
         {
             shield.Visible = true;
         }
     }
 }
        new private protected void OnTouchesEnded(List <CCTouch> touches, CCEvent touchEvent)
        {
            base.OnTouchesEnded(touches, touchEvent);
            switch (touches.Count)
            {
            case 1:
            {
                var touch = touches[0];
                if (DragAndDropObject != null)
                {
                    touchEvent.StopPropogation();
                    switch (HangarLayer.State)
                    {
                    case HangarLayer.HangarState.HANGAR:
                        var selectedAircraft = DragAndDropObject as Aircraft;
                        DragAndDropObject = null;
                        if (selectedAircraft != null)
                        {
                            // if an aircraft is dragged upon the takeoff node add it to the collection
                            if (!(TakeoffNode.BoundingBoxTransformedToParent.ContainsPoint(touch.Location) && TakeoffCollectionNode.AddToCollection(selectedAircraft)))
                            {
                                // if not, then place it back into the hangar
                                HangarLayer.AddAircraftChild(selectedAircraft);
                                selectedAircraft.Scale = Constants.STANDARD_SCALE;
                                HangarLayer.PlaceAircraft(selectedAircraft, HangarLayer.GUICoordinatesToHangar(selectedAircraft.Position));
                            }
                            if (TakeoffCollectionNode.Collection.Any())
                            {
                                GOButton.AddAction(HangarLayer.AddGOButton);
                                TakeoffCollectionLabel.Visible = false;
                            }
                            else if (!PopUp.TriggeredPlayLayer)
                            {
                                TakeoffCollectionLabel.Visible = true;
                            }
                        }
                        break;

                    case HangarLayer.HangarState.MODIFY_AIRCRAFT:
                    {
                        bool mounted = false;
                        HangarLayer.UpdateClosestMount();
                        // the object is a part
                        var part = (Part)DragAndDropObject;
                        DragAndDropObject = null;
                        // if it is a body and the aircraft currently has none (which means no parts at all)
                        if (HangarLayer.ModifiedAircraft.Body == null && part.Types.Contains(Part.Type.BODY) && CCPoint.IsNear(HangarLayer.GUICoordinatesToHangar(part.PositionWorldspace), HangarLayer.ModifiedAircraft.PositionWorldspace, MOUNT_DISTANCE))
                        {
                            // set it as the aircraft body
                            HangarLayer.ModifiedAircraft.InWorkshopConfiguration = false;
                            part.Scale = 1;
                            HangarLayer.ModifiedAircraft.Body = part;
                            HangarLayer.ModifiedAircraft.InWorkshopConfiguration = true;
                            HangarLayer.CalcBoundaries();                 // the aircraft has changed size, so update the boundaries
                            HangarLayer.DrawInModifyAircraftState();
                            mounted = true;
                        }
                        // check if the part is currently at a mount point where it can be mounted
                        else if (!mounted)
                        {
                            var possibleMounts = new List <PartMount>();
                            foreach (var modPart in HangarLayer.ModifiedAircraft.TotalParts)
                            {
                                foreach (var mountPoint in modPart.PartMounts)
                                {
                                    if (mountPoint.Available && mountPoint.CanMount(part))
                                    {
                                        if (CCPoint.IsNear(HangarLayer.GUICoordinatesToHangar(part.PositionWorldspace), mountPoint.PositionModifyAircraft, MOUNT_DISTANCE))
                                        {
                                            possibleMounts.Add(mountPoint);
                                        }
                                    }
                                }
                            }
                            // mount at the closest possible mount point
                            float     minDistance  = float.PositiveInfinity;
                            PartMount closestMount = null;
                            foreach (var mountPoint in possibleMounts)
                            {
                                float distance = CCPoint.Distance(HangarLayer.GUICoordinatesToHangar(part.PositionWorldspace), mountPoint.PositionModifyAircraft);
                                if (distance < minDistance)
                                {
                                    minDistance  = distance;
                                    closestMount = mountPoint;
                                }
                            }
                            if (closestMount != null)
                            {
                                // better mount in non-workshop configuration
                                HangarLayer.ModifiedAircraft.InWorkshopConfiguration = false;
                                part.Scale = 1;
                                closestMount.MyPart.MountPart(closestMount, part);
                                HangarLayer.ModifiedAircraft.InWorkshopConfiguration = true;
                                HangarLayer.CalcBoundaries();                 // the aircraft has probably changed size, so update the boundaries
                                HangarLayer.DrawInModifyAircraftState();
                                mounted = true;
                            }
                        }
                        // if the part has not been mounted the part is just dropped and added to the collection
                        if (!mounted)
                        {
                            // first disassemble it though
                            // and flip it if it is flipped
                            var totalParts = part.TotalParts;
                            part.Disassemble();
                            foreach (var singlePart in totalParts)
                            {
                                if (singlePart.Flipped)
                                {
                                    singlePart.Flip();
                                }
                                HangarLayer.AddPart(singlePart);
                            }
                        }
                    }
                    break;
                    }
                    DragAndDropObject = null;
                }
            }
            break;

            default:
                break;
            }
        }
Example #4
0
 internal static bool CollideCircleCircle(CCPoint circlePos1, float radius1, CCPoint circlePos2, float radius2)
 {
     return(circlePos1.IsNear(circlePos2, radius1 + radius2));
 }