Exemple #1
0
        public override void update(float dt, float update_time)
        {
            update_time_ = update_time;
            if (enumerator_ != null)
            {
                enumerator_.MoveNext();
            }
            if (alive_)
            {
                if (MyCollider.getHitOpponentForEnemy(collider_) != MyCollider.Type.None)
                {
                    rigidbody_.addTorque(MyRandom.Range(-100f, 100f),
                                         MyRandom.Range(-100f, 100f),
                                         MyRandom.Range(-100f, 100f));
                    rigidbody_.addForceZ(-10000f);
                    Explosion.Instance.spawn(ref rigidbody_.transform_.position_, update_time);
                    Hahen.Instance.spawn(ref rigidbody_.transform_.position_, update_time);
                    SystemManager.Instance.registSound(DrawBuffer.SE.Explosion);
                    MyCollider.disableForEnemy(collider_);
                    lock_target_.disable();
                    phase_ = Phase.Dying;
                }
                if (lock_target_.isHitted())
                {
                    rigidbody_.addTorque(MyRandom.Range(-100f, 100f),
                                         MyRandom.Range(-100f, 100f),
                                         MyRandom.Range(-100f, 100f));
                    rigidbody_.addForceZ(-10000f);
                    lock_target_.clearLock();
                    Explosion.Instance.spawn(ref lock_target_.updated_position_, update_time);
                    Hahen.Instance.spawn(ref lock_target_.updated_position_, update_time);
                    SystemManager.Instance.registSound(DrawBuffer.SE.Explosion);
                    MyCollider.disableForEnemy(collider_);
                    lock_target_.disable();
                    phase_ = Phase.Dying;
                }

                rigidbody_.update(dt);
                MyCollider.updateEnemy(collider_, ref rigidbody_.transform_.position_);
                lock_target_.update();
            }
        }
Exemple #2
0
        public void spawn(ref Vector3 pos, double update_time)
        {
            int id = spawn_index_;

            ++spawn_index_;
            if (spawn_index_ >= EXPLOSION_MAX)
            {
                spawn_index_ = 0;
            }

            if (positions_ == null)
            {
                Debug.LogWarning("null???");
                return;
            }
            positions_[id] = pos;
            var rot = MyRandom.Range(0, Mathf.PI * 2f);

            uv2_list_[id] = new Vector2((float)update_time, rot);
        }
Exemple #3
0
        public IEnumerator zako_act()
        {
            rigidbody_.setDamper(2f);
            rigidbody_.setRotateDamper(2f);
            target_position_.x = MyRandom.Range(-20f, 20);
            target_position_.y = MyRandom.Range(-20f, 20);
            rigidbody_.addForceZ(40f);
            yield return(null);

            // for (var i = Utility.WaitForSeconds(10f, update_time_); i.MoveNext();) {
            for (var i = new Utility.WaitForSeconds(10f, update_time_); !i.end(update_time_);)
            {
                rigidbody_.addForceX(target_position_.x - rigidbody_.transform_.position_.x * 2f);
                rigidbody_.addForceY(target_position_.y - rigidbody_.transform_.position_.y * 2f);
                rigidbody_.addForceZ(10f);
                rigidbody_.addTorqueZ(-rigidbody_.velocity_.x * 1f);

                if (MyRandom.ProbabilityForSecond(1.5f, SystemManager.Instance.getDT()))
                {
                    var pos = Player.Instance.rigidbody_.transform_.position_;
                    pos.z += MyRandom.Range(-10f, 10f);
                    EnemyBullet.create(ref rigidbody_.transform_.position_,
                                       ref pos,
                                       50f /* speed */,
                                       update_time_);
                }

                if (phase_ == Phase.Dying)
                {
                    // for (var j = Utility.WaitForSeconds(0.1f, update_time_); j.MoveNext();) {
                    for (var j = new Utility.WaitForSeconds(0.1f, update_time_); j.end(update_time_);)
                    {
                        yield return(null);
                    }
                    break;
                }

                yield return(null);
            }
            destroy();
        }
