Emit coins when treasure is found.

master
Martin Felis 2022-01-24 22:12:50 +01:00
parent d7049b43ed
commit 861f99b1cf
5 changed files with 38 additions and 10 deletions

View File

@ -2,15 +2,15 @@
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
path="res://.import/icon.png-9e2c68854eff2ba15efab32e39b37c44.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
source_file="res://addons/gdhexgrid/icon.png"
dest_files=[ "res://.import/icon.png-9e2c68854eff2ba15efab32e39b37c44.stex" ]
[params]
@ -28,6 +28,7 @@ process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true

View File

@ -8,7 +8,7 @@ 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():
@ -16,7 +16,7 @@ func _ready():
func _draw():
coin_sprite.offset.y = -z_pos
draw_circle(Vector2.ZERO, 5, Color("88000000"))
draw_circle(Vector2.ZERO, 5, Color(0.3, 0.3, 0.3, coin_sprite.modulate.a))
pass
func _process(delta):
@ -33,6 +33,21 @@ func _process(delta):
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()

View File

@ -4,6 +4,7 @@
[ext_resource path="res://scenes/Coin.gd" type="Script" id=2]
[node name="Node2D" type="Node2D"]
modulate = Color( 1, 1, 1, 0.792157 )
script = ExtResource( 2 )
[node name="CoinSprite" type="Sprite" parent="."]

View File

@ -1,11 +1,12 @@
extends Node2D
var Coin = preload("res://scenes/Coin.tscn")
onready var Coin = preload("./Coin.tscn")
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var coin_spread = 100
var coin_lifetime = 5
# Called when the node enters the scene tree for the first time.
func _ready():
@ -26,7 +27,8 @@ func create_coins (num, _position = null):
if _position != null:
coin.position = _position
coin.velocity = Vector2 (2 * rand_range(-coin_spread, coin_spread), rand_range (-coin_spread, coin_spread))
coin.velocity = Vector2 (rand_range(-coin_spread, coin_spread), rand_range (-coin_spread, coin_spread))
coin.lifetime = coin_lifetime
coin.z_pos = 0
coin.z_vel = rand_range(300, 800)
result.push_back(coin)

View File

@ -33,6 +33,7 @@ onready var MapTimer = get_node("UI/IslandMap/Timer")
var Island = preload("Island.gd")
var SpringDamper = preload("res://SpringDamper.gd")
var CoinSpawner = preload("res://scenes/CoinSpawner.tscn").instance()
var DigSiteSprite = preload("res://assets/digsite.svg")
var DigSiteTreasureSprite = preload("res://assets/treasuredigsite.svg")
@ -429,9 +430,12 @@ func on_dig_stopped():
if check_player_on_treasure():
emit_signal("treasure_found")
on_treasure_found()
var coins = CoinSpawner.create_coins(20, dig_site.transform.origin)
for coin in coins:
coin.z_index = PlayerChar.z_index + 1
add_child(coin)
dig_site.texture = DigSiteTreasureSprite
dig_site.z_index = PlayerChar.z_index + 1
dig_site.z_index = PlayerChar.z_index + 2
else:
emit_signal("wrong_digsite")
dig_site.texture = DigSiteSprite
@ -439,7 +443,11 @@ func on_dig_stopped():
DigSites.add_child(dig_site)
func on_treasure_found():
func on_treasure_opened():
pass
func on_treasure_found(tile):
RepeatButton.disabled = false
pass
@ -584,6 +592,7 @@ func handle_game_event(event):
return false
if event is InputEventMouseButton:
# var input_tile = Globals.HexGrid.get_hex_center(Globals.ScreenToHex(mouse_pos, WorldCamera))
# Move main character
if event.pressed and event.button_index == BUTTON_LEFT:
update_player_navigation_target (get_global_mouse_position())