PirateTreasureHunt/scenes/Coin.gd

42 lines
756 B
GDScript
Raw Normal View History

2022-01-23 11:47:18 +01:00
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
# 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("88000000"))
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
update()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass