sound and display for collecting crystals

This commit is contained in:
SyntaX 2019-11-24 13:45:09 +01:00
parent 68da963555
commit 03637820cd
5 changed files with 68 additions and 9 deletions

View File

@ -1,10 +1,11 @@
[gd_scene load_steps=9 format=2] [gd_scene load_steps=10 format=2]
[ext_resource path="res://Player/Player.gd" type="Script" id=1] [ext_resource path="res://Player/Player.gd" type="Script" id=1]
[ext_resource path="res://Player/Footsteps.gd" type="Script" id=2] [ext_resource path="res://Player/Footsteps.gd" type="Script" id=2]
[ext_resource path="res://Resources/Audio/Step.wav" type="AudioStream" id=3] [ext_resource path="res://Resources/Audio/Step.wav" type="AudioStream" id=3]
[ext_resource path="res://Player/UI/HUD.tscn" type="PackedScene" id=4] [ext_resource path="res://Player/UI/HUD.tscn" type="PackedScene" id=4]
[ext_resource path="res://Sounds/dino-eat.wav" type="AudioStream" id=5] [ext_resource path="res://Sounds/dino-eat.wav" type="AudioStream" id=5]
[ext_resource path="res://Sounds/ding.wav" type="AudioStream" id=6]
[sub_resource type="CylinderShape" id=1] [sub_resource type="CylinderShape" id=1]
height = 2.5 height = 2.5
@ -79,10 +80,14 @@ unit_db = -10.0
pitch_scale = 1.5 pitch_scale = 1.5
[node name="HUD" parent="." instance=ExtResource( 4 )] [node name="HUD" parent="." instance=ExtResource( 4 )]
collect_sound_path = NodePath("../CollectSound")
[node name="GameOverSound" type="AudioStreamPlayer" parent="."] [node name="GameOverSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 5 ) stream = ExtResource( 5 )
[node name="CollectSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 6 )
[node name="InteractArea" type="Area" parent="."] [node name="InteractArea" type="Area" parent="."]
gravity = 0.0 gravity = 0.0

View File

@ -2,11 +2,15 @@ extends Control
export(NodePath) var popup_nodepath export(NodePath) var popup_nodepath
export(NodePath) var gameover_sound_path export(NodePath) var gameover_sound_path
export(NodePath) var collect_sound_path
export(NodePath) var container_path export(NodePath) var container_path
var _popup: Popup var _popup: Popup
var _gameover_sound: AudioStreamPlayer var _gameover_sound: AudioStreamPlayer
var _collect_sound: AudioStreamPlayer
var _collectibles: GridContainer var _collectibles: GridContainer
var _itemWidth = 50;
var _score: int = 0 var _score: int = 0
var _init: bool = false var _init: bool = false
var _texCrystal = preload("res://Images/crystal-unlit.png") var _texCrystal = preload("res://Images/crystal-unlit.png")
@ -14,13 +18,15 @@ var _texCrystalLit = preload("res://Images/crystal.png")
func _ready(): func _ready():
_popup = get_node(popup_nodepath) as Popup _popup = get_node(popup_nodepath) as Popup
assert(null != _popup) assert(null != _popup)
_gameover_sound = get_node(gameover_sound_path) as AudioStreamPlayer _gameover_sound = get_node(gameover_sound_path) as AudioStreamPlayer
assert(null != _gameover_sound) assert(null != _gameover_sound)
_collect_sound = get_node(collect_sound_path) as AudioStreamPlayer
assert(null != _collect_sound)
_collectibles = get_node(container_path) as GridContainer _collectibles = get_node(container_path) as GridContainer
assert(null != _collectibles) assert(null != _collectibles)
@ -31,6 +37,9 @@ func _process(_delta):
# TODO: handle with signals # TODO: handle with signals
var count = Collector.getCount() var count = Collector.getCount()
_itemWidth = int(get_viewport_rect().size.x / (count + 1))
_collectibles.columns = count
for i in count: for i in count:
var rect = _createTexture(_texCrystal) var rect = _createTexture(_texCrystal)
_collectibles.add_child(rect) _collectibles.add_child(rect)
@ -41,9 +50,7 @@ func _createTexture(texture):
rect.texture = texture rect.texture = texture
rect.expand = true rect.expand = true
rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT
rect.rect_min_size = Vector2(50, 50) rect.rect_min_size = Vector2(_itemWidth, _itemWidth)
rect.rect_size = Vector2(50, 50)
return rect return rect
@ -51,10 +58,11 @@ func increaseScore():
_score += 1 _score += 1
Logger.info(String(_score) + " of " + String(Collector.getCount()) + " possible points") Logger.info(String(_score) + " of " + String(Collector.getCount()) + " possible points")
_collect_sound.play()
var rect = _createTexture(_texCrystalLit) var rect = _createTexture(_texCrystalLit)
#_collectibles.add_child(rect) _collectibles.add_child_below_node(_collectibles.get_child(0), rect)
_collectibles.add_child_below_node(self, rect) _collectibles.remove_child(_collectibles.get_child(0 if _score == 1 else _score))
_collectibles.remove_child(_collectibles.get_child(0))
if (_score >= (Collector.getCount())): if (_score >= (Collector.getCount())):
success() success()

View File

@ -68,5 +68,4 @@ value = 100.0
[node name="GridContainer" type="GridContainer" parent="."] [node name="GridContainer" type="GridContainer" parent="."]
margin_right = 250.0 margin_right = 250.0
margin_bottom = 150.0 margin_bottom = 150.0
columns = 15
[connection signal="pressed" from="Popup/Button" to="." method="_on_Button_pressed"] [connection signal="pressed" from="Popup/Button" to="." method="_on_Button_pressed"]

View File

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/ding.wav-88e1747ad335c067902263abe685dc63.sample"
[deps]
source_file="res://Sounds/ding.wav"
dest_files=[ "res://.import/ding.wav-88e1747ad335c067902263abe685dc63.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=true
edit/normalize=true
edit/loop=false
compress/mode=0

View File

@ -65,36 +65,62 @@ config/icon="res://icon.png"
Logger="*res://Util/gs_logger/logger.gd" Logger="*res://Util/gs_logger/logger.gd"
Collector="*res://Util/Collector.gd" Collector="*res://Util/Collector.gd"
[display]
window/size/width=1080
window/size/height=720
[input] [input]
move_fwrd={ move_fwrd={
"deadzone": 0.5, "deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
] ]
} }
move_back={ move_back={
"deadzone": 0.5, "deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
] ]
} }
move_left={ move_left={
"deadzone": 0.5, "deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null)
] ]
} }
move_right={ move_right={
"deadzone": 0.5, "deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null) "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
] ]
} }
move_jump={ move_jump={
"deadzone": 0.5, "deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
] ]
} }
move_sprint={ move_sprint={
"deadzone": 0.5, "deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null) "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777237,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":7,"pressure":0.0,"pressed":false,"script":null)
]
}
cam_move_left={
"deadzone": 0.5,
"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null)
]
}
cam_move_right={
"deadzone": 0.5,
"events": [ Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null)
] ]
} }
cam_move_up={ cam_move_up={