From 40b841e7af444f2c180fa546c2f0c1dbe211f119 Mon Sep 17 00:00:00 2001 From: Kilokem Date: Sat, 26 Oct 2024 13:34:01 +0200 Subject: [PATCH] Mostly health --- scenes/bullet.tscn | 27 +++++++++++ scenes/game.tscn | 63 +++++++++++++++++++++++++- scenes/gun.gd | 20 ++++++++ scenes/gun.tscn | 34 ++++++++++++++ scenes/player.tscn | 46 ++++++++++++++++++- scripts/bullet.gd | 21 +++++++++ scripts/enemy.gd | 6 +++ scripts/playerscript.gd | 15 +++++- sprites/objects/pistol.png | Bin 0 -> 1209 bytes sprites/objects/pistol.png.import | 34 ++++++++++++++ sprites/objects/projectile.png | Bin 0 -> 799 bytes sprites/objects/projectile.png.import | 34 ++++++++++++++ 12 files changed, 295 insertions(+), 5 deletions(-) create mode 100644 scenes/bullet.tscn create mode 100644 scenes/gun.gd create mode 100644 scenes/gun.tscn create mode 100644 scripts/bullet.gd create mode 100644 sprites/objects/pistol.png create mode 100644 sprites/objects/pistol.png.import create mode 100644 sprites/objects/projectile.png create mode 100644 sprites/objects/projectile.png.import diff --git a/scenes/bullet.tscn b/scenes/bullet.tscn new file mode 100644 index 0000000..9c01be5 --- /dev/null +++ b/scenes/bullet.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=4 format=3 uid="uid://4uk2iyn5fef2"] + +[ext_resource type="Script" path="res://scripts/bullet.gd" id="1_5kpin"] +[ext_resource type="Texture2D" uid="uid://ds114lnkh1ydj" path="res://sprites/objects/projectile.png" id="2_ugbet"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_m137n"] +radius = 5.09902 + +[node name="bullet" type="Area2D"] +top_level = true +rotation = 0.815342 +collision_mask = 3 +script = ExtResource("1_5kpin") + +[node name="Projectile" type="Sprite2D" parent="."] +position = Vector2(-4.28308, -1.28656) +rotation = 0.00146517 +scale = Vector2(0.296997, 0.352615) +texture = ExtResource("2_ugbet") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(-2.18388, -2.05686) +rotation = -2.34336 +scale = Vector2(1, 1) +shape = SubResource("CircleShape2D_m137n") + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/scenes/game.tscn b/scenes/game.tscn index 3aae1d1..62d3a75 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -3,7 +3,7 @@ [ext_resource type="PackedScene" uid="uid://c3i6a6ji8i1q8" path="res://scenes/player.tscn" id="1_fwjx1"] [ext_resource type="Script" path="res://scripts/game_manager.gd" id="1_gd2n3"] [ext_resource type="PackedScene" uid="uid://d65w0p8s6dv4" path="res://scenes/chest.tscn" id="2_u0oqr"] -[ext_resource type="PackedScene" uid="uid://cw2jmrfd0fivj" path="res://scenes/enemy.tscn" id="4_7i7ld"] +[ext_resource type="PackedScene" uid="uid://cw2jmrfd0fivj" path="res://sprites/characters/enemy.tscn" id="4_7i7ld"] [node name="Game" type="Node2D"] @@ -22,9 +22,68 @@ offset_right = 1124.0 offset_bottom = 637.0 color = Color(0.726739, 0.942318, 0.74966, 1) -[node name="Enemy" parent="." instance=ExtResource("4_7i7ld")] +[node name="Enemies" type="Node" parent="."] + +[node name="Enemy" parent="Enemies" instance=ExtResource("4_7i7ld")] position = Vector2(29, 37) +[node name="Enemy2" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-183, 47) + +[node name="Enemy4" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-246, -63) + +[node name="Enemy5" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-73, 63) + +[node name="Enemy6" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-106, -135) + +[node name="Enemy7" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(106, 154) + +[node name="Enemy8" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(307, 50) + +[node name="Enemy9" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(276, 177) + +[node name="Enemy10" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-1, 269) + +[node name="Enemy11" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-176, 259) + +[node name="Enemy12" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-374, 203) + +[node name="Enemy13" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-391, 54) + +[node name="Enemy14" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-561, 22) + +[node name="Enemy15" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-496, -164) + +[node name="Enemy16" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-361, -299) + +[node name="Enemy17" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(-187, -364) + +[node name="Enemy18" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(107, -366) + +[node name="Enemy19" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(245, -234) + +[node name="Enemy20" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(314, -53) + +[node name="Enemy3" parent="Enemies" instance=ExtResource("4_7i7ld")] +position = Vector2(65, -107) + [node name="player" parent="." instance=ExtResource("1_fwjx1")] position = Vector2(-86, -60) diff --git a/scenes/gun.gd b/scenes/gun.gd new file mode 100644 index 0000000..02c0328 --- /dev/null +++ b/scenes/gun.gd @@ -0,0 +1,20 @@ +extends Area2D + +func _physics_process(delta: float) -> void: + var enemies_in_range = get_overlapping_bodies() + if enemies_in_range.size() > 0: + var closest_target = enemies_in_range.front() + look_at(closest_target.global_position) + +func shoot(): + const BULLET = preload("res://scenes/bullet.tscn") + var new_bullet = BULLET.instantiate() + new_bullet.global_position = %shootingPoint.global_position + new_bullet.global_rotation = %weponPivot.global_rotation + %shootingPoint.add_child(new_bullet) + + + + +func _on_timer_timeout() -> void: + shoot() diff --git a/scenes/gun.tscn b/scenes/gun.tscn new file mode 100644 index 0000000..65d085d --- /dev/null +++ b/scenes/gun.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=4 format=3 uid="uid://woincqnmbsax"] + +[ext_resource type="Texture2D" uid="uid://d0heqigxyqlxk" path="res://sprites/objects/pistol.png" id="1_s3jta"] +[ext_resource type="Script" path="res://scenes/gun.gd" id="1_tnui5"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_bfjrk"] +radius = 251.149 + +[node name="gun" type="Area2D"] +collision_layer = 0 +collision_mask = 2 +script = ExtResource("1_tnui5") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(-7, 2) +shape = SubResource("CircleShape2D_bfjrk") + +[node name="weponPivot" type="Marker2D" parent="."] +unique_name_in_owner = true + +[node name="Pistol" type="Sprite2D" parent="weponPivot"] +position = Vector2(15, -2.5) +scale = Vector2(0.207111, 0.291078) +texture = ExtResource("1_s3jta") + +[node name="shootingPoint" type="Marker2D" parent="weponPivot/Pistol"] +unique_name_in_owner = true +position = Vector2(30.3333, -10.1852) + +[node name="Timer" type="Timer" parent="."] +wait_time = 0.3 +autostart = true + +[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] diff --git a/scenes/player.tscn b/scenes/player.tscn index 87ae772..fb09d3d 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=11 format=3 uid="uid://c3i6a6ji8i1q8"] +[gd_scene load_steps=15 format=3 uid="uid://c3i6a6ji8i1q8"] [ext_resource type="Texture2D" uid="uid://dl1pu82xwqw3m" path="res://sprites/characters/player.png" id="1_6xeiv"] [ext_resource type="Script" path="res://scripts/playerscript.gd" id="1_sty7f"] +[ext_resource type="PackedScene" uid="uid://woincqnmbsax" path="res://scenes/gun.tscn" id="3_2dsng"] [sub_resource type="AtlasTexture" id="AtlasTexture_0xuex"] atlas = ExtResource("1_6xeiv") @@ -57,6 +58,24 @@ animations = [{ radius = 5.0 height = 18.0 +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_vrmo8"] +radius = 7.0 +height = 22.0 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ax0mg"] +bg_color = Color(0.664164, 0, 0.0638879, 1) +corner_radius_top_left = 1 +corner_radius_top_right = 1 +corner_radius_bottom_right = 1 +corner_radius_bottom_left = 1 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_vh4rv"] +bg_color = Color(0, 0.724967, 0.216409, 1) +corner_radius_top_left = 1 +corner_radius_top_right = 1 +corner_radius_bottom_right = 1 +corner_radius_bottom_left = 1 + [node name="player" type="CharacterBody2D"] script = ExtResource("1_sty7f") @@ -65,8 +84,31 @@ position = Vector2(0, -8) sprite_frames = SubResource("SpriteFrames_gatfb") animation = &"idle" autoplay = "idle" -frame_progress = 0.0176069 +frame_progress = 0.491158 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, -9) shape = SubResource("CapsuleShape2D_4lp1q") + +[node name="Gun" parent="." instance=ExtResource("3_2dsng")] +position = Vector2(0, -7) + +[node name="Hurtbox" type="Area2D" parent="."] +unique_name_in_owner = true +collision_mask = 2 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hurtbox"] +position = Vector2(0, -9) +shape = SubResource("CapsuleShape2D_vrmo8") +debug_color = Color(0.821755, 0.152326, 0.89675, 0.42) + +[node name="ProgressBar" type="ProgressBar" parent="."] +unique_name_in_owner = true +offset_left = -13.0 +offset_top = -25.0 +offset_right = 14.0 +offset_bottom = -20.0 +theme_override_styles/background = SubResource("StyleBoxFlat_ax0mg") +theme_override_styles/fill = SubResource("StyleBoxFlat_vh4rv") +value = 100.0 +show_percentage = false diff --git a/scripts/bullet.gd b/scripts/bullet.gd new file mode 100644 index 0000000..d8fa500 --- /dev/null +++ b/scripts/bullet.gd @@ -0,0 +1,21 @@ +extends Area2D + +const SPEED = 500 +const RANGE = 500 + +var travelled_distance = 0 + +func _physics_process(delta: float) -> void: + var direction = Vector2.RIGHT.rotated(rotation) + position += direction * SPEED * delta + + travelled_distance += SPEED * delta + + if travelled_distance > RANGE: + queue_free() + + +func _on_body_entered(body: Node2D) -> void: + queue_free() + if body.has_method("take_damage"): + body.take_damage() diff --git a/scripts/enemy.gd b/scripts/enemy.gd index 8c16c14..0a6d1e1 100644 --- a/scripts/enemy.gd +++ b/scripts/enemy.gd @@ -1,8 +1,14 @@ extends CharacterBody2D +var health = 5 @onready var player = get_node("/root/Game/player") func _physics_process(delta: float) -> void: var direction = global_position.direction_to(player.global_position) velocity = direction * 50 move_and_slide() + +func take_damage(): + health -= 1 + if health == 0: + queue_free() diff --git a/scripts/playerscript.gd b/scripts/playerscript.gd index a798f50..b390338 100644 --- a/scripts/playerscript.gd +++ b/scripts/playerscript.gd @@ -1,7 +1,20 @@ extends CharacterBody2D +signal health_depleted + +var health = 100.0 +const DAMAGE_RATE = 5.0 + func _physics_process(delta): var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down") velocity = direction * 200 move_and_slide() - pass + + + var overlappong_mobs = %Hurtbox.get_overlapping_bodies() + + if overlappong_mobs.size() > 0 : + health -= DAMAGE_RATE * overlappong_mobs.size() * delta + %ProgressBar.value = health + if health <= 0.0: + health_depleted.emit() diff --git a/sprites/objects/pistol.png b/sprites/objects/pistol.png new file mode 100644 index 0000000000000000000000000000000000000000..cc24e8b0dbc9363b89a263ba6bf20c1d99b86aa1 GIT binary patch literal 1209 zcmV;q1V;ObP)5&IOS8VYmMP#Cka)t$lCn$k|CY_FJu-QRmk zX~8kY?al7tuq4^|)JY*uQQX<=JNB?tFpNnea-^m>4cC!=X%*#mBu1Dr5@W$gj0Gbx z7L3GLFcM?INQ?y|F&0P&v5yf3c;}nLL&(I`Y~Qi|$tMhBvPSi#hcRm=rsn#Not~XH zjLF}wuI4qpwm=XWIEa6I40gg_w!6<_2FCDMsk?-WR&HN#zr1RSY3j|GpunuEe$_?Z{aVOX}+CeBO{TtLH?% zs$)S#*j{sHLo;}EavZKf)s|AJlH`{?58N)MDJ~?^7?5&l55HXd8pV5eQL7$y%yF+Z z7%gt&tw9L9iUDCM*{?n~2x*}=H2l5wbF=Tt>pn1ZD#zzLa0JS$ zlA%_HFZ1on^Vi#FjuOL%ZUeFL(-li8?Qm0?k2HS#;>`uP0Ly13bs`y5QU<X@rl0T zNY_*RKns^(Dn@PU2HwB4n4WpMk0{EOsukB{3u7)u3~w2|ym-E6)^Mg2E9J#}Hsz|G zkm)1Auv-tj``x&41%=!H?P*BuIEgaqvSc>C`{X)Yh(Qe37b$TKHn0*C$Npo;elaX1 zpTt?%fVvfD;UUZ#RZ-Z1@VFR3_Wbx*cwLNLox4&4H{l_Sw`&`EzFc2Y=e%`9W44sC z7&7WsjYH`w7ZEH_*iFVmWud>4a# z`r67nVhJ9^vhDD3OuVPWEaO2Tq`WGHIdY5sL7KvT9}=V^B989f=lMK}Yl;__Pdonr X9<-xFRFqJp00000NkvXXu0mjf0(mlw literal 0 HcmV?d00001 diff --git a/sprites/objects/pistol.png.import b/sprites/objects/pistol.png.import new file mode 100644 index 0000000..cf74bcf --- /dev/null +++ b/sprites/objects/pistol.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d0heqigxyqlxk" +path="res://.godot/imported/pistol.png-4d0d56869593790c972adddea09fe2c1.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://sprites/objects/pistol.png" +dest_files=["res://.godot/imported/pistol.png-4d0d56869593790c972adddea09fe2c1.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 diff --git a/sprites/objects/projectile.png b/sprites/objects/projectile.png new file mode 100644 index 0000000000000000000000000000000000000000..42fb536c43ec5e91b95d663c482fe231a642492b GIT binary patch literal 799 zcmV+)1K|9LP)u7f3V$ zBsNGyqJkuiJ-in;X=0CS%U_lHlWb3B#?Jix-n@BZ;F2J4fvAsm88gmfD&C=ySWqa# z8&!u|TX6A4tTh{Po>i!j;lRy71wuTczqYBS5_ywA8?M-e*{_SG_wDd*Iin8lRUl=R z2E%Wj2VO=JSdetL#nRhdeRIZ4xJ#7|z9t)Z7!ozHy!XssomxmDchS*xy@N4mSl5j6 zde_D3-qvJAA|aW%%Rm9&dccpKSDvIK>8U2LSOVr`@Lr!~VhPE`UB1)ckGeqteoWzs zxpgJjrqshxR5Nw=2HnL;<}P7;B?0YjyuK{-%RleRf+msTC7lUpL z8iaa^yh&q?5x3`p^X0@?km}I33K7AukhJ_d3D(UzRS9?S1VwS|AT@t9&k)L@IU+0+ zMO3Iw`V2}oC5pt%FSR2fs*R$^Ldd)(b)mFhqVK*!QTW$@BxrLm(UM~QU5iRJ6v6cj zg!or?re}N_&JoHaIr++8%z~-Unc{MD)=MU*Pz|x(=!|QJVq9!-1M-C5XemLA;d^w} zfU5I3boQyw4=7FNOjp^|E!(7#_Z=UO&-Nctu!y_!x);zU0|b-CFen?gU^q6#xa#TV z$wC%HWx*Wf*cJKEMm$OwSG}!o%8eCUjD@9ut@3-|t@@)?n>SJ%W_eD8g>0d=#Y*$V z_$M+TS2xrlXsf%D!B+P?a&yBoYNt_liUL0erFO#(B)QXab4S-$_?N~6ZrGvuP($C` d;q@Y{(|<6Q?h)%9rt|;+002ovPDHLkV1i!&Y{>us literal 0 HcmV?d00001 diff --git a/sprites/objects/projectile.png.import b/sprites/objects/projectile.png.import new file mode 100644 index 0000000..873c68d --- /dev/null +++ b/sprites/objects/projectile.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ds114lnkh1ydj" +path="res://.godot/imported/projectile.png-b90d942ccb51346df1ff1fdf7ba87dd1.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://sprites/objects/projectile.png" +dest_files=["res://.godot/imported/projectile.png-b90d942ccb51346df1ff1fdf7ba87dd1.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