Skip to content

Commit

Permalink
Rewrite Projectile to use Area2D
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumlamm committed Apr 16, 2024
1 parent 55251f6 commit 4284c1b
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 111 deletions.
11 changes: 5 additions & 6 deletions src/scenes/projectiles/fireball.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource type="PackedScene" uid="uid://dyqpiguafbprl" path="res://scenes/projectiles/projectile.tscn" id="1_bb8xt"]

[sub_resource type="CircleShape2D" id="CircleShape2D_dlco6"]
[sub_resource type="CircleShape2D" id="CircleShape2D_ss7tq"]
resource_local_to_scene = true
radius = 3.0

Expand All @@ -12,12 +12,11 @@ speed = 140.0
ATTACK_DAMAGE = 18.0
KNOCKBACK_STRENGTH = 30.0

[node name="CollisionShape2D" parent="." index="0"]
position = Vector2(0, 0)
shape = SubResource("CircleShape2D_dlco6")

[node name="AnimatedSprite2D" parent="." index="1"]
[node name="AnimatedSprite2D" parent="." index="0"]
position = Vector2(-5, 1)
animation = &"fireball"
autoplay = "fireball"
frame_progress = 0.855749

[node name="CollisionShape2D" parent="." index="1"]
shape = SubResource("CircleShape2D_ss7tq")
19 changes: 9 additions & 10 deletions src/scenes/projectiles/firelike.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
[ext_resource type="PackedScene" uid="uid://dyqpiguafbprl" path="res://scenes/projectiles/projectile.tscn" id="1_1lx00"]
[ext_resource type="Texture2D" uid="uid://u8udjt605pon" path="res://assets/fireball.png" id="3_7k5d0"]

[sub_resource type="CircleShape2D" id="CircleShape2D_jf7y8"]
radius = 3.0

[sub_resource type="AtlasTexture" id="AtlasTexture_gv43n"]
atlas = ExtResource("3_7k5d0")
region = Rect2(0, 0, 16, 16)
Expand Down Expand Up @@ -70,18 +67,20 @@ animations = [{
"speed": 5.0
}]

[sub_resource type="CircleShape2D" id="CircleShape2D_jbsl1"]
resource_local_to_scene = true
radius = 3.0

[node name="Firelike" instance=ExtResource("1_1lx00")]
scale = Vector2(2, 2)
collision_mask = 80
speed = 50.0

[node name="CollisionShape2D" parent="." index="0"]
position = Vector2(0, 0)
shape = SubResource("CircleShape2D_jf7y8")

[node name="AnimatedSprite2D" parent="." index="1"]
position = Vector2(-13, -7)
[node name="AnimatedSprite2D" parent="." index="0"]
position = Vector2(-5, 1)
sprite_frames = SubResource("SpriteFrames_pbbgu")
animation = &"default"
autoplay = ""
centered = false

[node name="CollisionShape2D" parent="." index="1"]
shape = SubResource("CircleShape2D_jbsl1")
15 changes: 7 additions & 8 deletions src/scenes/projectiles/fish.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

[ext_resource type="PackedScene" uid="uid://dyqpiguafbprl" path="res://scenes/projectiles/projectile.tscn" id="1_hvx3w"]

[sub_resource type="CircleShape2D" id="CircleShape2D_kv7fu"]
[sub_resource type="CircleShape2D" id="CircleShape2D_0m4u6"]
resource_local_to_scene = true
radius = 5.0
radius = 3.0

[node name="Fish" instance=ExtResource("1_hvx3w")]
collision_mask = 32
speed = 120.0
ATTACK_DAMAGE = 2.0
KNOCKBACK_STRENGTH = 25.0
REMOVE_AFTER = 2.0
PIERCING = true
IS_FISH = true

[node name="CollisionShape2D" parent="." index="0"]
position = Vector2(0, 0)
shape = SubResource("CircleShape2D_kv7fu")

