Inheritance: MonoBehaviour
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);
        GUILayout.Space(-15f);

        EditorGUILayout.PropertyField(property.FindPropertyRelative("enabled"));
        SerializedProperty targetingMode = property.FindPropertyRelative("targetingMode");

        EditorGUILayout.PropertyField(targetingMode);
        switch (targetingMode.enumValueIndex)
        {
        case (int)ForceField.SelectionMethod.ETargetingMode.Collider:
            ForceField ff = property.serializedObject.targetObject as ForceField;
            if (ff.GetComponent <Collider>() == null && ff.GetComponent <Rigidbody>() == null)
            {
                EditorGUILayout.HelpBox(noColliderWarning, MessageType.Warning);
            }
            break;

        case (int)ForceField.SelectionMethod.ETargetingMode.Raycast:
            EditorGUILayout.PropertyField(property.FindPropertyRelative("rayCastOption"), true);
            break;

        case (int)ForceField.SelectionMethod.ETargetingMode.Manual:
            EditorGUILayout.PropertyField(property.FindPropertyRelative("targetsList"), true);
            break;
        }

        EditorGUI.EndProperty();
    }
 void OnEnable()
 {
     forceField             = target as ForceField;
     alwaysIgnoredList      = serializedObject.FindProperty("alwaysIgnoredList");
     selectionMethods       = serializedObject.FindProperty("selectionMethods");
     fieldFunctions         = serializedObject.FindProperty("fieldFunctions");
     layerMask              = serializedObject.FindProperty("layerMask");
     sendMessage            = serializedObject.FindProperty("sendMessage");
     ignoreMass             = serializedObject.FindProperty("ignoreMass");
     showTooltips           = serializedObject.FindProperty("showTooltips");
     gizmosMode             = serializedObject.FindProperty("gizmosMode");
     drawTargetsConnection  = serializedObject.FindProperty("drawTargetsConnection");
     drawFieldPointers      = serializedObject.FindProperty("drawFieldPointers");
     drawRaycastArea        = serializedObject.FindProperty("drawRaycastArea");
     targetsConnectionColor = serializedObject.FindProperty("targetsConnectionColor");
     testObject             = serializedObject.FindProperty("testObject");
     pointerLength          = serializedObject.FindProperty("pointerLength");
     pointerSpace           = serializedObject.FindProperty("pointerSpace");
     pointerXCount          = serializedObject.FindProperty("pointerXCount");
     pointerYCount          = serializedObject.FindProperty("pointerYCount");
     pointerZCount          = serializedObject.FindProperty("pointerZCount");
     strongPointerColor     = serializedObject.FindProperty("strongPointerColor");
     weakPointerColor       = serializedObject.FindProperty("weakPointerColor");
     strongThreshold        = serializedObject.FindProperty("strongThreshold");
     weakThreshold          = serializedObject.FindProperty("weakThreshold");
     raycastColor           = serializedObject.FindProperty("raycastColor");
     generalMultiplier      = serializedObject.FindProperty("generalMultiplier");
     useMassCenter          = serializedObject.FindProperty("useMassCenter");
     useLocalSpace          = serializedObject.FindProperty("useLocalSpace");
 }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="field"></param>
        /// <param name="dungeon"></param>
        public ForceFieldControl(ForceField field, Dungeon dungeon)
        {
            InitializeComponent();

            switch (field.Type)
            {
            case ForceFieldType.Spin:
                SpinRadioBox.Checked = true;
                break;

            case ForceFieldType.Move:
                MoveRadioBox.Checked = true;
                break;

            case ForceFieldType.Block:
                BlockRadioBox.Checked = true;
                break;

            case ForceFieldType.FaceTo:
                FaceToBox.Checked = true;
                break;
            }

            AffectItemsBox.Checked        = field.AffectItems;
            AffectMonstersBox.Checked     = field.AffectMonsters;
            AffectTeamBox.Checked         = field.AffectTeam;
            MoveDirectionBox.DataSource   = Enum.GetValues(typeof(CardinalPoint));
            MoveDirectionBox.SelectedItem = field.Direction;
            SpinDirectionBox.DataSource   = Enum.GetValues(typeof(CompassRotation));
            SpinDirectionBox.SelectedItem = field.Spin;


            Field = field;
        }
    void ClacDimension()
    {
        width = 1.5f * (cols - 1) + 1.0f;
        AspectRatio = (float)Screen.height / (float)Screen.width;
        float actualHeight = width * AspectRatio;
        height = actualHeight + SIN60 * 2.0f;
        rows = (int)(height / SIN60);
        if (rows % 2 == 0)
        {
            rows++;
        }
        
        Camera2D.orthographicSize = actualHeight * 0.5f;
        
        ScreenToContextMat = Matrix4x4.TRS(new Vector3(-width, -actualHeight, 0) * 0.5f, Quaternion.identity, Vector3.one * width / Screen.width);
        float w2 = width * 0.5f;
        float h2 = height * 0.5f;
        //BorderRect = new List<Point>() { new Point(-w2, -h2), new Point(w2, -h2), new Point(w2, h2), new Point(-w2, h2) };
        BorderVertices = new List<Vector2>() { new Vector2(-w2, -h2), new Vector2(w2, -h2), new Vector2(w2, h2), new Vector2(-w2, h2) };

        mForceField = new ForceField(width, actualHeight,2f);

        Debug.Log(mForceField);
        
    }
		/// <summary>
		/// 
		/// </summary>
		/// <param name="field"></param>
		/// <param name="dungeon"></param>
		public ForceFieldControl(ForceField field, Dungeon dungeon)
		{
			InitializeComponent();

			switch (field.Type)
			{
				case ForceFieldType.Spin:
				SpinRadioBox.Checked = true;
				break;
				case ForceFieldType.Move:
				MoveRadioBox.Checked = true;
				break;
				case ForceFieldType.Block:
				BlockRadioBox.Checked = true;
				break;
				case ForceFieldType.FaceTo:
				FaceToBox.Checked = true;
				break;
			}

			AffectItemsBox.Checked = field.AffectItems;
			AffectMonstersBox.Checked = field.AffectMonsters;
			AffectTeamBox.Checked = field.AffectTeam;
			MoveDirectionBox.DataSource = Enum.GetValues(typeof(CardinalPoint));
			MoveDirectionBox.SelectedItem = field.Direction;
			SpinDirectionBox.DataSource = Enum.GetValues(typeof(CompassRotation));
			SpinDirectionBox.SelectedItem = field.Spin;


			Field = field;
		}
Exemple #6
0
    /*
     * When the gameobject collides with the player do damage on the player
     */
    private void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.gameObject.CompareTag("Player") && collider.isTrigger && canDamage)
        {
            PlayerController player           = collider.GetComponent <PlayerController>();
            GameObject       ForceFieldObject = GameObject.FindGameObjectWithTag("ForceField");
            if (ForceFieldObject != null)
            {
                forceField = GameObject.FindGameObjectWithTag("ForceField").GetComponent <ForceField>();;
            }
            if (player != null && forceField != null && forceField.getShieldHealth() > 0 && canDamage)
            {
                forceField.damageShield();
                StartCoroutine(damageTimer(damageTimeout));
            }
            else
            {
                Vector2 direction = collider.transform.position - transform.position;
                Vector2 thrust    = direction.normalized * knockbackDistance;

                player.Damage(thrust, damageAmount);
                StartCoroutine(damageTimer(damageTimeout));
            }
        }
    }
