From 58bc799cb98797aa8dbb4b4a3fd80448f06663a0 Mon Sep 17 00:00:00 2001 From: Just Dzhi Date: Sat, 30 Sep 2023 23:00:40 +0400 Subject: [PATCH] Bat --- src/models/enemies/bat/Bat.tscn | 18 ++++++++++++ src/models/enemies/bat/bat.gd | 17 +++++++++++ src/models/enemies/bat/sprite.png | Bin 0 -> 1867 bytes src/models/enemies/bat/sprite.png.import | 35 +++++++++++++++++++++++ src/models/player/Player.tscn | 2 +- 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/models/enemies/bat/Bat.tscn create mode 100644 src/models/enemies/bat/bat.gd create mode 100644 src/models/enemies/bat/sprite.png create mode 100644 src/models/enemies/bat/sprite.png.import diff --git a/src/models/enemies/bat/Bat.tscn b/src/models/enemies/bat/Bat.tscn new file mode 100644 index 0000000..8379ea4 --- /dev/null +++ b/src/models/enemies/bat/Bat.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://src/models/enemies/bat/sprite.png" type="Texture" id=1] +[ext_resource path="res://src/models/enemies/bat/bat.gd" type="Script" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 4, 3 ) + +[node name="Bat" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) +centered = false + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( 7, 4 ) +shape = SubResource( 1 ) diff --git a/src/models/enemies/bat/bat.gd b/src/models/enemies/bat/bat.gd new file mode 100644 index 0000000..fc91a9f --- /dev/null +++ b/src/models/enemies/bat/bat.gd @@ -0,0 +1,17 @@ +extends KinematicBody2D + +var velocity = Vector2.ZERO +var speed = 48 + +func _process(_delta): + get_node("Sprite").flip_h = true if $"../Player".global_position.x > self.position.x else false + +func _physics_process(_delta): + if position.distance_to(Vector2($"../Player".global_position.x, $"../Player".global_position.y)) > 48: + velocity.x = speed * cos(get_angle_to(Vector2($"../Player".global_position.x + 7, $"../Player".global_position.y + 8))) + velocity.y = speed * sin(get_angle_to(Vector2($"../Player".global_position.x + 7, $"../Player".global_position.y + 8))) + else: + velocity = Vector2.ZERO + + move_and_slide(velocity) + diff --git a/src/models/enemies/bat/sprite.png b/src/models/enemies/bat/sprite.png new file mode 100644 index 0000000000000000000000000000000000000000..b30bf6145883f4a996535e972a755b5d34609647 GIT binary patch literal 1867 zcmcIlO=uid9G_4KHBxKULkO)76A(q;&gagT+2(6w6U@YrtZq_0_~yMgyF+&7jWd(% zZlsrbQDY$ol@bd*6j2b05%p4N!H+|r6rp&iv=zY*@Sq1T;z4|~U#-%{TwIu)H@m<0 z`~TkW|C{$-pPxH+U|?u~W|+bT2$SJ1Ly;sX_M_CNA)hfqm#(G-fk|zz zA&7dkVbbx5IVLt>B+5A{TT>V4IJ-lGpodPE zb9w%;vL9kvPae+{btaG^Oi4jtT~mQ%0aYr=mMuxPtUMv9Y|w@}EC?8;aBpCWeXqF} zsN>i(VUofSk(pvaV4`xqk8R1-6j?JcfV!oFyrQ|lG7Sx=NXITwC1mLNmM%8GNYQHM zL^i*jTTBt-=(%aD$UvrLVxTCh4m4LYfvMs=@Kj5Z6$xR}g&nPWcl#}SRrB* zR2X~7X*|wnP8#wvwsKo_NKEhw28#s zE4H-Wwmo(yvpqK(_I7*r&^s?k$d($j)8P8=g>iP0oSrF;mj>SsHn$JGI(GlQ^26n^ zx#wP-I9PnhePD6l&f+&ee|PfC$RDS!&DMu+oWk$EGxcHLSJKe@S^L+<_0z}C|M^4n z$d}U1q4=${2d`{wJYT;0i1o(Ri+$#?zOm1iKUw!a*R6pQzig(}_f9-D`oZ_>hsoiM zt=V%&zG&QdLA?3?w!Y)MwzZ80Fa3CV_M>yh-}D~+_Urz>zqnUEeP;8gkJD?}aW^wH LS3E!Q(#gL8w=h{k literal 0 HcmV?d00001 diff --git a/src/models/enemies/bat/sprite.png.import b/src/models/enemies/bat/sprite.png.import new file mode 100644 index 0000000..2b84f0a --- /dev/null +++ b/src/models/enemies/bat/sprite.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/sprite.png-742176af9ae55b1874092f535d7f098a.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/models/enemies/bat/sprite.png" +dest_files=[ "res://.import/sprite.png-742176af9ae55b1874092f535d7f098a.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/models/player/Player.tscn b/src/models/player/Player.tscn index 14e9b52..3b617e1 100644 --- a/src/models/player/Player.tscn +++ b/src/models/player/Player.tscn @@ -4,7 +4,7 @@ [ext_resource path="res://src/models/player/player.gd" type="Script" id=2] [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 4, 5.5 ) +extents = Vector2( 7, 11 ) [sub_resource type="RectangleShape2D" id=2] extents = Vector2( 7, 11 )