Get Map Gernation in #17

Closed
Snoweuph wants to merge 85 commits from dev-base into dev-player-movement
3 changed files with 306 additions and 6 deletions
Showing only changes of commit a0d1e09d91 - Show all commits

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=5 format=3 uid="uid://cpl4tllohhyel"]
[gd_scene load_steps=12 format=3 uid="uid://cpl4tllohhyel"]
[ext_resource type="Script" path="res://Scripts/EntitySystem/Bunny.gd" id="1_1kj2b"]
[ext_resource type="Texture2D" uid="uid://df2fluk0dlqar" path="res://Assets/Sprites/Bunny/bad_bunny_spritesheet.png" id="2_v8p70"]
@ -8,10 +8,119 @@
[sub_resource type="CircleShape2D" id="CircleShape2D_itvjj"]
radius = 14.0
[node name="Bunny" type="CharacterBody2D" node_paths=PackedStringArray("agent")]
[sub_resource type="Animation" id="Animation_l8j6b"]
resource_name = "MoveLeft"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 1,
"values": [5, 6, 7, 8, 9]
}
[sub_resource type="Animation" id="Animation_45lfy"]
resource_name = "MoveUp"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 1,
"values": [15, 16, 17, 18, 19]
}
[sub_resource type="Animation" id="Animation_olc18"]
resource_name = "MoveDown"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 1,
"values": [0, 1, 2, 3, 4]
}
[sub_resource type="Animation" id="Animation_agj62"]
resource_name = "MoveRight"
length = 0.5
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 1,
"values": [10, 11, 12, 13, 14]
}
[sub_resource type="Animation" id="Animation_6br4g"]
resource_name = "Idle"
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
[sub_resource type="Animation" id="Animation_mp212"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Sprite2D:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_uuf00"]
_data = {
"Idle": SubResource("Animation_6br4g"),
"MoveDown": SubResource("Animation_olc18"),
"MoveLeft": SubResource("Animation_l8j6b"),
"MoveRight": SubResource("Animation_agj62"),
"MoveUp": SubResource("Animation_45lfy"),
"RESET": SubResource("Animation_mp212")
}
[node name="Bunny" type="CharacterBody2D" node_paths=PackedStringArray("animation_player", "agent")]
collision_layer = 4
collision_mask = 15
script = ExtResource("1_1kj2b")
animation_player = NodePath("BunnyAnimator")
agent = NodePath("NavigationAgent")
[node name="Sprite2D" type="Sprite2D" parent="."]
@ -33,5 +142,10 @@ collision_mask = 4
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("CircleShape2D_itvjj")
[node name="BunnyAnimator" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_uuf00")
}
[connection signal="body_entered" from="Area2D" to="." method="_on_collision"]
[connection signal="body_exited" from="Area2D" to="." method="_of_collision"]

173
Scenes/GameBunnyAnims.tscn Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,7 @@
extends CharacterBody2D
class_name Bunny
@export var animation_player : AnimationPlayer
@export var min_distance_to_player := 80.0
@export var max_distance_to_player := 800.0
@export var agent : NavigationAgent2D
@ -33,6 +34,7 @@ func _physics_process(delta):
dir = self.global_position.direction_to(next_location).normalized()
if self.global_position.distance_to(player.global_position) > min_distance_to_player:
self.velocity = dir * delta * 60 * speed
update_animation()
if delta > 0.5:
print(delta)
move_and_slide()
@ -64,8 +66,19 @@ func sub_on_death(callback : Callable):
on_death_callbacks.push_front(callback)
pass
func update_animation():
var move_vector = Vector2(1 if velocity.x > 0 else (-1 if velocity.x < 0 else 0), 1 if velocity.y > 0 else (-1 if velocity.y < 0 else 0))
match move_vector:
Vector2.ZERO: animation_player.play("Idle")
Vector2.LEFT: animation_player.play("MoveLeft")
Vector2.RIGHT: animation_player.play("MoveRight")
Vector2.UP: animation_player.play("MoveUp")
Vector2.DOWN: animation_player.play("MoveDown")
_: handle_diagonal_animations(move_vector)
pass
func handle_diagonal_animations(dir : Vector2):
if (dir.y > 0 and dir.x < 0) or (dir.y < 0 and dir.x < 0): animation_player.play("MoveLeft")
elif (dir.y > 0 and dir.x > 0) or (dir.y < 0 and dir.x > 0): animation_player.play("MoveRight")
else: animation_player.play("Idle")
pass