Renderování textu, jumpscary, win a lose screen

This commit is contained in:
Perry 2026-03-09 20:05:21 +01:00
parent 9bfe63a166
commit e6128dc9f5
21 changed files with 360 additions and 84 deletions

View file

@ -10,7 +10,7 @@ namespace FNAF_Clone.GUI;
public class UIElement {
public bool Active { get; set; } = false;
public bool Active { get; set; } = true;
public bool Pressable { get; set; } = false;
public bool Visible { get; set; } = true;
@ -18,10 +18,10 @@ public class UIElement {
get;
private set { field = value; UpdateBounds(); }
} // TODO: Change this to support non-rectangular hitboxes
private (Point, Point) screenSpaceBounds;
private List<TextureRegion> textures = new();
private int currentTextureId = 0;
protected (Point, Point) screenSpaceBounds;
public List<TextureRegion> Textures = new();
protected int currentTextureId = 0;
private float _scaleMultiplier = 1;
public float ScaleMultiplier{
@ -44,12 +44,12 @@ public class UIElement {
}
public UIElement(TextureRegion texture, Point position) {
textures.Add(texture);
Textures.Add(texture);
Bounds = (position, position + new Point(texture.Width, texture.Height));
LoadPixelScaleMultiplier();
}
public UIElement(TextureRegion[] textures, Point position) {
this.textures.AddRange(textures);
this.Textures.AddRange(textures);
Bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
LoadPixelScaleMultiplier();
}
@ -60,9 +60,8 @@ public class UIElement {
LoadPixelScaleMultiplier();
}
public void SetTexture(int textureId) {
if (textureId >= textures.Count){
if (textureId >= Textures.Count){
Console.WriteLine($"WARNING: TEXTURE {textureId} OUT OF BOUNDS");
return;
}
@ -84,15 +83,21 @@ public class UIElement {
public virtual void OnMouseHold() { }
public void Draw(SpriteBatch spriteBatch) {
if (!Visible){
public virtual void Draw(SpriteBatch spriteBatch) {
if (!Visible || !Active){
return;
}
textures[currentTextureId].Draw(spriteBatch, screenSpaceBounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
Textures[currentTextureId].Draw(spriteBatch, screenSpaceBounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
// texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
}
public void SetPosition(Point position) {
Bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
Bounds = (position, position + new Point(Textures[0].Width, Textures[0].Height));
}
public UIElement Clone() {
return new UIElement(Textures.ToArray(), Bounds.Item1);
}
public TextureRegion[] GetTextures() => Textures.ToArray();
}