Exemple #4
0
 private IEnumerator act()
 {
     // SystemManager.Instance.registBgm(DrawBuffer.BGM.Battle);
     {
         var position = new Vector3(0f, -10f, 0f);
         var rotation = Quaternion.Euler(-90f, 0f, 0f);
         Enemy.create(Enemy.Type.Dragon, ref position, ref rotation);
     }
     for (;;)
     {
         {
             var position = new Vector3(MyRandom.Range(-10f, 10f), -10f, MyRandom.Range(-10f, 10f));
             var rotation = Quaternion.Euler(-90f, 0f, 0f);
             Enemy.create(Enemy.Type.Zako, ref position, ref rotation);
         }
         for (var i = new Utility.WaitForSeconds(MyRandom.Range(1f, 3f), update_time_); !i.end(update_time_);)
         {
             yield return(null);
         }
         yield return(null);
     }
 }
Exemple #5
0
        public override void update(float dt, double update_time)
        {
            if (MyCollider.getHitOpponentForEnemyBullet(collider_) != MyCollider.Type.None)
            {
                Spark.Instance.spawn(ref rigidbody_.transform_.position_, Spark.Type.EnemyBullet, update_time);
                destroy();
                return;
            }
            if (rigidbody_.transform_.position_.y < -16f)
            {
                destroy();
                var pos = new Vector3(rigidbody_.transform_.position_.x, -0.5f,
                                      rigidbody_.transform_.position_.z);
                for (var i = 0; i < 4; ++i)
                {
                    var spread = 2f;
                    var vel    = new Vector3(Mathf.Cos(i * Mathf.PI * (2f / 8f)) * spread,
                                             MyRandom.Range(3f, 7f),
                                             Mathf.Sin(i * Mathf.PI * (2f / 8f)) * spread);
                    WaterSplash.Instance.spawn(ref pos, ref vel, update_time);
                }
                return;
            }

            rigidbody_.update(dt);
            MyCollider.updateEnemyBullet(collider_, ref rigidbody_.transform_.position_);
            var diff = Player.Instance.rigidbody_.transform_.position_ - rigidbody_.transform_.position_;

            if (diff.sqrMagnitude < (50f * 50f))
            {
                WaterSurface.Instance.makeBump(ref rigidbody_.transform_.position_, -1f /* value */, 1f /* size */);
            }
            if (update_time - start_ > 4f)       // 寿命
            {
                destroy();
                return;
            }
        }
        private void alpha_update(float dt, double update_time)
        {
            if (MissileManager.Instance.checkHitAndClear(target_id_))
            {
                hit_time_ = update_time;
            }
            if (update_time - hit_time_ < 0.5f)
            {
                rigidbody_.setRotateDamper(0.2f);
                if (update_time - hit_time_ < 0.017f)
                {
                    var torque = MyRandom.onSphere(25f);
                    rigidbody_.addTorque(ref torque);
                }
            }
            else
            {
                rigidbody_.setRotateDamper(1f);
                alpha_normal_act(dt, update_time);
            }

            rigidbody_.update(dt);
        }
Exemple #7
0
        public static Enemy create(Type type)
        {
            Enemy enemy = Enemy.create();

            // enemy.type_ = type;
            enemy.phase_ = Phase.Alive;
            enemy.init();
            switch (type)
            {
            case Type.None:
                Debug.Assert(false);
                break;

            case Type.Zako:
            {
                var position = new Vector3(MyRandom.Range(-15f, 15f), MyRandom.Range(-6f, 6f), -100f);
                enemy.zako_init(ref position, ref CV.QuaternionIdentity);
            }
            break;

            case Type.Zako2:
            {
                var position = new Vector3(MyRandom.Range(-6f, 6f),
                                           MyRandom.Range(-6f, 6f),
                                           MyRandom.Range(194, 198f));
                enemy.zako2_init(ref position, ref CV.Quaternion180Y);
            }
            break;

            case Type.Dragon:
            {
                enemy.dragon_init();
            }
            break;
            }
            return(enemy);
        }
