Добавлен Павший

This commit is contained in:
Евгений Титаренко 2023-08-19 09:30:55 +03:00
parent 7c9a71504c
commit 429fe9b62f
12 changed files with 404 additions and 9 deletions

View file

@ -0,0 +1,41 @@
[gd_scene load_steps=6 format=3 uid="uid://bmyjqerhno5vi"]
[ext_resource type="SpriteFrames" uid="uid://blijqhtsnyq7n" path="res://sprites/enemies/wretched/wretched.tres" id="1_aqrsj"]
[ext_resource type="Script" path="res://scripts/enemies/Wretched.cs" id="1_ec388"]
[ext_resource type="PackedScene" uid="uid://cf0wpahgwygxx" path="res://prefabs/light_sense.tscn" id="2_16fib"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_svj4b"]
size = Vector2(24, 16)
[sub_resource type="CircleShape2D" id="CircleShape2D_nortt"]
radius = 15.0
[node name="Wretched" type="CharacterBody2D"]
collision_layer = 5
collision_mask = 5
script = ExtResource("1_ec388")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = ExtResource("1_aqrsj")
animation = &"NonActivatedUp"
frame_progress = 0.776966
[node name="Sprite2D" type="Sprite2D" parent="AnimatedSprite2D"]
[node name="LightSense" parent="." instance=ExtResource("2_16fib")]
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="LightSense"]
polygon = PackedVector2Array(-5, -16, -7, -3, -7, 9, -11, 14, -11, 16, 8, 16, 8, 8, 7, 4, 7, -16)
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(1, 8)
shape = SubResource("RectangleShape2D_svj4b")
[node name="PlayerCollision" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerCollision"]
position = Vector2(1, 8)
shape = SubResource("CircleShape2D_nortt")
[connection signal="area_entered" from="LightSense" to="." method="_OnLightEntered"]
[connection signal="body_entered" from="PlayerCollision" to="." method="_OnPlayerCollision"]

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://dqx43vr727ft8"]
[ext_resource type="Script" path="res://scripts/entities/Spikes.cs" id="1_r27mb"]
[ext_resource type="SpriteFrames" uid="uid://0xgmr60v1vxg" path="res://sprites/tiles/floor/spikes/spikes.tres" id="2_t76h0"]
[ext_resource type="SpriteFrames" uid="uid://uith5rxps4s" path="res://sprites/tiles/floor/spikes/spikes.tres" id="2_t76h0"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_guqiy"]
size = Vector2(32, 32)

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=26 format=3 uid="uid://dhn7yt46fyac8"]
[gd_scene load_steps=27 format=3 uid="uid://dhn7yt46fyac8"]
[ext_resource type="PackedScene" uid="uid://bhulqhxesd5gc" path="res://prefabs/player.tscn" id="1_65a7v"]
[ext_resource type="AudioStream" uid="uid://bsy2d0bl3lgg0" path="res://sounds/crank.ogg" id="1_cweq4"]
@ -15,6 +15,7 @@
[ext_resource type="PackedScene" uid="uid://bj1ixwjdpnooo" path="res://prefabs/entities/pressure_plate.tscn" id="12_ynt5e"]
[ext_resource type="PackedScene" uid="uid://dqx43vr727ft8" path="res://prefabs/entities/spikes.tscn" id="13_w1hk1"]
[ext_resource type="Script" path="res://scripts/DeathScreen.cs" id="15_12mhe"]
[ext_resource type="PackedScene" uid="uid://bmyjqerhno5vi" path="res://prefabs/enemies/wretched.tscn" id="16_wjfbi"]
[sub_resource type="Curve" id="Curve_o5byr"]
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0]
@ -26,7 +27,7 @@ light_mode = 2
[sub_resource type="ShaderMaterial" id="ShaderMaterial_m680d"]
shader = ExtResource("5_64d71")
[sub_resource type="ViewportTexture" id="ViewportTexture_slh0c"]
[sub_resource type="ViewportTexture" id="ViewportTexture_pqovb"]
viewport_path = NodePath("FlashlightViewport")
[sub_resource type="CircleShape2D" id="CircleShape2D_prnh4"]
@ -122,7 +123,7 @@ CameraBounds = Vector2(30, 20)
[node name="PointLight2D" type="PointLight2D" parent="PlayerCamera" node_paths=PackedStringArray("LightViewport")]
blend_mode = 2
range_item_cull_mask = 2
texture = SubResource("ViewportTexture_slh0c")
texture = SubResource("ViewportTexture_pqovb")
script = ExtResource("6_slohe")
LightViewport = NodePath("../../FlashlightViewport")
@ -227,4 +228,19 @@ Enabled = true
SpikesTimeout = 0.5
StartOffset = 0.5
[node name="Wretched" parent="." instance=ExtResource("16_wjfbi")]
position = Vector2(-84, 12)
[node name="Wretched2" parent="." instance=ExtResource("16_wjfbi")]
position = Vector2(-108, 30)
Facing = 2
[node name="Wretched3" parent="." instance=ExtResource("16_wjfbi")]
position = Vector2(-64, 29)
Facing = 0
[node name="Wretched4" parent="." instance=ExtResource("16_wjfbi")]
position = Vector2(-85, 51)
Facing = 1
[connection signal="timeout" from="CanvasLayer/DeathScreen/Timer" to="CanvasLayer/DeathScreen" method="Timeout"]

161
scripts/enemies/Wretched.cs Normal file
View file

@ -0,0 +1,161 @@
using Godot;
using System;
public partial class Wretched : CharacterBody2D
{
[Signal]
public delegate void KilledEventHandler();
public enum State
{
Waiting,
Moving,
Attack
}
public enum SideFace
{
Left,
Up,
Right,
Down
}
[Export] public SideFace Facing = SideFace.Down;
[Export] public float MovingSpeed = 32f;
[Export] public bool IsAlive = true;
public State CurrentState
{
get => _state;
private set
{
_state = value;
_timeSinceState = 0;
switch (_state)
{
case State.Waiting:
break;
case State.Moving:
break;
case State.Attack:
break;
}
}
}
private State _state;
private float _timeSinceState;
private AnimatedSprite2D _sprite;
private bool _isActivated;
public override void _Ready()
{
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
CurrentState = State.Waiting;
var animationName = "NonActivatedSide";
switch (Facing)
{
case SideFace.Left:
_sprite.FlipH = true;
break;
case SideFace.Right:
break;
case SideFace.Up:
animationName = "NonActivatedUp";
break;
case SideFace.Down:
animationName = "NonActivatedDown";
break;
}
_sprite.Play(animationName);
_sprite.Stop();
}
public override void _Process(double delta)
{
}
public override void _PhysicsProcess(double delta)
{
if (!IsAlive)
return;
_timeSinceState += (float)delta;
switch (_state)
{
case State.Attack:
break;
case State.Waiting:
break;
case State.Moving:
var direction = (Player.Instance.Position - Position).Normalized();
Velocity = direction * MovingSpeed;
var animationName = "ActivatedSide";
if (Velocity.Y > 0.001f)
animationName = "ActivatedDown";
else if (Velocity.Y < 0.001f)
animationName = "ActivatedUp";
if (Mathf.Abs(Velocity.X) >= Mathf.Abs(Velocity.Y))
animationName = "ActivatedSide";
_sprite.FlipH = Velocity.X < 0.001f && animationName == "ActivatedSide";
_sprite.Play(animationName);
MoveAndSlide();
break;
}
CheckIfLitUp();
}
private void _OnLightEntered(Area2D area)
{
if (area.GetParentOrNull<GameCamera>() is null)
return;
_isActivated = true;
}
private void _OnPlayerCollision(Node2D body)
{
if (body is not Player player)
return;
if (CurrentState is State.Waiting)
return;
player.Kill(this);
}
void CheckIfLitUp()
{
if (!_isActivated)
{
CurrentState = State.Waiting;
return;
}
if (CurrentState is State.Moving or State.Attack)
return;
CurrentState = State.Moving;
}
public void Kill(Node2D killer)
{
if (!IsAlive)
return;
GD.Print($"{this.Name} was killed by {killer.Name}");
IsAlive = false;
EmitSignal(SignalName.Killed);
QueueFree(); // TODO
}
}

