Example #1
0
    //-------------------------------------------------------------------------
    EbVector3 getHitPosition(EbVector3 fish_pos, EbVector3 bullet_pos)
    {
        float distance = fish_pos.getDistance(bullet_pos);

        if (distance > 0)
        {
            return(EbVector3.lerp(bullet_pos, fish_pos, mBoxY / distance));
        }
        return(fish_pos);
    }
Example #2
0
        //---------------------------------------------------------------------
        List <EbVector3> getMiddle(List <EbVector3> points)
        {
            List <EbVector3> middle = new List <EbVector3>();

            for (int i = 0; i < points.Count - 1; ++i)
            {
                middle.Add(EbVector3.lerp(points[i], points[i], 0.5f));
            }
            return(middle);
        }
Example #3
0
        void updateView(CRenderFish fish)
        {
            EbVector3 turret_position = mCRenderTurret.getTurretPos();
            EbVector3 fish_position   = fish.Position;

            float turret_fish_distance = turret_position.getDistance(fish_position);

            int rectangle_count = (int)(turret_fish_distance / mRectangleGap);

            if (rectangle_count < 0)
            {
                rectangle_count = 0;
            }
            if (mRectangle.Count > rectangle_count)
            {
                int remove_count = mRectangle.Count - rectangle_count;

                do
                {
                    mScene.getRenderObjectPool().freeStillSprite(mRectangle[0]);
                    mRectangle.RemoveAt(0);
                    --remove_count;
                } while (remove_count > 0);
            }
            else if (mRectangle.Count < rectangle_count)
            {
                int add_count = rectangle_count - mRectangle.Count;
                do
                {
                    newRectangleSprite();
                    --add_count;
                } while (add_count > 0);
            }


            float angle = CLogicUtility.getAngle(fish_position - turret_position);

            float node_count = mRectangle.Count + 2;

            for (int i = 0; i < mRectangle.Count; i++)
            {
                mRectangle[i].setPosition(EbVector3.lerp(turret_position, fish_position, ((float)i + 1) / node_count));
                mRectangle[i].setDirection(angle);
            }

            mArrow.setPosition(EbVector3.lerp(turret_position, fish_position, (node_count - 1) / node_count));
            mArrow.setDirection(angle);

            mNumber.setPosition(fish_position);
        }
Example #4
0
        //-----------------------------------------------------------------------------
        void _calculateDirection(float elapsed_tm)
        {
            if (mIsTurning)
            {
                float included_angle = _abs(CLogicUtility.getAngle(mTargetDirection - mDirection));
                float t = mAngleTurning * elapsed_tm / included_angle;

                mDirection = EbVector3.lerp(mDirection, mTargetDirection, t);

                if (t >= 1)
                {
                    mIsTurning = false;
                }
            }
        }
Example #5
0
        //-------------------------------------------------------------------------
        void create(EbVector3 cur_pos)
        {
            string animation_name = "";

            float scale_x = 1f;
            float scale_y = 1f;
            float width_x = 10f;
            float width_y = 60f;

            if (mScene.getLevel().getRandoNumber(0, 100) < 50)
            {
                animation_name = "lightening-yellow";
                scale_y        = width_y / 132f;
                width_x        = 360f;
            }
            else
            {
                animation_name = "lightning-green";
                scale_y        = width_y / 85f;
                width_x        = 420f;
            }
            foreach (var n in fish_list)
            {
                float distance = n.Position.getDistance(cur_pos);
                if (distance > 1100)
                {
                    continue;
                }
                EbVector3   middle_pos   = EbVector3.lerp(n.Position, cur_pos, 0.5f);
                StillSprite still_sprite = mScene.getRenderObjectPool().newStillSprite();
                still_sprite.setPosition(middle_pos);
                still_sprite.setLayer(mScene.getLayerAlloter().getLayer(_eLevelLayer.FishSwim));

                still_sprite.setDirection(CLogicUtility.getAngle(CLogicUtility.getVector2ByRotateAngle(cur_pos - n.Position, 90)));
                still_sprite.setScale(n.Position.getDistance(cur_pos) / width_x, scale_y);

                still_sprite.playAnimation(animation_name);

                mListLight.Add(still_sprite);

#if UNITY_EDITOR
                still_sprite.gameObject.name = "TkSpriteEffectLighting_" + animation_name;
#endif
            }
        }
Example #6
0
        //-----------------------------------------------------------------------------
        public void next(float elapsed_tm, float speed)
        {
            if (mDelayTime > 0)
            {
                mDelayTime -= elapsed_tm;
                return;
            }
            if (mIsEndRoute || speed == 0)
            {
                return;
            }

            EbVector3 current_point = EbVector3.lerp(mPoints[mAtWhichPoint], mPoints[mAtWhichPoint + 1], mCurrentT);
            float     max_distance  = current_point.getDistance(mPoints[mAtWhichPoint + 1]);
            float     need_distance = elapsed_tm * speed;

            if (need_distance < max_distance)
            {
                mCurrentT = (mGapList[mAtWhichPoint] - max_distance + need_distance) / mGapList[mAtWhichPoint];
                mPosition = EbVector3.lerp(mPoints[mAtWhichPoint], mPoints[mAtWhichPoint + 1], mCurrentT);
                _calculateDirection(elapsed_tm);
            }
            else
            {
                mAtWhichPoint += 1;
                mCurrentT      = 0;
                if (mAtWhichPoint >= mPoints.Count - 1)
                {
                    mPosition   = mPoints[mPoints.Count - 1];
                    mIsEndRoute = true;
                }
                else
                {
                    _initTurning();
                    next((need_distance - max_distance) / speed, speed);
                }
            }
        }
Example #7
0
 //---------------------------------------------------------------------
 public static CDirection slerp(CDirection left_direction, CDirection right_direction, float t)
 {
     return(new CDirection(EbVector3.lerp(left_direction.mDirection, right_direction.mDirection, t)));
 }