Adds Initial animations and enemy spawning

This commit is contained in:
txrpe 2024-10-05 17:57:40 +02:00
parent 1cda262976
commit 1a4878f32e
29 changed files with 522 additions and 26 deletions

BIN
Buttons/ERROR.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

34
Buttons/ERROR.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cw6je7hakttbq"
path="res://.godot/imported/ERROR.png-b61259a9cd49f5cf3869c7af0d132956.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Buttons/ERROR.png"
dest_files=["res://.godot/imported/ERROR.png-b61259a9cd49f5cf3869c7af0d132956.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
Buttons/FORBIDDEN.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://chckt1ppwsjq"
path="res://.godot/imported/FORBIDDEN.png-2caecaec5473cc18ee219ff66f0d7332.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Buttons/FORBIDDEN.png"
dest_files=["res://.godot/imported/FORBIDDEN.png-2caecaec5473cc18ee219ff66f0d7332.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
Buttons/FullPressed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://4c7qtuk0exng"
path="res://.godot/imported/FullPressed.png-f20f7171b0bcb8d71198a38c00af8073.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Buttons/FullPressed.png"
dest_files=["res://.godot/imported/FullPressed.png-f20f7171b0bcb8d71198a38c00af8073.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
Buttons/Idle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

34
Buttons/Idle.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://q85jhjrqsrxk"
path="res://.godot/imported/Idle.png-b446be287cb4debe9b9c6ef9fd0fd194.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Buttons/Idle.png"
dest_files=["res://.godot/imported/Idle.png-b446be287cb4debe9b9c6ef9fd0fd194.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
Buttons/PressedIn1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://blatwufdrwqml"
path="res://.godot/imported/PressedIn1.png-569043e67dd3e7c3f7e994945b5057a8.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Buttons/PressedIn1.png"
dest_files=["res://.godot/imported/PressedIn1.png-569043e67dd3e7c3f7e994945b5057a8.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
Buttons/PressedOut.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ncd65m8iq7l0"
path="res://.godot/imported/PressedOut.png-9796e7372947b19c113dcbcbde6b5b56.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Buttons/PressedOut.png"
dest_files=["res://.godot/imported/PressedOut.png-9796e7372947b19c113dcbcbde6b5b56.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
Worm/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

34
Worm/1.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bjb6konwfdwma"
path="res://.godot/imported/1.png-247616084d8c6df5f824301570c7e3df.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Worm/1.png"
dest_files=["res://.godot/imported/1.png-247616084d8c6df5f824301570c7e3df.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
Worm/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

34
Worm/2.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cowon23pejcb6"
path="res://.godot/imported/2.png-9f90c34ea3a109bedf7c22efae8619ce.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Worm/2.png"
dest_files=["res://.godot/imported/2.png-9f90c34ea3a109bedf7c22efae8619ce.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
Worm/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

34
Worm/3.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dl0wp6buga4d"
path="res://.godot/imported/3.png-3c71a66973d42fb571c23be36a651538.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Worm/3.png"
dest_files=["res://.godot/imported/3.png-3c71a66973d42fb571c23be36a651538.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
Worm/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

34
Worm/4.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c6cj6t3538iox"
path="res://.godot/imported/4.png-b38296328fae3e4fe3ee9cdb239540c5.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Worm/4.png"
dest_files=["res://.godot/imported/4.png-b38296328fae3e4fe3ee9cdb239540c5.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@ -1,20 +1,49 @@
extends Node2D
extends StaticBody2D
@export var input_name = ""
const ENEMY = preload("res://enemy.tscn")
const DISTANCE = 40
func _unhandled_input(event: InputEvent) -> void:
if(event.is_action_pressed(input_name)):
print_debug(input_name)
$AnimatedSprite2D.play("pressed")
var children = get_children(false)
var was_valid_input = false
for a in children:
if(a.has_method("button_pressed")):
a.button_pressed()
was_valid_input = true
if(!was_valid_input):
if get_parent().has_method("bad_press"):
get_parent().bad_press()
func _on_spawn_tick_timeout() -> void:
if(randi_range(0,1)==1):
spawn_enemy()
func spawn_enemy():
if get_children().any(func (a:Node):return a.has_method("button_pressed")):
return
elif(randi_range(0,1)==1):
var enemy = ENEMY.instantiate()
enemy.global_position = global_position
print_debug(randf_range(0.0, 2.0) * PI)
add_child(enemy)
enemy.global_position = global_position
enemy.global_rotation=randf_range(0, 2 * PI)
enemy.look_at(global_position)
enemy.enemy_attacked.connect(enemy_attacked)
func enemy_attacked():
#TODO: check for collisions
global_position = get_random_position()
func get_random_position():
var area2d:CollisionShape2D = get_parent().get_node(^"SpawnArea/CollisionShape2D")
var xa = area2d.shape.get_rect().position.x
var ya = area2d.global_position.y
# collison shape position is in the center of the shape :(( it took me too long to figure that out
var x = randi_range(area2d.global_position.x + area2d.shape.get_rect().position.x, area2d.global_position.x + area2d.shape.get_rect().end.x)
var y = randi_range(area2d.global_position.y + area2d.shape.get_rect().position.y, area2d.global_position.y + area2d.shape.get_rect().end.y)
return Vector2(x,y)

View File

@ -1,15 +1,16 @@
[gd_scene load_steps=6 format=3 uid="uid://bhvihrt8dipll"]
[gd_scene load_steps=8 format=3 uid="uid://bhvihrt8dipll"]
[ext_resource type="Script" path="res://button.gd" id="1_fkyus"]
[ext_resource type="Texture2D" uid="uid://0sorgpej62jh" path="res://kenney_inputPromptsPixel16×/Tiles/tile_0516.png" id="2_1qsw6"]
[ext_resource type="Texture2D" uid="uid://dlsmvp5ac602t" path="res://tile_0515.png" id="3_x67x8"]
[ext_resource type="Texture2D" uid="uid://cfv2iysf0vq6k" path="res://tile_0516.png" id="4_n1kdq"]
[ext_resource type="Texture2D" uid="uid://q85jhjrqsrxk" path="res://Buttons/Idle.png" id="2_01nlj"]
[ext_resource type="Texture2D" uid="uid://blatwufdrwqml" path="res://Buttons/PressedIn1.png" id="3_180hi"]
[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"]
[sub_resource type="SpriteFrames" id="SpriteFrames_leuex"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("3_x67x8")
"texture": ExtResource("2_01nlj")
}],
"loop": false,
"name": &"default",
@ -17,30 +18,40 @@ animations = [{
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("4_n1kdq")
"texture": ExtResource("3_180hi")
}, {
"duration": 3.0,
"texture": ExtResource("4_5m7c4")
}, {
"duration": 1.0,
"texture": ExtResource("3_x67x8")
"texture": ExtResource("5_3xqo8")
}, {
"duration": 1.0,
"texture": ExtResource("2_01nlj")
}],
"loop": false,
"name": &"pressed",
"speed": 10.0
"speed": 15.0
}]
[node name="Button" type="Node2D"]
script = ExtResource("1_fkyus")
[sub_resource type="CircleShape2D" id="CircleShape2D_gc3ws"]
radius = 30.0666
[node name="Icon" type="Sprite2D" parent="."]
visible = false
scale = Vector2(0.703125, 0.703125)
texture = ExtResource("2_1qsw6")
[node name="Button" type="StaticBody2D"]
script = ExtResource("1_fkyus")
metadata/_edit_group_ = true
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
scale = Vector2(5.625, 5.625)
scale = Vector2(1.38, 1.316)
sprite_frames = SubResource("SpriteFrames_leuex")
animation = &"pressed"
[node name="SpawnTick" type="Timer" parent="."]
wait_time = 0.5
wait_time = 0.439
autostart = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
scale = Vector2(1.56, 1.56)
shape = SubResource("CircleShape2D_gc3ws")
[connection signal="timeout" from="SpawnTick" to="." method="_on_spawn_tick_timeout"]

View File

@ -1,5 +1,7 @@
extends Node2D
signal enemy_attacked
func button_pressed():
queue_free()
@ -9,3 +11,11 @@ func _on_first_timer_timeout() -> void:
func _on_second_timer_timeout() -> void:
scale = Vector2(1.4,1.4)
func _ready() -> void:
$AnimatedSprite2D.play("new_animation")
func _on_animated_sprite_2d_animation_finished() -> void:
enemy_attacked.emit()
queue_free()

View File

@ -1,12 +1,44 @@
[gd_scene load_steps=3 format=3 uid="uid://cuvoq65ec58jk"]
[gd_scene load_steps=8 format=3 uid="uid://cuvoq65ec58jk"]
[ext_resource type="Script" path="res://enemy.gd" id="1_bn0a2"]
[ext_resource type="Texture2D" uid="uid://7a1smbkaiutn" path="res://icon.svg" id="1_rhutm"]
[ext_resource type="Texture2D" uid="uid://bjb6konwfdwma" path="res://Worm/1.png" id="3_owy1m"]
[ext_resource type="Texture2D" uid="uid://cowon23pejcb6" path="res://Worm/2.png" id="4_tiked"]
[ext_resource type="Texture2D" uid="uid://dl0wp6buga4d" path="res://Worm/3.png" id="5_vmogp"]
[ext_resource type="Texture2D" uid="uid://c6cj6t3538iox" path="res://Worm/4.png" id="6_h1mxl"]
[node name="Enemy" type="Node2D"]
[sub_resource type="SpriteFrames" id="SpriteFrames_5w8q8"]
animations = [{
"frames": [],
"loop": true,
"name": &"default",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("3_owy1m")
}, {
"duration": 3.0,
"texture": ExtResource("4_tiked")
}, {
"duration": 1.0,
"texture": ExtResource("5_vmogp")
}, {
"duration": 1.0,
"texture": ExtResource("6_h1mxl")
}],
"loop": false,
"name": &"new_animation",
"speed": 5.0
}]
[node name="Enemy" type="Node2D" groups=["enemy_group"]]
position = Vector2(10, 9)
script = ExtResource("1_bn0a2")
[node name="Icon" type="Sprite2D" parent="."]
visible = false
scale = Vector2(0.4, 0.4)
texture = ExtResource("1_rhutm")
[node name="FirstTimer" type="Timer" parent="."]
@ -18,5 +50,11 @@ wait_time = 2.0
one_shot = true
autostart = true
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(-22, -55)
sprite_frames = SubResource("SpriteFrames_5w8q8")
animation = &"new_animation"
[connection signal="timeout" from="FirstTimer" to="." method="_on_first_timer_timeout"]
[connection signal="timeout" from="SecondTimer" to="." method="_on_second_timer_timeout"]
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]

21
game.gd Normal file
View File

@ -0,0 +1,21 @@
extends Node2D
const MAX_HEALTH = 100.0
const RECOVERY_RATE = 10.0
const BAD_PRESS_DAMAGE = 20.0
const INIT_COLOR = Color(1,0,0,0)
var health = MAX_HEALTH
func _process(delta: float) -> void:
health = minf(health + RECOVERY_RATE * delta ,MAX_HEALTH)
var new_color = Color(INIT_COLOR)
new_color.a = 1 - health / MAX_HEALTH
%DamageColorOverlay.color = new_color
func bad_press():
health = maxf(health - BAD_PRESS_DAMAGE, 0)
if(health == 0):
print_debug("GAME OVER")

View File

@ -1,13 +1,50 @@
[gd_scene load_steps=2 format=3 uid="uid://decsef3jj3lt5"]
[gd_scene load_steps=4 format=3 uid="uid://decsef3jj3lt5"]
[ext_resource type="Script" path="res://game.gd" id="1_bhcvq"]
[ext_resource type="PackedScene" uid="uid://bhvihrt8dipll" path="res://button.tscn" id="1_j4pve"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_sesmb"]
size = Vector2(997, 471)
[node name="Game" type="Node2D"]
script = ExtResource("1_bhcvq")
[node name="CanvasLayer" type="CanvasLayer" parent="."]
layer = -1
follow_viewport_enabled = true
[node name="BackgroundColor" type="ColorRect" parent="CanvasLayer"]
z_index = -2
offset_right = 1150.0
offset_bottom = 650.0
[node name="DamageColorOverlay" type="ColorRect" parent="CanvasLayer"]
unique_name_in_owner = true
offset_right = 1152.0
offset_bottom = 654.0
scale = Vector2(1.00712, 1.00483)
color = Color(0.623529, 0.14902, 0.184314, 0.592157)
[node name="A" parent="." groups=["button_group"] instance=ExtResource("1_j4pve")]
position = Vector2(253, 174)
position = Vector2(872, 515)
input_name = "A"
[node name="Y" parent="." groups=["button_group"] instance=ExtResource("1_j4pve")]
position = Vector2(872, 330)
input_name = "Y"
[node name="X" parent="." groups=["button_group"] instance=ExtResource("1_j4pve")]
position = Vector2(777, 422)
input_name = "X"
[node name="B" parent="." instance=ExtResource("1_j4pve")]
position = Vector2(442, 178)
position = Vector2(954, 422)
input_name = "B"
[node name="SpawnArea" type="Area2D" parent="."]
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="SpawnArea"]
position = Vector2(568.5, 359.5)
shape = SubResource("RectangleShape2D_sesmb")
debug_color = Color(0, 0.6, 0.701961, 0.14902)

View File

@ -17,7 +17,7 @@ config/icon="res://icon.svg"
[editor_plugins]
enabled=PackedStringArray("res://addons/format_on_save/plugin.cfg", "res://addons/nklbdev.aseprite_importers/plugin.cfg")
enabled=PackedStringArray()
[input]
@ -31,3 +31,13 @@ B={
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
]
}
X={
"deadzone": 0.5,
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
]
}
Y={
"deadzone": 0.5,
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":true,"script":null)
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 B