View file

@ -58,13 +58,19 @@ public partial class Spikes : Area2D
private void _OnEntered(Node2D body)
{
if (body is not Player player)
return;
if (_state is State.Waiting)
return;
player.Kill(this);
switch (body)
{
case Wretched wretched:
wretched.Kill(this);
break;
case Player player:
player.Kill(this);
break;
default:
return;
}
}

View file

@ -0,0 +1,171 @@
[gd_resource type="SpriteFrames" load_steps=23 format=3 uid="uid://blijqhtsnyq7n"]
[ext_resource type="Texture2D" uid="uid://jt8w0gpcde42" path="res://sprites/enemies/wretched/wretched_bottom.png" id="1_42h2f"]
[ext_resource type="Texture2D" uid="uid://dx8chnbe6vmow" path="res://sprites/enemies/wretched/wretched_side.png" id="2_8muft"]
[ext_resource type="Texture2D" uid="uid://ceffjiq2vofiu" path="res://sprites/enemies/wretched/wretched_up.png" id="3_y353x"]
[sub_resource type="AtlasTexture" id="AtlasTexture_e1ng1"]
atlas = ExtResource("1_42h2f")
region = Rect2(32, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_h7wwv"]
atlas = ExtResource("1_42h2f")
region = Rect2(64, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_d2riq"]
atlas = ExtResource("1_42h2f")
region = Rect2(96, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_j1sxl"]
atlas = ExtResource("1_42h2f")
region = Rect2(128, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_1tjil"]
atlas = ExtResource("1_42h2f")
region = Rect2(160, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_qo1on"]
atlas = ExtResource("1_42h2f")
region = Rect2(192, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_gd2f2"]
atlas = ExtResource("2_8muft")
region = Rect2(32, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_j1id5"]
atlas = ExtResource("2_8muft")
region = Rect2(64, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_jujmv"]
atlas = ExtResource("2_8muft")
region = Rect2(96, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_5cpt1"]
atlas = ExtResource("2_8muft")
region = Rect2(128, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_8hfxb"]
atlas = ExtResource("3_y353x")
region = Rect2(32, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_t3n7s"]
atlas = ExtResource("3_y353x")
region = Rect2(64, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_k755r"]
atlas = ExtResource("3_y353x")
region = Rect2(96, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_7cl4u"]
atlas = ExtResource("3_y353x")
region = Rect2(128, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_3l3jb"]
atlas = ExtResource("3_y353x")
region = Rect2(160, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_xtic1"]
atlas = ExtResource("3_y353x")
region = Rect2(192, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_gj6u3"]
atlas = ExtResource("1_42h2f")
region = Rect2(0, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_8toq8"]
atlas = ExtResource("2_8muft")
region = Rect2(0, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_d30l2"]
atlas = ExtResource("3_y353x")
region = Rect2(0, 0, 32, 32)
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_e1ng1")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_h7wwv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_d2riq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_j1sxl")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_1tjil")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qo1on")
}],
"loop": true,
"name": &"ActivatedDown",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_gd2f2")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_j1id5")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_jujmv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_5cpt1")
}],
"loop": true,
"name": &"ActivatedSide",
"speed": 6.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_8hfxb")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_t3n7s")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_k755r")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_7cl4u")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_3l3jb")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xtic1")
}],
"loop": true,
"name": &"ActivatedUp",
"speed": 6.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_gj6u3")
}],
"loop": true,
"name": &"NonActivatedDown",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_8toq8")
}],
"loop": true,
"name": &"NonActivatedSide",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_d30l2")
}],
"loop": true,
"name": &"NonActivatedUp",
"speed": 5.0
}]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 946 B

After

Width:  |  Height:  |  Size: 917 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

After

Width:  |  Height:  |  Size: 833 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 855 B

After

Width:  |  Height:  |  Size: 812 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 946 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 862 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 855 B