1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 06:51:54 +08:00
Files
Dog-Lynx-And-HCN/scripts/Statemachine/ColorBar.gd
T
fallingshrimp ef8fd0db9f feat: Enhance game mechanics and structure
- Added `ColorBar` class for visual representation of values.
- Expanded `EntityBase` with new properties: `isBoss` and `weapons`, and implemented damage handling and entity generation methods.
- Updated `EntityStateBar` to use `ColorBar` for health representation.
- Introduced `BulletBase` scene and script for bullet mechanics, including damage handling and generation.
- Created `WorldTool` for managing the game world and root node.
- Implemented `EntityTool` for retrieving entities from hurtboxes.
- Added `GameRule` for managing game rules like friendly fire.
- Updated scene files to reflect new structures and added necessary resources.
2025-08-26 11:39:47 +08:00

35 lines
1.1 KiB
GDScript

@tool
extends Control
class_name ColorBar
@export var minValue: float = 0
@export var maxValue: float = 100
@export var currentValue: float = 50
@export var backColor: Color
@export var middleColor: Color
@export var frontColor: Color
@export var speed1: float = 0.9
@export var speed2: float = 0.01
var middleValue = 0
var frontValue = 0
var forwardDirection = -1
func getPercent(value: float):
return (value - minValue) / (maxValue - minValue)
func setCurrent(value: float):
forwardDirection = sign(value - currentValue)
currentValue = value
func _ready():
middleValue = currentValue
frontValue = currentValue
func _draw():
draw_rect(Rect2(0, 0, size.x, size.y), backColor)
draw_rect(Rect2(0, 0, size.x * getPercent(middleValue), size.y), middleColor)
draw_rect(Rect2(0, 0, size.x * getPercent(frontValue), size.y), frontColor)
func _process(_delta: float) -> void:
middleValue = lerpf(middleValue, currentValue, speed1 if forwardDirection > 0 else speed2)
frontValue = lerpf(frontValue, currentValue, speed1 if forwardDirection < 0 else speed2)
queue_redraw()