Removes button hopping, adds animations for red button transitions, tracks score, and accelerates spawn rate
This commit is contained in:
parent
9cccf190ad
commit
2cf9884f9d
50
button.gd
50
button.gd
@ -6,6 +6,9 @@ const ENEMY = preload("res://enemy.tscn")
|
|||||||
const DISTANCE = 40
|
const DISTANCE = 40
|
||||||
var red_button = false
|
var red_button = false
|
||||||
var should_move = false
|
var should_move = false
|
||||||
|
signal enemy_killed
|
||||||
|
|
||||||
|
var trans = false
|
||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if(event.is_action_pressed(input_name)):
|
if(event.is_action_pressed(input_name)):
|
||||||
@ -18,6 +21,7 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||||||
for a in children:
|
for a in children:
|
||||||
if(a.has_method("button_pressed")):
|
if(a.has_method("button_pressed")):
|
||||||
a.button_pressed()
|
a.button_pressed()
|
||||||
|
enemy_killed.emit()
|
||||||
was_valid_input = true
|
was_valid_input = true
|
||||||
if(!was_valid_input):
|
if(!was_valid_input):
|
||||||
if get_parent().has_method("bad_press"):
|
if get_parent().has_method("bad_press"):
|
||||||
@ -33,10 +37,25 @@ func set_red_button(is_red: bool):
|
|||||||
else:
|
else:
|
||||||
$AnimatedSprite2D.play("default")
|
$AnimatedSprite2D.play("default")
|
||||||
|
|
||||||
#func _process(delta: float) -> void:
|
func red_in():
|
||||||
#$AnimatedSprite2D.modulate = color_mix
|
red_button = true
|
||||||
|
trans = true
|
||||||
|
$AnimatedSprite2D.play("red_in")
|
||||||
|
|
||||||
|
func red_out():
|
||||||
|
red_button = true
|
||||||
|
trans = true
|
||||||
|
$AnimatedSprite2D.play("red_out")
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
if(!trans):
|
||||||
|
$AnimatedSprite2D.modulate = color_mix
|
||||||
|
else:
|
||||||
|
$AnimatedSprite2D.modulate = Color(1,1,1)
|
||||||
|
|
||||||
func spawn_enemy():
|
func spawn_enemy():
|
||||||
|
if(trans):
|
||||||
|
return
|
||||||
if get_has_enemy():
|
if get_has_enemy():
|
||||||
return
|
return
|
||||||
if(randi_range(0,1)==1):
|
if(randi_range(0,1)==1):
|
||||||
@ -53,13 +72,13 @@ func enemy_attacked():
|
|||||||
if red_button:
|
if red_button:
|
||||||
get_parent().change_red_button()
|
get_parent().change_red_button()
|
||||||
return
|
return
|
||||||
move_button()
|
#move_button()
|
||||||
|
get_parent().ate()
|
||||||
|
|
||||||
|
|
||||||
|
#func move_button():
|
||||||
func move_button():
|
#should_move = true
|
||||||
should_move = true
|
#global_position = get_random_position()
|
||||||
global_position = get_random_position()
|
|
||||||
|
|
||||||
|
|
||||||
func get_random_position():
|
func get_random_position():
|
||||||
@ -74,13 +93,20 @@ func get_random_position():
|
|||||||
|
|
||||||
var should_really_move = false
|
var should_really_move = false
|
||||||
|
|
||||||
func _on_area_2d_area_entered(area: Area2D) -> void:
|
#func _on_area_2d_area_entered(area: Area2D) -> void:
|
||||||
if should_really_move:
|
#if should_really_move:
|
||||||
move_button()
|
#move_button()
|
||||||
if should_move:
|
#if should_move:
|
||||||
move_button()
|
#move_button()
|
||||||
|
|
||||||
func _on_area_2d_area_exited(area: Area2D) -> void:
|
func _on_area_2d_area_exited(area: Area2D) -> void:
|
||||||
if should_move:
|
if should_move:
|
||||||
should_really_move = true
|
should_really_move = true
|
||||||
should_move = false
|
should_move = false
|
||||||
|
|
||||||
|
|
||||||
|
func _on_animated_sprite_2d_animation_finished() -> void:
|
||||||
|
if(trans):
|
||||||
|
if($AnimatedSprite2D.animation == "red_out"):
|
||||||
|
red_button = false
|
||||||
|
trans = false
|
||||||
|
54
button.tscn
54
button.tscn
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=9 format=3 uid="uid://bhvihrt8dipll"]
|
[gd_scene load_steps=10 format=3 uid="uid://bhvihrt8dipll"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://button.gd" id="1_fkyus"]
|
[ext_resource type="Script" path="res://button.gd" id="1_fkyus"]
|
||||||
[ext_resource type="Texture2D" uid="uid://q85jhjrqsrxk" path="res://Buttons/Idle.png" id="2_01nlj"]
|
[ext_resource type="Texture2D" uid="uid://q85jhjrqsrxk" path="res://Buttons/Idle.png" id="2_01nlj"]
|
||||||
@ -6,6 +6,7 @@
|
|||||||
[ext_resource type="Texture2D" uid="uid://4c7qtuk0exng" path="res://Buttons/FullPressed.png" id="4_5m7c4"]
|
[ext_resource type="Texture2D" uid="uid://4c7qtuk0exng" path="res://Buttons/FullPressed.png" id="4_5m7c4"]
|
||||||
[ext_resource type="Texture2D" uid="uid://ncd65m8iq7l0" path="res://Buttons/PressedOut.png" id="5_3xqo8"]
|
[ext_resource type="Texture2D" uid="uid://ncd65m8iq7l0" path="res://Buttons/PressedOut.png" id="5_3xqo8"]
|
||||||
[ext_resource type="Texture2D" uid="uid://chckt1ppwsjq" path="res://Buttons/FORBIDDEN.png" id="6_p5821"]
|
[ext_resource type="Texture2D" uid="uid://chckt1ppwsjq" path="res://Buttons/FORBIDDEN.png" id="6_p5821"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cw6je7hakttbq" path="res://Buttons/ERROR.png" id="7_3w6j8"]
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id="SpriteFrames_leuex"]
|
[sub_resource type="SpriteFrames" id="SpriteFrames_leuex"]
|
||||||
animations = [{
|
animations = [{
|
||||||
@ -41,6 +42,55 @@ animations = [{
|
|||||||
"loop": true,
|
"loop": true,
|
||||||
"name": &"red",
|
"name": &"red",
|
||||||
"speed": 5.0
|
"speed": 5.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("7_3w6j8")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("2_01nlj")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("7_3w6j8")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("2_01nlj")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("7_3w6j8")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("2_01nlj")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("6_p5821")
|
||||||
|
}],
|
||||||
|
"loop": false,
|
||||||
|
"name": &"red_in",
|
||||||
|
"speed": 3.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("7_3w6j8")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("2_01nlj")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("7_3w6j8")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("2_01nlj")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("7_3w6j8")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": ExtResource("2_01nlj")
|
||||||
|
}],
|
||||||
|
"loop": false,
|
||||||
|
"name": &"red_out",
|
||||||
|
"speed": 3.0
|
||||||
}]
|
}]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_l0l4p"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_l0l4p"]
|
||||||
@ -53,7 +103,6 @@ metadata/_edit_group_ = true
|
|||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
scale = Vector2(1.38, 1.316)
|
scale = Vector2(1.38, 1.316)
|
||||||
sprite_frames = SubResource("SpriteFrames_leuex")
|
sprite_frames = SubResource("SpriteFrames_leuex")
|
||||||
animation = &"pressed"
|
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="."]
|
[node name="Area2D" type="Area2D" parent="."]
|
||||||
scale = Vector2(1.21306, 1.21306)
|
scale = Vector2(1.21306, 1.21306)
|
||||||
@ -64,5 +113,6 @@ collision_mask = 2
|
|||||||
scale = Vector2(4.74125, 4.84)
|
scale = Vector2(4.74125, 4.84)
|
||||||
shape = SubResource("CircleShape2D_l0l4p")
|
shape = SubResource("CircleShape2D_l0l4p")
|
||||||
|
|
||||||
|
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]
|
||||||
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]
|
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]
|
||||||
[connection signal="area_exited" from="Area2D" to="." method="_on_area_2d_area_exited"]
|
[connection signal="area_exited" from="Area2D" to="." method="_on_area_2d_area_exited"]
|
||||||
|
46
game.gd
46
game.gd
@ -8,45 +8,71 @@ const MAX_ENEMIES = 3
|
|||||||
const INIT_COLOR = Color(1,0,0,0)
|
const INIT_COLOR = Color(1,0,0,0)
|
||||||
var health = MAX_HEALTH
|
var health = MAX_HEALTH
|
||||||
|
|
||||||
|
|
||||||
|
var spawn_interval = 1.5
|
||||||
|
var interval_step = 0.05
|
||||||
|
var max_out = 0.7
|
||||||
|
|
||||||
|
var player_score = 0
|
||||||
|
|
||||||
|
var first_time = true
|
||||||
|
|
||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
if event.is_action_pressed("ui_accept"):
|
if event.is_action_pressed("ui_accept"):
|
||||||
$SpawnTimer.paused = false
|
$SpawnTimer.paused = false
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
change_red_button()
|
change_red_button()
|
||||||
|
first_time = false
|
||||||
|
$SpawnTimer.wait_time = spawn_interval
|
||||||
|
for button in get_tree().get_nodes_in_group("button_group"):
|
||||||
|
button.enemy_killed.connect(on_enemy_killed)
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
health = minf(health + RECOVERY_RATE * delta ,MAX_HEALTH)
|
health = minf(health + RECOVERY_RATE * delta ,MAX_HEALTH)
|
||||||
|
|
||||||
|
if(spawn_interval > max_out):
|
||||||
|
spawn_interval -= interval_step*delta
|
||||||
|
|
||||||
var new_color = Color(INIT_COLOR)
|
var new_color = Color(INIT_COLOR)
|
||||||
new_color.a = 1 - health / MAX_HEALTH
|
new_color.a = 1 - health / MAX_HEALTH
|
||||||
%DamageColorOverlay.color = new_color
|
%DamageColorOverlay.color = new_color
|
||||||
if health < 5:
|
if health < 5:
|
||||||
$SpawnTimer.paused =true
|
$SpawnTimer.paused =true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func bad_press():
|
func bad_press():
|
||||||
health = maxf(health - BAD_PRESS_DAMAGE, 0)
|
health = maxf(health - BAD_PRESS_DAMAGE, 0)
|
||||||
|
spawn_interval -= interval_step
|
||||||
|
|
||||||
|
func ate():
|
||||||
|
health = maxf(health - BAD_PRESS_DAMAGE, 0)
|
||||||
|
spawn_interval += interval_step
|
||||||
|
|
||||||
func red_button_press():
|
func red_button_press():
|
||||||
health = 0
|
health = 0
|
||||||
|
|
||||||
func change_red_button():
|
func change_red_button():
|
||||||
var buttons = get_tree().get_nodes_in_group("button_group")
|
var buttons = get_tree().get_nodes_in_group("button_group")
|
||||||
var index = -1
|
var old_red_button_index = -1
|
||||||
if buttons.filter(func (n: Node): return n.red_button).size() > 0:
|
if buttons.filter(func (n: Node): return n.red_button).size() > 0:
|
||||||
var old_red_button = buttons.filter(func (n: Node): return n.red_button)[0]
|
var old_red_button = buttons.filter(func (n: Node): return n.red_button)[0]
|
||||||
old_red_button.set_red_button(false)
|
old_red_button_index = buttons.find(old_red_button)
|
||||||
index = buttons.find(old_red_button)
|
|
||||||
var r = randi_range(0, buttons.size()-1)
|
var r = randi_range(0, buttons.size()-1)
|
||||||
|
|
||||||
while (r == index):
|
while (r == old_red_button_index || buttons[r].get_has_enemy()):
|
||||||
r= randi_range(0, buttons.size()-1)
|
r= randi_range(0, buttons.size()-1)
|
||||||
buttons[r].set_red_button(true)
|
if(!first_time):
|
||||||
|
buttons[old_red_button_index].red_out()
|
||||||
|
buttons[r].red_in()
|
||||||
|
else:
|
||||||
|
buttons[r].set_red_button(true)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_spawn_timer_timeout() -> void:
|
func _on_spawn_timer_timeout() -> void:
|
||||||
|
$SpawnTimer.wait_time = spawn_interval
|
||||||
var buttons = get_tree().get_nodes_in_group("button_group")
|
var buttons = get_tree().get_nodes_in_group("button_group")
|
||||||
var enemies_to_spawn = randi_range(1, MAX_ENEMIES)
|
var enemies_to_spawn = randi_range(1, MAX_ENEMIES)
|
||||||
while (enemies_to_spawn > 0):
|
while (enemies_to_spawn > 0):
|
||||||
@ -57,5 +83,7 @@ func _on_spawn_timer_timeout() -> void:
|
|||||||
continue
|
continue
|
||||||
button.spawn_enemy()
|
button.spawn_enemy()
|
||||||
enemies_to_spawn -=1
|
enemies_to_spawn -=1
|
||||||
|
|
||||||
return
|
return
|
||||||
|
func on_enemy_killed():
|
||||||
|
player_score+=1
|
||||||
|
print_debug(player_score)
|
||||||
|
24
game.tscn
24
game.tscn
@ -4,7 +4,7 @@
|
|||||||
[ext_resource type="PackedScene" uid="uid://bhvihrt8dipll" path="res://button.tscn" id="1_j4pve"]
|
[ext_resource type="PackedScene" uid="uid://bhvihrt8dipll" path="res://button.tscn" id="1_j4pve"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_sesmb"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_sesmb"]
|
||||||
size = Vector2(469, 405.155)
|
size = Vector2(995, 433.534)
|
||||||
|
|
||||||
[node name="Game" type="Node2D"]
|
[node name="Game" type="Node2D"]
|
||||||
process_mode = 3
|
process_mode = 3
|
||||||
@ -31,6 +31,26 @@ position = Vector2(872, 515)
|
|||||||
input_name = "A"
|
input_name = "A"
|
||||||
color_mix = Color(1.01075e-06, 0.583986, 0.337423, 1)
|
color_mix = Color(1.01075e-06, 0.583986, 0.337423, 1)
|
||||||
|
|
||||||
|
[node name="DOWN" parent="." groups=["button_group"] instance=ExtResource("1_j4pve")]
|
||||||
|
position = Vector2(236, 515)
|
||||||
|
input_name = "DOWN"
|
||||||
|
color_mix = Color(1.01075e-06, 0.583986, 0.337423, 1)
|
||||||
|
|
||||||
|
[node name="UP" parent="." groups=["button_group"] instance=ExtResource("1_j4pve")]
|
||||||
|
position = Vector2(236, 330)
|
||||||
|
input_name = "UP"
|
||||||
|
color_mix = Color(1.01075e-06, 0.583986, 0.337423, 1)
|
||||||
|
|
||||||
|
[node name="RIGHT" parent="." groups=["button_group"] instance=ExtResource("1_j4pve")]
|
||||||
|
position = Vector2(334, 422)
|
||||||
|
input_name = "RIGHT"
|
||||||
|
color_mix = Color(1.01075e-06, 0.583986, 0.337423, 1)
|
||||||
|
|
||||||
|
[node name="LEFT" parent="." groups=["button_group"] instance=ExtResource("1_j4pve")]
|
||||||
|
position = Vector2(143, 422)
|
||||||
|
input_name = "LEFT"
|
||||||
|
color_mix = Color(1.01075e-06, 0.583986, 0.337423, 1)
|
||||||
|
|
||||||
[node name="Y" parent="." groups=["button_group"] instance=ExtResource("1_j4pve")]
|
[node name="Y" parent="." groups=["button_group"] instance=ExtResource("1_j4pve")]
|
||||||
position = Vector2(872, 330)
|
position = Vector2(872, 330)
|
||||||
input_name = "Y"
|
input_name = "Y"
|
||||||
@ -51,7 +71,7 @@ scale = Vector2(1, 1.02189)
|
|||||||
metadata/_edit_group_ = true
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="SpawnArea"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="SpawnArea"]
|
||||||
position = Vector2(832.5, 392.423)
|
position = Vector2(569.5, 378.233)
|
||||||
shape = SubResource("RectangleShape2D_sesmb")
|
shape = SubResource("RectangleShape2D_sesmb")
|
||||||
debug_color = Color(0, 0.6, 0.701961, 0.14902)
|
debug_color = Color(0, 0.6, 0.701961, 0.14902)
|
||||||
|
|
||||||
|
@ -41,3 +41,23 @@ Y={
|
|||||||
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":true,"script":null)
|
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":true,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
LEFT={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":13,"pressure":0.0,"pressed":true,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
RIGHT={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":true,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
UP={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":11,"pressure":0.0,"pressed":true,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
DOWN={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":true,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user