Removes button hopping, adds animations for red button transitions, tracks score, and accelerates spawn rate

This commit is contained in:
txrpe 2024-10-06 14:18:16 +02:00
parent 9cccf190ad
commit 2cf9884f9d
5 changed files with 169 additions and 25 deletions

View File

@ -6,6 +6,9 @@ const ENEMY = preload("res://enemy.tscn")
const DISTANCE = 40
var red_button = false
var should_move = false
signal enemy_killed
var trans = false
func _unhandled_input(event: InputEvent) -> void:
if(event.is_action_pressed(input_name)):
@ -18,6 +21,7 @@ func _unhandled_input(event: InputEvent) -> void:
for a in children:
if(a.has_method("button_pressed")):
a.button_pressed()
enemy_killed.emit()
was_valid_input = true
if(!was_valid_input):
if get_parent().has_method("bad_press"):
@ -33,10 +37,25 @@ func set_red_button(is_red: bool):
else:
$AnimatedSprite2D.play("default")
#func _process(delta: float) -> void:
#$AnimatedSprite2D.modulate = color_mix
func red_in():
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():
if(trans):
return
if get_has_enemy():
return
if(randi_range(0,1)==1):
@ -53,13 +72,13 @@ func enemy_attacked():
if red_button:
get_parent().change_red_button()
return
move_button()
#move_button()
get_parent().ate()
func move_button():
should_move = true
global_position = get_random_position()
#func move_button():
#should_move = true
#global_position = get_random_position()
func get_random_position():
@ -74,13 +93,20 @@ func get_random_position():
var should_really_move = false
func _on_area_2d_area_entered(area: Area2D) -> void:
if should_really_move:
move_button()
if should_move:
move_button()
#func _on_area_2d_area_entered(area: Area2D) -> void:
#if should_really_move:
#move_button()
#if should_move:
#move_button()
func _on_area_2d_area_exited(area: Area2D) -> void:
if should_move:
should_really_move = true
should_move = false
func _on_animated_sprite_2d_animation_finished() -> void:
if(trans):
if($AnimatedSprite2D.animation == "red_out"):
red_button = false
trans = false

View File

@ -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="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://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://cw6je7hakttbq" path="res://Buttons/ERROR.png" id="7_3w6j8"]
[sub_resource type="SpriteFrames" id="SpriteFrames_leuex"]
animations = [{
@ -41,6 +42,55 @@ animations = [{
"loop": true,
"name": &"red",
"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"]
@ -53,7 +103,6 @@ metadata/_edit_group_ = true
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
scale = Vector2(1.38, 1.316)
sprite_frames = SubResource("SpriteFrames_leuex")
animation = &"pressed"
[node name="Area2D" type="Area2D" parent="."]
scale = Vector2(1.21306, 1.21306)
@ -64,5 +113,6 @@ collision_mask = 2
scale = Vector2(4.74125, 4.84)
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_exited" from="Area2D" to="." method="_on_area_2d_area_exited"]

44
game.gd
View File

@ -8,45 +8,71 @@ const MAX_ENEMIES = 3
const INIT_COLOR = Color(1,0,0,0)
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:
if event.is_action_pressed("ui_accept"):
$SpawnTimer.paused = false
func _ready() -> void:
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:
health = minf(health + RECOVERY_RATE * delta ,MAX_HEALTH)
if(spawn_interval > max_out):
spawn_interval -= interval_step*delta
var new_color = Color(INIT_COLOR)
new_color.a = 1 - health / MAX_HEALTH
%DamageColorOverlay.color = new_color
if health < 5:
$SpawnTimer.paused =true
func bad_press():
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():
health = 0
func change_red_button():
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:
var old_red_button = buttons.filter(func (n: Node): return n.red_button)[0]
old_red_button.set_red_button(false)
index = buttons.find(old_red_button)
old_red_button_index = buttons.find(old_red_button)
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)
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:
$SpawnTimer.wait_time = spawn_interval
var buttons = get_tree().get_nodes_in_group("button_group")
var enemies_to_spawn = randi_range(1, MAX_ENEMIES)
while (enemies_to_spawn > 0):
@ -57,5 +83,7 @@ func _on_spawn_timer_timeout() -> void:
continue
button.spawn_enemy()
enemies_to_spawn -=1
return
func on_enemy_killed():
player_score+=1
print_debug(player_score)

View File

@ -4,7 +4,7 @@
[ext_resource type="PackedScene" uid="uid://bhvihrt8dipll" path="res://button.tscn" id="1_j4pve"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_sesmb"]
size = Vector2(469, 405.155)
size = Vector2(995, 433.534)
[node name="Game" type="Node2D"]
process_mode = 3
@ -31,6 +31,26 @@ position = Vector2(872, 515)
input_name = "A"
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")]
position = Vector2(872, 330)
input_name = "Y"
@ -51,7 +71,7 @@ scale = Vector2(1, 1.02189)
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="SpawnArea"]
position = Vector2(832.5, 392.423)
position = Vector2(569.5, 378.233)
shape = SubResource("RectangleShape2D_sesmb")
debug_color = Color(0, 0.6, 0.701961, 0.14902)

View File

@ -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)
]
}
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)
]
}