Exemple #8
0
        IEnumerator loop()
        {
            ready_ = true;

            GetComponent <MeshRenderer>().sharedMaterial = material_;
            var range = 2.5f;

            for (;;)
            {
                Shield.Instance.begin();
                var pos = new Vector3(Random.Range(-range, range),
                                      Random.Range(-range, range),
                                      Random.Range(-range, range));
                var target = new Vector3(0, 0, 0);
                Shield.Instance.spawn(ref pos,
                                      ref target,
                                      Time.time,
                                      (MyRandom.Range(0f, 1f) < 0.5f ?
                                       Shield.Type.Green :
                                       Shield.Type.Red));
                Shield.Instance.end(0 /* front */);
                yield return(null);
            }
        }
Exemple #9
0
        void initialize()
        {
            MyRandom.setSeed(12345L);
            camera_final_         = GameObject.Find("FinalCamera").GetComponent <Camera>();
            camera_final_.enabled = false;
            if ((float)Screen.width / (float)Screen.height < 16f / 9f)
            {
                var size = camera_final_.orthographicSize * ((16f / 9f) * ((float)Screen.height / (float)Screen.width));
                camera_final_.orthographicSize = size;
            }
            meter_draw_ = true;

            Application.targetFrameRate = (int)RENDER_FPS; // necessary for iOS because the default is 30fps.
            // QualitySettings.vSyncCount = 1;

            stopwatch_ = new System.Diagnostics.Stopwatch();
            stopwatch_.Start();
            rendering_front_ = 0;

            setFPS(DefaultFps);
            update_frame_      = 0;
            update_time_       = 100.0; // ゼロクリア状態を過去のものにするため増やしておく
            render_frame_      = 0;
            render_sync_frame_ = 0;
            pause_             = false;
            spectator_mode_    = true;

            camera_          = GameObject.Find("Main Camera").GetComponent <Camera>();
            ProjectionMatrix = camera_.projectionMatrix;

            MissileManager.Instance.initialize(camera_);
            InputManager.Instance.init();
            Controller.Instance.init(false /* auto */);
            TaskManager.Instance.init();
            Fighter.createPool();
            Spark.Instance.init(spark_material_);
            Debris.Instance.init(debris_material_);
            MySprite.Instance.init(sprites_, sprite_material_);
            MySpriteRenderer.Instance.init(camera_);
            MyFont.Instance.init(font_, font_material_);
            MyFontRenderer.Instance.init();

            PerformanceMeter.Instance.init();

            draw_buffer_ = new DrawBuffer[2];
            for (int i = 0; i < 2; ++i)
            {
                draw_buffer_[i].init();
            }

            debug_camera_     = DebugCamera.create();
            spectator_camera_ = SpectatorCamera.create();
            set_camera();

            // audio
            audio_sources_explosion_ = new AudioSource[AUDIOSOURCE_EXPLOSION_MAX];
            for (var i = 0; i < AUDIOSOURCE_EXPLOSION_MAX; ++i)
            {
                audio_sources_explosion_[i]        = gameObject.AddComponent <AudioSource>();
                audio_sources_explosion_[i].clip   = se_explosion_;
                audio_sources_explosion_[i].volume = 0.01f;
                audio_sources_explosion_[i].pitch  = 0.25f;
            }
            audio_source_explosion_index_ = 0;
            audio_sources_laser_          = new AudioSource[AUDIOSOURCE_LASER_MAX];
            for (var i = 0; i < AUDIOSOURCE_LASER_MAX; ++i)
            {
                audio_sources_laser_[i]        = gameObject.AddComponent <AudioSource>();
                audio_sources_laser_[i].clip   = se_laser_;
                audio_sources_laser_[i].volume = 0.025f;
            }
            audio_source_laser_index_ = 0;

            GameManager.Instance.init(debug_mode_);

#if UNITY_PS4 || UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
            int rw = 1920;
            int rh = 1080;
#else
            int rw = 1024;
            int rh = 576;
#endif
            render_texture_ = new RenderTexture(rw, rh, 24 /* depth */, RenderTextureFormat.ARGB32);
            render_texture_.Create();
            camera_.targetTexture       = render_texture_;
            final_material_.mainTexture = render_texture_;
            alpha_matrices_             = new Matrix4x4[ALPHA_MAX];
            frustum_planes_             = new Vector4[6];

            initialized_          = true;
            camera_final_.enabled = true;
        }
