diff --git a/januaryproject/assets/graphics/destructables/crate.png b/januaryproject/assets/graphics/destructables/crate.png new file mode 100644 index 0000000..2b8bdcd Binary files /dev/null and b/januaryproject/assets/graphics/destructables/crate.png differ diff --git a/januaryproject/assets/graphics/destructables/crate.png.import b/januaryproject/assets/graphics/destructables/crate.png.import new file mode 100644 index 0000000..d88f777 --- /dev/null +++ b/januaryproject/assets/graphics/destructables/crate.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dh1d2qkxwg3vt" +path="res://.godot/imported/crate.png-91961d6f3a0764bc8758ad055606c6d0.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/destructables/crate.png" +dest_files=["res://.godot/imported/crate.png-91961d6f3a0764bc8758ad055606c6d0.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/januaryproject/assets/graphics/player/idle/Player Idle 48x48.png b/januaryproject/assets/graphics/player/idle/Player Idle 48x48.png new file mode 100644 index 0000000..b618511 Binary files /dev/null and b/januaryproject/assets/graphics/player/idle/Player Idle 48x48.png differ diff --git a/januaryproject/assets/graphics/player/idle/Player Idle 48x48.png.import b/januaryproject/assets/graphics/player/idle/Player Idle 48x48.png.import new file mode 100644 index 0000000..152f4c6 --- /dev/null +++ b/januaryproject/assets/graphics/player/idle/Player Idle 48x48.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c8esv4rqrll0u" +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/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/januaryproject/assets/graphics/player/jump/player jump 48x48.png b/januaryproject/assets/graphics/player/jump/player jump 48x48.png new file mode 100644 index 0000000..dff105c Binary files /dev/null and b/januaryproject/assets/graphics/player/jump/player jump 48x48.png differ diff --git a/januaryproject/assets/graphics/player/jump/player jump 48x48.png.import b/januaryproject/assets/graphics/player/jump/player jump 48x48.png.import new file mode 100644 index 0000000..c1af1c4 --- /dev/null +++ b/januaryproject/assets/graphics/player/jump/player jump 48x48.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cpksf8fvm4k26" +path="res://.godot/imported/player jump 48x48.png-1ccba0c36041038682bf917e1f6cf991.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/player/jump/player jump 48x48.png" +dest_files=["res://.godot/imported/player jump 48x48.png-1ccba0c36041038682bf917e1f6cf991.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/januaryproject/assets/graphics/player/run/player run 48x48.png b/januaryproject/assets/graphics/player/run/player run 48x48.png new file mode 100644 index 0000000..aca5b55 Binary files /dev/null and b/januaryproject/assets/graphics/player/run/player run 48x48.png differ diff --git a/januaryproject/assets/graphics/player/run/player run 48x48.png.import b/januaryproject/assets/graphics/player/run/player run 48x48.png.import new file mode 100644 index 0000000..8bedd36 --- /dev/null +++ b/januaryproject/assets/graphics/player/run/player run 48x48.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://lum1fe47ggoy" +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/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/januaryproject/assets/graphics/projectiles/pixel_bullet.png b/januaryproject/assets/graphics/projectiles/pixel_bullet.png new file mode 100644 index 0000000..900d030 Binary files /dev/null and b/januaryproject/assets/graphics/projectiles/pixel_bullet.png differ diff --git a/januaryproject/assets/graphics/projectiles/pixel_bullet.png.import b/januaryproject/assets/graphics/projectiles/pixel_bullet.png.import new file mode 100644 index 0000000..02bf04c --- /dev/null +++ b/januaryproject/assets/graphics/projectiles/pixel_bullet.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c4rwvfk7efpru" +path="res://.godot/imported/pixel_bullet.png-30d6d1e8b5e1332f8b2e2cee72a9e790.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/projectiles/pixel_bullet.png" +dest_files=["res://.godot/imported/pixel_bullet.png-30d6d1e8b5e1332f8b2e2cee72a9e790.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/januaryproject/assets/graphics/terrains/Terrain (32x32).png b/januaryproject/assets/graphics/terrains/Terrain (32x32).png new file mode 100644 index 0000000..ddf1eaf Binary files /dev/null and b/januaryproject/assets/graphics/terrains/Terrain (32x32).png differ diff --git a/januaryproject/assets/graphics/terrains/Terrain (32x32).png.import b/januaryproject/assets/graphics/terrains/Terrain (32x32).png.import new file mode 100644 index 0000000..8e1673a --- /dev/null +++ b/januaryproject/assets/graphics/terrains/Terrain (32x32).png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dcx8qbotrbgpp" +path="res://.godot/imported/Terrain (32x32).png-7361ca574569f6e5ff16ef11d25a8904.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/terrains/Terrain (32x32).png" +dest_files=["res://.godot/imported/Terrain (32x32).png-7361ca574569f6e5ff16ef11d25a8904.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/januaryproject/project.godot b/januaryproject/project.godot index 3e030a8..e12a171 100644 --- a/januaryproject/project.godot +++ b/januaryproject/project.godot @@ -15,6 +15,14 @@ run/main_scene="res://scenes/game.tscn" config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://icon.svg" +[display] + +window/size/viewport_width=320 +window/size/viewport_height=180 +window/size/window_width_override=960 +window/size/window_height_override=540 +window/stretch/mode="viewport" + [file_customization] folder_colors={ diff --git a/januaryproject/scenes/bullet.tscn b/januaryproject/scenes/bullet.tscn index b9fad73..820761c 100644 --- a/januaryproject/scenes/bullet.tscn +++ b/januaryproject/scenes/bullet.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://ckc5gbyie17tm"] +[gd_scene load_steps=4 format=3 uid="uid://ckc5gbyie17tm"] [ext_resource type="Script" path="res://scripts/bullet.gd" id="1_fxxmp"] +[ext_resource type="Texture2D" uid="uid://c4rwvfk7efpru" path="res://assets/graphics/projectiles/pixel_bullet.png" id="2_0y61d"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_rws30"] size = Vector2(10, 4) @@ -12,4 +13,11 @@ script = ExtResource("1_fxxmp") shape = SubResource("RectangleShape2D_rws30") debug_color = Color(0.892283, 0.284139, 0.402358, 0.42) +[node name="Sprite2D" type="Sprite2D" parent="."] +texture_filter = 1 +position = Vector2(-3, -2) +rotation = 3.14089 +scale = Vector2(0.0794906, 0.0794906) +texture = ExtResource("2_0y61d") + [connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/januaryproject/scenes/crate.tscn b/januaryproject/scenes/crate.tscn index 4622fa3..7124af5 100644 --- a/januaryproject/scenes/crate.tscn +++ b/januaryproject/scenes/crate.tscn @@ -1,10 +1,18 @@ -[gd_scene load_steps=2 format=3 uid="uid://di3tq4f0xmdqc"] +[gd_scene load_steps=3 format=3 uid="uid://di3tq4f0xmdqc"] + +[ext_resource type="Texture2D" uid="uid://dh1d2qkxwg3vt" path="res://assets/graphics/destructables/crate.png" id="1_vh3j5"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_jqoba"] [node name="RigidBody2D" type="RigidBody2D" groups=["destructable"]] metadata/_edit_group_ = true +[node name="Sprite2D" type="Sprite2D" parent="."] +texture_filter = 1 +position = Vector2(0, 2) +scale = Vector2(0.0719266, 0.0719266) +texture = ExtResource("1_vh3j5") + [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource("RectangleShape2D_jqoba") debug_color = Color(0.801265, 0.412511, 0.212642, 0.42) diff --git a/januaryproject/scenes/game.tscn b/januaryproject/scenes/game.tscn index f149201..5b4959b 100644 --- a/januaryproject/scenes/game.tscn +++ b/januaryproject/scenes/game.tscn @@ -26,21 +26,6 @@ metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] shape = SubResource("RectangleShape2D_jk5qv") -[node name="RigidBody2D" parent="." instance=ExtResource("1_tfj4n")] -position = Vector2(291, 405) -rotation = 2.0228 - -[node name="RigidBody2D2" parent="." instance=ExtResource("1_tfj4n")] -position = Vector2(509, 216) - -[node name="RigidBody2D3" parent="." instance=ExtResource("1_tfj4n")] -position = Vector2(576, 241) -rotation = -1.0315 - -[node name="RigidBody2D4" parent="." instance=ExtResource("1_tfj4n")] -position = Vector2(540, 178) -rotation = 0.0531393 - [node name="floor" type="StaticBody2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="floor"] @@ -65,5 +50,22 @@ position = Vector2(178, 316) unique_name_in_owner = true script = ExtResource("6_1kka5") +[node name="crates" type="Node2D" parent="."] + +[node name="RigidBody2D" parent="crates" instance=ExtResource("1_tfj4n")] +position = Vector2(291, 405) +rotation = 2.0228 + +[node name="RigidBody2D2" parent="crates" instance=ExtResource("1_tfj4n")] +position = Vector2(509, 216) + +[node name="RigidBody2D3" parent="crates" instance=ExtResource("1_tfj4n")] +position = Vector2(576, 241) +rotation = -1.0315 + +[node name="RigidBody2D4" parent="crates" instance=ExtResource("1_tfj4n")] +position = Vector2(540, 178) +rotation = 0.0531393 + [connection signal="areaTrigger" from="Area2D" to="." method="_on_trigger"] [connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"] diff --git a/januaryproject/scenes/player.tscn b/januaryproject/scenes/player.tscn index a84c7a9..bea574d 100644 --- a/januaryproject/scenes/player.tscn +++ b/januaryproject/scenes/player.tscn @@ -1,9 +1,177 @@ -[gd_scene load_steps=3 format=3 uid="uid://dcbk086hhrn7y"] +[gd_scene load_steps=28 format=3 uid="uid://dcbk086hhrn7y"] [ext_resource type="Script" path="res://scripts/charactercontroller.gd" id="1_6alft"] +[ext_resource type="Texture2D" uid="uid://c8esv4rqrll0u" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_itql4"] +[ext_resource type="Texture2D" uid="uid://cpksf8fvm4k26" path="res://assets/graphics/player/jump/player jump 48x48.png" id="3_fjlo4"] +[ext_resource type="Texture2D" uid="uid://lum1fe47ggoy" path="res://assets/graphics/player/run/player run 48x48.png" id="3_fp3hq"] [sub_resource type="CircleShape2D" id="CircleShape2D_qrixx"] +[sub_resource type="AtlasTexture" id="AtlasTexture_xei83"] +atlas = ExtResource("2_itql4") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_0rt17"] +atlas = ExtResource("2_itql4") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_sud8s"] +atlas = ExtResource("2_itql4") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_l40ca"] +atlas = ExtResource("2_itql4") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fccip"] +atlas = ExtResource("2_itql4") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fsk16"] +atlas = ExtResource("2_itql4") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ub2tx"] +atlas = ExtResource("2_itql4") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_7c3ch"] +atlas = ExtResource("2_itql4") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_yr10o"] +atlas = ExtResource("2_itql4") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_xw5gp"] +atlas = ExtResource("2_itql4") +region = Rect2(432, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_4x1vb"] +atlas = ExtResource("3_fjlo4") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_secem"] +atlas = ExtResource("3_fjlo4") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gwif0"] +atlas = ExtResource("3_fjlo4") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_5c5x4"] +atlas = ExtResource("3_fp3hq") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_12spb"] +atlas = ExtResource("3_fp3hq") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_atg7s"] +atlas = ExtResource("3_fp3hq") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_xrqff"] +atlas = ExtResource("3_fp3hq") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_exuqk"] +atlas = ExtResource("3_fp3hq") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_1g4qy"] +atlas = ExtResource("3_fp3hq") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_6po63"] +atlas = ExtResource("3_fp3hq") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_epwr5"] +atlas = ExtResource("3_fp3hq") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="SpriteFrames" id="SpriteFrames_yi1g3"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_xei83") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_0rt17") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_sud8s") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_l40ca") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fccip") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fsk16") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ub2tx") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_7c3ch") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_yr10o") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_xw5gp") +}], +"loop": true, +"name": &"idle", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_4x1vb") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_secem") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_gwif0") +}], +"loop": false, +"name": &"jump", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_5c5x4") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_12spb") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_atg7s") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_xrqff") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_exuqk") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_1g4qy") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_6po63") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_epwr5") +}], +"loop": true, +"name": &"run", +"speed": 12.0 +}] + [node name="CharacterBody2D" type="CharacterBody2D" groups=["player"]] script = ExtResource("1_6alft") metadata/_edit_group_ = true @@ -23,3 +191,11 @@ position = Vector2(10, -5) [node name="LeftTarget" type="Node2D" parent="."] position = Vector2(-10, -5) + +[node name="Camera2D" type="Camera2D" parent="."] + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +texture_filter = 1 +sprite_frames = SubResource("SpriteFrames_yi1g3") +animation = &"jump" +autoplay = "jump" diff --git a/januaryproject/scripts/bullet.gd b/januaryproject/scripts/bullet.gd index d64553c..1da33b1 100644 --- a/januaryproject/scripts/bullet.gd +++ b/januaryproject/scripts/bullet.gd @@ -1,4 +1,5 @@ class_name Bullet extends Area2D +@onready var bulletGraphic: Sprite2D = $Sprite2D var speed = 700 signal hit @@ -17,9 +18,13 @@ func _physics_process(delta: float) -> void: func setSpeed(value): speed = value + if speed <0: + bulletGraphic.flip_h = true + else: + bulletGraphic.flip_h = false func _on_body_entered(body: Node2D) -> void: print("Bullet hit sumtin") if not body.is_in_group("player"): - hit.emit(body) + hit.emit(self, body) diff --git a/januaryproject/scripts/charactercontroller.gd b/januaryproject/scripts/charactercontroller.gd index d27ddf2..5b59901 100644 --- a/januaryproject/scripts/charactercontroller.gd +++ b/januaryproject/scripts/charactercontroller.gd @@ -4,6 +4,7 @@ extends CharacterBody2D const SPEED = 500.0 const JUMP_VELOCITY = -600.0 @export var BUMP_FORCE = 90 +@onready var animation: AnimatedSprite2D = $AnimatedSprite2D # Shove Attack Variables @onready var right_ray: RayCast2D = $RightRay @@ -18,15 +19,21 @@ var pushLeftEnabled = false @onready var right_target: Node2D = $RightTarget @onready var left_target: Node2D = $LeftTarget +var isJumping = false func _physics_process(delta: float) -> void: # Add the gravity. if not is_on_floor(): + velocity += get_gravity() * delta - + else: + isJumping = false + # Handle jump. if Input.is_action_just_pressed("jump") and is_on_floor(): velocity.y = JUMP_VELOCITY + animation.play("jump") + isJumping = true # Shove Attack if Input.is_action_just_pressed("shove"): @@ -36,26 +43,33 @@ func _physics_process(delta: float) -> void: pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 2 ) # Handle Shooting if Input.is_action_just_pressed("shoot"): - # make a new bullet - var myBullet = %SceneManager.bulletFactory() - - #var myBullet = bullet.instantiate() - owner.add_child(myBullet) - myBullet.transform = right_target.global_transform + if faceLeft == true: - myBullet.transform = left_target.global_transform - myBullet.setSpeed(-700) - + var myBullet = %SceneManager.makeBullet(left_target.global_transform, -700) + #myBullet.transform = left_target.global_transform + #myBullet.setSpeed(-700) + if faceLeft == false: + var myBullet = %SceneManager.makeBullet(right_target.global_transform, 700) + # 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("left", "right") if direction: velocity.x = direction * SPEED if direction <0: + if not isJumping: + animation.play("run") faceLeft = true + animation.flip_h = true if direction >0: + if not isJumping: + animation.play("run") faceLeft = false + animation.flip_h = false + else: + if not isJumping: + animation.play("idle") velocity.x = move_toward(velocity.x, 0, SPEED) move_and_slide() diff --git a/januaryproject/scripts/gamecontroller.gd b/januaryproject/scripts/gamecontroller.gd index 5b61119..1c2c8e8 100644 --- a/januaryproject/scripts/gamecontroller.gd +++ b/januaryproject/scripts/gamecontroller.gd @@ -3,6 +3,9 @@ extends Node2D var boxTotal = 4 var timer:= Timer.new() var countdown = 10 +var totalCrates = 0 + +signal destroyBox(body) # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -36,5 +39,7 @@ func _on_trigger(effect: Variant, body) -> void: func bulletHit(body): print("Game controller knows bullet hit something") if body.is_in_group("destructable"): - body.queue_free() - + destroyBox.emit(body) + +func countCrates(value): + totalCrates = value diff --git a/januaryproject/scripts/scene_manager.gd b/januaryproject/scripts/scene_manager.gd index 7b4895a..94a4e68 100644 --- a/januaryproject/scripts/scene_manager.gd +++ b/januaryproject/scripts/scene_manager.gd @@ -1,11 +1,23 @@ extends Node @onready var game: Node2D = $".." +@onready var crates: Node2D = $"../crates" var bullet = preload("res://scenes/bullet.tscn") +var bulletArray:Array = [] +var bulletsMadeTotal :=0 +var totalCrates := 0 # Called when the node enters the scene tree for the first time. func _ready() -> void: - pass # Replace with function body. + game.destroyBox.connect(boxDestroy) + for obj in crates.get_children(): + if obj.is_in_group("destructable"): + #increase the box counter + totalCrates +=1 + + + + # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -14,10 +26,31 @@ func _process(delta: float) -> void: func bulletFactory(): print("Factory will make a bullet") - var myBullet = bullet.instantiate() - myBullet.connect("hit", onBulletHit) + var myBullet + if bulletArray.size() < 4: + myBullet = bullet.instantiate() + myBullet.connect("hit", onBulletHit) + owner.add_child(myBullet) + else: + myBullet = bulletArray.pop_back() + + bulletArray.push_front(myBullet) return myBullet -func onBulletHit(body): + +func makeBullet(position, speed): + var myBullet = bulletFactory() + myBullet.transform = position + myBullet.setSpeed(speed) + return myBullet + +func onBulletHit(bullet, body): + bullet.position = Vector2(-100,-100) + bullet.setSpeed(0) + print("Scene manager knows bullet hit") game.bulletHit(body) + +func boxDestroy(body): + body.queue_free() +