diff --git a/Scenes/game.tscn b/Scenes/game.tscn index 61778b3..2ee547f 100644 --- a/Scenes/game.tscn +++ b/Scenes/game.tscn @@ -5,6 +5,7 @@ [ext_resource type="Script" uid="uid://cnm7tj6umtwtm" path="res://Scripts/scene_manager.gd" id="2_wowpa"] [ext_resource type="PackedScene" uid="uid://caa73phf3ng5m" path="res://Scenes/player.tscn" id="3_wowpa"] [ext_resource type="Script" uid="uid://4hekg0d8n04f" path="res://Scripts/trigger.gd" id="3_wrm1d"] +[ext_resource type="PackedScene" uid="uid://dotmw0uwnqv6w" path="res://Scenes/grenade.tscn" id="6_i6g32"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_2poj3"] size = Vector2(84, 20) @@ -54,10 +55,13 @@ debug_color = Color(0.7716697, 0.28327075, 0.8513461, 0.41960785) position = Vector2(385, 428) [node name="Crate2" parent="Crates" unique_id=1931037062 instance=ExtResource("2_3dryh")] -position = Vector2(430, 140) +position = Vector2(436, 433) [node name="Crate4" parent="Crates" unique_id=585069069 instance=ExtResource("2_3dryh")] -position = Vector2(461, 134) +position = Vector2(481, 433) + +[node name="Grenade" parent="." unique_id=638454305 instance=ExtResource("6_i6g32")] +position = Vector2(385, 375) [connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"] [connection signal="triggerActiveSignal" from="Area2D" to="." method="_on_triggerSignal"] diff --git a/Scenes/grenade.tscn b/Scenes/grenade.tscn new file mode 100644 index 0000000..17aaa18 --- /dev/null +++ b/Scenes/grenade.tscn @@ -0,0 +1,17 @@ +[gd_scene format=3 uid="uid://dotmw0uwnqv6w"] + +[ext_resource type="Script" uid="uid://bd8br3emm1nhb" path="res://Scripts/grenade.gd" id="1_v44n1"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_b5j7x"] +radius = 5.0 + +[node name="Grenade" type="RigidBody2D" unique_id=638454305] +contact_monitor = true +max_contacts_reported = 3 +script = ExtResource("1_v44n1") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1542775089] +shape = SubResource("CircleShape2D_b5j7x") +debug_color = Color(0.81554836, 0.40704176, 0.03861203, 0.41960785) + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/Scenes/player.tscn b/Scenes/player.tscn index 0131a50..f31f40b 100644 --- a/Scenes/player.tscn +++ b/Scenes/player.tscn @@ -1,9 +1,150 @@ [gd_scene format=3 uid="uid://caa73phf3ng5m"] [ext_resource type="Script" uid="uid://btmoyp0rwqmxe" path="res://Scripts/player.gd" id="1_v0iea"] +[ext_resource type="Texture2D" uid="uid://dlax6d4nhkl4p" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_cvnsp"] +[ext_resource type="Texture2D" uid="uid://bc251ptp8ujsv" path="res://assets/graphics/player/run/player run 48x48.png" id="3_6t5aa"] [sub_resource type="CircleShape2D" id="CircleShape2D_2poj3"] +[sub_resource type="AtlasTexture" id="AtlasTexture_6t5aa"] +atlas = ExtResource("2_cvnsp") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_vgqql"] +atlas = ExtResource("2_cvnsp") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fkybt"] +atlas = ExtResource("2_cvnsp") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_x3wgy"] +atlas = ExtResource("2_cvnsp") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_3smsa"] +atlas = ExtResource("2_cvnsp") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_8erm5"] +atlas = ExtResource("2_cvnsp") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_f1ek2"] +atlas = ExtResource("2_cvnsp") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_tx1dd"] +atlas = ExtResource("2_cvnsp") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gymyn"] +atlas = ExtResource("2_cvnsp") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_pu2lt"] +atlas = ExtResource("2_cvnsp") +region = Rect2(432, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ukyrk"] +atlas = ExtResource("3_6t5aa") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_7dp3o"] +atlas = ExtResource("3_6t5aa") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_h4iuc"] +atlas = ExtResource("3_6t5aa") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fd4e3"] +atlas = ExtResource("3_6t5aa") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_qqcod"] +atlas = ExtResource("3_6t5aa") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_igrcy"] +atlas = ExtResource("3_6t5aa") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fs7ks"] +atlas = ExtResource("3_6t5aa") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_l6n3p"] +atlas = ExtResource("3_6t5aa") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="SpriteFrames" id="SpriteFrames_ukyrk"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_6t5aa") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_vgqql") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fkybt") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_x3wgy") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_3smsa") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_8erm5") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_f1ek2") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_tx1dd") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_gymyn") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_pu2lt") +}], +"loop": true, +"name": &"idle", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_ukyrk") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_7dp3o") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_h4iuc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fd4e3") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_qqcod") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_igrcy") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fs7ks") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_l6n3p") +}], +"loop": true, +"name": &"run", +"speed": 12.0 +}] + [node name="Player" type="CharacterBody2D" unique_id=1717313761] script = ExtResource("1_v0iea") metadata/_edit_group_ = true @@ -17,3 +158,18 @@ target_position = Vector2(17, 0) [node name="LeftCast" type="RayCast2D" parent="." unique_id=839132816] target_position = Vector2(-17, 0) + +[node name="RightSpawn" type="Marker2D" parent="." unique_id=1154451890] +position = Vector2(13, -8) + +[node name="LeftSpawn" type="Marker2D" parent="." unique_id=52406940] +position = Vector2(-14, -8) + +[node name="PlayerGraphic" type="AnimatedSprite2D" parent="." unique_id=149398795] +texture_filter = 1 +position = Vector2(0, -6) +sprite_frames = SubResource("SpriteFrames_ukyrk") +animation = &"run" +autoplay = "idle" +frame = 5 +frame_progress = 0.17384599 diff --git a/Scripts/grenade.gd b/Scripts/grenade.gd new file mode 100644 index 0000000..d90fa68 --- /dev/null +++ b/Scripts/grenade.gd @@ -0,0 +1,24 @@ +class_name Grenade extends RigidBody2D + +var timer = Timer.new() + +func _ready() -> void: + add_child(timer) + #how long + timer.wait_time = 2 + #one time only + timer.one_shot = true + timer.connect("timeout", explode) + timer.start() + +func explode()->void: + print("ima splode") + self.queue_free() + + + +func _on_body_entered(body: Node) -> void: + print("Collision w Grenade!!") + if body.is_in_group("destructible"): + body.queue_free() + explode() diff --git a/Scripts/grenade.gd.uid b/Scripts/grenade.gd.uid new file mode 100644 index 0000000..0fdc6d0 --- /dev/null +++ b/Scripts/grenade.gd.uid @@ -0,0 +1 @@ +uid://bd8br3emm1nhb diff --git a/Scripts/player.gd b/Scripts/player.gd index 5e95a4f..429ecda 100644 --- a/Scripts/player.gd +++ b/Scripts/player.gd @@ -1,6 +1,9 @@ class_name Player extends CharacterBody2D @onready var right_cast: RayCast2D = $RightCast @onready var left_cast: RayCast2D = $LeftCast +@onready var right_spawn: Marker2D = $RightSpawn +@onready var left_spawn: Marker2D = $LeftSpawn +@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic const SPEED = 300.0 @@ -8,6 +11,8 @@ const JUMP_VELOCITY = -400.0 var direction enum FaceDirection{LEFT,RIGHT} var facing:FaceDirection = FaceDirection.RIGHT +enum PlayerState{IDLE,RUNNING} +var current_player_state:PlayerState = PlayerState.IDLE var pushTarget:RigidBody2D var pushEnabled:bool = false @@ -15,10 +20,16 @@ var pushEnabled:bool = false func _physics_process(delta: float) -> void: handle_input() handle_movement(delta) + handle_state() + handle_animation() move_and_slide() handle_collisions() func handle_input()->void: + if Input.is_action_just_pressed("chuck"): + print("Chuck a grenade") + %SceneManager.makeGrenade(right_spawn.global_transform, 1) + if Input.is_action_just_pressed("shove") and pushEnabled: print("Shove somethin") # determine what direction to shove the thing @@ -38,8 +49,10 @@ func handle_input()->void: direction = Input.get_axis("left", "right") if direction<0: facing = FaceDirection.LEFT + player_graphic.flip_h = true if direction>0: facing = FaceDirection.RIGHT + player_graphic.flip_h = false func handle_movement(delta)->void: # Add the gravity. @@ -72,4 +85,21 @@ func handle_collisions()->void: var c = get_slide_collision(i) if c.get_collider() is RigidBody2D: #deliver the impact - c.get_collider().apply_central_impulse(-c.get_normal() * 100) + if not c.get_collider() is Grenade: + c.get_collider().apply_central_impulse(-c.get_normal() * 100) + +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 + +func handle_animation()->void: + match current_player_state: + PlayerState.IDLE: + player_graphic.play("idle") + PlayerState.RUNNING: + player_graphic.play("run") + diff --git a/Scripts/scene_manager.gd b/Scripts/scene_manager.gd index cb8a2f5..402796f 100644 --- a/Scripts/scene_manager.gd +++ b/Scripts/scene_manager.gd @@ -1,6 +1,7 @@ class_name SceneManager extends Node2D @onready var game: Node2D = $".." @onready var crates: Node2D = $"../Crates" +var grenade = preload("res://Scenes/grenade.tscn") func _ready() -> void: print("Scene manager is ready!") @@ -25,3 +26,11 @@ func updateCrates()->void: _crateTotal +=1 print("Number of crates: "+str(_crateTotal)) game.totalCrates(_crateTotal) + +func makeGrenade(_grenadePosition, _grenadeDirection)->void: + print("SM wants to make a grenade") + var myGrenade:Grenade = grenade.instantiate() + owner.add_child(myGrenade) + myGrenade.transform = _grenadePosition + myGrenade.apply_central_impulse(Vector2(_grenadeDirection,-1)*200) + 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 0000000..b618511 Binary files /dev/null and b/assets/graphics/player/idle/Player Idle 48x48.png differ diff --git a/assets/graphics/player/idle/Player Idle 48x48.png.import b/assets/graphics/player/idle/Player Idle 48x48.png.import new file mode 100644 index 0000000..acee59d --- /dev/null +++ b/assets/graphics/player/idle/Player Idle 48x48.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dlax6d4nhkl4p" +path="res://.godot/imported/Player Idle 48x48.png-9f43f14976963a2821a06ddf8579a76a.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/player/idle/Player Idle 48x48.png" +dest_files=["res://.godot/imported/Player Idle 48x48.png-9f43f14976963a2821a06ddf8579a76a.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/run/player run 48x48.png b/assets/graphics/player/run/player run 48x48.png new file mode 100644 index 0000000..aca5b55 Binary files /dev/null and b/assets/graphics/player/run/player run 48x48.png differ diff --git a/assets/graphics/player/run/player run 48x48.png.import b/assets/graphics/player/run/player run 48x48.png.import new file mode 100644 index 0000000..41e16f0 --- /dev/null +++ b/assets/graphics/player/run/player run 48x48.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bc251ptp8ujsv" +path="res://.godot/imported/player run 48x48.png-6d66612d48bfa4c8721495ba557ab7c6.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/player/run/player run 48x48.png" +dest_files=["res://.godot/imported/player run 48x48.png-6d66612d48bfa4c8721495ba557ab7c6.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 fcc6d16..b96c827 100644 --- a/project.godot +++ b/project.godot @@ -44,6 +44,11 @@ right={ "events": [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":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +chuck={ +"deadzone": 0.2, +"events": [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":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null) +] +} [physics]