Ejemplo n.º 1
0
        public void Update(GameTime gameTime, int time_multiplier, MouseState mousestate)
        {
            float delta_time = gameTime.ElapsedGameTime.Milliseconds / 1000f;
            float new_x      = Center.X + m_speed * delta_time * time_multiplier;
            StagePositionInformation info_obj = m_current_stage.InfoAt(-new_x);

            if (info_obj.valid)
            {
                Center   = new Vector2(new_x, -info_obj.height + m_road_offset + m_texture.Height / 2);
                Rotation = GetRotation();
            }
            base.Update();
        }
Ejemplo n.º 2
0
        public float GetRotation()
        {
            StagePositionInformation info_left  = m_current_stage.InfoAt(-TopLeftPosition.X);
            StagePositionInformation info_right = m_current_stage.InfoAt(-TopRightPosition.X);

            if (!info_left.valid || !info_right.valid)
            {
                return(0f);
            }
            Vector2 diff = new Vector2(TopRightPosition.X, info_right.height) - new Vector2(TopLeftPosition.X, info_left.height);

            return((float)Math.Atan2(-diff.Y, diff.X));
        }
Ejemplo n.º 3
0
        public StagePositionInformation InfoAt(float x)
        {
            StagePositionInformation info_object = new StagePositionInformation();

            x = -x;
            StageSegment target_segment = null;

            for (int i = (int)Math.Floor(x / RoadWidth); i < m_stage_segments.Count; i++)
            {
                if (m_stage_segments[i].Position.X <= x && m_stage_segments[i].Position.X + RoadWidth >= x)
                {
                    target_segment = m_stage_segments[i];
                    break;
                }
            }
            if (target_segment == null)
            {
                Console.WriteLine("ERROR: InfoAt(" + x + ") - Could not find target segment.");
                info_object.valid = false;
                return(info_object);
            }

            float start_y  = target_segment.TopLeftPosition.Y;
            float target_y = start_y;

            switch (target_segment.SegmentType)
            {
            case SegmentType.Down5:
            case SegmentType.Down10:
                start_y  = target_segment.TopLeftPosition.Y + target_segment.Corrector;
                target_y = target_segment.BottomRightPosition.Y - RoadHeight;
                break;

            case SegmentType.Up5:
            case SegmentType.Up10:
                start_y  = target_segment.Position.Y - RoadHeight + target_segment.Corrector;
                target_y = target_segment.TopRightPosition.Y;
                break;
            }

            info_object.valid         = true;
            info_object.stage_segment = target_segment;
            info_object.height        = -MathHelper.Lerp(start_y, target_y, (x - target_segment.TopLeftPosition.X) / RoadWidth);
            return(info_object);
        }