From e66b95c1f150838e90a9e5d4a3e85289c50b145a Mon Sep 17 00:00:00 2001 From: OddlyTimbot Date: Mon, 16 Mar 2026 20:58:20 -0400 Subject: [PATCH] bullet factory, object pooling, state machine, animations, npc --- .../player/idle/Player Idle 48x48.png | Bin 0 -> 1853 bytes .../player/idle/Player Idle 48x48.png.import | 40 ++++ .../player/jump_fall/player jump 48x48.png | Bin 0 -> 1021 bytes .../jump_fall/player jump 48x48.png.import | 40 ++++ .../player/running/player run 48x48.png | Bin 0 -> 3199 bytes .../running/player run 48x48.png.import | 40 ++++ scenes/bullet.tscn | 2 + scenes/game.tscn | 12 +- scenes/npc_character.tscn | 12 ++ scenes/player.tscn | 182 ++++++++++++++++++ scripts/bullet.gd | 9 +- scripts/gameController.gd | 14 +- scripts/npc_character.gd | 12 ++ scripts/npc_character.gd.uid | 1 + scripts/player.gd | 78 ++++++-- scripts/scene_manager.gd | 30 +++ 16 files changed, 447 insertions(+), 25 deletions(-) create mode 100644 assets/graphics/player/idle/Player Idle 48x48.png create mode 100644 assets/graphics/player/idle/Player Idle 48x48.png.import create mode 100644 assets/graphics/player/jump_fall/player jump 48x48.png create mode 100644 assets/graphics/player/jump_fall/player jump 48x48.png.import create mode 100644 assets/graphics/player/running/player run 48x48.png create mode 100644 assets/graphics/player/running/player run 48x48.png.import create mode 100644 scenes/npc_character.tscn create mode 100644 scripts/npc_character.gd create mode 100644 scripts/npc_character.gd.uid diff --git a/assets/graphics/player/idle/Player Idle 48x48.png b/assets/graphics/player/idle/Player Idle 48x48.png new file mode 100644 index 0000000000000000000000000000000000000000..b618511699269f9bd10ff834f6b382e147588ebd GIT binary patch literal 1853 zcma)7_g9k%7X30{KoA&uC&-k*2m(V}iiV98siI(^NQA(IG9>gOk_3>BBH$vuD&Qj0 zI|zutNC=Ul^rDWTh5#RBW5}0Z;id z0D!HW)LQ)TllZ>qrSM6Dh1{@21Fy#v)&T&1WM%eGr^rIaB8?#7EyK6Nbb3T-b(Qi9 z@b#CjK%>(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ouFOAKKtr?u-6Zv(YkUXdi)sf zak0Mh>nO11+UfNJza4o$n<0Rk1Z07%>MV|KH|Cnd*}PH={w!JoU_k}q;T@2{2S2OR zD+a#QyBe@rHR$i1USRL^qA`5(r#B^2wb1c{XQEaxHcV>?NY(}bx#42)8SNHPEAhx+ zwgbTUmm?2ozQJTIB3(a3CTazbJxT1)Zea|u@~8|2{NOX;WZ4432(zCtQ7d>^3MYza z`pO61;cUJh#UB&2?YppT6D78R|4^6h|6#?IDsW4&75XzcI( zI|u+6TJ`se!ZF#4lOpqh+0S5p*beUt&(-{yaUWs}2=GNDGqzgZXbL{yCx91`EdrAH za5aCX+;6jxRN?`E{`@|6r*cN^Po;%Do_#4@uM~^*CnFzWVt7lNu6Os9ze}qfq(y&z zAN~3LRNk#6AiixSnJ2yu4LOwnk>Ay7)+Q(!7+wzKMJ61R2SEE47DYJB3DHoS125zG z=NfjWa)C7$d|>gvJRb?fU-ZQUv9Iw_V7=DGio;H>%!gN%iq-8`MjGM)49-BT&x$2f zCLY@o5T)$9hFE?0!P#ULO;mw=BX5G;-Lu&+QdMkLz^zYNPI6;W(H&45@yQ*hzGvh%)2y re59^(3$vL{@`WG>f*=TjXb=AZ>!Ac3Jx|zZ00000NkvXXu0mjfKxWs7 literal 0 HcmV?d00001 diff --git a/assets/graphics/player/jump_fall/player jump 48x48.png.import b/assets/graphics/player/jump_fall/player jump 48x48.png.import new file mode 100644 index 0000000..3ec9e9c --- /dev/null +++ b/assets/graphics/player/jump_fall/player jump 48x48.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bihghvekq435s" +path="res://.godot/imported/player jump 48x48.png-bb6ba8ccf76c9bd3765199af95f48c3c.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/player/jump_fall/player jump 48x48.png" +dest_files=["res://.godot/imported/player jump 48x48.png-bb6ba8ccf76c9bd3765199af95f48c3c.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +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/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +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/assets/graphics/player/running/player run 48x48.png b/assets/graphics/player/running/player run 48x48.png new file mode 100644 index 0000000000000000000000000000000000000000..aca5b5560dba7381b8b06e68e76b1cadf80992cb GIT binary patch literal 3199 zcma)9^;^@A6Mt`Xi~$1$1SS$rKnI9~AWT9A7By5FhZ0gs*VyPV2z5#h>5vvhLVEb2 z6#|ptye9JS+HM=N^|Z-|@euWVtE3n8^*?bSqWe%{ z{V-W{aT4hZ2<_8CQ3D)(XS!5(_Hx+b5)1WD<~>ZdI)J-m~pd!=O9z#Dri_@&m0->;X0VOz8_M}@&=jH)9< zAoz>Fo1E=(9R&E|=bX@VK^*3Pxe2L*kRzQlt^{A9zE3xzP=68{-nyZ;y|ZUO%pUMO zUq#k?8kDW@PAtJg-zJIO*oU&sZh1Oea3ACC|9#T60)Xq}{$wfq_?%Q&k=+tgP#R%4 z^xF+PCsE+659=(^cAeReHaZ-FJ#>KrlmD{pD&fV?;h8Pu3b-o^yz+8YREOxKm~&76 zw#s?o#PUS*W*n7E^v*t#=@k6!RzF80d~Fh{i@aF*f;So1@yqN)i#$GL?h&$lc2uec zvUaYECHH6A+h(bD^ozxcoJ87u0WjF14%}@?{<2mnkvkIPAt!k_gJwHcRg8MyqxpFL zZ5g8|R76U!u&QNVZy6(w?vDx%ISY_Zns3yDkWOMh2LG7EmIT~7u@)pP z`}?XzT!6kP+l^f|4-)t1Gz+JlKd1u5UG?O?x_t>!!M1R_gWpCKOB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b?HST6{0u zt-NFu?p!&_3G{1C@@s%*QiQnS#3$d%`S84ly*w3(u4K9+tn>UuidcXe$yypjl#RXT zAu;;zzr9+O9!I6ZU&=9!b=rLjJO7E8H<-=Rt$*%6ZJzt5Q`~56hL{V?x^*`vyJ>v8 zd30Sbd)eLYhltO?{XW&S@1(lQ!R<+Kj*#FdT0Ea~yB;a>2p9fM{`*)0U(>}xDSKq5 z)8*au-nEiU!Z+V}^|>oXweHC7pD3{>T_f$MIJGV)_-VGJ;8)b7BbjGPzW;t6z36i- zE!9tJOeasOndQ*=p-%Z5b0_*^zKK0*;Gz>mF`jBsrh-uGabKpX>i2W8J;+m69*F8a z6C*aprH~}3p{E-0${^A7#sRRl&1Sdcd3;RSahG^t_Abg?!*tPs`;|IFrm`Pr*{5ai z!VtL_;cn$QHB5DX$)r!I+j*fSF*ZN&^BL^j1oK%c0ExR0x?+;xMwC8y#x^%Mueh_2 zl-vy+8MYzo6x);!DmlA|r>MN-94(Ms)e1Ok@tCFH7q>Q3&A{o>8$apnoqxI_!m<~m zhBM~>@C#2^xQb4=Jh!zDyG0IFNCqYfO1u~yeJ3L&IochrJz{Ca*vQhh? zW_}Av(1LbjYB?MEeA+18F~xKjp{7IyqhxK!(PWi_+6Ti#9v&Xn4`POH4n;m+Lk%<^#MQn9S^(1@J3 zZlg7tAI}f^1;J3o8h5cn!?`9lkF+or9Q7+-Si%q$0;61#wf7&QFSxyF|M3Bf8SF-} zw7q~81r8G9)Xj-*W}uk0`7EuDyIKrQ0c>mMzy~8L%+QgGNkGQ51&&xQtXbH6{qI$4 zxACe8b3>AO+8KdFPP?c!Qx9gYw!{6GrS z==WVi3O>3E@SB%Kn^*OE3k&fXn!6bYx=$O!|Bp+2x^9*+7ox)Z{G!>$$wvVg>fg~T I)3Fc#A5dKsJ^%m! literal 0 HcmV?d00001 diff --git a/assets/graphics/player/running/player run 48x48.png.import b/assets/graphics/player/running/player run 48x48.png.import new file mode 100644 index 0000000..1749d9a --- /dev/null +++ b/assets/graphics/player/running/player run 48x48.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://3c7ngirfyrkh" +path="res://.godot/imported/player run 48x48.png-3529730a2a1b5884902527ab512e774d.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/player/running/player run 48x48.png" +dest_files=["res://.godot/imported/player run 48x48.png-3529730a2a1b5884902527ab512e774d.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +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/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +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/scenes/bullet.tscn b/scenes/bullet.tscn index 3ce9f43..b764a0a 100644 --- a/scenes/bullet.tscn +++ b/scenes/bullet.tscn @@ -11,3 +11,5 @@ script = ExtResource("1_mkf8s") [node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=646324606] shape = SubResource("RectangleShape2D_h1aey") debug_color = Color(0.93031675, 0.24960315, 0.23292288, 0.41960785) + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/scenes/game.tscn b/scenes/game.tscn index 5d6152e..6d8e266 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -5,7 +5,7 @@ [ext_resource type="PackedScene" uid="uid://b6lw2go5mwk3h" path="res://scenes/crate.tscn" id="2_lnu2h"] [ext_resource type="PackedScene" uid="uid://s0utas3jmhjk" path="res://scenes/player.tscn" id="3_iywne"] [ext_resource type="PackedScene" uid="uid://bf50mxdma8wq4" path="res://scenes/trigger.tscn" id="4_lbhrr"] -[ext_resource type="PackedScene" uid="uid://ium8i6770pf4" path="res://scenes/bullet.tscn" id="6_p57ef"] +[ext_resource type="PackedScene" uid="uid://bgi18lbutp5ui" path="res://scenes/npc_character.tscn" id="6_u5sy4"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_8cj0n"] size = Vector2(74, 20) @@ -39,16 +39,16 @@ effect = "powerup" [node name="Crates" type="Node2D" parent="." unique_id=1983554973] [node name="Crate" parent="Crates" unique_id=1307809047 instance=ExtResource("2_lnu2h")] -position = Vector2(703, 418.00003) +position = Vector2(650, 418) [node name="Crate2" parent="Crates" unique_id=1988562966 instance=ExtResource("2_lnu2h")] -position = Vector2(684, 387) +position = Vector2(587.99994, 414.99997) [node name="Crate3" parent="Crates" unique_id=1771442258 instance=ExtResource("2_lnu2h")] position = Vector2(575, 255) [node name="Crate4" parent="Crates" unique_id=34543093 instance=ExtResource("2_lnu2h")] -position = Vector2(694, 351) +position = Vector2(620, 416) [node name="Level" type="Node2D" parent="." unique_id=1225714734] @@ -67,5 +67,5 @@ metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="Level/StaticBody2D2" unique_id=895098891] shape = SubResource("WorldBoundaryShape2D_lbhrr") -[node name="Bullet" parent="." unique_id=1756277677 instance=ExtResource("6_p57ef")] -position = Vector2(359, 364) +[node name="NPCCharacter" parent="." unique_id=597270257 instance=ExtResource("6_u5sy4")] +position = Vector2(474, 404) diff --git a/scenes/npc_character.tscn b/scenes/npc_character.tscn new file mode 100644 index 0000000..6005f72 --- /dev/null +++ b/scenes/npc_character.tscn @@ -0,0 +1,12 @@ +[gd_scene format=3 uid="uid://bgi18lbutp5ui"] + +[ext_resource type="Script" uid="uid://gutmbv5ff4u4" path="res://scripts/npc_character.gd" id="1_xtrxv"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_aykgk"] + +[node name="NPCCharacter" type="CharacterBody2D" unique_id=597270257] +script = ExtResource("1_xtrxv") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=895564969] +shape = SubResource("CircleShape2D_aykgk") +debug_color = Color(0.9234807, 0.19196323, 0.5046088, 0.41960785) diff --git a/scenes/player.tscn b/scenes/player.tscn index 3dbb17e..e4a74a7 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,9 +1,182 @@ [gd_scene format=3 uid="uid://s0utas3jmhjk"] [ext_resource type="Script" uid="uid://c17de7vvtri1e" path="res://scripts/player.gd" id="1_3vyb7"] +[ext_resource type="Texture2D" uid="uid://bihghvekq435s" path="res://assets/graphics/player/jump_fall/player jump 48x48.png" id="2_dqkch"] +[ext_resource type="Texture2D" uid="uid://dyus25iplw8ei" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_g2els"] +[ext_resource type="Texture2D" uid="uid://3c7ngirfyrkh" path="res://assets/graphics/player/running/player run 48x48.png" id="3_qhqgy"] [sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"] +[sub_resource type="AtlasTexture" id="AtlasTexture_i4ail"] +atlas = ExtResource("2_dqkch") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_qhqgy"] +atlas = ExtResource("2_g2els") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_dqkch"] +atlas = ExtResource("2_g2els") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_qlg0r"] +atlas = ExtResource("2_g2els") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"] +atlas = ExtResource("2_g2els") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fjrip"] +atlas = ExtResource("2_g2els") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_smehm"] +atlas = ExtResource("2_g2els") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ur7pv"] +atlas = ExtResource("2_g2els") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_y4r1p"] +atlas = ExtResource("2_g2els") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_d2wvv"] +atlas = ExtResource("2_g2els") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_3v2ag"] +atlas = ExtResource("2_g2els") +region = Rect2(432, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_a38lo"] +atlas = ExtResource("2_dqkch") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_4ni07"] +atlas = ExtResource("2_dqkch") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_jej6c"] +atlas = ExtResource("3_qhqgy") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_f1ej7"] +atlas = ExtResource("3_qhqgy") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_oprun"] +atlas = ExtResource("3_qhqgy") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_a8ls1"] +atlas = ExtResource("3_qhqgy") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_qfm1y"] +atlas = ExtResource("3_qhqgy") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fulsm"] +atlas = ExtResource("3_qhqgy") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_4r5pv"] +atlas = ExtResource("3_qhqgy") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_60mlk"] +atlas = ExtResource("3_qhqgy") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="SpriteFrames" id="SpriteFrames_jej6c"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_i4ail") +}], +"loop": false, +"name": &"falling", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_qhqgy") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_dqkch") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_qlg0r") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_tuyoq") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fjrip") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_smehm") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ur7pv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_y4r1p") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_d2wvv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_3v2ag") +}], +"loop": true, +"name": &"idle", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_a38lo") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_4ni07") +}], +"loop": false, +"name": &"jumping", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_jej6c") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_f1ej7") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_oprun") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_a8ls1") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_qfm1y") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fulsm") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_4r5pv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_60mlk") +}], +"loop": true, +"name": &"running", +"speed": 12.0 +}] + [node name="Player" type="CharacterBody2D" unique_id=161143934] script = ExtResource("1_3vyb7") metadata/_edit_group_ = true @@ -17,3 +190,12 @@ position = Vector2(15, -3) [node name="LeftTarget" type="Marker2D" parent="." unique_id=212282016] position = Vector2(-15, -3) + +[node name="PlayerGraphic" type="AnimatedSprite2D" parent="." unique_id=726229378] +texture_filter = 1 +position = Vector2(1, -7) +sprite_frames = SubResource("SpriteFrames_jej6c") +animation = &"falling" +autoplay = "idle" + +[connection signal="animation_finished" from="PlayerGraphic" to="." method="_on_animation_finished"] diff --git a/scripts/bullet.gd b/scripts/bullet.gd index 77d2224..83d355c 100644 --- a/scripts/bullet.gd +++ b/scripts/bullet.gd @@ -1,12 +1,17 @@ class_name Bullet extends Area2D var speed:float = 700 - +signal bulletDamageSignal(body, bullet) # Called when the node enters the scene tree for the first time. func _ready() -> void: pass # Replace with function body. - +func setSpeed(value)->void: + speed = value # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: position += transform.x * speed *delta + + +func _on_body_entered(body: Node2D) -> void: + bulletDamageSignal.emit(body, self) diff --git a/scripts/gameController.gd b/scripts/gameController.gd index ea24d12..2819d70 100644 --- a/scripts/gameController.gd +++ b/scripts/gameController.gd @@ -11,6 +11,7 @@ var timeAvailable := 10 # Called when the node enters the scene tree for the first time. func _ready() -> void: + get_window().grab_focus() add_child(timer) timer.wait_time = 1 timer.one_shot= false @@ -33,10 +34,6 @@ func _on_trigger(body: Variant, effect, trigger) -> void: if body is Crate: match effect: "destroy": - crateTotal -=1 - if crateTotal <=0: - print("You WON!!!") - levelChangeSignal.emit(currentScene) destroySignal.emit(body) "teleport": print("GC teleport an object") @@ -52,3 +49,12 @@ func _on_trigger(body: Variant, effect, trigger) -> void: func crateUpdate(cratesAmount)->void: crateTotal = cratesAmount print("GC updated crates: "+str(crateTotal)) + if crateTotal <=0: + print("You WON!!!") + levelChangeSignal.emit(currentScene) + +func bulletDamage(body:Node2D, bullet:Bullet)->void: + if body is Crate: + #destroy crate + destroySignal.emit(body) + destroySignal.emit(bullet) diff --git a/scripts/npc_character.gd b/scripts/npc_character.gd new file mode 100644 index 0000000..7c9252b --- /dev/null +++ b/scripts/npc_character.gd @@ -0,0 +1,12 @@ +class_name NPCCharacter extends CharacterBody2D + +func _physics_process(delta: float) -> void: + if not is_on_floor(): + velocity += get_gravity() * delta + + move_and_slide() + +func knockBack(direction, duration:float=0.2): + velocity = direction + await get_tree().create_timer(duration).timeout + velocity = Vector2.ZERO diff --git a/scripts/npc_character.gd.uid b/scripts/npc_character.gd.uid new file mode 100644 index 0000000..44ea95c --- /dev/null +++ b/scripts/npc_character.gd.uid @@ -0,0 +1 @@ +uid://gutmbv5ff4u4 diff --git a/scripts/player.gd b/scripts/player.gd index e81c810..42dcd97 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -2,6 +2,7 @@ class_name Player extends CharacterBody2D @onready var right_target: Marker2D = $RightTarget @onready var left_target: Marker2D = $LeftTarget +@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic const SPEED = 300.0 @@ -9,11 +10,32 @@ const JUMP_VELOCITY = -400.0 const BUMP_POWER = 50 enum FaceDirection{LEFT, RIGHT} var facing:FaceDirection = FaceDirection.RIGHT +var direction +enum PlayerState{IDLE,RUNNING, JUMPING, FALLING} +var current_player_state:PlayerState = PlayerState.IDLE +var jumpUp:bool = false func _physics_process(delta: float) -> void: - # Add the gravity. - if not is_on_floor(): - velocity += get_gravity() * delta + + handle_input() + handle_movement(delta) + handle_state() + handle_animation() + move_and_slide() + handle_collisions() + +func handle_input()->void: + direction = Input.get_axis("ui_left", "ui_right") + if direction <0: + player_graphic.flip_h = true + if direction >0: + player_graphic.flip_h = false + + # Handle jump. + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + velocity.y = JUMP_VELOCITY + current_player_state = PlayerState.JUMPING + jumpUp = true # Handle Shoot if Input.is_action_just_pressed("shoot"): print("Player wants to shoot") @@ -24,14 +46,36 @@ func _physics_process(delta: float) -> void: FaceDirection.LEFT: print("Shoot to the left") %SceneManager.makeBullet(left_target.global_transform, -700) - - # Handle jump. - if Input.is_action_just_pressed("ui_accept") and is_on_floor(): - velocity.y = JUMP_VELOCITY - - # Get the input direction and handle the movement/deceleration. - # As good practice, you should replace UI actions with custom gameplay actions. - var direction := Input.get_axis("ui_left", "ui_right") +func handle_state()->void: + match current_player_state: + PlayerState.IDLE when velocity.x !=0: + #change to running!! + current_player_state = PlayerState.RUNNING + PlayerState.RUNNING when velocity.x == 0: + current_player_state = PlayerState.IDLE + PlayerState.JUMPING when velocity.y > 0: + current_player_state = PlayerState.FALLING + PlayerState.FALLING when is_on_floor(): + if velocity.x ==0: + current_player_state = PlayerState.IDLE + else: + current_player_state = PlayerState.RUNNING +func handle_animation()->void: + match current_player_state: + PlayerState.IDLE: + player_graphic.play("idle") + PlayerState.RUNNING: + player_graphic.play("running") + PlayerState.JUMPING: + if jumpUp: + player_graphic.play("jumping") + PlayerState.FALLING: + player_graphic.play("falling") + +func handle_movement(delta)->void: + # Add the gravity. + if not is_on_floor(): + velocity += get_gravity() * delta if direction: velocity.x = direction * SPEED if direction <0: @@ -40,9 +84,17 @@ func _physics_process(delta: float) -> void: facing=FaceDirection.RIGHT else: velocity.x = move_toward(velocity.x, 0, SPEED) - - move_and_slide() +func handle_collisions()->void: for i in get_slide_collision_count(): var c = get_slide_collision(i) if c.get_collider() is RigidBody2D: c.get_collider().apply_central_impulse(-c.get_normal()*BUMP_POWER) + if c.get_collider() is NPCCharacter: + var myCharacter:NPCCharacter = c.get_collider() + var direction = -c.get_normal()*BUMP_POWER + myCharacter.knockBack(direction) + +func _on_animation_finished() -> void: + match current_player_state: + PlayerState.JUMPING: + jumpUp = false diff --git a/scripts/scene_manager.gd b/scripts/scene_manager.gd index d50ad47..69db837 100644 --- a/scripts/scene_manager.gd +++ b/scripts/scene_manager.gd @@ -4,6 +4,9 @@ class_name SceneManager extends Node2D @onready var level: Node2D = $"../Level" @onready var game: GameController = $".." +var bullet = preload("res://scenes/bullet.tscn") +var bulletArray:Array[Bullet] = [] +var totalAllowedBullets:int = 7 # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -43,6 +46,9 @@ func updateCrates()->void: game.crateUpdate(totalCrates) func destroy(body)->void: + if body is Bullet: + stashBullet(body) + return body.queue_free() func teleport(body)->void: if body is Crate: @@ -54,5 +60,29 @@ func teleport(body)->void: func loadLevel(level:String)->void: get_tree().call_deferred("change_scene_to_file", level) +func stashBullet(bullet:Bullet)->void: + var stashPosition:Vector2 = Vector2(-100,100) + bullet.position = stashPosition + bullet.setSpeed(0) + bullet.set_process(false) + +func bulletFactory()->Bullet : + var myBullet:Bullet + #how many bullets have been made? + if bulletArray.size() <= totalAllowedBullets: + myBullet = bullet.instantiate() + if not myBullet.bulletDamageSignal.is_connected(game.bulletDamage): + myBullet.bulletDamageSignal.connect(game.bulletDamage) + game.add_child(myBullet) + else: + myBullet = bulletArray.pop_back() + + bulletArray.push_front(myBullet) + return myBullet func makeBullet(targetPosition, speed)->void: print("Make a bullet!") + print("bullets created: "+str( bulletArray.size() )) + var myBullet:Bullet = bulletFactory() + myBullet.transform = targetPosition + myBullet.setSpeed(speed) + myBullet.set_process(true)