[node name="AnimatedSprite2D" parent="." index="1"]
animation = &"fish"
[node name="AnimatedSprite2D" parent="." index="0"]
autoplay = "fish"
speed_scale = 10.0

[node name="CollisionShape2D" parent="." index="1"]
shape = SubResource("CircleShape2D_0m4u6")
14 changes: 7 additions & 7 deletions src/scenes/projectiles/lightning.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

[ext_resource type="PackedScene" uid="uid://dyqpiguafbprl" path="res://scenes/projectiles/projectile.tscn" id="1_w1h7g"]

[sub_resource type="CircleShape2D" id="CircleShape2D_p8obe"]
resource_local_to_scene = true
radius = 3.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mtuls"]
size = Vector2(12, 8)

[node name="Lightning" instance=ExtResource("1_w1h7g")]
speed = 150.0
ATTACK_DAMAGE = 8.0

[node name="CollisionShape2D" parent="." index="0"]
shape = SubResource("CircleShape2D_p8obe")

[node name="AnimatedSprite2D" parent="." index="1"]
[node name="AnimatedSprite2D" parent="." index="0"]
animation = &"lightning"
autoplay = "lightning"

[node name="CollisionShape2D" parent="." index="1"]
shape = SubResource("RectangleShape2D_mtuls")
21 changes: 11 additions & 10 deletions src/scenes/projectiles/projectile.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
[ext_resource type="Texture2D" uid="uid://d36grl02ydtdq" path="res://assets/boxing-glove.png" id="5_5x4rg"]
[ext_resource type="Texture2D" uid="uid://dl0w501n8mfnr" path="res://assets/ugly-dagger.png" id="6_hon0c"]

[sub_resource type="CircleShape2D" id="CircleShape2D_lbg23"]
resource_local_to_scene = true
radius = 3.0

[sub_resource type="AtlasTexture" id="AtlasTexture_t6lrc"]
atlas = ExtResource("2_ckgqm")
region = Rect2(0, 0, 16, 16)
Expand Down Expand Up @@ -164,16 +160,21 @@ animations = [{
"speed": 5.0
}]

[node name="ProjectileBase" type="CharacterBody2D"]
[sub_resource type="CircleShape2D" id="CircleShape2D_46dli"]
resource_local_to_scene = true
radius = 3.0

[node name="ProjectileBase" type="Area2D"]
collision_layer = 0
collision_mask = 48
script = ExtResource("1_s58pv")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(5, -1)
shape = SubResource("CircleShape2D_lbg23")