Exemple #10
0
 private IEnumerator fetch_auto()
 {
     for (;;)
     {
         for (var w = new Utility.WaitForSeconds(MyRandom.Range(2f, 4f), update_time_);
              !w.end(update_time_);)
         {
             if (latest_.horizontal_ < 0f)
             {
                 for (var w0 = new Utility.WaitForSeconds(MyRandom.Range(0.1f, 1f), update_time_);
                      !w0.end(update_time_);)
                 {
                     latest_.left_button_ = true;
                     yield return(null);
                 }
             }
             else
             {
                 for (var w0 = new Utility.WaitForSeconds(MyRandom.Range(0.1f, 1f), update_time_);
                      !w0.end(update_time_);)
                 {
                     latest_.right_button_ = true;
                     yield return(null);
                 }
             }
             for (var w0 = new Utility.WaitForSeconds(MyRandom.Range(0.1f, 0.6f), update_time_);
                  !w0.end(update_time_);)
             {
                 yield return(null);
             }
             yield return(null);
         }
         if (MyRandom.Probability(0.5f))
         {
             for (var w = new Utility.WaitForSeconds(MyRandom.Range(0.8f, 1.2f), update_time_);
                  !w.end(update_time_);)
             {
                 latest_.jump_button_ = true;
                 yield return(null);
             }
         }
         if (MyRandom.Probability(0.1f))
         {
             for (var w = new Utility.WaitForSeconds(MyRandom.Range(3f, 4f), update_time_);
                  !w.end(update_time_);)
             {
                 for (var w0 = new Utility.WaitForSeconds(MyRandom.Range(0.2f, 0.4f), update_time_);
                      !w0.end(update_time_);)
                 {
                     latest_.left_button_ = true;
                     yield return(null);
                 }
                 for (var w0 = new Utility.WaitForSeconds(MyRandom.Range(0.2f, 0.4f), update_time_);
                      !w0.end(update_time_);)
                 {
                     latest_.right_button_ = true;
                     yield return(null);
                 }
                 yield return(null);
             }
         }
         for (var w = new Utility.WaitForSeconds(MyRandom.Range(0.2f, 0.8f), update_time_);
              !w.end(update_time_);)
         {
             yield return(null);
         }
         yield return(null);
     }
 }
        void OnGUI()
        {
            int x = 20;
            int y = 60;
            int w = 240;
            int h = 40;

            GUI.Box(new Rect(Screen.width - (x + w + 10), y - 40, w, y + h * 10 + 10), "Posture Param");
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "body damper");
            y += h / 2;
            float body_damper = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), body_damper_, 0f, 100f);

            if (body_damper_ != body_damper)
            {
                body_damper_ = body_damper;
            }
            y += h;
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "body spring");
            y += h / 2;
            float body_spring = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), body_spring_, 0f, 2000f);

            if (body_spring_ != body_spring)
            {
                body_spring_ = body_spring;
            }
            y += h;
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "arm damper");
            y += h / 2;
            float arm_damper = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), arm_damper_, 0f, 100f);

            if (arm_damper_ != arm_damper)
            {
                arm_damper_ = arm_damper;
            }
            y += h;
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "arm spring");
            y += h / 2;
            float arm_spring = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), arm_spring_, 0f, 2000f);

            if (arm_spring_ != arm_spring)
            {
                arm_spring_ = arm_spring;
            }
            y += h;
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "leg damper");
            y += h / 2;
            float leg_damper = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), leg_damper_, 0f, 100f);

            if (leg_damper_ != leg_damper)
            {
                leg_damper_ = leg_damper;
            }
            y += h;
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "leg spring");
            y += h / 2;
            float leg_spring = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), leg_spring_, 0f, 2000f);

            if (leg_spring_ != leg_spring)
            {
                leg_spring_ = leg_spring;
            }
            y += h;


            x = 20;
            y = 40;
            w = 180;
            h = 30;
            GUI.Box(new Rect(x - 10, y - 20, x + w, y + h * 10 + 10), "Posture Menu");

            if (GUI.Button(new Rect(x, y, w, h), "apose") || Input.GetKeyDown(KeyCode.Alpha0))
            {
                current_posture_ = posture_apose_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "pre_throw_l_arm") || Input.GetKeyDown(KeyCode.Alpha1))
            {
                current_posture_ = posture_pre_throw_l_arm_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "throw_l_arm") || Input.GetKeyDown(KeyCode.Alpha2))
            {
                current_posture_ = posture_throw_l_arm_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "pre_throw_r_arm") || Input.GetKeyDown(KeyCode.Alpha3))
            {
                current_posture_ = posture_pre_throw_r_arm_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "throw_r_arm") || Input.GetKeyDown(KeyCode.Alpha4))
            {
                current_posture_ = posture_throw_r_arm_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "pre_jump") || Input.GetKeyDown(KeyCode.Alpha5))
            {
                current_posture_ = posture_pre_jump_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "hit") || Input.GetKeyDown(KeyCode.Alpha6))
            {
                var torque0 = MyRandom.onSphere(1f) * 2000f;
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs).rigidbody_.addTorque(ref torque0);
                var torque1 = MyRandom.onSphere(1f) * 2000f;
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs2).rigidbody_.addTorque(ref torque1);
                var torque2 = MyRandom.onSphere(1f) * 2000f;
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs3).rigidbody_.addTorque(ref torque2);
            }
            y += h;

            y          += 8;
            gui_lookat_ = GUI.HorizontalSlider(new Rect(x, y, w, h), gui_lookat_, 0f, 1f);
            y          += 10;
            GUI.Label(new Rect(x, y, w, h), "value:" + gui_lookat_);
            y          += h;
            gui_hand_   = GUI.Toggle(new Rect(x, y, w, h), gui_hand_, "hand");
            y          += h;
            gui_rotate_ = GUI.Toggle(new Rect(x, y, w, h), gui_rotate_, "rotate");
            y          += h;
        }
