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

View File

@ -8,7 +8,7 @@ var z_pos = 0
var z_vel = 0 var z_vel = 0
var gravity = 1500 var gravity = 1500
var bounciness = 0.5 var bounciness = 0.5
var lifetime = 10
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
@ -16,7 +16,7 @@ func _ready():
func _draw(): func _draw():
coin_sprite.offset.y = -z_pos 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 pass
func _process(delta): func _process(delta):
@ -33,6 +33,21 @@ func _process(delta):
velocity = velocity * 0.5 velocity = velocity * 0.5
position = position + velocity * delta 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() update()

View File

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

View File

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

View File

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