[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_7xxmc")
animation = &"pushback"
animation = &"fish"
autoplay = "default"

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_46dli")

[connection signal="body_entered" from="." to="." method="_on_body_entered"]
13 changes: 7 additions & 6 deletions src/scenes/projectiles/pushback.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[ext_resource type="PackedScene" uid="uid://dyqpiguafbprl" path="res://scenes/projectiles/projectile.tscn" id="1_c2ba0"]

[sub_resource type="CircleShape2D" id="CircleShape2D_bdgte"]
[sub_resource type="CircleShape2D" id="CircleShape2D_bx4mi"]
resource_local_to_scene = true
radius = 3.0
radius = 8.0

[sub_resource type="Animation" id="Animation_bxbwp"]
resource_name = "default"
Expand Down Expand Up @@ -34,12 +34,13 @@ ATTACK_DAMAGE = 0.0
KNOCKBACK_STRENGTH = 1000.0
REMOVE_AFTER = 1.0

[node name="CollisionShape2D" parent="." index="0"]
shape = SubResource("CircleShape2D_bdgte")

[node name="AnimatedSprite2D" parent="." index="1"]
[node name="AnimatedSprite2D" parent="." index="0"]
rotation = 6.19875
scale = Vector2(-1, -1)
animation = &"pushback"

[node name="CollisionShape2D" parent="." index="1"]
shape = SubResource("CircleShape2D_bx4mi")

[node name="AnimationPlayer" type="AnimationPlayer" parent="." index="2"]
libraries = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
[gd_scene load_steps=20 format=3 uid="uid://b5512kvsldk7f"]

[ext_resource type="PackedScene" uid="uid://dyqpiguafbprl" path="res://scenes/projectiles/projectile.tscn" id="1_4crrr"]
[ext_resource type="Texture2D" uid="uid://c2kg4efmhgd0j" path="res://assets/lemon.png" id="2_32o2o"]
[ext_resource type="Script" path="res://scripts/spearlike.gd" id="2_rga45"]
[ext_resource type="Texture2D" uid="uid://ca6yk4v42d5pu" path="res://assets/spear.png" id="4_3bxd2"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_j74m0"]
size = Vector2(8, 5)
[ext_resource type="PackedScene" uid="uid://dyqpiguafbprl" path="res://scenes/projectiles/projectile.tscn" id="1_5aqb1"]
[ext_resource type="Script" path="res://scripts/spearlike.gd" id="2_d4tsf"]
[ext_resource type="Texture2D" uid="uid://c2kg4efmhgd0j" path="res://assets/lemon.png" id="3_lxi47"]
[ext_resource type="Texture2D" uid="uid://ca6yk4v42d5pu" path="res://assets/spear.png" id="4_ve2oc"]

[sub_resource type="AtlasTexture" id="AtlasTexture_oktyp"]
atlas = ExtResource("2_32o2o")
atlas = ExtResource("3_lxi47")
region = Rect2(0, 0, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_5t4dt"]
atlas = ExtResource("2_32o2o")
atlas = ExtResource("3_lxi47")
region = Rect2(16, 0, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_vufvr"]
atlas = ExtResource("2_32o2o")
atlas = ExtResource("3_lxi47")
region = Rect2(32, 0, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_ofvd5"]
atlas = ExtResource("2_32o2o")
atlas = ExtResource("3_lxi47")
region = Rect2(48, 0, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_5mj4b"]
atlas = ExtResource("4_3bxd2")
atlas = ExtResource("4_ve2oc")
region = Rect2(0, 0, 41, 7)

[sub_resource type="AtlasTexture" id="AtlasTexture_w6smy"]
atlas = ExtResource("4_3bxd2")
atlas = ExtResource("4_ve2oc")
region = Rect2(41, 0, 41, 7)

[sub_resource type="AtlasTexture" id="AtlasTexture_d7bra"]
atlas = ExtResource("4_3bxd2")
atlas = ExtResource("4_ve2oc")
region = Rect2(82, 0, 41, 7)

[sub_resource type="AtlasTexture" id="AtlasTexture_2f70e"]
atlas = ExtResource("4_3bxd2")
atlas = ExtResource("4_ve2oc")
region = Rect2(123, 0, 41, 7)

[sub_resource type="AtlasTexture" id="AtlasTexture_417i6"]
atlas = ExtResource("4_3bxd2")
atlas = ExtResource("4_ve2oc")
region = Rect2(164, 0, 41, 7)

[sub_resource type="AtlasTexture" id="AtlasTexture_w2cjg"]
atlas = ExtResource("4_3bxd2")
atlas = ExtResource("4_ve2oc")
region = Rect2(205, 0, 41, 7)

[sub_resource type="AtlasTexture" id="AtlasTexture_3matk"]
atlas = ExtResource("4_3bxd2")
atlas = ExtResource("4_ve2oc")
region = Rect2(246, 0, 41, 7)

[sub_resource type="AtlasTexture" id="AtlasTexture_63854"]
atlas = ExtResource("4_3bxd2")
atlas = ExtResource("4_ve2oc")
region = Rect2(287, 0, 41, 7)

[sub_resource type="AtlasTexture" id="AtlasTexture_jttmp"]
atlas = ExtResource("4_3bxd2")
atlas = ExtResource("4_ve2oc")
region = Rect2(328, 0, 41, 7)

[sub_resource type="SpriteFrames" id="SpriteFrames_pbbgu"]
Expand Down Expand Up @@ -112,22 +109,23 @@ animations = [{
"speed": 5.0
}]

[node name="Spearlike" instance=ExtResource("1_4crrr")]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_w2mlk"]

[node name="Spear" instance=ExtResource("1_5aqb1")]
scale = Vector2(2, 2)
collision_mask = 64
script = ExtResource("2_rga45")
script = ExtResource("2_d4tsf")
speed = 0.0
ATTACK_DAMAGE = 1.0
ATTACK_DAMAGE = 5.0
PIERCING = true

[node name="CollisionShape2D" parent="." index="0"]
position = Vector2(2, 0.5)
shape = SubResource("RectangleShape2D_j74m0")

[node name="AnimatedSprite2D" parent="." index="1"]
[node name="AnimatedSprite2D" parent="." index="0"]
position = Vector2(0, -6)
sprite_frames = SubResource("SpriteFrames_pbbgu")
animation = &"spear"
autoplay = "spear"
centered = false
flip_h = true

[node name="CollisionShape2D" parent="." index="1"]
shape = SubResource("RectangleShape2D_w2mlk")
14 changes: 7 additions & 7 deletions src/scenes/projectiles/strike.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

[ext_resource type="PackedScene" uid="uid://dyqpiguafbprl" path="res://scenes/projectiles/projectile.tscn" id="1_gf3ie"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_7pfd4"]
size = Vector2(7, 14)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8x8lb"]
size = Vector2(5, 13)

[sub_resource type="Animation" id="Animation_4lstb"]
resource_name = "rot"
Expand Down Expand Up @@ -31,13 +31,13 @@ ATTACK_DAMAGE = 20.0
KNOCKBACK_STRENGTH = 25.0
REMOVE_AFTER = 1.0

[node name="CollisionShape2D" parent="." index="0"]
position = Vector2(-0.5, 0)
shape = SubResource("RectangleShape2D_7pfd4")

[node name="AnimatedSprite2D" parent="." index="1"]
[node name="AnimatedSprite2D" parent="." index="0"]
animation = &"strike"

[node name="CollisionShape2D" parent="." index="1"]
position = Vector2(-0.5, 0)
shape = SubResource("RectangleShape2D_8x8lb")

[node name="AnimationPlayer" type="AnimationPlayer" parent="." index="2"]
libraries = {
"": SubResource("AnimationLibrary_bdptt")
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/enemies/bookworm.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var attack_target := Vector2(0, 0)
@onready var anim: AnimationPlayer = $AnimationPlayer
@onready var map: TileMap = get_parent().find_child('Map')

const Spear = preload("res://scenes/projectiles/spearlike.tscn")
const Spear = preload("res://scenes/projectiles/spear.tscn")

func _ready() -> void:
super._ready()
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/enemies/enemy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func do_physics(delta: float):
take_damage(SPIKE_DAMAGE)
spike_damage_timer = SPIKE_DAMAGE_COOLDOWN

func hit_player(player: CharacterBody2D):
func hit_player(body: CharacterBody2D):
var direction = velocity
direction = direction.normalized() + direction * KNOCKBACK_VELOCITY_SCALING
player.knockback = direction * KNOCKBACK_STRENGTH
player.take_damage(ATTACK_DAMAGE)
body.knockback = direction * KNOCKBACK_STRENGTH
body.take_damage(ATTACK_DAMAGE)

func take_damage(dmg: int):
SfxAudio.play_sfx(SfxAudio.Sound.HIT)
Expand Down
5 changes: 3 additions & 2 deletions src/scripts/enemies/firedevil.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ func _physics_process(delta: float):
var collider = $ViewRay.get_collider()
if collider == player and cooldown <= 0:
var fire = Fire.instantiate()
if not is_facing_right:
fire.direction *= -1
fire.flip()
fire.position = position
fire.direction = Vector2(1, 0) if is_facing_right else Vector2(-1, 0)
fire.set_flipped(not is_facing_right)
get_parent().add_child(fire)
cooldown = SHOOT_COOLDOWN

Expand Down
Loading

0 comments on commit 4284c1b

Please sign in to comment.