Exemple #12
0
        public void end(int front, CameraBase camera)
        {
            const float SIZE = 16f;
            float       size = SIZE;

            switch (phase_)
            {
            case 0:
                cnt_  = MyRandom.Range(300, 400);
                cnt1_ = 0;
                ++phase_;
                break;

            case 1:
                --cnt_;
                if (cnt_ < 0)
                {
                    cnt_ = 16;
                    size = 0f;
                    ++phase_;
                }
                break;

            case 2:
                size = (float)(16 - cnt_) / 16f * SIZE;
                --cnt_;
                if (cnt_ < 0)
                {
                    cnt_ = 12;
                    ++phase_;
                }
                break;

            case 3:
                --cnt_;
                if (cnt_ < 0)
                {
                    cnt_ = 4;
                    ++phase_;
                }
                break;

            case 4:
                --cnt_;
                if (cnt_ < 0)
                {
                    cnt_ = 12;
                    ++cnt1_;
                    if (cnt1_ > 8)
                    {
                        phase_ = 0;
                    }
                    else
                    {
                        --phase_;
                    }
                }
                break;
            }

            if (phase_ != 2 && phase_ != 3)
            {
                return;
            }

            for (var i = 0; i < regist_index_; ++i)
            {
                var spos = (camera != null ?
                            camera.getScreenPoint(ref positions_[i]) :
                            positions_[i]);
                float size0 = spos.z > 1f ? size : 0f;
                vertices_[front][i * 6 + 0].x = spos.x + size0;
                vertices_[front][i * 6 + 0].y = spos.y;
                vertices_[front][i * 6 + 1].x = spos.x;
                vertices_[front][i * 6 + 1].y = spos.y + size0;
                vertices_[front][i * 6 + 2].x = spos.x - size0;
                vertices_[front][i * 6 + 2].y = spos.y;
                vertices_[front][i * 6 + 3].x = spos.x;
                vertices_[front][i * 6 + 3].y = spos.y - size0;
                vertices_[front][i * 6 + 4].x = spos.x + size0 * 2f;
                vertices_[front][i * 6 + 4].y = spos.y - size0 * 3f;
                vertices_[front][i * 6 + 5].x = spos.x + size0 * 4f;
                vertices_[front][i * 6 + 5].y = spos.y - size0 * 3f;
            }
        }
