added player animations for walking
This commit is contained in:
BIN
assets/textures/debug/dummy-player-atlas.png
Normal file
BIN
assets/textures/debug/dummy-player-atlas.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
34
assets/textures/debug/dummy-player-atlas.png.import
Normal file
34
assets/textures/debug/dummy-player-atlas.png.import
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://olceowuycu8c"
|
||||||
|
path="res://.godot/imported/dummy-player-atlas.png-68f05802eecc35f4774851352daddd72.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/textures/debug/dummy-player-atlas.png"
|
||||||
|
dest_files=["res://.godot/imported/dummy-player-atlas.png-68f05802eecc35f4774851352daddd72.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/bptc_ldr=0
|
||||||
|
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
|
Binary file not shown.
Before Width: | Height: | Size: 576 B After Width: | Height: | Size: 552 B |
@@ -1,19 +1,61 @@
|
|||||||
[gd_scene load_steps=5 format=3 uid="uid://ujfhvssvbgpg"]
|
[gd_scene load_steps=13 format=3 uid="uid://ujfhvssvbgpg"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"]
|
[ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"]
|
||||||
[ext_resource type="Texture2D" uid="uid://377657cxmdpa" path="res://assets/textures/debug/dummy-player-normal.png" id="2_48656"]
|
[ext_resource type="Texture2D" uid="uid://olceowuycu8c" path="res://assets/textures/debug/dummy-player-atlas.png" id="2_yu1q5"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_tirvd"]
|
||||||
|
atlas = ExtResource("2_yu1q5")
|
||||||
|
region = Rect2(0, 0, 84, 128)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_0qv2m"]
|
||||||
|
atlas = ExtResource("2_yu1q5")
|
||||||
|
region = Rect2(84, 0, 84, 128)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_qomfj"]
|
||||||
|
atlas = ExtResource("2_yu1q5")
|
||||||
|
region = Rect2(168, 0, 84, 128)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_ulejc"]
|
||||||
|
atlas = ExtResource("2_yu1q5")
|
||||||
|
region = Rect2(252, 0, 84, 128)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_1x805"]
|
||||||
|
atlas = ExtResource("2_yu1q5")
|
||||||
|
region = Rect2(252, 128, 84, 128)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_x338k"]
|
||||||
|
atlas = ExtResource("2_yu1q5")
|
||||||
|
region = Rect2(0, 128, 84, 128)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_6ynw8"]
|
||||||
|
atlas = ExtResource("2_yu1q5")
|
||||||
|
region = Rect2(84, 128, 84, 128)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_2yirn"]
|
||||||
|
atlas = ExtResource("2_yu1q5")
|
||||||
|
region = Rect2(168, 128, 84, 128)
|
||||||
|
|
||||||
[sub_resource type="SpriteFrames" id="SpriteFrames_2x1cy"]
|
[sub_resource type="SpriteFrames" id="SpriteFrames_2x1cy"]
|
||||||
animations = [{
|
animations = [{
|
||||||
"frames": [ExtResource("2_48656")],
|
"frames": [SubResource("AtlasTexture_tirvd"), SubResource("AtlasTexture_0qv2m"), SubResource("AtlasTexture_tirvd"), SubResource("AtlasTexture_qomfj")],
|
||||||
"loop": true,
|
"loop": true,
|
||||||
"name": &"default",
|
"name": &"move_down",
|
||||||
"speed": 5.0
|
"speed": 8.0
|
||||||
|
}, {
|
||||||
|
"frames": [SubResource("AtlasTexture_ulejc"), SubResource("AtlasTexture_1x805")],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"move_side",
|
||||||
|
"speed": 8.0
|
||||||
|
}, {
|
||||||
|
"frames": [SubResource("AtlasTexture_x338k"), SubResource("AtlasTexture_6ynw8"), SubResource("AtlasTexture_x338k"), SubResource("AtlasTexture_2yirn")],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"move_up",
|
||||||
|
"speed": 8.0
|
||||||
}]
|
}]
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_38v5o"]
|
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_38v5o"]
|
||||||
radius = 18.057
|
radius = 18.057
|
||||||
height = 56.0051
|
height = 43.9998
|
||||||
|
|
||||||
[node name="player" type="CharacterBody2D"]
|
[node name="player" type="CharacterBody2D"]
|
||||||
process_mode = 1
|
process_mode = 1
|
||||||
@@ -23,6 +65,7 @@ script = ExtResource("1_qehox")
|
|||||||
position = Vector2(-0.0625, -17.0625)
|
position = Vector2(-0.0625, -17.0625)
|
||||||
scale = Vector2(0.733398, 0.733398)
|
scale = Vector2(0.733398, 0.733398)
|
||||||
frames = SubResource("SpriteFrames_2x1cy")
|
frames = SubResource("SpriteFrames_2x1cy")
|
||||||
|
animation = &"move_down"
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
position = Vector2(0, 12)
|
position = Vector2(0, 12)
|
||||||
|
@@ -7,18 +7,12 @@ public partial class player : CharacterBody2D
|
|||||||
public string playerName;
|
public string playerName;
|
||||||
[Export]
|
[Export]
|
||||||
public int speed = 400;
|
public int speed = 400;
|
||||||
|
public Vector2 velocity;
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
MoveAndCollide(new Vector2
|
velocity = Input.GetVector("move_left", "move_right", "move_up", "move_down").LimitLength(1);
|
||||||
(
|
MoveAndCollide(velocity * speed * (float)delta);
|
||||||
Input.GetActionStrength("move_right")
|
|
||||||
- Input.GetActionStrength("move_left"),
|
|
||||||
Input.GetActionStrength("move_down")
|
|
||||||
- Input.GetActionStrength("move_up")
|
|
||||||
).LimitLength(1)
|
|
||||||
* speed * (float)delta
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
public void ChangeProcess(bool process){ if(process) ProcessMode = ProcessModeEnum.Inherit; else ProcessMode = ProcessModeEnum.Disabled; }
|
public void ChangeProcess(bool process){ if(process) ProcessMode = ProcessModeEnum.Inherit; else ProcessMode = ProcessModeEnum.Disabled; }
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
@@ -29,9 +23,30 @@ public partial class player : CharacterBody2D
|
|||||||
if (Input.IsActionJustPressed("move_left")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(-raylength, 0);
|
if (Input.IsActionJustPressed("move_left")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(-raylength, 0);
|
||||||
if (Input.IsActionJustPressed("move_down")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, raylength);
|
if (Input.IsActionJustPressed("move_down")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, raylength);
|
||||||
if (Input.IsActionJustPressed("move_up")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, -raylength);
|
if (Input.IsActionJustPressed("move_up")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, -raylength);
|
||||||
|
|
||||||
//call event in raycasted object
|
//call event in raycasted object
|
||||||
if (Input.IsActionJustPressed("ui_accept") && GetNode<RayCast2D>("ray_cast_2d").IsColliding())
|
if (Input.IsActionJustPressed("ui_accept") && GetNode<RayCast2D>("ray_cast_2d").IsColliding())
|
||||||
GetNode<RayCast2D>("ray_cast_2d").GetCollider().Call("OnInteraction", playerName);
|
GetNode<RayCast2D>("ray_cast_2d").GetCollider().Call("OnInteraction", playerName);
|
||||||
|
//animation system (with controller support wcih cant get normalized vector)
|
||||||
|
var animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
|
||||||
|
if (velocity.Length() != 0)
|
||||||
|
animatedSprite.Play();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
animatedSprite.Frame = 0;
|
||||||
|
animatedSprite.Stop();
|
||||||
|
}
|
||||||
|
if (Input.IsActionPressed("move_right") || Input.IsActionPressed("move_left"))
|
||||||
|
{
|
||||||
|
animatedSprite.Animation = "move_side";
|
||||||
|
animatedSprite.FlipH = velocity.x < 0.5;
|
||||||
|
animatedSprite.SpeedScale = Math.Abs(velocity.x);
|
||||||
|
}
|
||||||
|
else if (Input.IsActionPressed("move_up") || Input.IsActionPressed("move_down"))
|
||||||
|
{
|
||||||
|
if (velocity.y > 0.05) animatedSprite.Animation = "move_down";
|
||||||
|
if (velocity.y < 0.05) animatedSprite.Animation = "move_up";
|
||||||
|
animatedSprite.FlipH = false;
|
||||||
|
animatedSprite.SpeedScale = Math.Abs(velocity.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user