Exemple #7
0
        public ForceField AddForceField(Vector2 position, int crystalRequired)
        {
            var result = new ForceField(position, crystalRequired);

            this._gameObjectCollection.Add(result);
            return(result);
        }
    public void Attract(ForceField a)
    {
        Vector3 attraction = a.Position - transform.position;
        float   distance   = attraction.magnitude;

        attraction.Normalize();

        if (a.Mode == ForceField.FieldMode.Destroy && distance < a.range)
        {
            _emitter.RemoveParticle(this);
            Destroy(gameObject);
        }

        if (distance > 100)
        {
            attraction *= a.strength;
            if (a.Mode == ForceField.FieldMode.Attract)
            {
                _attraction += attraction * Time.deltaTime;
            }
        }
        else
        {
            attraction *= a.strength * Mathf.Clamp(Utils.Map(distance, 0, a.range, 1, 0), 0, 1);
            if (a.Mode == ForceField.FieldMode.Attract)
            {
                _attraction += attraction * Time.deltaTime;
            }
            else
            {
                _attraction -= attraction * Time.deltaTime;
            }
        }
    }
        public void CreateBoxForceField()
        {
            using (CreateCoreAndScene())
            {
                BoxForceFieldShapeDescription boxForceFieldShapeDesc = new BoxForceFieldShapeDescription()
                {
                    Size = new Vector3(10, 10, 10)
                };

                ForceFieldLinearKernelDescription kernelDesc = new ForceFieldLinearKernelDescription()
                {
                    Constant = new Vector3(0, 100.0f, 0)
                };

                ForceFieldLinearKernel kernel = this.Scene.CreateForceFieldLinearKernel(kernelDesc);

                ForceFieldShapeGroupDescription shapeGroupDesc = new ForceFieldShapeGroupDescription()
                {
                    Shapes = { boxForceFieldShapeDesc }
                };

                ForceFieldShapeGroup shapeGroup = this.Scene.CreateForceFieldShapeGroup(shapeGroupDesc);

                BoxForceFieldShape boxForceFieldShape = shapeGroup.CreateShape(boxForceFieldShapeDesc) as BoxForceFieldShape;
                boxForceFieldShape.Pose = Matrix.Translation(new Vector3(30, 5, 0));

                ForceFieldDescription forceFieldDesc = new ForceFieldDescription()
                {
                    Kernel      = kernel,
                    ShapeGroups = { shapeGroup }
                };

                ForceField forceField = this.Scene.CreateForceField(forceFieldDesc);
            }
        }
Exemple #10
0
    public void NewForceField()
    {
        ForceField f = new ForceField();

        f.v = new Vector3D(1, 0, 0);
        f.s = 1f;
        Forces.Add(f);
    }
Exemple #11
0
 // Start is called before the first frame update
 void Start()
 {
     vehicleBehavior = FindObjectOfType <VehicleBehavior>();
     ui_Controller   = FindObjectOfType <ui_controller>();
     Wheel_Detach    = gameObject.GetComponentInChildren <Player_Wheel_Detach>();
     forceField      = gameObject.GetComponentInChildren <ForceField>();
     //dF = GetComponent<Rigidbody>();
 }
Exemple #12
0
    public override void TriggerAbility(Vector3 source, Vector3 destination)
    {
        GameObject go = AbilityController.Instantiate(Prefab, destination, Quaternion.Euler(0, 0, 0));
        ForceField ff = go.GetComponent <ForceField>();

        ff.Initialize(Damage, Radius, HitForce, TimeToLive, UpForce);

        base.TriggerAbility(source, destination);
    }
Exemple #13
0
        private void LoadContent(
            StringReader mbg,
            uint bulletEmitterCount,
            uint lazerEmitterCount,
            uint maskEmitterCount,
            uint reflexBoardCount,
            uint forceFieldCount)
        {
            var linkers = new List <Action>();

            BulletEmitters = new List <BulletEmitter>();
            for (uint i = 0; i < bulletEmitterCount; ++i)
            {
                var result = BulletEmitter.ParseFrom(mbg.ReadLine(), this);
                linkers.Add(result.Item2);
                BulletEmitters.Add(result.Item1);
            }


            LazerEmitters = new List <LazerEmitter>();
            for (uint i = 0; i < lazerEmitterCount; ++i)
            {
                var result = LazerEmitter.ParseFrom(mbg.ReadLine(), this);
                linkers.Add(result.Item2);
                LazerEmitters.Add(result.Item1);
            }

            Masks = new List <Mask>();
            for (uint i = 0; i < maskEmitterCount; ++i)
            {
                var result = Mask.ParseFrom(mbg.ReadLine(), this);
                linkers.Add(result.Item2);
                Masks.Add(result.Item1);
            }

            ReflexBoards = new List <ReflexBoard>();
            for (uint i = 0; i < reflexBoardCount; ++i)
            {
                ReflexBoards.Add(ReflexBoard.ParseFrom(mbg.ReadLine()));
            }

            ForceFields = new List <ForceField>();
            for (uint i = 0; i < forceFieldCount; ++i)
            {
                ForceFields.Add(ForceField.ParseFrom(mbg.ReadLine()));
            }

            foreach (var l in linkers)
            {
                l();
            }
        }
    private void Awake()
    {
        id               = "magnet";
        cooldownTime     = 8;
        forceFieldPrefab = PrefabManager.instance.forceField;

        forceField                      = Instantiate(forceFieldPrefab).GetComponent <ForceField>();
        forceField.targetDim            = Vector3.zero;
        forceField.transform.localScale = Vector3.zero;
        forceField.follow               = transform;
        forceField.magnet               = this;

        AudioManager.instance.Play(soundName);
    }
Exemple #15
0
        /// <summary>
        /// Starts a new game.
        /// </summary>
        private void StartNewGame()
        {
            // Set up the game screen
            Clear(Colors.Black);

            _mothership = new MotherShip(this, 1);
            _forceField = new ForceField(this, 12);
            _playerShip = new PlayerShip(this, 38);

            _score = 0;
            _lives = 3;

            _state = GameState.InGame;

            // A bit faster will do...
            SetFps(6);
        }
