fix sound and remove menu button

This commit is contained in:
Mylloon 2023-02-26 17:39:03 +01:00
parent ee4bf46a85
commit 8232a4382a
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
8 changed files with 123 additions and 123 deletions

View file

@ -13,44 +13,44 @@ var next = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
rng.randomize()
rng.randomize()
reset_timer()
me.play(animations[0])
reset_timer()
me.play(animations[0])
func reset_timer() -> void:
timer = 0
limit_random = rng.randi_range(2, 10)
timer = 0
limit_random = rng.randi_range(2, 10)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta) -> void:
timer += delta
timer += delta
var max_frame = me.frames.get_frame_count(me.animation) - 1
var current_anim_idx = animations.find(me.animation)
if current_anim_idx >= animations.size() - 1:
# Last animation reached
check_next_animframe(max_frame, animations[0])
else:
check_next_animframe(max_frame, animations[current_anim_idx + 1])
var max_frame = me.frames.get_frame_count(me.animation) - 1
var current_anim_idx = animations.find(me.animation)
if current_anim_idx >= animations.size() - 1:
# Last animation reached
check_next_animframe(max_frame, animations[0])
else:
check_next_animframe(max_frame, animations[current_anim_idx + 1])
# Jump to next animation at the end of the current one
func check_next_animframe(max_frame, next_animation) -> void:
if me.frame == 0 and next:
me.play(next_animation)
next = false
if next_animation == animations[0]:
# Reset random for first animation
reset_timer()
return
if max_frame == me.frame:
# Last frame of animation reached
next = true
return
if max_frame == -1 and timer >= limit_random:
# No frame in animation, use time
next = true
return
if me.frame == 0 and next:
me.play(next_animation)
next = false
if next_animation == animations[0]:
# Reset random for first animation
reset_timer()
return
if max_frame == me.frame:
# Last frame of animation reached
next = true
return
if max_frame == -1 and timer >= limit_random:
# No frame in animation, use time
next = true
return

View file

@ -5,8 +5,8 @@ onready var sprite = $"../Sprite"
func _on_Area2D_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
if event is InputEventMouseButton:
event = event as InputEventMouseButton
if event.pressed and event.button_index == BUTTON_LEFT:
screen.visible = true
sprite.modulate = Color(0.66, 0.51, 0.85) # shade
if event is InputEventMouseButton:
event = event as InputEventMouseButton
if event.pressed and event.button_index == BUTTON_LEFT:
screen.visible = true
sprite.modulate = Color(0.66, 0.51, 0.85) # shade

View file

@ -8,34 +8,34 @@ onready var folder_icon = $"../../../Sprite"
func drag_change_state():
is_dragging = !is_dragging
grabbed_offset = window.get_position() - get_global_mouse_position()
is_dragging = !is_dragging
grabbed_offset = window.get_position() - get_global_mouse_position()
func _process(_delta) -> void:
if is_dragging:
var new_pos = get_global_mouse_position() + grabbed_offset
if new_pos.x > 150:
window.set_position(new_pos)
else:
drag_change_state()
if is_dragging:
var new_pos = get_global_mouse_position() + grabbed_offset
if new_pos.x > 150:
window.set_position(new_pos)
else:
drag_change_state()
func _on_Area2D_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
if event is InputEventMouseButton:
event = event as InputEventMouseButton
if event.pressed and event.button_index == BUTTON_LEFT:
drag_change_state()
#print("here haha")
elif event.button_index == BUTTON_LEFT and !event.pressed:
drag_change_state()
#print("here huhu")
if event is InputEventMouseButton:
event = event as InputEventMouseButton
if event.pressed and event.button_index == BUTTON_LEFT:
drag_change_state()
#print("here haha")
elif event.button_index == BUTTON_LEFT and !event.pressed:
drag_change_state()
#print("here huhu")
func _on_Area2D2_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
if event is InputEventMouseButton:
event = event as InputEventMouseButton
if event.pressed and event.button_index == BUTTON_LEFT:
drag_change_state()
window.visible = false
folder_icon.modulate = Color(1, 1, 1) # reset shade
if event is InputEventMouseButton:
event = event as InputEventMouseButton
if event.pressed and event.button_index == BUTTON_LEFT:
drag_change_state()
window.visible = false
folder_icon.modulate = Color(1, 1, 1) # reset shade

