示例#1
0
        private void update_collision(double update_time)
        {
            // shield
            {
                Vector3 intersect_point = new Vector3(0f, 0f, 0f);
                if (MyCollider.getHitOpponentForPlayer(collider_, ref intersect_point) != MyCollider.Type.None)
                {
                    SystemManager.Instance.registSound(DrawBuffer.SE.Shield);
                    Shield.Instance.spawn(ref intersect_point,
                                          ref rigidbody_.transform_.position_,
                                          update_time,
                                          Shield.Type.Green);
                }
            }

            // collider
            MyCollider.updatePlayer(collider_, ref rigidbody_.transform_.position_);
        }
示例#2
0
        public override void update(float dt, double update_time)
        {
            var controller = Controller.Instance.getLatest();

            muscle_motion_.setTarget(posture_apose_);
            if (controller.isLeftButtonUp())
            {
                throwing_cnt_l_ = (int)(0.5f / dt);
            }
            if (controller.isRightButtonUp())
            {
                throwing_cnt_r_ = (int)(0.5f / dt);
            }
            if (throwing_cnt_l_ > 0)
            {
                muscle_motion_.setTarget(posture_throw_l_arm_);
                // muscle_motion_.addTorqueY(MuscleMotion.Parts.Ribs2, 8000f);
                // muscle_motion_.addTorqueY(MuscleMotion.Parts.Hip, 8000f);
                // muscle_motion_.addTorqueX(MuscleMotion.Parts.L_Thigh, 8000f);
                // muscle_motion_.addTorqueX(MuscleMotion.Parts.L_Knee, 8000f);
                if (throwing_cnt_l_ < (int)(0.45f / dt))
                {
                    fire_left(update_time);
                }
                --throwing_cnt_l_;
            }
            if (throwing_cnt_r_ > 0)
            {
                muscle_motion_.setTarget(posture_throw_r_arm_);
                // muscle_motion_.addTorqueY(MuscleMotion.Parts.Ribs2, -8000f);
                // muscle_motion_.addTorqueY(MuscleMotion.Parts.Hip, -8000f);
                // muscle_motion_.addTorqueX(MuscleMotion.Parts.R_Thigh, 8000f);
                // muscle_motion_.addTorqueX(MuscleMotion.Parts.R_Knee, 8000f);
                if (throwing_cnt_r_ < (int)(0.45f / dt))
                {
                    fire_right(update_time);
                }
                --throwing_cnt_r_;
            }
            if (controller.isLeftButtonDown())
            {
                MuscleMotion.Node node = muscle_motion_.getNode(MuscleMotion.Parts.L_Wrist);
                fire_left(update_time);
                left_held_bullet_ = Bullet.create(ref node.rigidbody_.transform_.position_,
                                                  ref CV.QuaternionIdentity);
            }
            if (controller.isRightButtonDown())
            {
                MuscleMotion.Node node = muscle_motion_.getNode(MuscleMotion.Parts.R_Wrist);
                fire_right(update_time);
                right_held_bullet_ = Bullet.create(ref node.rigidbody_.transform_.position_,
                                                   ref CV.QuaternionIdentity);
            }
            if (controller.isLeftButton())
            {
                throwing_cnt_l_  = 0;
                throwing_cnt_r_ -= (int)(0.25f / dt);
                muscle_motion_.setTarget(posture_pre_throw_l_arm_);
                bullet_tame_left_ += dt;
            }
            if (controller.isRightButton())
            {
                throwing_cnt_l_ -= (int)(0.25f / dt);
                throwing_cnt_r_  = 0;
                muscle_motion_.setTarget(posture_pre_throw_r_arm_);
                bullet_tame_right_ += dt;
            }
            if (left_held_bullet_ != null)
            {
                MuscleMotion.Node node = muscle_motion_.getNode(MuscleMotion.Parts.L_Wrist);
                left_held_bullet_.setPosition(ref node.rigidbody_.transform_.position_);
                left_held_bullet_.setPower(Mathf.Clamp(bullet_tame_left_, 0.25f, 2f));
            }
            if (right_held_bullet_ != null)
            {
                MuscleMotion.Node node = muscle_motion_.getNode(MuscleMotion.Parts.R_Wrist);
                right_held_bullet_.setPosition(ref node.rigidbody_.transform_.position_);
                right_held_bullet_.setPower(Mathf.Clamp(bullet_tame_right_, 0.25f, 2f));
            }

            if (controller.isJumpButton() && on_ground_)
            {
                muscle_motion_.getRootNode().rigidbody_.addRelativeTorqueX(1000f);
                muscle_motion_.setTarget(posture_pre_jump_,
                                         MuscleMotion.PartsBit.LowerBody |
                                         MuscleMotion.PartsBit.Ribs |
                                         MuscleMotion.PartsBit.Ribs2 |
                                         MuscleMotion.PartsBit.Ribs3);
                jump_tame_duration_ += dt;
            }

            if (controller.isJumpButtonUp())
            {
                if (jump_tame_duration_ > 0.5f)
                {
                    jump_propel_remain_ = Mathf.Min((jump_tame_duration_ - 0.5f) + 0.5f, 1f) * 2f;
                    rigidbody_.addForceY(1000f);
                    WaterSurface.Instance.makeBump(ref rigidbody_.transform_.position_,
                                                   -1f /* value */, 1f /* size */);
                    on_ground_time_ = 0f;
                    somersault_     = MyRandom.Probability(0.25f);
                }
                jump_tame_duration_ = 0f;
            }

            float hori          = controller.getHorizontal();
            float ground_height = 1.25f;

            if (hori != 0f)
            {
                ground_height = 1f;
            }

            if (jump_propel_remain_ > 0f)
            {
                rigidbody_.addForceY(100f);
                jump_propel_remain_ -= dt;
            }
            on_ground_ = (rigidbody_.transform_.position_.y <= 1f);

            rigidbody_.addTargetTorque(ref look_at_, 500f /* torque_level */, -1f /* max_level */);
            rigidbody_.addRelativeForceX(hori * 64f);
            if (hori != 0f)
            {
                rigidbody_.addRelativeForceZ(10f);
            }
            rigidbody_.addForceY(-9.8f * 5f);   // gravity
            if (rigidbody_.transform_.position_.y < ground_height)
            {
                rigidbody_.addSpringForceY(ground_height, 100f);
            }
            rigidbody_.solveForGround(0.0f /* ground_height */, dt);
            rigidbody_.addRelativeTorqueZ(-hori * 100f);
            {
                var forward = rigidbody_.transform_.rotation_ * CV.Vector3Forward;
                var q       = Quaternion.LookRotation(forward);
                rigidbody_.addSpringTorque(ref q, 10000f);
            }
            rigidbody_.update(dt);

            if (rigidbody_.transform_.position_.y < 5f)
            {
                WaterSurface.Instance.makeBump(ref rigidbody_.transform_.position_, -0.05f /* value */, 0.6f /* size */);
                var pos = rigidbody_.transform_.position_;
                pos.y = -2f;
                float vel_y;
                if (hori != 0f)
                {
                    vel_y = MyRandom.Range(7f, 9f);
                }
                else
                {
                    vel_y = MyRandom.Range(5f, 7f);
                }
                var vel = new Vector3(0f,
                                      vel_y,
                                      0f);
                if (MyRandom.Probability(0.2f))
                {
                    WaterSplash.Instance.spawn(ref pos, ref vel, update_time);
                }
            }

            var root_node = muscle_motion_.getRootNode();

            root_node.rigidbody_.transform_.position_ =
                rigidbody_.transform_.position_ + new Vector3((Mathf.PerlinNoise((float)update_time * 4f, 0.0f) - 0.5f) * 0.04f,
                                                              (Mathf.PerlinNoise((float)update_time * 4f, 0.5f) - 0.5f) * 0.04f,
                                                              (Mathf.PerlinNoise((float)update_time * 4f, 1.0f) - 0.5f) * 0.04f);

            if (somersault_ && on_ground_time_ < 0.25f)
            {
                root_node.rigidbody_.addRelativeTorqueX(-3000f);
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs).rigidbody_.addRelativeTorqueX(-3000f);
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs2).rigidbody_.addRelativeTorqueX(-3000f);
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs3).rigidbody_.addRelativeTorqueX(-3000f);
                muscle_motion_.getNode(MuscleMotion.Parts.Hip).rigidbody_.addRelativeTorqueX(-3000f);
            }
            else
            {
                root_node.rigidbody_.addTorqueY(hori * 1000f);
                root_node.rigidbody_.addRelativeTorqueZ(-hori * 1000f);
                root_node.rigidbody_.addSpringTorque(ref rigidbody_.transform_.rotation_, 4000f);
            }

            muscle_motion_.addTorqueX(MuscleMotion.Parts.L_Tale1, MyRandom.Range(500f, 1200f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.L_Tale4, MyRandom.Range(-4000f, 4000f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.R_Tale1, MyRandom.Range(500f, 1200f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.R_Tale4, MyRandom.Range(-4000f, 4000f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.L_SusoBack, MyRandom.Range(300f, 600f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.L_SusoFront, MyRandom.Range(-600f, -300f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.R_SusoBack, MyRandom.Range(300f, 600f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.R_SusoFront, MyRandom.Range(-600f, -300f));

            Vector3 e_pos;

            if (jump_tame_duration_ > 0.75f || on_ground_time_ < 1f)
            {
                var node = muscle_motion_.getNode(MuscleMotion.Parts.Head);
                node.rigidbody_.addRelativeTorqueX(-4000f);
            }
            else if (MyCollider.getNearestEnemyPosition(out e_pos))
            {
                muscle_motion_.getNode(MuscleMotion.Parts.Head).rigidbody_.addSpringTorque(ref e_pos, 4000f);
            }

            {
                var intersect_point = CV.Vector3Zero;
                if (MyCollider.getHitOpponentForPlayer(collider_, ref intersect_point) == MyCollider.Type.EnemyBullet)
                {
                    var node   = muscle_motion_.getNode(MuscleMotion.Parts.Ribs3);
                    var torque = MyRandom.onSphere(1f) * 5000f;
                    node.rigidbody_.addTorque(ref torque);
                    Shield.Instance.spawn(ref intersect_point,
                                          ref rigidbody_.transform_.position_,
                                          update_time,
                                          Shield.Type.Green);
                    SystemManager.Instance.registSound(DrawBuffer.SE.Shield);
                    // hit_time_ = (float)update_time;
                    // hit_position_ = intersect_point;
                }
                MyCollider.updatePlayer(collider_, ref rigidbody_.transform_.position_);
            }

            muscle_motion_.update(dt);
            on_ground_time_ += dt;
        }
示例#3
0
        public override void update(float dt, float update_time)
        {
            update_time_ = update_time;

            if (MyCollider.getHitOpponentForPlayer(collider_) != MyCollider.Type.None)
            {
                var pos = new Vector3(MyRandom.Range(-2f, 2f),
                                      MyRandom.Range(-2f, 2f),
                                      MyRandom.Range(-2f, 2f));
                HUD.Instance.setDamagePoint(ref pos);
            }

            if (Options.Instance.AutoPlay)
            {
                enumerator_.MoveNext();
            }

            int  hori        = getButton(InputManager.Button.Horizontal);
            int  vert        = getButton(InputManager.Button.Vertical);
            bool fire_button = getButton(InputManager.Button.Fire) > 0;
            int  lr          = getButton(InputManager.Button.Roll);

            roll_target_ += (float)(lr) * 150f * dt;
            roll_         = Mathf.Lerp(roll_, roll_target_, 0.1f);
            const float MOVE_FORCE   = 1f;
            const float CURSOR_FORCE = 6f;

            float sn = Mathf.Sin(roll_ * Mathf.Deg2Rad);
            float cs = Mathf.Cos(roll_ * Mathf.Deg2Rad);
            float vx = hori * cs - vert * sn;
            float vy = hori * sn + vert * cs;

            rigidbody_.addForceXY(vx * MOVE_FORCE, vy * MOVE_FORCE);
            target_cursor_.addForceXY(vx * CURSOR_FORCE, vy * CURSOR_FORCE);

            if (hori < 0)
            {
                pitch_acceleration_ += 2000f;
            }
            else if (hori > 0)
            {
                pitch_acceleration_ += -2000f;
            }

            // cursor update
            {
                // 外に向けさせない
                float x    = rigidbody_.transform_.position_.x + target_cursor_.transform_.position_.x;
                float y    = rigidbody_.transform_.position_.y + target_cursor_.transform_.position_.y;
                float len2 = x * x + y * y;
                float R    = 64f;
                if (len2 > Tube.RADIUS_SQR)
                {
                    R = 256f;
                }
                target_cursor_.addForceX(-target_cursor_.transform_.position_.x * R);
                target_cursor_.addForceY(-target_cursor_.transform_.position_.y * R);
                target_cursor_.update(dt);
            }

            // pitch
            pitch_acceleration_ += -pitch_ * 8f;          // spring
            pitch_acceleration_ += -pitch_velocity_ * 4f; // friction
            pitch_velocity_     += pitch_acceleration_ * dt;
            pitch_ += pitch_velocity_ * dt;
            pitch_acceleration_ = 0f;

            // rotate
            rigidbody_.transform_.rotation_ = Quaternion.LookRotation(target_cursor_.transform_.position_) * Quaternion.Euler(0, 0, pitch_);

            // update
            rigidbody_.update(dt);
            float radius = Tube.RADIUS - PLAYER_WIDTH2;

            if (rigidbody_.transform_.position_.sqrMagnitude >= radius * radius)
            {
                hit_wall_ = true;
                rigidbody_.cancelUpdateForTube(dt);
                if (MyRandom.ProbabilityForSecond(60f, SystemManager.Instance.getDT()))
                {
                    float x    = rigidbody_.transform_.position_.x;
                    float y    = rigidbody_.transform_.position_.y;
                    float z    = rigidbody_.transform_.position_.z;
                    float len  = Mathf.Sqrt(x * x + y * y);
                    float rlen = 1f / len;
                    float r    = rlen * Tube.RADIUS;
                    var   v    = new Vector3(x * r, y * r, z);
                    Spark.Instance.spawn(ref v, Spark.Type.Orange, update_time);
                }
            }
            else
            {
                hit_wall_ = false;
            }

            // collider
            MyCollider.updatePlayer(collider_, ref rigidbody_.transform_.position_);

            // fire bullets
            if (fire_button && update_time - fire_time_ > 0.06667f)
            {
                var lpos = rigidbody_.transform_.transformPosition(ref l_bullet_locator_);
                Bullet.create(ref lpos, ref rigidbody_.transform_.rotation_, 120f /* speed */, update_time);
                var rpos = rigidbody_.transform_.transformPosition(ref r_bullet_locator_);
                Bullet.create(ref rpos, ref rigidbody_.transform_.rotation_, 120f /* speed */, update_time);
                SystemManager.Instance.registSound(DrawBuffer.SE.Bullet);
                fire_time_ = update_time;
            }

            // fire missiles
            if (fire_button && !prev_fire_button_)                              // tmp
            {
                bool fired = LockTarget.fireMissiles(this);
                if (fired)
                {
                    SystemManager.Instance.registSound(DrawBuffer.SE.Missile);
                }
            }
            prev_fire_button_ = fire_button;

            // trail
            {
                float flow_z = -30f * dt;
                var   lpos   = rigidbody_.transform_.transformPosition(ref l_trail_locator_);
                Trail.Instance.update(l_trail_, ref lpos, flow_z, update_time);
                var rpos = rigidbody_.transform_.transformPosition(ref r_trail_locator_);
                Trail.Instance.update(r_trail_, ref rpos, flow_z, update_time);
            }
        }