Exemple #16
0
    public ResetLevel()
    {
        editorMode = gameInfo.First().GetComponent <GameInfo> ().levelEditorMode;        //store the current game mode
        //add listener to both reset buttons
        foreach (GameObject go in buttons)
        {
            if (go.name == "ResetButton")
            {
                go.GetComponent <Button>().onClick.AddListener(resetAll);
            }
            else if (go.name == "ResetBallButton")
            {
                go.GetComponent <Button>().onClick.AddListener(resetBall);
            }
        }
        //set initial values of every object in the game
        foreach (GameObject go in draggable)
        {
            go.GetComponent <Draggable>().initialPosition = go.transform.position;
        }
        foreach (GameObject go in forceFields)
        {
            ForceField ff = go.GetComponent <ForceField>();
            ff.initialSizeX = ff.transform.localScale.z;
            ff.initialSizeY = ff.transform.localScale.x;
            if (ff.ffType == 0)
            {
                go.GetComponent <Mass>().initialValue = go.GetComponent <Mass>().value;
            }
            else if (ff.ffType == 1 || ff.ffType == 2)
            {
                go.GetComponent <Charge>().initialValue = go.GetComponent <Charge>().value;
            }
            ff.initialDirection = ff.direction;
        }
        Move mv = movingGO.First().GetComponent <Move>();

        mv.initialPostion   = mv.gameObject.transform.position;
        mv.initialSpeed     = mv.speed;
        mv.playerSpeed      = mv.speed;
        mv.initialDirection = mv.direction;
        mv.playerDirection  = mv.direction;

        resetAll();
    }
Exemple #17
0
    void resetAll()
    {
        resetBall();
        Move mv = movingGO.First().GetComponent <Move> ();

        //set ball's values to initial values in the level
        mv.speed     = mv.initialSpeed;
        mv.direction = mv.initialDirection;
        Vector3 newDir = Vector3.RotateTowards(mv.directionGO.transform.forward, mv.direction, 360, 0);

        mv.directionGO.transform.rotation = Quaternion.LookRotation(newDir);                            //rotate the direction displayer
        foreach (GameObject ff in forceFields)                                                          //delete the force fields generated by generators
        {
            if (ff.GetComponent <IsEditable> ().isEditable&& ff.GetComponent <Draggable>().isDraggable) //if the force field is editable and draggable
            {
                foreach (GameObject ffg in ffGenerator)
                {
                    if (ffg.GetComponent <FFNbLimit> ().ffType == ff.GetComponent <ForceField> ().ffType)
                    {
                        ffg.GetComponent <FFNbLimit> ().available++;                       //increase the number of available force fields every time one is deleted
                    }
                }
                //deleted the force field
                GameObjectManager.unbind(ff);
                GameObject.Destroy(ff);
            }
        }
        //set force fields values to their initial values in the level
        foreach (GameObject go in forceFields)
        {
            ForceField ff = go.GetComponent <ForceField> ();
            ff.transform.localScale = new Vector3(ff.initialSizeX, ff.transform.localScale.y, ff.initialSizeY);
            if (ff.ffType == 0)
            {
                go.GetComponent <Mass>().value = go.GetComponent <Mass>().initialValue;
            }
            else if (ff.ffType == 1 || ff.ffType == 2)
            {
                go.GetComponent <Charge>().value = go.GetComponent <Charge>().initialValue;
            }
            ff.direction = ff.initialDirection;
        }
        gameInfo.First().GetComponent <GameInfo>().askClearPlayUndo = true;
    }
Exemple #18
0
    //When enemies' hitboxes collide with undestroyed defences, set it as their target
    private void OnTriggerEnter(Collider col)
    {
        if (col.CompareTag("Defence"))
        {
            Obelisk obelisk = col.gameObject.GetComponent <Obelisk>();
            if (obelisk != null && obelisk.IsAlive)
            {
                Target = obelisk;
                return;
            }

            ForceField forceField = col.gameObject.GetComponent <ForceField>();
            if (forceField != null && forceField.IsAlive)
            {
                Target = forceField;
                return;
            }
        }
    }
Exemple #19
0
    // TODO Applying a forceField gives all objects in its field a ConstantForce (Should not do this)
    public override void ApplyEffect(RaycastHit hit)
    {
        Transform existingForceFieldObj = hit.transform.Find("ForceField");

        if (existingForceFieldObj == null)
        {
            forceField = pShapeHit.transform.Find("ForceField").gameObject;
            Transform cloneForceFieldObj = hit.transform.Find("ForceField(Clone)");
            if (cloneForceFieldObj == null)
            {
                Instantiate(forceField, hit.transform);
            }
        }
        else
        {
            ForceField existingForceField = existingForceFieldObj.GetComponent <ForceField>();
            existingForceField.force = force;
            //existingForceField.SetRange(force);
        }
    }
Exemple #20
0
    // Use this for initialization
    void Start()
    {
        SetInputStrings();

        rb                = GetComponent <Rigidbody2D>();
        ff                = forceField.GetComponent <ForceField>();
        bCollider         = ballCollider.GetComponent <Collider2D>();
        ball              = GameManager.instance.ball;
        kickTrigger       = kickTriggerObj.GetComponent <KickTrigger>();
        repulsionEmitter  = repulsionParticle.GetComponent <ParticleSystem>();
        thrusterParticles = ThrusterParticleObj.GetComponent <ParticleSystem>();
        initDrag          = rb.drag;

        if (teamSide == TeamSide.Blue)
        {
            playerSprite.GetComponent <SpriteRenderer>().color = Color.blue;
        }
        else
        {
            playerSprite.GetComponent <SpriteRenderer>().color = Color.red;
        }
    }
Exemple #21
0
 void Start()
 {
     forceField = GetComponent <ForceField>();
     StartCoroutine(Glitch());
 }
Exemple #22
0
 // Use this for initialization
 void Start()
 {
     initDrag   = rb.drag;
     forceField = forceFieldObj.GetComponent <ForceField>();
     ball       = GameObject.FindGameObjectWithTag("Ball");
 }
Exemple #23
0
		/*
		 // this function allows dynamic scaling of the particle Radii
void ParticleEnsemble::ScaleParticleRadii(double newScaleFac){
  // update the particle radii
  radiiScaleFactor = newScaleFac;
  for(int i=0; i<GetNumberOfParticles(); ++i){
	SetParticleRadius(i,radiiScaleFactor*pParticleVector[i]->getInitialRadius());
  }
  // update any necessary forceField terms (e.g., LJ terms for SoftSpheres)
  if((GetForceFieldObject(0)->getForceFieldType())=="SoftSphereForceField"){
	GetForceFieldObject(0)->updateEnergyTerms(this);      
  }
};
		 */

		// add an external forcefield from the pixels on the end of the pForceFieldVector 
		public void AddAPixelField(ForceField pixels)
		{
			pForceFieldVector.Add(pixels);
		}
Exemple #24
0
        /// <summary>
        /// Renders the dungeon
        /// </summary>
        private void RenderDungeon()
        {
            if (SpriteBatch == null)
            {
                return;
            }

            glControl.MakeCurrent();
            Display.ClearBuffers();

            SpriteBatch.Begin();

            // Background texture
            Rectangle dst = new Rectangle(Point.Empty, glControl.Size);

            SpriteBatch.Draw(CheckerBoard, dst, dst, Color.White);


            // Nom maze, bye bye
            if (Maze == null)
            {
                SpriteBatch.End();
                glControl.SwapBuffers();
                return;
            }


            #region Squares
            for (int y = 0; y < Maze.Size.Height; y++)
            {
                for (int x = 0; x < Maze.Size.Width; x++)
                {
                    Point  coord  = new Point(x, y);
                    Square block  = Maze.GetSquare(coord);
                    int    tileid = block.Type == SquareType.Ground ? 1 : 0;

                    // Location of the block on the screen
                    Point location = new Point(Offset.X + x * 25, Offset.Y + y * 25);


                    Color color = Color.White;
                    if (block.Type == SquareType.Illusion)
                    {
                        color = Color.LightGreen;
                    }

                    SpriteBatch.DrawTile(Icons, tileid, location, color);

                    if (block.ItemCount > 0)
                    {
                        SpriteBatch.DrawTile(Icons, 19, location);
                    }


                    #region Actor
                    if (block.Actor != null)
                    {
                        // Doors
                        if (block.Actor is Door)
                        {
                            Door door = block.Actor as Door;

                            if (Maze.IsDoorNorthSouth(block.Location))
                            {
                                tileid = 3;
                            }
                            else
                            {
                                tileid = 2;
                            }


                            // Door opened or closed
                            if (door.State == DoorState.Broken || door.State == DoorState.Opened || door.State == DoorState.Opening)
                            {
                                tileid += 2;
                            }

                            SpriteBatch.DrawTile(Icons, tileid, location);
                        }


                        else if (block.Actor is PressurePlate)
                        {
                            SpriteBatch.DrawTile(Icons, 18, location);
                        }

                        else if (block.Actor is Pit)
                        {
                            SpriteBatch.DrawTile(Icons, 9, location);
                        }

                        else if (block.Actor is Teleporter)
                        {
                            SpriteBatch.DrawTile(Icons, 11, location);
                        }

                        else if (block.Actor is ForceField)
                        {
                            ForceField field = block.Actor as ForceField;

                            if (field.Type == ForceFieldType.Spin)
                            {
                                tileid = 12;
                            }
                            else if (field.Type == ForceFieldType.Move)
                            {
                                tileid = 13 + (int)field.Direction;
                            }
                            else
                            {
                                tileid = 17;
                            }

                            SpriteBatch.DrawTile(Icons, tileid, location);
                        }

                        else if (block.Actor is Stair)
                        {
                            Stair stair = block.Actor as Stair;
                            tileid = stair.Type == StairType.Up ? 6 : 7;
                            SpriteBatch.DrawTile(Icons, tileid, location);
                        }

                        else if (block.Actor is EventSquare)
                        {
                            SpriteBatch.DrawTile(Icons, 26, location);
                        }
                        else if (block.Actor is WallSwitch)
                        {
                            // Display coords
                            Point[] sides = new Point[]
                            {
                                new Point(7, 0),
                                new Point(7, 19),
                                new Point(0, 7),
                                new Point(19, 7),
                            };

                            WallSwitch wall = block.Actor as WallSwitch;

                            tileid = (int)wall.Side > 1 ? 102 : 103;
                            SpriteBatch.DrawTile(Icons, tileid, new Point(
                                                     Offset.X + x * 25 + sides[(int)wall.Side].X,
                                                     Offset.Y + y * 25 + sides[(int)wall.Side].Y));
                        }
                    }
                    #endregion


                    #region Decoration
                    if (block.HasDecorations)
                    {
                        foreach (CardinalPoint side in Enum.GetValues(typeof(CardinalPoint)))
                        {
                            if (block.HasDecoration(side))
                            {
                                Point[] from = new Point[]
                                {
                                    new Point(1, 1),
                                    new Point(1, 24),
                                    new Point(1, 1),
                                    new Point(24, 1),
                                };

                                Point[] to = new Point[]
                                {
                                    new Point(24, 1),
                                    new Point(24, 24),
                                    new Point(1, 24),
                                    new Point(24, 24),
                                };

                                Point offset = new Point(Offset.X + x * 25, Offset.Y + y * 25);

                                SpriteBatch.DrawLine(
                                    new Point(from[(int)side].X + offset.X, from[(int)side].Y + offset.Y),
                                    new Point(to[(int)side].X + offset.X, to[(int)side].Y + offset.Y),
                                    Color.LightGreen);
                            }
                        }
                    }
                    #endregion


                    if (block.NoMonster)
                    {
                        SpriteBatch.FillRectangle(new Rectangle(location.X, location.Y, 25, 25), Color.FromArgb(128, Color.Blue));
                    }


                    if (block.NoGhost)
                    {
                        SpriteBatch.FillRectangle(new Rectangle(location.X, location.Y, 25, 25), Color.FromArgb(128, Color.Green));
                    }


                    // Monsters
                    if (block.Monsters[0] != null)
                    {
                        SpriteBatch.FillRectangle(new Rectangle(location.X + 4, location.Y + 4, 4, 4), Color.Red);
                    }
                    if (block.Monsters[1] != null)
                    {
                        SpriteBatch.FillRectangle(new Rectangle(location.X + 16, location.Y + 4, 4, 4), Color.Red);
                    }
                    if (block.Monsters[2] != null)
                    {
                        SpriteBatch.FillRectangle(new Rectangle(location.X + 4, location.Y + 16, 4, 4), Color.Red);
                    }
                    if (block.Monsters[3] != null)
                    {
                        SpriteBatch.FillRectangle(new Rectangle(location.X + 16, location.Y + 16, 4, 4), Color.Red);
                    }
                }
            }
            #endregion


            // Preview pos
            SpriteBatch.DrawTile(Icons, 22 + (int)PreviewLoc.Direction, new Point(Offset.X + PreviewLoc.Coordinate.X * 25, Offset.Y + PreviewLoc.Coordinate.Y * 25));


            // Starting point
            if (Dungeon.StartLocation.Maze == Maze.Name)
            {
                SpriteBatch.DrawTile(Icons, 20,
                                     new Point(Offset.X + Dungeon.StartLocation.Coordinate.X * 25, Offset.Y + Dungeon.StartLocation.Coordinate.Y * 25));
            }


            // Surround the selected object
            if (CurrentSquare != null)
            {
                SpriteBatch.DrawRectangle(new Rectangle(CurrentSquare.Location.X * 25 + Offset.X, CurrentSquare.Location.Y * 25 + Offset.Y, 25, 25), Color.White);
            }


            // If the current actor has scripts
            if (SquareUnderMouse != null && SquareUnderMouse.Actor != null)
            {
                SquareActor actor = SquareUnderMouse.Actor;
                foreach (DungeonLocation target in actor.GetTargets())
                {
                    if (target == null)
                    {
                        continue;
                    }

                    //DungeonLocation target = script.Action.Target;
                    if (target.Maze == Maze.Name)
                    {
                        Point from = new Point(BlockCoord.X * 25 + Offset.X + 12, BlockCoord.Y * 25 + Offset.Y + 12);
                        Point to   = new Point(target.Coordinate.X * 25 + Offset.X + 12, target.Coordinate.Y * 25 + Offset.Y + 12);
                        SpriteBatch.DrawLine(from, to, Color.Red);
                        SpriteBatch.DrawRectangle(new Rectangle(target.Coordinate.X * 25 + Offset.X, target.Coordinate.Y * 25 + Offset.Y, 25, 25), Color.Red);
                    }
                }
            }


            #region Display zones

            /*
             * if (DisplayZonesBox.Checked)
             * {
             *
             *      foreach (MazeZone zone in Maze.Zones)
             *      {
             *              Rectangle rect = new Rectangle(zone.Rectangle.X * 25, zone.Rectangle.Y * 25, zone.Rectangle.Width * 25, zone.Rectangle.Height * 25);
             *              Color color = Color.FromArgb(100, Color.Red);
             *
             *              if (CurrentZone == zone)
             *              {
             *                      color = Color.FromArgb(100, Color.Red);
             *                      SpriteBatch.DrawRectangle(rect, Color.White);
             *              }
             *
             *              SpriteBatch.FillRectangle(rect, color);
             *      }
             *
             *
             *      if (CurrentZone != null)
             *      {
             *              Rectangle rect = new Rectangle(CurrentZone.Rectangle.X * 25, CurrentZone.Rectangle.Y * 25, CurrentZone.Rectangle.Width * 25, CurrentZone.Rectangle.Height * 25);
             *              SpriteBatch.FillRectangle(rect, Color.FromArgb(128, Color.Blue));
             *      }
             * }
             */
            #endregion


            SpriteBatch.End();
            glControl.SwapBuffers();
        }
 public CentralAI()
 {
     health = 40; maxHP = 40; defense = 1; type = "Central AI"; passive = new ForceField(this); champion = true; energy = 100;
 }
 private void Start()
 {
     color = GetComponent<ColorComponent>();
     forceField = transform.parent.FindChild ("Force Field").GetComponent<ForceField> ();
     myAudioSource = GetComponent<AudioSource>();
 }