View file

@ -4,29 +4,29 @@ onready var villain = $"../../../../Villain/AnimatedSprite"
onready var villain_animations = $"../../../../Villain"
var etat = false
var remplissage = 0;
var remplissage = 0
const texture_pressed = preload("res://Assets/tres_button/hover-pressed.png")
const texture_released = preload("res://Assets/tres_button/normal.png")
# Called every frame. '_delta' is the elapsed time since the previous frame.
func _process(_delta) -> void:
if etat:
if villain.animation == villain_animations.animations[-1]:
assert(get_tree().change_scene("res://Scenes/gameover.tscn") == OK)
if(remplissage == 60*10): # fermer le dossier et enlever l'icone
etat = false
self.get_parent().get_parent().visible = false;
else :
remplissage+=1;
print(remplissage)
if etat:
if villain.animation == villain_animations.animations[-1]:
assert(get_tree().change_scene("res://Scenes/gameover.tscn") == OK)
if remplissage == 60 * 10: # fermer le dossier et enlever l'icone
etat = false
self.get_parent().get_parent().visible = false
else:
remplissage += 1
print(remplissage)
func _on_Button_pressed() -> void:
etat = !etat
var new_stylebox_normal = self.get_stylebox("normal").duplicate()
if etat:
new_stylebox_normal.texture = texture_pressed
else:
new_stylebox_normal.texture = texture_released
self.add_stylebox_override("normal", new_stylebox_normal)
etat = !etat
var new_stylebox_normal = self.get_stylebox("normal").duplicate()
if etat:
new_stylebox_normal.texture = texture_pressed
else:
new_stylebox_normal.texture = texture_released
self.add_stylebox_override("normal", new_stylebox_normal)

38
Scenes/Scripts/Desktop.gd Normal file → Executable file
View file

@ -8,26 +8,28 @@ onready var alert = $"Alert"
var rng = RandomNumberGenerator.new()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
rng.randomize()
var nbDossier = rng.randi_range(0, 3)
for i in range(nbDossier):
var dossier = get_child(2).duplicate()
dossier.position = Vector2(dossier.position.x, dossier.position.y+150*(i+1))
dossier.set_z_index(dossier.get_z_index()+10*(i+1))
add_child(dossier)
rng.randomize()
var nbDossier = rng.randi_range(0, 3)
for i in range(nbDossier):
var dossier = get_child(2).duplicate()
dossier.position = Vector2(dossier.position.x, dossier.position.y + 150 * (i + 1))
dossier.set_z_index(dossier.get_z_index() + 10 * (i + 1))
add_child(dossier)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta) -> void:
if villain.animation == villain_animations.animations[-1]:
mainMusic.set_volume_db(-80)
eyeMusic.set_volume_db(0)
if(alert.is_playing()):
alert.stop()
elif villain.animation == villain_animations.animations[1] :
if(!alert.is_playing()):
alert.play()
else :
mainMusic.set_volume_db(0)
eyeMusic.set_volume_db(-80)
if villain.animation == villain_animations.animations[-1]:
mainMusic.set_volume_db(-80)
eyeMusic.set_volume_db(0)
if alert.is_playing():
alert.stop()
elif villain.animation == villain_animations.animations[1]:
if !alert.is_playing():
alert.play()
else:
mainMusic.set_volume_db(0)
eyeMusic.set_volume_db(-80)

View file

@ -1,9 +1,10 @@
extends Node2D
onready var hover_sound = $"Hover"
func _on_RestartButton_pressed() -> void:
assert(get_tree().change_scene("res://Scenes/menu.tscn") == OK)
assert(get_tree().change_scene("res://Scenes/menu.tscn") == OK)
func _on_RestartButton_mouse_entered() -> void:
hover_sound.play()
hover_sound.play()

View file

@ -1,25 +1,26 @@
extends Control
onready var hover_sound = $"Hover"
func _on_PlayButton_pressed() -> void:
assert(get_tree().change_scene("res://Scenes/DesktopScreen.tscn") == OK)
assert(get_tree().change_scene("res://Scenes/DesktopScreen.tscn") == OK)
func _on_Help_Button_pressed() -> void:
print("help me")
print("help me")
func _on_Quit_Button_pressed() -> void:
get_tree().quit()
get_tree().quit()
func _on_PlayButton_mouse_entered() -> void:
hover_sound.play()
hover_sound.play()
func _on_Quit_Button_mouse_entered() -> void:
hover_sound.play()
hover_sound.play()
func _on_Help_Button_mouse_entered() -> void:
hover_sound.play()
hover_sound.play()

