Beispiel #1
0
        public Platform(Vector2 position, HazardTypes hazardType, bool moving)
        {
            Texture2D texture = ContentLoader.LoadTexture("Platform");

            sprite      = new Sprite(texture, position);
            BoundingBox = new BoundingBox2D(position, texture.Width, texture.Height);
            Moving      = moving;

            if (hazardType != HazardTypes.NONE)
            {
                CreateHazard(hazardType);
            }
        }
Beispiel #2
0
        private void GeneratePlatforms()
        {
            float topY = platforms[platforms.Count - 1].BoundingBox.Center.Y;

            if (topY > Camera.Instance.VisibleArea.Top + MIN_VERTICAL_SPACING)
            {
                float x = Functions.GetRandomFloat(GENERATION_EDGE_OFFSET, Constants.SCREEN_WIDTH - GENERATION_EDGE_OFFSET + 1);
                float y = topY - Functions.GetRandomFloat(MIN_VERTICAL_SPACING, MAX_VERTICAL_SPACING) - GENERATION_VERTICAL_OFFSET;

                HazardTypes hazardType = (HazardTypes)random.Next(0, Hazard.NumHazardTypes);

                platforms.Add(new Platform(new Vector2(x, y), hazardType, false));
            }
        }
Beispiel #3
0
        private void CreateHazard(HazardTypes hazardType)
        {
            switch (hazardType)
            {
            case HazardTypes.STATIONARY_SPIKES:
                hazard = new StationarySpikes(this);
                break;

            case HazardTypes.RETRACTABLE_SPIKES:
                hazard = new RetractableSpikes(this);
                break;

            case HazardTypes.LAVA_FALLS:
                hazard = new Lavafall(this);
                break;
            }

            hazards.Add(hazard);
        }
Beispiel #4
0
#pragma warning restore IDE0044 // Add readonly modifier

        public static Hazard CreateHazard(HazardTypes type, IntVector2 worldPosition)
        {
            GameObject hazardObject;

            switch (type)
            {
            case HazardTypes.Stalag: hazardObject = Instance._stalag; break;

            default: throw new ArgumentException($"Unknown item type of {type}.");
            }

            hazardObject = Instantiate(hazardObject);
            hazardObject.transform.position = worldPosition;
            hazardObject.name = $"{type} at [{worldPosition.X}, {worldPosition.Y}]";

            var hazard = hazardObject.GetComponent <Hazard>();

            _log.ErrorIfNull(hazard, $"Hazard of type `{type}` has not been given a 'hazard' component.");

            return(hazard);
        }
Beispiel #5
0
 protected Hazard(HazardTypes type)
 {
     Type = type;
 }
Beispiel #6
0
        private CollisionDirections GetCollisionDirection(BoundingBox2D playerBox, BoundingBox2D hazardBox, HazardTypes hazardType)
        {
            switch (hazardType)
            {
            case HazardTypes.STATIONARY_SPIKES:
                return(CollisionDirections.UP);

            case HazardTypes.RETRACTABLE_SPIKES:
                return(CollisionDirections.DOWN);

            case HazardTypes.LAVA_FALLS:
                return(playerBox.Left < hazardBox.Left ? CollisionDirections.RIGHT : CollisionDirections.LEFT);
            }

            return(CollisionDirections.NONE);
        }
Beispiel #7
0
 public static Type ConvertToType(HazardTypes enumType) => _enumToType[enumType];