PirateTreasureHunt/scenes/Coin.gd

57 lines
1.1 KiB
GDScript

extends Node2D
onready var coin_sprite = get_node("CoinSprite")
var velocity = Vector2(0, 0)
var z_pos = 0
var z_vel = 0
var gravity = 1500
var bounciness = 0.5
var lifetime = 10
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _draw():
coin_sprite.offset.y = -z_pos
draw_circle(Vector2.ZERO, 5, Color(0.3, 0.3, 0.3, coin_sprite.modulate.a))
pass
func _process(delta):
z_vel = z_vel - gravity * delta
z_pos = z_pos + z_vel * delta
if z_pos < 0:
z_vel = - z_vel * bounciness
z_pos = 0
if z_vel < 0.01:
z_vel = 0
velocity = velocity * 0.5
position = position + velocity * delta
lifetime = lifetime - delta
if lifetime > 1:
if lifetime < 3:
if int(lifetime * 5) % 2 == 0:
coin_sprite.modulate = Color("AAffffff")
else:
coin_sprite.modulate = Color("ffffffff")
else:
coin_sprite.modulate = lerp (Color("0fff"), Color("ffff"), lifetime)
if lifetime < 0:
queue_free()
update()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass