Ejemplo n.º 1
0
        public void Draw(CanvasRenderingContext2D canvas, Sonic character, SensorM sensorResult)
        {
            var x = Help.Floor(character.X) - SonicManager.Instance.WindowLocation.X;
            var y = Help.Floor(character.Y) - SonicManager.Instance.WindowLocation.Y;

            canvas.BeginPath();
            if (sensorResult.Truthy() && sensorResult.Chosen) {
                canvas.StrokeStyle = "#FFF76D";
                canvas.LineWidth = 4;
            } else {
                canvas.StrokeStyle = Color;
                canvas.LineWidth = 2;
            }
            switch (character.Mode) {
                case RotationMode.Floor:
                    canvas.MoveTo(( x + X1 ), ( y + Y1 ));
                    canvas.LineTo(( x + X2 ), ( y + Y2 ));
                    break;
                case RotationMode.LeftWall:
                    canvas.MoveTo(( x - Y1 ), ( y + X1 ));
                    canvas.LineTo(( x - Y2 ), ( y + X2 ));
                    break;
                case RotationMode.Ceiling:
                    canvas.MoveTo(( x - X1 ), ( y - Y1 ));
                    canvas.LineTo(( x - X2 ), ( y - Y2 ));
                    break;
                case RotationMode.RightWall:
                    canvas.MoveTo(( x + Y1 ), ( y - X1 ));
                    canvas.LineTo(( x + Y2 ), ( y - X2 ));
                    break;
            }

            canvas.ClosePath();
            canvas.Stroke();
        }
Ejemplo n.º 2
0
        private SensorM GetBestSensor(SensorM sensor1, SensorM sensor2, RotationMode mode)
        {
            if (sensor1 == null && sensor2 == null) return null;

            if (sensor1 == null) return sensor2;
            if (sensor2 == null) return sensor1;

            switch (mode) {
                case RotationMode.Floor:
                    return sensor1.Value < sensor2.Value ? sensor1 : sensor2;
                case RotationMode.LeftWall:
                    return sensor1.Value > sensor2.Value ? sensor1 : sensor2;
                case RotationMode.Ceiling:
                    return sensor1.Value > sensor2.Value ? sensor1 : sensor2;
                case RotationMode.RightWall:
                    return sensor1.Value < sensor2.Value ? sensor1 : sensor2;
            }
            return null;
        }