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); } }
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)); } }
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); }
#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); }
protected Hazard(HazardTypes type) { Type = type; }
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); }
public static Type ConvertToType(HazardTypes enumType) => _enumToType[enumType];