-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Developed player character and its animations
- Loading branch information
1 parent
d018100
commit 487198e
Showing
5 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://n8ohc7onas8v" | ||
path="res://.godot/imported/Character.png-bbf5947120bf90fb25be265ba323242e.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://Character.png" | ||
dest_files=["res://.godot/imported/Character.png-bbf5947120bf90fb25be265ba323242e.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Citation: https://docs.godotengine.org/en/stable/getting_started/first_2d_game/02.player_scene.html | ||
# Character Images by Antifarea: https://opengameart.org/content/twelve-more-16x18-rpg-character-sprites | ||
|
||
extends Area2D | ||
signal hit | ||
|
||
|
||
# Establish how fast the player will move (pixels/sec) | ||
@export var speed = 300 | ||
# Establish screen size of the game window | ||
var screen_size | ||
|
||
|
||
# Call when the node enters the scene tree for the first time | ||
func _ready(): | ||
# hide() | ||
screen_size = get_viewport_rect().size | ||
start(screen_size / 2) | ||
|
||
|
||
# Move the player by detecting associated keyboard presses with up, down, etc. | ||
func _process(delta): | ||
var velocity = Vector2.ZERO | ||
if Input.is_action_pressed("move_right"): | ||
velocity.x += 1 | ||
if Input.is_action_pressed("move_left"): | ||
velocity.x -= 1 | ||
if Input.is_action_pressed("move_down"): | ||
velocity.y += 1 | ||
if Input.is_action_pressed("move_up"): | ||
velocity.y -= 1 | ||
position += velocity * delta * speed | ||
|
||
# Animate the player based on direction of movement | ||
if velocity.x > 0: | ||
$AnimatedSprite2D.animation = "walk_right" | ||
elif velocity.x < 0: | ||
$AnimatedSprite2D.animation = "walk_left" | ||
elif velocity.y < 0: | ||
$AnimatedSprite2D.animation = "walk_up" | ||
elif velocity.y > 0: | ||
$AnimatedSprite2D.animation = "walk_down" | ||
|
||
|
||
func _on_body_entered(body): | ||
# Make the player disappear after being hit by a mob then a signal is emitted | ||
hide() | ||
hit.emit() | ||
# Disable the player's collision so that the hit signal is not hit more than once | ||
$CollisionShape2D.set_deferred("disabled", true) | ||
|
||
|
||
# Call to reset the player when starting a new game | ||
func start(pos): | ||
position = pos | ||
show() | ||
$CollisionShape2D.disabled = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
[gd_scene load_steps=13 format=3 uid="uid://q0r8m30rtu5m"] | ||
|
||
[ext_resource type="Script" path="res://player.gd" id="1_n0yeq"] | ||
[ext_resource type="Texture2D" uid="uid://n8ohc7onas8v" path="res://Character.png" id="2_c3qmv"] | ||
|
||
[sub_resource type="AtlasTexture" id="AtlasTexture_wn7rk"] | ||
atlas = ExtResource("2_c3qmv") | ||
region = Rect2(2, 36, 16, 18) | ||
|
||
[sub_resource type="AtlasTexture" id="AtlasTexture_dy8vt"] | ||
atlas = ExtResource("2_c3qmv") | ||
region = Rect2(34, 36, 16, 18) | ||
|
||
[sub_resource type="AtlasTexture" id="AtlasTexture_cjiu1"] | ||
atlas = ExtResource("2_c3qmv") | ||
region = Rect2(1, 54, 16, 18) | ||
|
||
[sub_resource type="AtlasTexture" id="AtlasTexture_7inig"] | ||
atlas = ExtResource("2_c3qmv") | ||
region = Rect2(33, 54, 16, 18) | ||
|
||
[sub_resource type="AtlasTexture" id="AtlasTexture_mhsis"] | ||
atlas = ExtResource("2_c3qmv") | ||
region = Rect2(2, 18, 16, 18) | ||
|
||
[sub_resource type="AtlasTexture" id="AtlasTexture_kvsem"] | ||
atlas = ExtResource("2_c3qmv") | ||
region = Rect2(34, 18, 16, 18) | ||
|
||
[sub_resource type="AtlasTexture" id="AtlasTexture_bqxl4"] | ||
atlas = ExtResource("2_c3qmv") | ||
region = Rect2(1, 0, 16, 18) | ||
|
||
[sub_resource type="AtlasTexture" id="AtlasTexture_5h77f"] | ||
atlas = ExtResource("2_c3qmv") | ||
region = Rect2(33, 0, 16, 18) | ||
|
||
[sub_resource type="SpriteFrames" id="SpriteFrames_alulf"] | ||
animations = [{ | ||
"frames": [{ | ||
"duration": 1.0, | ||
"texture": SubResource("AtlasTexture_wn7rk") | ||
}, { | ||
"duration": 1.0, | ||
"texture": SubResource("AtlasTexture_dy8vt") | ||
}], | ||
"loop": true, | ||
"name": &"walk_down", | ||
"speed": 5.0 | ||
}, { | ||
"frames": [{ | ||
"duration": 1.0, | ||
"texture": SubResource("AtlasTexture_cjiu1") | ||
}, { | ||
"duration": 1.0, | ||
"texture": SubResource("AtlasTexture_7inig") | ||
}], | ||
"loop": true, | ||
"name": &"walk_left", | ||
"speed": 5.0 | ||
}, { | ||
"frames": [{ | ||
"duration": 1.0, | ||
"texture": SubResource("AtlasTexture_mhsis") | ||
}, { | ||
"duration": 1.0, | ||
"texture": SubResource("AtlasTexture_kvsem") | ||
}], | ||
"loop": true, | ||
"name": &"walk_right", | ||
"speed": 5.0 | ||
}, { | ||
"frames": [{ | ||
"duration": 1.0, | ||
"texture": SubResource("AtlasTexture_bqxl4") | ||
}, { | ||
"duration": 1.0, | ||
"texture": SubResource("AtlasTexture_5h77f") | ||
}], | ||
"loop": true, | ||
"name": &"walk_up", | ||
"speed": 5.0 | ||
}] | ||
|
||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_gs5fv"] | ||
size = Vector2(46, 51) | ||
|
||
[node name="Player" type="Area2D"] | ||
position = Vector2(0, 5) | ||
script = ExtResource("1_n0yeq") | ||
metadata/_edit_group_ = true | ||
|
||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] | ||
position = Vector2(-1.43051e-06, 0) | ||
scale = Vector2(3.375, 3) | ||
sprite_frames = SubResource("SpriteFrames_alulf") | ||
animation = &"walk_up" | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
position = Vector2(0, 0.5) | ||
shape = SubResource("RectangleShape2D_gs5fv") | ||
|
||
[connection signal="body_entered" from="." to="." method="_on_body_entered"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters