Пример #1
0
        private void OpenBulletPhysics_Click(object sender, RoutedEventArgs e)
        {
            BinaryFormatter formatter    = new BinaryFormatter();
            TextBlock       selectedFile = (TextBlock)BulletPreset.SelectedItem;

            try
            {
                using (FileStream fs = new FileStream(Environment.CurrentDirectory + "/data/mapeditor/particle_systems/presets_gun/" + selectedFile.Text, FileMode.OpenOrCreate))
                {
                    bulletPhysics           = (BulletPhysics)formatter.Deserialize(fs);
                    NameBullet.Text         = bulletPhysics.GetNameBullet();
                    NameGun.SelectedItem    = SelectedNameGun();
                    LongRange.Text          = bulletPhysics.GetLongRange().ToString();
                    DifficultUseGun.Text    = bulletPhysics.GetDifficultUse().ToString();
                    CountsBullet.Text       = bulletPhysics.GetCountBullets().ToString();
                    VelocityBullet.Text     = bulletPhysics.GetVelocity().ToString();
                    SizeBullet.Text         = bulletPhysics.GetSizeBullet().ToString();
                    OnBurstbullet.IsChecked = bulletPhysics.GetBurstBullet();
                    MessageBox.Show(string.Format("Пресет открыт"));
                }
            }
            catch
            {
                MessageBox.Show(string.Format("Пресет не выбран"));
            }
        }
Пример #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            ScreenContext.CameraMotionProvider = new BasicCameraControllerMotionProvider(this, this);
            BasicGrid grid = new BasicGrid();

            grid.Load(RenderContext);
            WorldSpace.AddResource(grid);
            bulletPhysics = new BulletPhysics(new Vector3(0, -9.8f, 0f));
            ground        = bulletPhysics.CreatePlane(0, Matrix.Identity);
            ball_Model    = MMDModel.OpenLoad("1.pmx", RenderContext);
            ball_Model2   = MMDModel.OpenLoad("1.pmx", RenderContext);
            RigidBodyData data = ball_Model.Model.RigidBodyList.RigidBodies[0];

            ball  = bulletPhysics.CreateSphere(data.Size.X, Matrix.Translation(-15, 12f, 0), 1f, 1f, 0f);
            ball2 = bulletPhysics.CreateSphere(data.Size.X, Matrix.Translation(15, 12f, 0), 1f, 1f, 0f);

            rigid2model = GetModelWorldFromRigid();

            WorldSpace.AddResource(ball_Model);
            WorldSpace.AddResource(ball_Model2);
            CreateWalls();
            ball.ApplyCentralImpulse(new Vector3(2, 0.01f, 0f));
            ball2.ApplyCentralImpulse(new Vector3(-2, 0, 0));
            brush  = SpriteBatch.CreateSolidColorBrush(Color.Brown);
            format = SpriteBatch.CreateTextformat("Meiriyo", 30);
            format.Format.ParagraphAlignment = ParagraphAlignment.Center;
            format.Format.TextAlignment      = TextAlignment.Center;
            timer1.Start();
        }
Пример #3
0
        public FreeFall()
        {
            var gravity = new Vector3(0, -9.8f, 0);

            bulletPhysics = new BulletPhysics(gravity);
            CreateBarRigid();
            CreateBoxRigid();
        }
Пример #4
0
 public void FIRE(PhotonPlayer owner, float rangeMod, float speedMod)
 {
     if (reloadUntil <= Time.time)
     {
         BulletPhysics bullet = ((GameObject)Instantiate(shot, transform.position, transform.rotation)).GetComponent <BulletPhysics>();
         bullet.Setup(owner, rangeMod, speedMod);
         reloadUntil = Time.time + reloadDelay;
     }
 }
Пример #5
0
        // コンストラクタ
        public FreeFall(List <MMDModel> models)
        {
            this.models = models;
            var gravity = new Vector3(0, -9.8f * 2.5f, 0);

            bulletPhysics          = new BulletPhysics(gravity);
            model_world_from_rigid = GetModelWorldFromRigid();
            CreateSphereRigids();
            CreateBoxRigid();
        }
Пример #6
0
    public void FireBullet(Vector2 direction)
    {
        GameObject bullet = (GameObject)Instantiate(PlayerBullet);

        bullet.transform.position = transform.position;

        BulletPhysics bulletPhysics = bullet.GetComponent <BulletPhysics>();

        bulletPhysics.playerSpeed = stats.currentSpeed;
        bulletPhysics.SetDirection(direction);
    }
