Skip to content

Commit

Permalink
Developed player character and its animations
Browse files Browse the repository at this point in the history
  • Loading branch information
KellyLTran committed Apr 6, 2024
1 parent d018100 commit 487198e
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 0 deletions.
Binary file added Character.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Character.png.import
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
57 changes: 57 additions & 0 deletions player.gd
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
103 changes: 103 additions & 0 deletions player.tscn
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"]
24 changes: 24 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,29 @@ config_version=5
[application]

config/name="Mental Maze"
run/main_scene="res://player.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg"

[input]

move_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
move_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
move_up={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
move_down={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}

0 comments on commit 487198e

Please sign in to comment.