Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 88 additions & 9 deletions Scenes/enemy_1.tscn → Scenes/enemy.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
[gd_scene load_steps=26 format=3 uid="uid://camr3gvm2kgi0"]
[gd_scene load_steps=36 format=3 uid="uid://camr3gvm2kgi0"]

[ext_resource type="Texture2D" uid="uid://c432dkt1nanwf" path="res://Sprite Character/Enemy/Enemy (orc)/orc1_walk.png" id="1_dimyw"]
[ext_resource type="Script" uid="uid://k0yjavcp14rq" path="res://Scripts/enemy_1.gd" id="1_x361n"]
[ext_resource type="Script" uid="uid://k0yjavcp14rq" path="res://Scripts/enemy.gd" id="1_x361n"]
[ext_resource type="Texture2D" uid="uid://b2ev2c2ttr75p" path="res://Sprite Character/Enemy/Enemy (orc)/orc1_death.png" id="2_afpow"]

[sub_resource type="AtlasTexture" id="AtlasTexture_287tu"]
atlas = ExtResource("2_afpow")
region = Rect2(0, 0, 64, 64)

[sub_resource type="AtlasTexture" id="AtlasTexture_0830c"]
atlas = ExtResource("2_afpow")
region = Rect2(64, 0, 64, 64)

[sub_resource type="AtlasTexture" id="AtlasTexture_ghaa6"]
atlas = ExtResource("2_afpow")
region = Rect2(128, 0, 64, 64)

[sub_resource type="AtlasTexture" id="AtlasTexture_1dp5w"]
atlas = ExtResource("2_afpow")
region = Rect2(192, 0, 64, 64)

[sub_resource type="AtlasTexture" id="AtlasTexture_auwsv"]
atlas = ExtResource("2_afpow")
region = Rect2(256, 0, 64, 64)

[sub_resource type="AtlasTexture" id="AtlasTexture_8uf12"]
atlas = ExtResource("2_afpow")
region = Rect2(320, 0, 64, 64)

[sub_resource type="AtlasTexture" id="AtlasTexture_po0sg"]
atlas = ExtResource("2_afpow")
region = Rect2(384, 0, 64, 64)

[sub_resource type="AtlasTexture" id="AtlasTexture_haro7"]
atlas = ExtResource("2_afpow")
region = Rect2(448, 0, 64, 64)

[sub_resource type="AtlasTexture" id="AtlasTexture_0a874"]
atlas = ExtResource("1_dimyw")
Expand Down Expand Up @@ -87,6 +120,35 @@ region = Rect2(320, 64, 64, 64)
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_287tu")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_0830c")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ghaa6")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_1dp5w")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_auwsv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_8uf12")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_po0sg")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_haro7")
}],
"loop": true,
"name": &"die",
"speed": 10.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_0a874")
}, {
"duration": 1.0,
Expand Down Expand Up @@ -167,30 +229,47 @@ animations = [{
}]

[sub_resource type="CircleShape2D" id="CircleShape2D_dimyw"]
radius = 10.440307
radius = 8.0

[sub_resource type="CircleShape2D" id="CircleShape2D_qfyam"]
radius = 91.00549
radius = 100.0

[sub_resource type="CircleShape2D" id="CircleShape2D_0a874"]
radius = 19.026299

[node name="enemy" type="CharacterBody2D"]
collision_layer = 3
collision_mask = 3
script = ExtResource("1_x361n")

[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_x424e")
animation = &"idle"
animation = &"die"
autoplay = "idle"
frame_progress = 0.5748886
frame_progress = 0.054674506
offset = Vector2(0, -6)

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, -4)
position = Vector2(0, -8)
shape = SubResource("CircleShape2D_dimyw")

[node name="DetectionArea" type="Area2D" parent="."]
collision_layer = 2
collision_mask = 2
collision_layer = 4
collision_mask = 4

[node name="CollisionShape2D" type="CollisionShape2D" parent="DetectionArea"]
position = Vector2(0, -9)
shape = SubResource("CircleShape2D_qfyam")

[node name="enemy_hitbox" type="Area2D" parent="."]
collision_layer = 4
collision_mask = 4

[node name="CollisionShape2D" type="CollisionShape2D" parent="enemy_hitbox"]
position = Vector2(0, -8)
shape = SubResource("CircleShape2D_0a874")

[connection signal="body_entered" from="DetectionArea" to="." method="_on_detection_area_body_entered"]
[connection signal="body_exited" from="DetectionArea" to="." method="_on_detection_area_body_exited"]
[connection signal="body_entered" from="enemy_hitbox" to="." method="_on_enemy_hitbox_body_entered"]
[connection signal="body_exited" from="enemy_hitbox" to="." method="_on_enemy_hitbox_body_exited"]
18 changes: 2 additions & 16 deletions Scenes/game.tscn

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions Scenes/hudai.tscn

This file was deleted.

37 changes: 30 additions & 7 deletions Scenes/player.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=58 format=3 uid="uid://3nex5v62sryu"]
[gd_scene load_steps=59 format=3 uid="uid://3nex5v62sryu"]