Exemple #13
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;
        }
Exemple #14
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);
            }
        }
Exemple #15
0
        public void update(float dt,
                           double update_time,
                           ref RigidbodyTransform grand_parent_rigidbody,
                           ref RigidbodyTransform parent_rigidbody,
                           ref RigidbodyTransform child_rigidbody,
                           bool head,
                           bool tail)
        {
#if false
            if (MyCollider.getHitOpponentForEnemy(collider_) != MyCollider.Type.None)
            {
                rigidbody_.addTorque(MyRandom.Range(-20f, 20f),
                                     MyRandom.Range(-20f, 20f),
                                     MyRandom.Range(-20f, 20f));
            }
            rigidbody_.addSpringTorque(ref parent_transform.rotation_, 10f /* torque_level */);
            rigidbody_.transform_.position_ = parent_transform.transformPosition(ref locator_);
            rigidbody_.update(dt);
#else
            if (head)
            {
                rigidbody_.updateVerlet(dt, 0.8f /* damper */);
            }
            else
            {
                rigidbody_.updateVerlet(dt, 0.8f /* damper */);
            }
            if (head)
            {
                var head_offset = new Vector3(0f, 0f, -3f);
                var pos         = parent_rigidbody.transform_.transformPosition(ref head_offset);
                rigidbody_.restrictPositionVerletFixed(ref pos, 0f /* length */);
            }
            else
            {
                rigidbody_.restrictPositionVerlet(ref grand_parent_rigidbody,
                                                  ref parent_rigidbody,
                                                  3f /* length */, 60f /* max_degree */);
            }
            if (!tail)
            {
                rigidbody_.solveRotationVerlet(ref parent_rigidbody, ref child_rigidbody);
            }
#endif
            MyCollider.updateEnemy(collider_, ref rigidbody_.transform_.position_);
            MyCollider.updateEnemyHoming(collider_homing_, ref rigidbody_.transform_.position_);

            if (-2f < rigidbody_.transform_.position_.y && rigidbody_.transform_.position_.y < 2f)
            {
                WaterSurface.Instance.makeBump(ref rigidbody_.transform_.position_, -0.025f /* value */, 1f /* size */);
                var wpos = rigidbody_.transform_.position_;
                wpos.y = -1.5f;
                var th  = MyRandom.Range(0f, Mathf.PI * 2f);
                var cos = Mathf.Cos(th);
                var sin = Mathf.Sin(th);
                wpos.x += cos * 1.25f;
                wpos.z += sin * 1.25f;
                var vel = new Vector3(cos * 0.8f,
                                      MyRandom.Range(5f, 8f),
                                      sin * 0.8f);
                WaterSplash.Instance.spawn(ref wpos, ref vel, update_time);
            }
            if (MyRandom.Probability(0.1f))
            {
                var pos = rigidbody_.transform_.position_;
                pos.x += MyRandom.Range(-1f, 1f);
                pos.z += MyRandom.Range(-1f, 1f);
                WaterSplash.Instance.spawn(ref pos,
                                           ref CV.Vector3Zero, update_time - 0.2f);
            }
        }
        private IEnumerator act()
        {
            game_phase_ = GamePhase.Title;
            Player.Instance.setPhaseTitle();
            Player.Instance.setPositionXY(0f, -27f);
            SystemManager.Instance.registBgm(DrawBuffer.BGM.Stop);
            SystemManager.Instance.registMotion(DrawBuffer.Motion.Play);
            SystemManager.Instance.setFlowSpeed(0f);
            SystemManager.Instance.setSubjective(true);

            for (var w = new Utility.WaitForSeconds(4f, update_time_); !w.end(update_time_);)
            {
                yield return(null);
            }
            Notice notice;
            {
                notice = Notice.create(-400f, 400f,
                                       MySprite.Kind.GamePadPress,
                                       MySprite.Type.Full,
                                       false /* blink */);
            }
            var leave_time_start = update_time_;

            while (game_phase_ == GamePhase.Title)
            {
                bool exit_title   = false;
                var  elapsed_time = update_time_ - leave_time_start;
                if (InputManager.Instance.getButton(InputManager.Button.Fire) > 0)
                {
                    exit_title = true;
                    replay_manager_.startRecording(update_time_);
                    replay_mode_ = false;
                }
                else
                {
                    if (replay_manager_.hasRecorded())
                    {
                        bool start_replay = false;
                        if (replay_mode_)
                        {
                            if (elapsed_time > 1f)
                            {
                                start_replay = true;
                            }
                        }
                        else
                        {
                            if (elapsed_time > 30f)
                            {
                                start_replay = true;
                                replay_mode_ = true;
                            }
                        }
                        if (start_replay)
                        {
                            exit_title = true;
                            SystemManager.Instance.setSubjective(false);
                            replay_manager_.startPlaying(update_time_, Player.Instance);
                        }
                    }
                }
                if (exit_title)
                {
                    game_phase_ = GamePhase.Game;
                    SystemManager.Instance.registSound(DrawBuffer.SE.Missile);
                    SystemManager.Instance.registMotion(DrawBuffer.Motion.GoodLuck);
                }
                yield return(null);
            }
            notice.destroy();
            MyRandom.setSeed(123456789u);

            for (var w = new Utility.WaitForSeconds(1.5f, update_time_); !w.end(update_time_);)
            {
                yield return(null);
            }
            Player.Instance.setPhaseStart();
            SystemManager.Instance.registBgm(DrawBuffer.BGM.Battle);
            for (var w = new Utility.WaitForSeconds(4f, update_time_); !w.end(update_time_);)
            {
                yield return(null);
            }
            Notice.create(0f, 0f,
                          update_time_ + 3f,
                          MySprite.Kind.GamePadPress,
                          MySprite.Type.Full,
                          true /* blink */);
            for (var w = new Utility.WaitForSeconds(1f, update_time_); !w.end(update_time_);)
            {
                yield return(null);
            }

            Player.Instance.setPhaseBattle();
            SystemManager.Instance.setFlowSpeed(-100f);
            while (TubeScroller.Instance.getDistance() < 100f)
            {
                yield return(null);
            }

            for (var j = 0; j < 4; ++j)
            {
                for (var w = new Utility.WaitForSeconds(2f, update_time_); !w.end(update_time_);)
                {
                    yield return(null);
                }
                for (var i = 0; i < 4; ++i)
                {
                    for (var w = new Utility.WaitForSeconds(0.5f, update_time_); !w.end(update_time_);)
                    {
                        yield return(null);
                    }
                    Enemy.create(Enemy.Type.Zako2);
                }

                if (j == 1)
                {
                    Notice.create(-200f, 200f,
                                  update_time_ + 3f,
                                  MySprite.Kind.GamePadRelease,
                                  MySprite.Type.Full,
                                  true /* blink */);
                }
            }

            while (TubeScroller.Instance.getDistance() < 2400f)
            {
                yield return(null);
            }

            Enemy dragon = Enemy.create(Enemy.Type.Dragon);

            SystemManager.Instance.setFlowSpeed(-10f);

            while (TubeScroller.Instance.getDistance() < 2800f)
            {
                for (var w = new Utility.WaitForSeconds(5f, update_time_); !w.end(update_time_);)
                {
                    yield return(null);
                }
                for (var j = new Utility.WaitForSeconds(2f, update_time_); !j.end(update_time_);)
                {
                    yield return(null);

                    Enemy.create(Enemy.Type.Zako2);
                    for (var w = new Utility.WaitForSeconds(0.25f, update_time_); !w.end(update_time_);)
                    {
                        yield return(null);
                    }
                }
                yield return(null);
            }

            float flow_speed = 150f;

            SystemManager.Instance.setFlowSpeed(-150f);
            dragon.setMode(Dragon.Mode.Chase);

            for (var i = 0; i < 4; ++i)
            {
                for (var v = new Utility.WaitForSeconds(3f, update_time_); !v.end(update_time_);)
                {
                    Enemy.create(Enemy.Type.Zako2);
                    for (var w = new Utility.WaitForSeconds(0.5f, update_time_); !w.end(update_time_);)
                    {
                        yield return(null);
                    }
                }
                for (var w = new Utility.WaitForSeconds(2f, update_time_); !w.end(update_time_);)
                {
                    yield return(null);
                }
            }

            for (var w = new Utility.WaitForSeconds(2f, update_time_); !w.end(update_time_);)
            {
                yield return(null);
            }
            dragon.setMode(Dragon.Mode.Farewell);
            for (var i = 0; i < 16; ++i)
            {
                float rot = 30f * i;
                Shutter.create(rot, flow_speed, update_time_);
                Shutter.create(rot + 180f, flow_speed, update_time_);
                for (var w = new Utility.WaitForSeconds(1f, update_time_); !w.end(update_time_);)
                {
                    yield return(null);
                }
            }
            while (TubeScroller.Instance.getDistance() < 9400f)
            {
                yield return(null);
            }

            dragon.setMode(Dragon.Mode.LastAttack);
            for (var w = new Utility.WaitForSeconds(11f, update_time_); !w.end(update_time_);)
            {
                yield return(null);
            }
            Notice.create(0f, 0f,
                          update_time_ + 6f,
                          MySprite.Kind.Logo,
                          MySprite.Type.Full,
                          false);
            for (var w = new Utility.WaitForSeconds(5f, update_time_); !w.end(update_time_);)
            {
                yield return(null);
            }

            SystemManager.Instance.restart();
        }
Exemple #17
0
        private IEnumerator unitychan_act()
        {
            float wait_sec;

            for (;;)
            {
                wait_sec = MyRandom.Range(5f, 15f);
                for (var i = new Utility.WaitForSeconds(wait_sec, update_time_); !i.end(update_time_);)
                {
                    yield return(null);
                }
                unitychan_height_ratio_ = 4f / 128f;
                for (unitychan_width_ratio_ = 0f;
                     unitychan_width_ratio_ < 1f;
                     unitychan_width_ratio_ += 8f * current_dt_)
                {
                    yield return(null);
                }
                unitychan_width_ratio_ = 1f;

                for (;
                     unitychan_height_ratio_ < 1f;
                     unitychan_height_ratio_ += 8f * current_dt_)
                {
                    yield return(null);
                }
                unitychan_height_ratio_ = 1f;

                DrawBuffer.SE voice = DrawBuffer.SE.VoiceIkuyo;
                switch (MyRandom.Range(0, 5))
                {
                case 0:
                    voice           = DrawBuffer.SE.VoiceIkuyo;
                    unitychan_kind_ = MySprite.Kind.UnityChanLaugh;
                    break;

                case 1:
                    voice           = DrawBuffer.SE.VoiceUwaa;
                    unitychan_kind_ = MySprite.Kind.UnityChanOuch;
                    break;

                case 2:
                    voice           = DrawBuffer.SE.VoiceSorosoro;
                    unitychan_kind_ = MySprite.Kind.UnityChanLaugh;
                    break;

                case 3:
                    voice           = DrawBuffer.SE.VoiceOtoto;
                    unitychan_kind_ = MySprite.Kind.UnityChanGrin;
                    break;

                case 4:
                    voice           = DrawBuffer.SE.VoiceYoshi;
                    unitychan_kind_ = MySprite.Kind.UnityChanGrin;
                    break;
                }
                SystemManager.Instance.registSound(voice);
                wait_sec = MyRandom.Range(2f, 3f);
                for (var i = new Utility.WaitForSeconds(wait_sec, update_time_); !i.end(update_time_);)
                {
                    yield return(null);
                }

                for (;
                     unitychan_height_ratio_ > 4f / 128f;
                     unitychan_height_ratio_ -= 8f * current_dt_)
                {
                    yield return(null);
                }
                unitychan_height_ratio_ = 4f / 128f;
                for (;
                     unitychan_width_ratio_ > 0f;
                     unitychan_width_ratio_ -= 8f * current_dt_)
                {
                    yield return(null);
                }
                unitychan_width_ratio_ = 0f;
            }
        }