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

View file

@ -5,8 +5,8 @@ onready var sprite = $"../Sprite"
func _on_Area2D_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void: func _on_Area2D_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
if event is InputEventMouseButton: if event is InputEventMouseButton:
event = event as InputEventMouseButton event = event as InputEventMouseButton
if event.pressed and event.button_index == BUTTON_LEFT: if event.pressed and event.button_index == BUTTON_LEFT:
screen.visible = true screen.visible = true
sprite.modulate = Color(0.66, 0.51, 0.85) # shade 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(): func drag_change_state():
is_dragging = !is_dragging is_dragging = !is_dragging
grabbed_offset = window.get_position() - get_global_mouse_position() grabbed_offset = window.get_position() - get_global_mouse_position()
func _process(_delta) -> void: func _process(_delta) -> void:
if is_dragging: if is_dragging:
var new_pos = get_global_mouse_position() + grabbed_offset var new_pos = get_global_mouse_position() + grabbed_offset
if new_pos.x > 150: if new_pos.x > 150:
window.set_position(new_pos) window.set_position(new_pos)
else: else:
drag_change_state() drag_change_state()
func _on_Area2D_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void: func _on_Area2D_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
if event is InputEventMouseButton: if event is InputEventMouseButton:
event = event as InputEventMouseButton event = event as InputEventMouseButton
if event.pressed and event.button_index == BUTTON_LEFT: if event.pressed and event.button_index == BUTTON_LEFT:
drag_change_state() drag_change_state()
#print("here haha") #print("here haha")
elif event.button_index == BUTTON_LEFT and !event.pressed: elif event.button_index == BUTTON_LEFT and !event.pressed:
drag_change_state() drag_change_state()
#print("here huhu") #print("here huhu")
func _on_Area2D2_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void: func _on_Area2D2_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
if event is InputEventMouseButton: if event is InputEventMouseButton:
event = event as InputEventMouseButton event = event as InputEventMouseButton
if event.pressed and event.button_index == BUTTON_LEFT: if event.pressed and event.button_index == BUTTON_LEFT:
drag_change_state() drag_change_state()
window.visible = false window.visible = false
folder_icon.modulate = Color(1, 1, 1) # reset shade 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" onready var villain_animations = $"../../../../Villain"
var etat = false var etat = false
var remplissage = 0; var remplissage = 0
const texture_pressed = preload("res://Assets/tres_button/hover-pressed.png") const texture_pressed = preload("res://Assets/tres_button/hover-pressed.png")
const texture_released = preload("res://Assets/tres_button/normal.png") const texture_released = preload("res://Assets/tres_button/normal.png")
# Called every frame. '_delta' is the elapsed time since the previous frame. # Called every frame. '_delta' is the elapsed time since the previous frame.
func _process(_delta) -> void: func _process(_delta) -> void:
if etat: if etat:
if villain.animation == villain_animations.animations[-1]: if villain.animation == villain_animations.animations[-1]:
assert(get_tree().change_scene("res://Scenes/gameover.tscn") == OK) assert(get_tree().change_scene("res://Scenes/gameover.tscn") == OK)
if(remplissage == 60*10): # fermer le dossier et enlever l'icone if remplissage == 60 * 10: # fermer le dossier et enlever l'icone
etat = false etat = false
self.get_parent().get_parent().visible = false; self.get_parent().get_parent().visible = false
else : else:
remplissage+=1; remplissage += 1
print(remplissage) print(remplissage)
func _on_Button_pressed() -> void: func _on_Button_pressed() -> void:
etat = !etat etat = !etat
var new_stylebox_normal = self.get_stylebox("normal").duplicate() var new_stylebox_normal = self.get_stylebox("normal").duplicate()
if etat: if etat:
new_stylebox_normal.texture = texture_pressed new_stylebox_normal.texture = texture_pressed
else: else:
new_stylebox_normal.texture = texture_released new_stylebox_normal.texture = texture_released
self.add_stylebox_override("normal", new_stylebox_normal) 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() var rng = RandomNumberGenerator.new()
# 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() -> void: func _ready() -> void:
rng.randomize() rng.randomize()
var nbDossier = rng.randi_range(0, 3) var nbDossier = rng.randi_range(0, 3)
for i in range(nbDossier): for i in range(nbDossier):
var dossier = get_child(2).duplicate() var dossier = get_child(2).duplicate()
dossier.position = Vector2(dossier.position.x, dossier.position.y+150*(i+1)) dossier.position = Vector2(dossier.position.x, dossier.position.y + 150 * (i + 1))
dossier.set_z_index(dossier.get_z_index()+10*(i+1)) dossier.set_z_index(dossier.get_z_index() + 10 * (i + 1))
add_child(dossier) add_child(dossier)
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta) -> void: func _process(_delta) -> void:
if villain.animation == villain_animations.animations[-1]: if villain.animation == villain_animations.animations[-1]:
mainMusic.set_volume_db(-80) mainMusic.set_volume_db(-80)
eyeMusic.set_volume_db(0) eyeMusic.set_volume_db(0)
if(alert.is_playing()): if alert.is_playing():
alert.stop() alert.stop()
elif villain.animation == villain_animations.animations[1] : elif villain.animation == villain_animations.animations[1]:
if(!alert.is_playing()): if !alert.is_playing():
alert.play() alert.play()
else : else:
mainMusic.set_volume_db(0) mainMusic.set_volume_db(0)
eyeMusic.set_volume_db(-80) eyeMusic.set_volume_db(-80)