[ext_resource type="Script" uid="uid://bobxei87ya0ba" path="res://Scripts/player.gd" id="1_cvnsp"]
[ext_resource type="Texture2D" uid="uid://crvqffvratr8w" path="res://Sprite Character/Player/walk_128.png" id="1_v0iea"]
Expand Down Expand Up @@ -265,7 +265,7 @@ animations = [{
}],
"loop": true,
"name": &"slashDown",
"speed": 10.0
"speed": 15.0
}, {
"frames": [{
"duration": 1.0,
Expand All @@ -288,7 +288,7 @@ animations = [{
}],
"loop": true,
"name": &"slashSide",
"speed": 10.0
"speed": 15.0
}, {
"frames": [{
"duration": 1.0,
Expand All @@ -311,7 +311,7 @@ animations = [{
}],
"loop": true,
"name": &"slashUp",
"speed": 10.0
"speed": 15.0
}, {
"frames": [{
"duration": 1.0,
Expand Down Expand Up @@ -412,17 +412,40 @@ animations = [{

[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_ikpov"]
radius = 11.0
height = 40.0
height = 44.0

[sub_resource type="CircleShape2D" id="CircleShape2D_vgqql"]
radius = 31.06445

[node name="Player" type="CharacterBody2D"]
collision_layer = 7
collision_mask = 7
script = ExtResource("1_cvnsp")

[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(0, -3)
sprite_frames = SubResource("SpriteFrames_ewr8r")
animation = &"idleDown"
animation = &"slashUp"
autoplay = "idleDown"
frame_progress = 0.079561815

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 7)
position = Vector2(0, 2)
shape = SubResource("CapsuleShape2D_ikpov")

[node name="player_hitbox" type="Area2D" parent="."]

[node name="CollisionShape2D" type="CollisionShape2D" parent="player_hitbox"]
position = Vector2(0, 4)
shape = SubResource("CircleShape2D_vgqql")

[node name="attack_cooldown" type="Timer" parent="."]
wait_time = 0.5

[node name="deal_attack_timer" type="Timer" parent="."]
wait_time = 0.5

[connection signal="body_entered" from="player_hitbox" to="." method="_on_player_hitbox_body_entered"]
[connection signal="body_exited" from="player_hitbox" to="." method="_on_player_hitbox_body_exited"]
[connection signal="timeout" from="attack_cooldown" to="." method="_on_attack_cooldown_timeout"]
[connection signal="timeout" from="deal_attack_timer" to="." method="_on_deal_attack_timer_timeout"]
31 changes: 28 additions & 3 deletions Scripts/enemy_1.gd → Scripts/enemy.gd
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
extends CharacterBody2D

var speed = 50
var speed = 70
var player = null
var player_chase = false

var health = 100
var player_inattack_range = false

@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D


func enemy():
pass

func _physics_process(delta: float) -> void:
deal_with_damage()

if player_chase:
animated_sprite.play("walkDown")
position += (player.position - position)/speed
else:
animated_sprite.play("idle")



func _on_detection_area_body_entered(body: Node2D) -> void:
player = body
player_chase = true

func _on_detection_area_body_exited(body: Node2D) -> void:
player = null
player_chase = false

func _on_enemy_hitbox_body_entered(body: Node2D) -> void:
if body.has_method("player"):
player_inattack_range = true


func _on_enemy_hitbox_body_exited(body: Node2D) -> void:
if body.has_method("player"):
player_inattack_range = false

func deal_with_damage():
if player_inattack_range and Global.player_current_attack == true:
health = health - 20
print("enemy health: ", health)
if health <= 0:
self.queue_free()

File renamed without changes.
3 changes: 3 additions & 0 deletions Scripts/global.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extends Node

var player_current_attack = false
1 change: 1 addition & 0 deletions Scripts/global.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://c6xsutet740sc
82 changes: 78 additions & 4 deletions Scripts/player.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
extends CharacterBody2D

var enemy_inattack_range = false
var enemy_attack_cooldown = true
var health = 100
var player_alive = true

var attack_ip = false

const SPEED = 200.0
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
@onready var attack_cooldown: Timer = $attack_cooldown
@onready var deal_attack_timer: Timer = $deal_attack_timer

func _ready() -> void:
animated_sprite.play("downIdle")

func _physics_process(delta: float) -> void:
player_movement(delta)
enemy_attack()
attack()

if health <= 0:
player_alive = false #end screen add
health = 0
print("Player has been killed")
self.queue_free()

var current_dir

func player_movement(delta):
if Input.is_action_pressed("Left"):
current_dir = "left"
Expand Down Expand Up @@ -45,23 +64,78 @@ func play_anim(movement):
if movement == 1:
animated_sprite.play("walkSide")
else:
animated_sprite.play("idleSide")
if attack_ip == false:
animated_sprite.play("idleSide")
elif dir == "left":
animated_sprite.flip_h = true
if movement == 1:
animated_sprite.play("walkSide")
else:
animated_sprite.play("idleSide")
if attack_ip == false:
animated_sprite.play("idleSide")
elif dir == "down":
animated_sprite.flip_h = false
if movement == 1:
animated_sprite.play("walkDown")
else:
animated_sprite.play("idleDown")
if attack_ip == false:
animated_sprite.play("idleDown")
elif dir == "up":
animated_sprite.flip_h = false
if movement == 1:
animated_sprite.play("walkUp")
else:
animated_sprite.play("idleUp")
if attack_ip == false:
animated_sprite.play("idleUp")

func player():
pass

func _on_player_hitbox_body_entered(body: Node2D) -> void:
if body.has_method("enemy"):
enemy_inattack_range = true


func _on_player_hitbox_body_exited(body: Node2D) -> void:
if body.has_method("enemy"):
enemy_inattack_range = false

func enemy_attack():
if enemy_inattack_range and enemy_attack_cooldown == true:
health = health - 20
enemy_attack_cooldown = false
attack_cooldown.start()
print(health)


func _on_attack_cooldown_timeout() -> void:
enemy_attack_cooldown = true

func attack():
var dir = current_dir

if Input.is_action_just_pressed("Slash"):
Global.player_current_attack = true
attack_ip = true
if dir == "right":
animated_sprite.flip_h = false
animated_sprite.play("slashSide")
deal_attack_timer.start()
if dir == "left":
animated_sprite.flip_h = true
animated_sprite.play("slashSide")
deal_attack_timer.start()
if dir == "up":
animated_sprite.flip_h = false
animated_sprite.play("slashUp")
deal_attack_timer.start()
if dir == "down":
animated_sprite.flip_h = false
animated_sprite.play("slashDown")
deal_attack_timer.start()


func _on_deal_attack_timer_timeout() -> void:
deal_attack_timer.stop()
Global.player_current_attack = false
attack_ip = false
Loading