Exemplo n.º 1
0
        private void internal_update_for_playing(float dt, double update_time)
        {
            update_posture(dt);
            switch (phase_)
            {
            case Phase.Title:
                rigidbody_.setDamper(2f);
                float valx = Mathf.PerlinNoise((float)update_time * 0.2f, 0f) - 0.5f;
                float valy = Mathf.PerlinNoise((float)update_time * 0.3f, 0.5f) - 0.5f;
                rigidbody_.addForceX(valx * 2f);
                rigidbody_.addForceY(valy * 2.5f);
                rigidbody_.addSpringForceXY(0f, -27f, 4f);
                rigidbody_.update(dt);
                break;

            case Phase.Start:
                update_attack(update_time, false /* replay */);
                rigidbody_.setDamper(2f);
                rigidbody_.addForceY(10f);
                rigidbody_.addSpringForceX(0f, 4f);
                rigidbody_.update(dt);
                break;

            case Phase.Battle:
                update_attack(update_time, false /* replay */);
                rigidbody_.setDamper(16f);
                update_maneuver(dt, update_time);
                update_collision(update_time);
                break;
            }
        }
Exemplo n.º 2
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);
            }
        }