View file

@ -17,22 +17,20 @@ scale = Vector2( 0.5, 0.5 )
z_index = -2
texture = ExtResource( 6 )
[node name="MenuButton" type="MenuButton" parent="."]
margin_left = 480.0
margin_top = 232.0
margin_right = 584.0
margin_bottom = 392.0
script = ExtResource( 1 )
[node name="VBoxContainer" type="VBoxContainer" parent="MenuButton"]
margin_left = -48.0
margin_top = 40.0
margin_right = 88.0
margin_bottom = 272.0
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 432.0
margin_top = 272.0
margin_right = 568.0
margin_bottom = 504.0
custom_constants/separation = 26
alignment = 1
script = ExtResource( 1 )
[node name="PlayButton" type="Button" parent="MenuButton/VBoxContainer"]
[node name="Hover" type="AudioStreamPlayer" parent="VBoxContainer"]
stream = ExtResource( 8 )
volume_db = -7.0
[node name="PlayButton" type="Button" parent="VBoxContainer"]
margin_top = 34.0
margin_right = 136.0
margin_bottom = 71.0
@ -44,7 +42,7 @@ custom_styles/pressed = ExtResource( 4 )
custom_styles/normal = ExtResource( 3 )
text = "PLAY"
[node name="Help_Button" type="Button" parent="MenuButton/VBoxContainer"]
[node name="Help_Button" type="Button" parent="VBoxContainer"]
margin_top = 97.0
margin_right = 136.0
margin_bottom = 134.0
@ -56,7 +54,7 @@ custom_styles/pressed = ExtResource( 4 )
custom_styles/normal = ExtResource( 3 )
text = "HELP"
[node name="Quit_Button" type="Button" parent="MenuButton/VBoxContainer"]
[node name="Quit_Button" type="Button" parent="VBoxContainer"]
margin_top = 160.0
margin_right = 136.0
margin_bottom = 197.0
@ -68,16 +66,14 @@ custom_styles/pressed = ExtResource( 4 )
custom_styles/normal = ExtResource( 3 )
text = "QUIT"
[node name="Hover" type="AudioStreamPlayer" parent="MenuButton"]
stream = ExtResource( 8 )
[node name="MenuMusic" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 7 )
volume_db = 8.0
autoplay = true
[connection signal="mouse_entered" from="MenuButton/VBoxContainer/PlayButton" to="MenuButton" method="_on_PlayButton_mouse_entered"]
[connection signal="pressed" from="MenuButton/VBoxContainer/PlayButton" to="MenuButton" method="_on_PlayButton_pressed"]
[connection signal="mouse_entered" from="MenuButton/VBoxContainer/Help_Button" to="MenuButton" method="_on_Help_Button_mouse_entered"]
[connection signal="pressed" from="MenuButton/VBoxContainer/Help_Button" to="MenuButton" method="_on_Help_Button_pressed"]
[connection signal="mouse_entered" from="MenuButton/VBoxContainer/Quit_Button" to="MenuButton" method="_on_Quit_Button_mouse_entered"]
[connection signal="pressed" from="MenuButton/VBoxContainer/Quit_Button" to="MenuButton" method="_on_Quit_Button_pressed"]
[connection signal="mouse_entered" from="VBoxContainer/PlayButton" to="VBoxContainer" method="_on_PlayButton_mouse_entered"]
[connection signal="pressed" from="VBoxContainer/PlayButton" to="VBoxContainer" method="_on_PlayButton_pressed"]
[connection signal="mouse_entered" from="VBoxContainer/Help_Button" to="VBoxContainer" method="_on_Help_Button_mouse_entered"]
[connection signal="pressed" from="VBoxContainer/Help_Button" to="VBoxContainer" method="_on_Help_Button_pressed"]
[connection signal="mouse_entered" from="VBoxContainer/Quit_Button" to="VBoxContainer" method="_on_Quit_Button_mouse_entered"]
[connection signal="pressed" from="VBoxContainer/Quit_Button" to="VBoxContainer" method="_on_Quit_Button_pressed"]