Exemple #27
0
    void AddEnergyBonus()
    {
        ForceField _forcefield = ship.transform.GetChild(0).GetComponent <ForceField>();

        _forcefield.AddBonusEnergy(amount);
    }
Exemple #28
0
 void Start()
 {
     rb         = GetComponent <Rigidbody2D>();
     gc         = FindObjectOfType <GameController>();
     forceField = GetComponentInChildren <ForceField>();
 }
Exemple #29
0
		/*
		public void SetParticleMass(int i, double newmass)
		{
			Particles[i].Mass = newmass;
		}

		public void SetParticleRadius(int i, double newradius)
		{
			//Particles[i].Radius = newradius;
		}
		*/

		#endregion

		#endregion							

		#region Force Field Objects
		
		/// <summary>
		/// add an external forcefield from the pixels on the end of the pForceFieldVector 
		/// </summary>
		/// <param name="pixels"></param>
		public void AddForceFieldObject(ForceField pixels)
		{
			ForceFields.Add(pixels);
		}
 private void Start()
 {
     color         = GetComponent <ColorComponent>();
     forceField    = transform.parent.FindChild("Force Field").GetComponent <ForceField> ();
     myAudioSource = GetComponent <AudioSource>();
 }
Exemple #31
0
        public void LoadPhysics()
        {
            Core  _core  = this.Core;
            Scene _scene = this.Scene;

            #region Some Boxes
            for (int x = 0; x < 5; x++)
            {
                BoxShapeDescription boxShapeDesc = new BoxShapeDescription(2, 3, 8);

                ActorDescription actorDesc = new ActorDescription()
                {
                    Name            = String.Format("Box {0}", x),
                    BodyDescription = new BodyDescription(10.0f),
                    GlobalPose      = Matrix.Translation(100, 15 + 3 * x, 20),
                    Shapes          = { boxShapeDesc }
                };

                Actor actor = _scene.CreateActor(actorDesc);
            }
            #endregion

            //#region Cloth (Flag)
            //{
            //    // Create a Grid of Points
            //    VertexGrid grid = VertexGrid.CreateGrid( 10, 10 );

            //    ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
            //        clothMeshDesc.AllocateVertices<Vector3>( grid.Points.Length );
            //        clothMeshDesc.AllocateTriangles<int>( grid.Indices.Length / 3 );

            //        clothMeshDesc.VertexCount = grid.Points.Length;
            //        clothMeshDesc.TriangleCount = grid.Indices.Length / 3;

            //        clothMeshDesc.VerticesStream.SetData( grid.Points );
            //        clothMeshDesc.TriangleStream.SetData( grid.Indices );

            //        // We are using 32 bit integers, so make sure the 16 bit flag is removed.
            //        // 32 bits are the default, so this isn't technically needed
            //        clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;

            //    // Write the cooked data to memory
            //    MemoryStream memoryStream = new MemoryStream();

            //    Cooking.InitializeCooking();
            //    Cooking.CookClothMesh( clothMeshDesc, memoryStream );
            //    Cooking.CloseCooking();

            //    // Need to reset the position of the stream to the beginning
            //    memoryStream.Position = 0;

            //    ClothMesh clothMesh = _core.CreateClothMesh( memoryStream );

            //    //

            //    ClothDescription clothDesc = new ClothDescription()
            //    {
            //        ClothMesh = clothMesh,
            //        Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
            //        GlobalPose =
            //            Matrix.CreateFromYawPitchRoll( 0, (float)Math.PI / 2.0f, (float)Math.PI / 2.0f ) *
            //            Matrix.CreateTranslation( 0, 20, 0 )
            //    };
            //    clothDesc.MeshData.AllocatePositions<Vector3>( grid.Points.Length );
            //    clothDesc.MeshData.AllocateIndices<int>( grid.Indices.Length );

            //    clothDesc.MeshData.MaximumVertices = grid.Points.Length;
            //    clothDesc.MeshData.MaximumIndices = grid.Indices.Length;

            //    clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
            //    clothDesc.MeshData.NumberOfIndices = grid.Indices.Length;

            //    _flag = _scene.CreateCloth( clothDesc );

            //    // Flag Pole
            //    ActorDescription flagPoleActorDesc = new ActorDescription()
            //    {
            //        GlobalPose = Matrix.CreateTranslation( 0, 10, 0 ),
            //        Shapes = { new BoxShapeDescription( 1.0f, 20.0f, 1.0f ) }
            //    };

            //    Actor flagPoleActor = _scene.CreateActor( flagPoleActorDesc );

            //    _flag.AttachToShape( flagPoleActor.Shapes[ 0 ], 0 );
            //    _flag.WindAcceleration = new Vector3( 10, 10, 10 );
            //    _flag.BendingStiffness = 0.1f;
            //}
            //#endregion

            #region Revolute Joint
            {
                BoxShapeDescription boxShapeDescA = new BoxShapeDescription(3, 3, 3);
                BoxShapeDescription boxShapeDescB = new BoxShapeDescription(3, 3, 3);

                ActorDescription actorDescA = new ActorDescription()
                {
                    BodyDescription = new BodyDescription(10.0f),
                    GlobalPose      = Matrix.Translation(75, 1.5f, 55),
                    Shapes          = { boxShapeDescA }
                };
                Actor actorA = _scene.CreateActor(actorDescA);

                ActorDescription actorDescB = new ActorDescription()
                {
                    BodyDescription = new BodyDescription(10.0f),
                    GlobalPose      = Matrix.Translation(70, 1.5f, 55),
                    Shapes          = { boxShapeDescB }
                };
                Actor actorB = _scene.CreateActor(actorDescB);

                //

                RevoluteJointDescription revoluteJointDesc = new RevoluteJointDescription()
                {
                    Actor1 = actorA,
                    Actor2 = actorB,
                    Motor  = new MotorDescription(20, 20.1f, true)
                };
                revoluteJointDesc.Flags |= RevoluteJointFlag.MotorEnabled;
                revoluteJointDesc.SetGlobalAnchor(new Vector3(73.5f, 1.5f, 55));
                revoluteJointDesc.SetGlobalAxis(new Vector3(1, 0, 0));

                RevoluteJoint revoluteJoint = _scene.CreateJoint(revoluteJointDesc) as RevoluteJoint;
            }
            #endregion

            #region Prismatic Joint with Limit
            {
                Actor actorA, actorB;
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

                    BodyDescription bodyDesc = new BodyDescription(10.0f);
                    bodyDesc.BodyFlags |= BodyFlag.Kinematic;

                    ActorDescription actorDesc = new ActorDescription()
                    {
                        BodyDescription = bodyDesc,
                        GlobalPose      = Matrix.Translation(70, 25, 65),
                        Shapes          = { boxShapeDesc }
                    };
                    actorA = _scene.CreateActor(actorDesc);
                }
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

                    ActorDescription actorDesc = new ActorDescription()
                    {
                        BodyDescription = new BodyDescription(10.0f),
                        GlobalPose      = Matrix.Translation(70, 15, 65),
                        Shapes          = { boxShapeDesc }
                    };
                    actorB = _scene.CreateActor(actorDesc);
                }

                PrismaticJointDescription prismaticJointDesc = new PrismaticJointDescription()
                {
                    Actor1 = actorA,
                    Actor2 = actorB,
                };
                prismaticJointDesc.SetGlobalAnchor(new Vector3(70, 20, 65));
                prismaticJointDesc.SetGlobalAxis(new Vector3(0, 1, 0));

                PrismaticJoint prismaticJoint = _scene.CreateJoint(prismaticJointDesc) as PrismaticJoint;

                LimitPlane limitPlane = new LimitPlane(new Vector3(0, 1, 0), new Vector3(-30, 8, -30), 0);
                prismaticJoint.AddLimitPlane(limitPlane);
            }
            #endregion

            #region Fluid
            {
                const int maximumParticles = 1000;

                FluidEmitterDescription fluidEmitterDesc = new FluidEmitterDescription()
                {
                    DimensionX   = 0.5f,
                    DimensionY   = 0.5f,
                    Rate         = 15,
                    RelativePose = Matrix.Translation(-40, 10, 50),
                    Shape        = EmitterShape.Rectangular,
                    Type         = EmitterType.ConstantFlowRate,
                    RandomAngle  = 0.5f
                };
                fluidEmitterDesc.Flags |= (FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization);

                FluidDescription fluidDesc = new FluidDescription()
                {
                    Emitters         = { fluidEmitterDesc },
                    Flags            = FluidFlag.Enabled | FluidFlag.Visualization,
                    MaximumParticles = maximumParticles
                };
                fluidDesc.ParticleWriteData.AllocatePositionBuffer <Vector3>(maximumParticles);
                fluidDesc.ParticleWriteData.NumberOfParticles = maximumParticles;

                Fluid fluid = _scene.CreateFluid(fluidDesc);

                // Ledge
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);

                    ActorDescription drainActorDesc = new ActorDescription()
                    {
                        GlobalPose = Matrix.RotationX(0.5f) * Matrix.Translation(-40, 5, 52),
                        Shapes     = { boxShapeDesc }
                    };

                    Actor drianActor = _scene.CreateActor(drainActorDesc);
                }

                // Drain
                {
                    BoxShapeDescription boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);
                    boxShapeDesc.Flags |= ShapeFlag.FluidDrain;

                    ActorDescription drainActorDesc = new ActorDescription()
                    {
                        GlobalPose = Matrix.Translation(-40, 0, 55),
                        Shapes     = { boxShapeDesc }
                    };

                    Actor drianActor = _scene.CreateActor(drainActorDesc);
                }
            }
            #endregion

            #region Force Field
            {
                BoxForceFieldShapeDescription boxForceFieldShapeDesc = new BoxForceFieldShapeDescription()
                {
                    Size = new Vector3(10, 10, 10)
                };

                ForceFieldLinearKernelDescription kernelDesc = new ForceFieldLinearKernelDescription()
                {
                    Constant = new Vector3(0, 100.0f, 0)
                };

                ForceFieldLinearKernel kernel = _scene.CreateForceFieldLinearKernel(kernelDesc);

                ForceFieldShapeGroupDescription shapeGroupDesc = new ForceFieldShapeGroupDescription()
                {
                    Shapes = { boxForceFieldShapeDesc }
                };

                ForceFieldShapeGroup shapeGroup = _scene.CreateForceFieldShapeGroup(shapeGroupDesc);

                BoxForceFieldShape boxForceFieldShape = shapeGroup.CreateShape(boxForceFieldShapeDesc) as BoxForceFieldShape;
                boxForceFieldShape.Pose = Matrix.Translation(30, 5, 0);

                ForceFieldDescription forceFieldDesc = new ForceFieldDescription()
                {
                    Kernel      = kernel,
                    ShapeGroups = { shapeGroup }
                };
                ForceField forceField = _scene.CreateForceField(forceFieldDesc);
            }
            #endregion

            #region Heightfield
            {
                int rows    = 25;
                int columns = 25;

                HeightFieldSample[] samples = new HeightFieldSample[rows * columns];
                for (int r = 0; r < rows; r++)
                {
                    for (int c = 0; c < columns; c++)
                    {
                        // Put a z and x curve together
                        double h = Math.Sin(c) * Math.Cos(r) * short.MaxValue;

                        HeightFieldSample sample = new HeightFieldSample()
                        {
                            Height           = (short)h,
                            MaterialIndex0   = 0,
                            MaterialIndex1   = 1,
                            TessellationFlag = 0
                        };

                        samples[r * columns + c] = sample;
                    }
                }

                HeightFieldDescription heightFieldDesc = new HeightFieldDescription()
                {
                    NumberOfRows    = rows,
                    NumberOfColumns = columns
                };
                heightFieldDesc.SetSamples(samples);

                HeightField heightField = _core.CreateHeightField(heightFieldDesc);

                //

                HeightFieldShapeDescription heightFieldShapeDesc = new HeightFieldShapeDescription()
                {
                    HeightField  = heightField,
                    HoleMaterial = 2,
                    // The max height of our samples is short.MaxValue and we want it to be 1
                    HeightScale = 1.0f / (float)short.MaxValue,
                    RowScale    = 3,
                    ColumnScale = 3
                };
                heightFieldShapeDesc.LocalPosition = new Vector3(-0.5f * rows * 1 * heightFieldShapeDesc.RowScale, 0, -0.5f * columns * 1 * heightFieldShapeDesc.ColumnScale);

                ActorDescription actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(100, 0, 0),
                    Shapes     = { heightFieldShapeDesc }
                };
                Actor actor = _scene.CreateActor(actorDesc);
            }
            #endregion

            //#region Convex Mesh
            //{
            //    ModelMesh mesh = _torusModel.Meshes.First();

            //    Matrix[] transforms = new Matrix[ _torusModel.Bones.Count ];
            //    _torusModel.CopyAbsoluteBoneTransformsTo( transforms );

            //    // Gets the vertices from the mesh
            //    VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[ mesh.MeshParts[ 0 ].NumVertices ];
            //    mesh.VertexBuffer.GetData<VertexPositionNormalTexture>( vertices );

            //    //

            //    // Allocate memory for the points and triangles
            //    var convexMeshDesc = new ConvexMeshDescription()
            //    {
            //        PointCount = vertices.Length
            //    };
            //    convexMeshDesc.Flags |= ConvexFlag.ComputeConvex;
            //    convexMeshDesc.AllocatePoints<Vector3>( vertices.Length );

            //    // Write in the points and triangles
            //    // We only want the Position component of the vertex. Also scale down the mesh
            //    foreach( VertexPositionNormalTexture vertex in vertices )
            //    {
            //        Vector3 position = Vector3.Transform( vertex.Position, Matrix.CreateScale( 0.1f, 0.1f, 0.1f ) * transforms[ 0 ] );

            //        convexMeshDesc.PointsStream.Write( position );
            //    }

            //    //

            //    // Cook to memory or to a file
            //    MemoryStream stream = new MemoryStream();
            //    //FileStream stream = new FileStream( @"Convex Mesh.cooked", FileMode.CreateNew );

            //    Cooking.InitializeCooking( new ConsoleOutputStream() );
            //    Cooking.CookConvexMesh( convexMeshDesc, stream );
            //    Cooking.CloseCooking();

            //    stream.Position = 0;

            //    ConvexMesh convexMesh = _core.CreateConvexMesh( stream );

            //    ConvexShapeDescription convexShapeDesc = new ConvexShapeDescription( convexMesh );

            //    ActorDescription actorDesc = new ActorDescription()
            //    {
            //        BodyDescription = new BodyDescription( 10.0f ),
            //        GlobalPose = Matrix.CreateTranslation( 30, 30, 0 )
            //    };
            //    actorDesc.Shapes.Add( convexShapeDesc );

            //    _torusActor = _scene.CreateActor( actorDesc );
            //}
            //#endregion

            //#region SoftBody
            //if( false ) // Enable to view soft bodies, they run slowly
            //{
            //    XmlDocument doc = new XmlDocument();
            //        doc.Load( "Teapot.xml" );

            //    // Not how NxuStream are meant to used but what ever :S
            //    Vector3[] vertices = ReadVertices( doc.SelectSingleNode( "/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/vertices" ) );
            //    int[] tetrahedraSingles = ReadTetrahedra( doc.SelectSingleNode( "/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/tetrahedra" ) );

            //    var softBodyMeshDesc = new SoftBodyMeshDescription()
            //    {
            //        VertexCount = vertices.Length,
            //        TetrahedraCount = tetrahedraSingles.Length / 4 // Tetrahedras come in quadruples of ints
            //    };

            //    softBodyMeshDesc.AllocateVertices<Vector3>( softBodyMeshDesc.VertexCount );
            //    softBodyMeshDesc.AllocateTetrahedra<int>( softBodyMeshDesc.TetrahedraCount ); // Note: T is an int. T is the type of each point

            //    softBodyMeshDesc.VertexStream.SetData( vertices );
            //    softBodyMeshDesc.TetrahedraStream.SetData( tetrahedraSingles );

            //    MemoryStream memoryStream = new MemoryStream();

            //    Cooking.InitializeCooking();
            //    Cooking.CookSoftBodyMesh( softBodyMeshDesc, memoryStream );
            //    Cooking.CloseCooking();

            //    memoryStream.Position = 0;

            //    SoftBodyMesh softBodyMesh = _core.CreateSoftBodyMesh( memoryStream );

            //    SoftBodyDescription desc = new SoftBodyDescription()
            //    {
            //        GlobalPose = Matrix.CreateTranslation( -30, 20, -30 ),
            //        SoftBodyMesh = softBodyMesh
            //    };
            //    desc.Flags |= SoftBodyFlag.Visualization;

            //    desc.MeshData.AllocatePositions<Vector3>( vertices.Length );
            //    desc.MeshData.AllocateIndices<int>( tetrahedraSingles.Length );

            //    SoftBody softBody = _scene.CreateSoftBody( desc );
            //}
            //#endregion

            //#region Reports
            //// Contact report
            //// When the capsule actor hits the ground make it bounce by using the conact report
            //{
            //    CapsuleShapeDescription capsuleShapeDesc = new CapsuleShapeDescription( 1, 5 );

            //    ActorDescription actorDesc = new ActorDescription()
            //    {
            //        GlobalPose = Matrix.CreateTranslation( -30, 20, 0 ),
            //        BodyDescription = new BodyDescription( 10.0f ),
            //        Name = "Report Capsule",
            //        Shapes = { capsuleShapeDesc }
            //    };

            //    _contactReportActor = _scene.CreateActor( actorDesc );

            //    _scene.SetActorPairFlags( _contactReportActor, _groundActor, ContactPairFlag.All );

            //    _scene.UserContactReport = new ContactReport( this );
            //}

            //// Trigger Reports
            //{
            //    BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 15, 8, 15 );
            //        boxShapeDesc.Flags |= ( ShapeFlag.TriggerOnEnter | ShapeFlag.TriggerOnLeave );

            //    ActorDescription actorDesc = new ActorDescription()
            //    {
            //        GlobalPose = Matrix.CreateTranslation( -30, 4, 0 ),
            //        Shapes = { boxShapeDesc }
            //    };
            //    _scene.CreateActor( actorDesc );

            //    _scene.UserTriggerReport = new TriggerReport( this );
            //}

            //_scene.UserNotify = new Notify( this );
            //#endregion

            //#region Wheel
            //{
            //    _basicVehicle = new Vehicle( this );
            //}
            //#endregion

            #region Controller
            {
                ControllerManager manager = _scene.CreateControllerManager();

                CapsuleControllerDescription capsuleControllerDesc = new CapsuleControllerDescription(4, 3);

                CapsuleController capsuleController = manager.CreateController <CapsuleController>(capsuleControllerDesc);
                capsuleController.Position   = new Vector3(0, 1.5f + 2, -15);
                capsuleController.Actor.Name = "BoxController";
                capsuleController.SetCollisionEnabled(true);
            }
            #endregion
        }