View file

@ -1,9 +1,10 @@
extends Node2D extends Node2D
onready var hover_sound = $"Hover" onready var hover_sound = $"Hover"
func _on_RestartButton_pressed() -> void: 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: func _on_RestartButton_mouse_entered() -> void:
hover_sound.play() hover_sound.play()

View file

@ -1,25 +1,26 @@
extends Control extends Control
onready var hover_sound = $"Hover" onready var hover_sound = $"Hover"
func _on_PlayButton_pressed() -> void: 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: func _on_Help_Button_pressed() -> void:
print("help me") print("help me")
func _on_Quit_Button_pressed() -> void: func _on_Quit_Button_pressed() -> void:
get_tree().quit() get_tree().quit()
func _on_PlayButton_mouse_entered() -> void: func _on_PlayButton_mouse_entered() -> void:
hover_sound.play() hover_sound.play()
func _on_Quit_Button_mouse_entered() -> void: func _on_Quit_Button_mouse_entered() -> void:
hover_sound.play() hover_sound.play()
func _on_Help_Button_mouse_entered() -> void: 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 z_index = -2
texture = ExtResource( 6 ) texture = ExtResource( 6 )
[node name="MenuButton" type="MenuButton" parent="."] [node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 480.0 margin_left = 432.0
margin_top = 232.0 margin_top = 272.0
margin_right = 584.0 margin_right = 568.0
margin_bottom = 392.0 margin_bottom = 504.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
custom_constants/separation = 26 custom_constants/separation = 26
alignment = 1 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_top = 34.0
margin_right = 136.0 margin_right = 136.0
margin_bottom = 71.0 margin_bottom = 71.0
@ -44,7 +42,7 @@ custom_styles/pressed = ExtResource( 4 )
custom_styles/normal = ExtResource( 3 ) custom_styles/normal = ExtResource( 3 )
text = "PLAY" text = "PLAY"
[node name="Help_Button" type="Button" parent="MenuButton/VBoxContainer"] [node name="Help_Button" type="Button" parent="VBoxContainer"]
margin_top = 97.0 margin_top = 97.0
margin_right = 136.0 margin_right = 136.0
margin_bottom = 134.0 margin_bottom = 134.0
@ -56,7 +54,7 @@ custom_styles/pressed = ExtResource( 4 )
custom_styles/normal = ExtResource( 3 ) custom_styles/normal = ExtResource( 3 )
text = "HELP" text = "HELP"
[node name="Quit_Button" type="Button" parent="MenuButton/VBoxContainer"] [node name="Quit_Button" type="Button" parent="VBoxContainer"]
margin_top = 160.0 margin_top = 160.0
margin_right = 136.0 margin_right = 136.0
margin_bottom = 197.0 margin_bottom = 197.0
@ -68,16 +66,14 @@ custom_styles/pressed = ExtResource( 4 )
custom_styles/normal = ExtResource( 3 ) custom_styles/normal = ExtResource( 3 )
text = "QUIT" text = "QUIT"
[node name="Hover" type="AudioStreamPlayer" parent="MenuButton"]
stream = ExtResource( 8 )
[node name="MenuMusic" type="AudioStreamPlayer" parent="."] [node name="MenuMusic" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 7 ) stream = ExtResource( 7 )
volume_db = 8.0
autoplay = true autoplay = true
[connection signal="mouse_entered" from="MenuButton/VBoxContainer/PlayButton" to="MenuButton" method="_on_PlayButton_mouse_entered"] [connection signal="mouse_entered" from="VBoxContainer/PlayButton" to="VBoxContainer" method="_on_PlayButton_mouse_entered"]
[connection signal="pressed" from="MenuButton/VBoxContainer/PlayButton" to="MenuButton" method="_on_PlayButton_pressed"] [connection signal="pressed" from="VBoxContainer/PlayButton" to="VBoxContainer" method="_on_PlayButton_pressed"]
[connection signal="mouse_entered" from="MenuButton/VBoxContainer/Help_Button" to="MenuButton" method="_on_Help_Button_mouse_entered"] [connection signal="mouse_entered" from="VBoxContainer/Help_Button" to="VBoxContainer" method="_on_Help_Button_mouse_entered"]
[connection signal="pressed" from="MenuButton/VBoxContainer/Help_Button" to="MenuButton" method="_on_Help_Button_pressed"] [connection signal="pressed" from="VBoxContainer/Help_Button" to="VBoxContainer" method="_on_Help_Button_pressed"]
[connection signal="mouse_entered" from="MenuButton/VBoxContainer/Quit_Button" to="MenuButton" method="_on_Quit_Button_mouse_entered"] [connection signal="mouse_entered" from="VBoxContainer/Quit_Button" to="VBoxContainer" method="_on_Quit_Button_mouse_entered"]
[connection signal="pressed" from="MenuButton/VBoxContainer/Quit_Button" to="MenuButton" method="_on_Quit_Button_pressed"] [connection signal="pressed" from="VBoxContainer/Quit_Button" to="VBoxContainer" method="_on_Quit_Button_pressed"]