diff --git a/project.godot b/project.godot index f409213..f74bfc0 100644 --- a/project.godot +++ b/project.godot @@ -21,3 +21,16 @@ folder_colors={ "res://scenes/": "green", "res://scripts/": "orange" } + +[input] + +Shove={ +"deadzone": 0.5, +"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":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null) +] +} +Shoot={ +"deadzone": 0.5, +"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":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null) +] +} diff --git a/scenes/bullet.tscn b/scenes/bullet.tscn new file mode 100644 index 0000000..8d2a0c5 --- /dev/null +++ b/scenes/bullet.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=3 format=3 uid="uid://b53r5iysu7d4t"] + +[ext_resource type="Script" path="res://scripts/bullet.gd" id="1_qubif"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_qxj7e"] +size = Vector2(19, 4) + +[node name="Area2D" type="Area2D"] +script = ExtResource("1_qubif") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(-0.5, 0) +shape = SubResource("RectangleShape2D_qxj7e") +debug_color = Color(0.717124, 0, 0.290401, 0.42) + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/scenes/game.tscn b/scenes/game.tscn index a360818..d069116 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,8 +1,8 @@ -[gd_scene load_steps=9 format=3 uid="uid://dhgts0kodsujx"] +[gd_scene load_steps=8 format=3 uid="uid://dhgts0kodsujx"] [ext_resource type="PackedScene" uid="uid://djkjmi7bo58uv" path="res://scenes/crate.tscn" id="1_6shkr"] [ext_resource type="Script" path="res://scripts/gameController.gd" id="1_7tjsy"] -[ext_resource type="Script" path="res://scripts/charController.gd" id="2_uc4yi"] +[ext_resource type="PackedScene" uid="uid://b2hyqfqh02ep6" path="res://scenes/player.tscn" id="3_bssht"] [ext_resource type="Script" path="res://scripts/trigger.gd" id="3_t4lk8"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_n7xvc"] @@ -11,9 +11,6 @@ size = Vector2(92, 20) [sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_gasd3"] distance = -484.0 -[sub_resource type="CircleShape2D" id="CircleShape2D_uvblg"] -radius = 32.5576 - [sub_resource type="CircleShape2D" id="CircleShape2D_5ph8t"] radius = 62.0 @@ -27,30 +24,13 @@ metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="firstPlatform"] shape = SubResource("RectangleShape2D_n7xvc") -[node name="RigidBody2D" parent="." instance=ExtResource("1_6shkr")] -position = Vector2(605, 106) -rotation = -0.706362 - -[node name="RigidBody2D2" parent="." instance=ExtResource("1_6shkr")] -position = Vector2(603, 208) - [node name="Floor" type="StaticBody2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="Floor"] shape = SubResource("WorldBoundaryShape2D_gasd3") -[node name="RigidBody2D4" parent="." instance=ExtResource("1_6shkr")] -position = Vector2(629, 37) - -[node name="CharacterBody2D" type="CharacterBody2D" parent="."] -position = Vector2(524, 393) -script = ExtResource("2_uc4yi") -PUSH_FORCE = 100 -metadata/_edit_group_ = true - -[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"] -shape = SubResource("CircleShape2D_uvblg") -debug_color = Color(0.872789, 0.000463018, 0.842707, 0.42) +[node name="CharacterBody2D" parent="." instance=ExtResource("3_bssht")] +position = Vector2(188, 575) [node name="Area2D" type="Area2D" parent="."] position = Vector2(952, 434) @@ -61,8 +41,17 @@ metadata/_edit_group_ = true shape = SubResource("CircleShape2D_5ph8t") debug_color = Color(0.630721, 0.529414, 1.92523e-07, 0.42) -[node name="RigidBody2D3" parent="." instance=ExtResource("1_6shkr")] -position = Vector2(534, 53) +[node name="RigidBody2D" parent="." groups=["pushables"] instance=ExtResource("1_6shkr")] +position = Vector2(209, 113) +rotation = 2.09219 + +[node name="RigidBody2D2" parent="." groups=["pushables"] instance=ExtResource("1_6shkr")] +position = Vector2(595, 192) +rotation = 4.86807 + +[node name="RigidBody2D3" parent="." groups=["pushables"] instance=ExtResource("1_6shkr")] +position = Vector2(373, 200) +rotation = -0.0982481 [connection signal="areaTrigger" from="Area2D" to="." method="_on_trigger"] [connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"] diff --git a/scenes/player.tscn b/scenes/player.tscn new file mode 100644 index 0000000..9c25e11 --- /dev/null +++ b/scenes/player.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=3 format=3 uid="uid://b2hyqfqh02ep6"] + +[ext_resource type="Script" path="res://scripts/charController.gd" id="1_4o8do"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_uvblg"] +radius = 32.5576 + +[node name="CharacterBody2D" type="CharacterBody2D"] +script = ExtResource("1_4o8do") +PUSH_FORCE = 100 +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_uvblg") +debug_color = Color(0.872789, 0.000463018, 0.842707, 0.42) + +[node name="RightRay" type="RayCast2D" parent="."] +target_position = Vector2(76, 0) + +[node name="LeftRay" type="RayCast2D" parent="."] +target_position = Vector2(-76, 0) + +[node name="MarkerRight" type="Node2D" parent="."] +position = Vector2(35, -10) + +[node name="MarkerLeft" type="Node2D" parent="."] +position = Vector2(-35, -10) diff --git a/scripts/bullet.gd b/scripts/bullet.gd new file mode 100644 index 0000000..3b1aa49 --- /dev/null +++ b/scripts/bullet.gd @@ -0,0 +1,14 @@ +extends Area2D + +@export var speed := 700 +signal hit(bullet, body) + +func set_speed(speedval): + speed = speedval + +func _physics_process(delta): + position += transform.x * speed * delta + + +func _on_body_entered(body): + print ("Hit a thing") # Replace with function body. diff --git a/scripts/charController.gd b/scripts/charController.gd index 6a0ced6..8cf212a 100644 --- a/scripts/charController.gd +++ b/scripts/charController.gd @@ -3,7 +3,21 @@ extends CharacterBody2D const SPEED = 500.0 const JUMP_VELOCITY = -600.0 -@export var PUSH_FORCE = 90 +@export var BUMP_FORCE = 90 +@export var PUSH_FORCE = 700 + + +var faceLeft = false +var pushLeftEnabled = false +var pushRightEnabled = false +var pushTarget + +var bullet = preload("res://scenes/bullet.tscn") + +@onready var right_ray = $RightRay +@onready var left_ray = $LeftRay +@onready var marker_right = $MarkerRight +@onready var marker_left = $MarkerLeft func _physics_process(delta: float) -> void: @@ -14,10 +28,42 @@ func _physics_process(delta: float) -> void: # Handle jump. if Input.is_action_just_pressed("ui_accept") and is_on_floor(): velocity.y = JUMP_VELOCITY + + if pushTarget: + if Input.is_action_just_pressed("Shove") && pushLeftEnabled && faceLeft: + print("shove left") + pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 10) + pushLeftEnabled = false + + if Input.is_action_just_pressed("Shove") && pushRightEnabled && not faceLeft: + print("shove right") + pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 15) + pushRightEnabled = false + + if Input.is_action_just_pressed("Shoot"): + var mybullet = bullet.instantiate() + print("I will shoot") + if faceLeft: + print("shoot left") + mybullet.set_speed(-700) + mybullet.transform = marker_right.global_transform + else: + print("shoot right") + mybullet.transform = marker_right.global_transform + + owner.add_child(mybullet) # 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") + if direction < 0: + faceLeft = true + if direction > 0: + faceLeft = false + + + + if direction: velocity.x = direction * SPEED else: @@ -27,4 +73,25 @@ func _physics_process(delta: float) -> 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()*PUSH_FORCE) + c.get_collider().apply_central_impulse(-c.get_normal()*BUMP_FORCE) + + pushTarget = false + if left_ray.is_colliding(): + print("Left ray collision") + var collider = left_ray.get_collider() + if collider is Node: + if collider.is_in_group("pushables"): + pushLeftEnabled = true + pushTarget = collider + else: + pushLeftEnabled = false + + if right_ray.is_colliding(): + print("Right ray collision") + var collider = right_ray.get_collider() + if collider is Node: + if collider.is_in_group("pushables"): + pushRightEnabled = true + pushTarget = collider + else: + pushRightEnabled = false diff --git a/scripts/gameController.gd b/scripts/gameController.gd index 4bd1cad..0b7b3a8 100644 --- a/scripts/gameController.gd +++ b/scripts/gameController.gd @@ -1,6 +1,6 @@ extends Node2D -var boxTotal = 4 +var boxTotal = 3 var timer:= Timer.new() @export var secondCount= 15