Exemple #32
0
 public void BindForceField(ForceField ff, float reset)
 {
     this.ff    = ff;
     this.reset = reset;
 }
 // Use this for initialization
 void Start()
 {
     initDrag = rb.drag;
     forceField = forceFieldObj.GetComponent<ForceField>();
     ball = GameObject.FindGameObjectWithTag("Ball");
 }
Exemple #34
0
    // Use this for initialization
    void Start()
    {
        ForceField ff = gameObject.transform.GetChild(1).gameObject.AddComponent <ForceField> ();

        gameObject.transform.GetChild(0).gameObject.AddComponent <Component> ().BindForceField(ff, this.resistorResetTime);
    }
    // Use this for initialization
    void Start()
    {
        SetInputStrings();

        rb = GetComponent<Rigidbody2D>();
        ff = forceField.GetComponent<ForceField>();
        bCollider = ballCollider.GetComponent<Collider2D>();
        ball = GameManager.instance.ball;
        kickTrigger = kickTriggerObj.GetComponent<KickTrigger>();
        repulsionEmitter = repulsionParticle.GetComponent<ParticleSystem>();
        thrusterParticles = ThrusterParticleObj.GetComponent<ParticleSystem>();
        initDrag = rb.drag;

        if (teamSide == TeamSide.Blue)
            playerSprite.GetComponent<SpriteRenderer>().color = Color.blue;
        else
            playerSprite.GetComponent<SpriteRenderer>().color = Color.red;
    }
Exemple #36
0
        /// <summary>
        /// 以InterpolationPrecision为时间间隔, 绘制每一个粒子的位置
        /// </summary>
        /// <param name="deltaTime"></param>
        /// <returns></returns>
        public List <KeyValuePair <XXParticleElement, List <ASSPointF> > > RenderPoint()
        {
            Dictionary <XXParticleElement, List <ASSPointF> > parDic = new Dictionary <XXParticleElement, List <ASSPointF> >();
            Queue <XXParticleElement> bornList = new Queue <XXParticleElement>();

            for (double born = StartTime; born <= EndTime; born += 1.0 / Emitter.NumberPerSecond)
            {
                XXParticleElement par = Emitter.GenerateParticleElement(born);
                if (par == null)
                {
                    continue;
                }
                par.Born = born;
                bornList.Enqueue(par);
            }
            List <XXParticleElement> liveList = new List <XXParticleElement>();

            for (double time = StartTime; liveList.Count > 0 || bornList.Count > 0; time += InterpolationPrecision)
            {
                while (bornList.Count > 0 && bornList.Peek().Born <= time)
                {
                    XXParticleElement newPar = bornList.Dequeue();
                    liveList.Add(newPar);
                    parDic[newPar] = new List <ASSPointF>();
                }
                liveList = liveList.Where(x => x.Born + x.Life > time).ToList();
                List <ASSPointF> newPosition = new List <ASSPointF>();
                List <ASSPointF> newSpeed    = new List <ASSPointF>();
                ASSPointF        gravPos     = null;
                if (GravityPosition != null)
                {
                    gravPos = GravityPosition.GetGravityPosition(time);
                }
                foreach (XXParticleElement par in liveList)
                {
                    double    intense = 0;
                    ASSPointF force   = ForceField.GetForceField(time + par.ForceTimeOffset);
                    if (force == null)
                    {
                        force = new ASSPointF {
                            X = 0, Y = 0
                        }
                    }
                    ;
                    ASSPointF rforce = new ASSPointF {
                        X = Common.Sqr(par.Speed.X) * Resistance, Y = Common.Sqr(par.Speed.Y) * Resistance
                    };
                    if (par.Speed.X > 0)
                    {
                        rforce.X = -rforce.X;
                    }
                    if (par.Speed.Y > 0)
                    {
                        rforce.Y = -rforce.Y;
                    }
                    force.X += rforce.X;
                    force.Y += rforce.Y;
                    if (Gravity != 0)
                    {
                        double r = Common.GetDistance(par.Position.X, par.Position.Y, gravPos.X, gravPos.Y);
                        r = 1;
                        //if (Math.Abs(r) > 2)
                        {
                            double gravr = par.Mass / Common.Sqr(r) * Gravity;
                            //double gravr = par.Mass * r * Gravity / 100;
                            double gravag = -Common.GetAngle(par.Position.X, par.Position.Y, gravPos.X, gravPos.Y);
                            double gravx  = gravr * Math.Cos(gravag);
                            double gravy  = gravr * Math.Sin(gravag);
                            force.X -= gravx;
                            force.Y -= gravy;
                        }
                    }
                    if (Repulsion != 0)
                    {
                        foreach (XXParticleElement par2 in liveList)
                        {
                            if (par != par2)
                            {
                                double r = Common.GetDistance(par.Position.X, par.Position.Y, par2.Position.X, par2.Position.Y);
                                if (r < 4)
                                {
                                    if (r < 1)
                                    {
                                        r = 1;
                                    }
                                    intense += 1;
                                }
                                if (Math.Abs(r) < 2)
                                {
                                    continue;
                                }
                                double repr  = par.Mass * par2.Mass / Common.Sqr(r) * Repulsion;
                                double repag = -Common.GetAngle(par.Position.X, par.Position.Y, par2.Position.X, par2.Position.Y);
                                double repx  = repr * Math.Cos(repag);
                                double repy  = repr * Math.Sin(repag);
                                force.X += repx;
                                force.Y += repy;
                            }
                        }
                    }
                    double vx1 = force.X * InterpolationPrecision / par.Mass + par.Speed.X;
                    double vy1 = force.Y * InterpolationPrecision / par.Mass + par.Speed.Y;
                    double sx  = par.Speed.X * InterpolationPrecision;
                    double sy  = par.Speed.Y * InterpolationPrecision;
                    newPosition.Add(new ASSPointF {
                        X = par.Position.X + sx, Y = par.Position.Y + sy
                    });
                    double vag1 = -Common.GetAngle(vx1, vy1, 0, 0);
                    double vr1  = Common.GetDistance(vx1, vy1, 0, 0);
                    vag1 += par.Spin * InterpolationPrecision;
                    vx1   = vr1 * Math.Cos(vag1);
                    vy1   = vr1 * Math.Sin(vag1);
                    newSpeed.Add(new ASSPointF {
                        X = vx1, Y = vy1
                    });
                    parDic[par].Add(new ASSPointF {
                        X = par.Position.X, Y = par.Position.Y, T = time, Intense = intense
                    });
                }
                for (int i = 0; i < liveList.Count; i++)
                {
                    liveList[i].Position = newPosition[i];
                    liveList[i].Speed    = newSpeed[i];
                }
            }
            return(parDic.ToList());
        }
    }