hero-mark-2/objects/collectibles/star.gd

41 lines
1.1 KiB
GDScript

tool
extends Node2D
enum StarColor {RED, YELLOW, GREEN, BLUE, MAGENTA}
const COLORS = [
preload("res://graphics/collectibles/pal_star_red.png"),
preload("res://graphics/collectibles/pal_star_yellow.png"),
preload("res://graphics/collectibles/pal_star_green.png"),
preload("res://graphics/collectibles/pal_star_blue.png"),
preload("res://graphics/collectibles/pal_star_magenta.png")
]
export(StarColor) var color setget _set_color
export var value = 1
onready var sprite = $AnimatedSprite
func _ready():
#Sync all coinframes
sprite.play()
#Change color
_set_color(color)
func _set_color(value):
color = value
if is_inside_tree():
sprite.material.set_shader_param("palette", COLORS[color])
func _on_Area2D_body_entered(body):
#Collect
if body.is_in_group("player"):
Audio.play_sound(Audio.a_star,Audio.ac_collectible)
Game.score += 100
Game.stars[color] = true
#5 Star reward
if Game.stars[0] && Game.stars[1] && Game.stars[2] && Game.stars[3] && Game.stars[4]:
Audio.play_shard_sound()
Game.shards += 1
Game.shards_collected[4] = true
Game.score += 500
queue_free()