diff --git a/assets/graphics/player/idle/Player Idle 48x48(1).png b/assets/graphics/player/idle/Player Idle 48x48(1).png new file mode 100644 index 0000000..b618511 Binary files /dev/null and b/assets/graphics/player/idle/Player Idle 48x48(1).png differ diff --git a/assets/graphics/player/idle/Player Idle 48x48(1).png.import b/assets/graphics/player/idle/Player Idle 48x48(1).png.import new file mode 100644 index 0000000..d5bfdfd --- /dev/null +++ b/assets/graphics/player/idle/Player Idle 48x48(1).png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cy1khw337wx4h" +path="res://.godot/imported/Player Idle 48x48(1).png-c705822b0c34bad463ef0f6f931f02b9.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/player/idle/Player Idle 48x48(1).png" +dest_files=["res://.godot/imported/Player Idle 48x48(1).png-c705822b0c34bad463ef0f6f931f02b9.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/jump_fall/player jump 48x48.png b/assets/graphics/player/jump_fall/player jump 48x48.png new file mode 100644 index 0000000..dff105c Binary files /dev/null and b/assets/graphics/player/jump_fall/player jump 48x48.png differ 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..38d6cb0 --- /dev/null +++ b/assets/graphics/player/jump_fall/player jump 48x48.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cvcfc7qj6sxfp" +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(1).png b/assets/graphics/player/running/player run 48x48(1).png new file mode 100644 index 0000000..aca5b55 Binary files /dev/null and b/assets/graphics/player/running/player run 48x48(1).png differ diff --git a/assets/graphics/player/running/player run 48x48(1).png.import b/assets/graphics/player/running/player run 48x48(1).png.import new file mode 100644 index 0000000..5c1e320 --- /dev/null +++ b/assets/graphics/player/running/player run 48x48(1).png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cvs62nydereyb" +path="res://.godot/imported/player run 48x48(1).png-f4f8489bea2d5fd6507c190ae77c5d2d.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/player/running/player run 48x48(1).png" +dest_files=["res://.godot/imported/player run 48x48(1).png-f4f8489bea2d5fd6507c190ae77c5d2d.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/project.godot b/project.godot index a0266a6..4c03cd0 100644 --- a/project.godot +++ b/project.godot @@ -17,6 +17,30 @@ config/icon="res://icon.svg" [input] +ui_accept={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194309,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194310,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) +] +} +ui_left={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":13,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) +] +} +ui_right={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) +] +} Shoot={ "deadzone": 0.2, "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(355, 24),"global_position":Vector2(364, 72),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) diff --git a/scenes/bullet.tscn b/scenes/bullet.tscn index 7fc6c47..d8a1898 100644 --- a/scenes/bullet.tscn +++ b/scenes/bullet.tscn @@ -11,3 +11,5 @@ script = ExtResource("1_mkf8s") scale = Vector2(0.47999987, 8.651428) shape = SubResource("RectangleShape2D_h1aey") debug_color = Color(1, 0, 0, 1) + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/scenes/game.tscn b/scenes/game.tscn index e605033..074b59e 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -5,6 +5,7 @@ [ext_resource type="PackedScene" uid="uid://xvv1nyl3ny2g" path="res://scenes/crate.tscn" id="2_lnu2h"] [ext_resource type="PackedScene" uid="uid://dyxqdgvctjshx" path="res://scenes/player.tscn" id="3_iywne"] [ext_resource type="PackedScene" uid="uid://c7i6hsic2uojx" path="res://scenes/trigger.tscn" id="4_lbhrr"] +[ext_resource type="PackedScene" uid="uid://bmkh4wsfm3fbq" path="res://scenes/npc_charector.tscn" id="6_p57ef"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_8cj0n"] size = Vector2(74, 20) @@ -44,7 +45,7 @@ position = Vector2(644, 404) position = Vector2(609, 403) [node name="Crate3" parent="Crates" unique_id=1771442258 instance=ExtResource("2_lnu2h")] -position = Vector2(506, 353.99994) +position = Vector2(585.99994, 378.99997) [node name="Level" type="Node2D" parent="." unique_id=219661874] @@ -62,3 +63,6 @@ metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="Level/Floor" unique_id=895098891] shape = SubResource("WorldBoundaryShape2D_lbhrr") + +[node name="NPCCharector" parent="." unique_id=912777798 instance=ExtResource("6_p57ef")] +position = Vector2(460, 422) diff --git a/scenes/npc_charector.tscn b/scenes/npc_charector.tscn new file mode 100644 index 0000000..afb69d8 --- /dev/null +++ b/scenes/npc_charector.tscn @@ -0,0 +1,12 @@ +[gd_scene format=3 uid="uid://bmkh4wsfm3fbq"] + +[ext_resource type="Script" uid="uid://cj5rps4p0rgja" path="res://scripts/npc_charector.gd" id="1_r6gjy"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_loa6c"] + +[node name="NPCCharector" type="CharacterBody2D" unique_id=912777798] +script = ExtResource("1_r6gjy") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1840833487] +shape = SubResource("CircleShape2D_loa6c") +debug_color = Color(0.9623242, 2.0214916e-06, 0.5080306, 0.41960785) diff --git a/scenes/player.tscn b/scenes/player.tscn index de9fa15..a2a7500 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,12 +1,184 @@ [gd_scene format=3 uid="uid://dyxqdgvctjshx"] [ext_resource type="Script" uid="uid://ctm4xm3lnquco" path="res://scripts/player.gd" id="1_3vyb7"] +[ext_resource type="Texture2D" uid="uid://cvcfc7qj6sxfp" path="res://assets/graphics/player/jump_fall/player jump 48x48.png" id="2_dqkch"] +[ext_resource type="Texture2D" uid="uid://cy1khw337wx4h" path="res://assets/graphics/player/idle/Player Idle 48x48(1).png" id="2_g2els"] +[ext_resource type="Texture2D" uid="uid://cvs62nydereyb" path="res://assets/graphics/player/running/player run 48x48(1).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=401513938] script = ExtResource("1_3vyb7") -metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=31138863] shape = SubResource("CircleShape2D_uwrxv") @@ -17,3 +189,13 @@ position = Vector2(15, -3) [node name="Left Gun" type="Marker2D" parent="." unique_id=1828444534] position = Vector2(-15, -3) + +[node name="PlayerGraphic" type="AnimatedSprite2D" parent="." unique_id=2124252059] +texture_filter = 1 +position = Vector2(0, -10) +sprite_frames = SubResource("SpriteFrames_jej6c") +animation = &"falling" +autoplay = "idle" +frame_progress = 1.0 + +[connection signal="animation_finished" from="PlayerGraphic" to="." method="_on_animation_finished"] diff --git a/scripts/SceneManager.gd b/scripts/SceneManager.gd index 01d5ec4..e6e8894 100644 --- a/scripts/SceneManager.gd +++ b/scripts/SceneManager.gd @@ -5,6 +5,10 @@ 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: buildLevel() @@ -27,7 +31,7 @@ func buildLevel()->void: func updateTriggers()->void: if triggers: for obj in triggers.get_children(): - if obj is trigger: + if obj is Trigger: if not obj.AreaTrigger.is_connected(game._on_trigger): obj.AreaTrigger.connect(game._on_trigger) func updateCrates()->void: @@ -41,6 +45,9 @@ func updateCrates()->void: totalCrates +=1 game.crateUpdate(totalCrates) func destroy(body)->void: + if body is Bullet: + stashBullet(body) + return body.queue_free() func teleport(body)->void: @@ -53,6 +60,27 @@ func teleport(body)->void: func loadLevel(level:String)->void: get_tree().call_deferred("change_scene_to_file", level) - +func stashBullet(bullet:Bullet)->void: + var stashPos:Vector2 = Vector2(-100, -100) + bullet.position = stashPos + bullet.setSpeed(0) + bullet.set_process(false) +func bullectFactory()->Bullet : + var myBullet:Bullet + #how many bullets have we 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 bullet") + print("bullets created"+str(bulletArray.size())) + var myBullet:Bullet = bullectFactory() + myBullet.transform = targetPosition + myBullet.setSpeed(speed) + myBullet.set_process(true) diff --git a/scripts/bullet.gd b/scripts/bullet.gd index 5dde12a..45d24b6 100644 --- a/scripts/bullet.gd +++ b/scripts/bullet.gd @@ -1,11 +1,17 @@ -class_name bullet extends Area2D +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 2887957..3d649b8 100644 --- a/scripts/gameController.gd +++ b/scripts/gameController.gd @@ -10,6 +10,7 @@ var timer := Timer.new() 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 @@ -32,10 +33,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") @@ -48,3 +45,11 @@ 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: + destroySignal.emit(body) + destroySignal.emit(bullet) diff --git a/scripts/npc_charector.gd b/scripts/npc_charector.gd new file mode 100644 index 0000000..fdf897f --- /dev/null +++ b/scripts/npc_charector.gd @@ -0,0 +1,11 @@ +class_name NPCCharector 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_charector.gd.uid b/scripts/npc_charector.gd.uid new file mode 100644 index 0000000..9fd2b7c --- /dev/null +++ b/scripts/npc_charector.gd.uid @@ -0,0 +1 @@ +uid://cj5rps4p0rgja diff --git a/scripts/player.gd b/scripts/player.gd index d328991..ac938b0 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -2,18 +2,46 @@ class_name Player extends CharacterBody2D @onready var right_gun: Marker2D = $"Right Gun" @onready var left_gun: Marker2D = $"Left Gun" +@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic const SPEED = 300 -const JUMP_VELOCITY = -1000.0 -const BUMP_POWER = 50 +const JUMP_VELOCITY = -400.0 +const BUMP_POWER = 100000 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 Shoot + + handle_input() + handle_movement(delta) + handle_state() + handle_animation() + + # Get the input direction and handle the movement/deceleration. + # As good practice, you should replace UI actions with custom gameplay actions. + + + + move_and_slide() + handle_collisions() + +func handle_input()->void: + # Handle jump. + direction = Input.get_axis("ui_left", "ui_right") + if direction <0: + player_graphic.flip_h = true + if direction >0: + player_graphic.flip_h = false + if Input.is_action_just_pressed("ui_accept") : + velocity.y = JUMP_VELOCITY + current_player_state = PlayerState.JUMPING + jumpUp = true if Input.is_action_just_pressed("Shoot"): print("player wants to shoot") match facing: @@ -23,13 +51,36 @@ func _physics_process(delta: float) -> void: FaceDirection.LEFT: print("shoot to the left") %SceneManager.makeBullet(left_gun.global_transform, -700) - # Handle jump. - if Input.is_action_just_pressed("ui_accept") : - 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: + 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 + if velocity.x !=0: + 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: @@ -38,9 +89,18 @@ func _physics_process(delta: float) -> void: facing=FaceDirection.LEFT 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 NPCCharector: + var myCharector:NPCCharector = c.get_collider() + var direction = -c.get_normal()*BUMP_POWER + myCharector.knockBack(direction) + + +func _on_animation_finished() -> void: + match current_player_state: + PlayerState.JUMPING: + jumpUp = false diff --git a/scripts/trigger.gd b/scripts/trigger.gd index 6eaf7c3..38c538d 100644 --- a/scripts/trigger.gd +++ b/scripts/trigger.gd @@ -1,4 +1,4 @@ -class_name trigger extends Area2D +class_name Trigger extends Area2D signal AreaTrigger(body, effect, trigger) @export var effect="destroy"