Reworked Cultist
This commit is contained in:
@@ -1,7 +1,31 @@
|
||||
@tool
|
||||
class_name CultistSprite
|
||||
extends AnimatedSprite2D
|
||||
extends Sprite2D
|
||||
|
||||
|
||||
enum View {
|
||||
Front,
|
||||
Right,
|
||||
Left,
|
||||
}
|
||||
|
||||
|
||||
const SHADER_SWITCH_COLORS = "shader_parameter/switch_colors"
|
||||
const SHADER_INTENSITY = "shader_parameter/intensity"
|
||||
const SHADER_SEED = "shader_parameter/seed"
|
||||
|
||||
|
||||
const is_color_switched : Dictionary[Cultist.Type, bool] = {
|
||||
Cultist.Type.White: false,
|
||||
Cultist.Type.Black: true,
|
||||
Cultist.Type.Gray: false,
|
||||
}
|
||||
const intensity : Dictionary[Cultist.Type, float] = {
|
||||
Cultist.Type.White: 1.0,
|
||||
Cultist.Type.Black: 1.0,
|
||||
Cultist.Type.Gray: 0.5,
|
||||
}
|
||||
|
||||
const ANIMATION_FALL = "fall"
|
||||
const ANIMATION_FALL_LEFT = "fall_left"
|
||||
const ANIMATION_FALL_RIGHT = "fall_right"
|
||||
@@ -21,3 +45,41 @@ const LOOK_AROUND_ANIMATIONS : Array[String] = [
|
||||
ANIMATION_LOOK_AROUND_1,
|
||||
ANIMATION_LOOK_AROUND_2,
|
||||
]
|
||||
|
||||
|
||||
@export var type := Cultist.Type.White:
|
||||
set(value):
|
||||
type = value
|
||||
if is_node_ready():
|
||||
_update_type()
|
||||
|
||||
@export var view := View.Front:
|
||||
set(value):
|
||||
view = value
|
||||
if is_node_ready():
|
||||
_update_view()
|
||||
|
||||
|
||||
@onready var animated_sprite : AnimatedSprite2D = $SubViewport/AnimatedSprite2D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_update_type()
|
||||
_update_view()
|
||||
if not Engine.is_editor_hint():
|
||||
material.set(SHADER_SEED, randf())
|
||||
|
||||
|
||||
func _update_type() -> void:
|
||||
material.set(SHADER_INTENSITY, intensity[type])
|
||||
material.set(SHADER_SWITCH_COLORS, is_color_switched[type])
|
||||
|
||||
|
||||
func _update_view() -> void:
|
||||
match view:
|
||||
View.Front:
|
||||
animated_sprite.animation = ANIMATION_IDLE
|
||||
View.Left:
|
||||
animated_sprite.animation = ANIMATION_WALK_LEFT
|
||||
View.Right:
|
||||
animated_sprite.animation = ANIMATION_WALK_RIGHT
|
||||
|
||||
Reference in New Issue
Block a user