some workable stuff

This commit is contained in:
Victor Turgeon 2023-10-10 14:54:21 -04:00
parent b763efc1f6
commit 2687a2fdfe
7 changed files with 70 additions and 25 deletions

View File

@ -0,0 +1,20 @@
[gd_scene load_steps=4 format=3 uid="uid://vd3ffjat2jln"]
[ext_resource type="PackedScene" uid="uid://b8s2seg2lf7wo" path="res://Scenes/Tilemaps/tileset_1.tscn" id="1_287nl"]
[ext_resource type="PackedScene" uid="uid://b5lnjonlf4i1b" path="res://Scenes/enemy.tscn" id="2_ftshv"]
[ext_resource type="PackedScene" uid="uid://brnx3xyyd0e71" path="res://Scenes/Spawnables/bat_spawnable.tscn" id="3_a1ucf"]
[node name="Level1" type="Node2D"]
[node name="TileSet1" parent="." instance=ExtResource("1_287nl")]
[node name="Decor" type="Node2D" parent="."]
[node name="Enemy" parent="." instance=ExtResource("2_ftshv")]
position = Vector2(998, 507)
[node name="BatSpawnable" parent="." instance=ExtResource("3_a1ucf")]
position = Vector2(805, 420)
[node name="BatSpawnable2" parent="." instance=ExtResource("3_a1ucf")]
position = Vector2(1201, 446)

View File

@ -1,4 +1,4 @@
extends AITemplate
func getDirection(position, enemyPosition) -> Vector2:
return Vector2.ZERO
return Vector2(enemyPosition - position).normalized()

View File

@ -6,7 +6,7 @@
[node name="BatSpawnable" instance=ExtResource("1_verf7")]
maxHp = 10
attackSpeed = 10.0
speed = 100.0
speed = 2000.0
damage = 1
priority = 1

View File

@ -6,11 +6,13 @@ extends CharacterBody2D
@export var speed : float = 0
@export var damage : int = 0
@export var priority : int = 0
@export var canAttack : bool = true
@onready var ai : Node = $AI
@onready var animatedSprite : AnimatedSprite2D = $AnimatedSprite2D
var isAlive : bool = true
var isFacingLeft : bool = false
var direction : Vector2 = Vector2.ZERO
var enemy : CharacterBody2D = null
@ -27,19 +29,28 @@ func _process(delta):
return
if enemy != null:
direction = ai.getDirection(position, enemy.position)
direction = ai.getDirection(global_position, enemy.global_position)
else:
direction = Vector2.ZERO
if !isFacingLeft && velocity.x >= 0:
isFacingLeft = true
scale = Vector2(1, 1)
elif isFacingLeft && velocity.x < 0:
isFacingLeft = false
scale = Vector2(-1, 1)
velocity = direction * speed * delta
move_and_slide()
func attack(target):
func attack():
if !canAttack || !isAlive:
return
animatedSprite.play("attack")
animatedSprite.connect("animation_finished", endAttack(target))
animatedSprite.connect("animation_finished", endAttack)
func endAttack(target):
target.receive_damage(damage)
func endAttack():
animatedSprite.play("default")
func receive_damage(dmg):
@ -55,13 +66,13 @@ func receive_damage(dmg):
func die():
isAlive = false
animatedSprite.play("death")
animatedSprite.connect("animation_finished", self.fadeOut())
animatedSprite.connect("animation_finished", fadeOut)
func fadeOut():
var tween = Tween.new()
add_child(tween)
var tween = get_tree().create_tween()
tween.tween_property(animatedSprite, "modulate", Color(0,0,0,0), 1)
tween.tween_callback(clean())
tween.tween_callback(clean)
func clean():
queue_free()

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=36 format=3 uid="uid://kkfxguj0lr5a"]
[gd_scene load_steps=37 format=3 uid="uid://kkfxguj0lr5a"]
[ext_resource type="Script" path="res://Scenes/Spawnables/template_spawnable.gd" id="1_rkej7"]
[ext_resource type="Texture2D" uid="uid://f60ndepwmpj2" path="res://Assets/Bat/noBKG_BatAttack_strip.png" id="2_7ayi7"]
@ -150,7 +150,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_bxitd")
}],
"loop": true,
"loop": false,
"name": &"attack",
"speed": 12.0
}, {
@ -185,7 +185,7 @@ animations = [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_7bunh")
}],
"loop": true,
"loop": false,
"name": &"death",
"speed": 12.0
}, {
@ -224,8 +224,12 @@ radius = 6.0
height = 14.0
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_2l8j3"]
radius = 7.0
height = 22.0
radius = 4.0
height = 14.0
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_o2kl1"]
radius = 2.0
height = 16.0
[node name="TemplateSpawnable" type="CharacterBody2D"]
collision_layer = 6
@ -234,7 +238,9 @@ script = ExtResource("1_rkej7")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_k6v1d")
frame_progress = 0.107531
animation = &"attack"
frame = 7
frame_progress = 0.387978
[node name="BodyCollision" type="CollisionShape2D" parent="."]
rotation = 1.5708
@ -243,8 +249,15 @@ shape = SubResource("CapsuleShape2D_5aviq")
[node name="Attack" type="Area2D" parent="."]
[node name="AttackCollision" type="CollisionShape2D" parent="Attack"]
position = Vector2(1, 1)
rotation = 1.5708
shape = SubResource("CapsuleShape2D_2l8j3")
debug_color = Color(0.803922, 0, 0.180392, 0.419608)
debug_color = Color(0.678431, 0.556863, 0.137255, 0.419608)
[node name="DamageCollision" type="CollisionShape2D" parent="Attack"]
position = Vector2(2, 2)
rotation = 1.5708
shape = SubResource("CapsuleShape2D_o2kl1")
debug_color = Color(0.639216, 0, 0.156863, 0.419608)
[node name="AI" type="Node" parent="."]

View File

@ -445,3 +445,4 @@ debug_color = Color(0.956863, 0.203922, 0, 0.419608)
[connection signal="animation_looped" from="Sprite" to="." method="_on_sprite_animation_looped"]
[connection signal="timeout" from="Atk_cooldown" to="." method="_on_atk_cooldown_timeout"]
[connection signal="body_entered" from="AttackArea" to="." method="_on_attack_area_body_entered"]

View File

@ -12,6 +12,7 @@ extends CharacterBody2D
@export var maxvel: float = 2
@export var experience: int = 0
@export var state: String = "Idle"
@export var damage: int = 5
@onready var anim: Node = get_node("Sprite")
@onready var cooldown: Node = get_node("Atk_cooldown")
@ -35,14 +36,8 @@ func _process(delta):
# AI STUFF
#velocity = processAI(objects,velocity,delta)
velocity.x += delta
velocity.y += delta
if abs(velocity.x + velocity.y) > maxvel:
velocity.x *= maxvel / velocity.x
velocity.y *= maxvel / velocity.y
position += velocity
move_and_slide()
func processAI(objs, delta):
@ -116,3 +111,8 @@ func _on_sprite_animation_looped():
stop_attack()
is_dying = false
func _on_attack_area_body_entered(body):
if typeof(body) == typeof(TemplateSpawnable):
body.receive_damage(damage)