Пример #7
0
 private void ApplyValuesBullet_Click(object sender, RoutedEventArgs e)
 {
     if (checkValuesBullet())
     {
         clickCanvasOn = true;
         bulletPhysics = new BulletPhysics(Convert.ToInt32(VelocityBullet.Text), Convert.ToInt32(CountsBullet.Text), Convert.ToInt32(DifficultUseGun.Text), Convert.ToInt32(SizeBullet.Text), Convert.ToInt32(LongRange.Text), OnBurstbullet.IsChecked.Value, NameBullet.Text, (NameGun.SelectedItem as TextBlock).Text);
         SaveGunSettingsButton.IsEnabled = true;
         MessageBox.Show(string.Format("Кликните по рабочей области"));
     }
     else
     {
         MessageBox.Show(string.Format("Не все поля заполнены!"));
     }
 }
Пример #8
0
    void OnCollisionEnter2D(Collision2D c){
       
        if (c.transform.tag == "Bullet" && !dead) {
            bulPhys = c.gameObject.GetComponent<BulletPhysics>();
            Debug.Log(bulPhys.getDamage());
            Destroy(c.gameObject);
            health = health - bulPhys.getDamage();
            GameObject bloodclone = Instantiate(blood, transform.position, Quaternion.identity) as GameObject;
            if (health <= 0)
            {
                dead = true;
                GetComponent<BoxCollider2D>().enabled = false;
                GetComponentInChildren<Animator>().SetBool("isDead", true);
                gameObject.tag = "Corpse";
                GetComponentInChildren<SpriteRenderer>().sortingLayerName = "Corpses";

            }
		}
	}
Пример #9
0
        /// <summary>
        ///     コンストラクタ
        /// </summary>
        /// <param name="renderContext">レンダーコンテキスト</param>
        public Billiard(RenderContext renderContext)
        {
            CreateBallRayout();
            Vector3 gravity = new Vector3(0, -9.8f * 2.5f, 0);

            bulletPhysics = new BulletPhysics(gravity);

            MMDModel model = MMDModel.OpenLoad("../../res/ビリヤード台.pmx", renderContext);

            models.Add(model);
            CreateBilliardRigids(model);

            for (int i = 0; i < ballRayout.Count; ++i)
            {
                model = MMDModel.OpenLoad("../../res/" + (i + 1) + ".pmx", renderContext);
                models.Add(model);
                CreateSphereRigid(model, ballRayout[i]);
            }
            transferMatrixFromRigidToModel = GetTransferMatrixFromRigidToModel();
        }
    //Integration method 3
    //upVec is a vector perpendicular (in the upwards direction) to the direction the bullet is travelling in
    //is only needed if we calculate the lift force
    public static void Heuns(float timeStep, Vector3 currentPos, Vector3 currentVel, Vector3 upVec, BulletData bulletData, out Vector3 newPos, out Vector3 newVel)
    {
        //Add all factors that affects the acceleration
        //Gravity
        Vector3 accFactorEuler = gravityVec;

        //Drag
        accFactorEuler += BulletPhysics.CalculateBulletDragAcc(currentVel, bulletData);
        //Lift
        accFactorEuler += BulletPhysics.CalculateBulletLiftAcc(currentVel, bulletData, upVec);


        //Calculate the new velocity and position
        //y_k+1 = y_k + timeStep * 0.5 * (f(t_k, y_k) + f(t_k+1, y_k+1))
        //Where f(t_k+1, y_k+1) is calculated with Forward Euler: y_k+1 = y_k + timeStep * f(t_k, y_k)

        //Step 1. Find new pos and new vel with Forward Euler
        Vector3 newVelEuler = currentVel + timeStep * accFactorEuler;

        //New position with Forward Euler (is not needed here)
        //Vector3 newPosEuler = currentPos + timeStep * currentVel;


        //Step 2. Heuns method's final step
        //If we take drag into account, then acceleration is not constant - it also depends on the velocity
        //So we have to calculate another acceleration factor
        //Gravity
        Vector3 accFactorHeuns = gravityVec;

        //Drag
        //This assumes that windspeed is constant between the steps, which it should be because wind doesnt change that often
        accFactorHeuns += BulletPhysics.CalculateBulletDragAcc(newVelEuler, bulletData);
        //Lift
        accFactorHeuns += BulletPhysics.CalculateBulletLiftAcc(newVelEuler, bulletData, upVec);

        newVel = currentVel + timeStep * 0.5f * (accFactorEuler + accFactorHeuns);

        newPos = currentPos + timeStep * 0.5f * (currentVel + newVelEuler);
    }
Пример #11
0
 public Bullet(GameObject shooter, Vector2 origin, Vector2 target) : base(origin)
 {
     Shooter = shooter;
     physics = AddComponent <BulletPhysics>(new BulletPhysics(shooter, target));
     AddComponent(new BulletGraphics());
 }
Пример #12
0
 public void AddToPhysics(BulletPhysics physicsWorld)
 {
     physicsWorld.AddStaticGeometry(AttachedObject, Matrix4.CreateTranslation(Vector3.Zero), this);
 }