diff --git a/novembergame/project.godot b/novembergame/project.godot index dc28117..3168b3b 100644 --- a/novembergame/project.godot +++ b/novembergame/project.godot @@ -20,3 +20,18 @@ config/icon="res://icon.svg" folder_colors={ "res://scripts/": "green" } + +[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":83,"key_label":0,"unicode":115,"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":4194438,"key_label":0,"unicode":48,"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) +, 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":4194439,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null) +] +} diff --git a/novembergame/scenes/box.tscn b/novembergame/scenes/box.tscn index 4056a2b..b3c2ffa 100644 --- a/novembergame/scenes/box.tscn +++ b/novembergame/scenes/box.tscn @@ -3,7 +3,7 @@ [sub_resource type="RectangleShape2D" id="RectangleShape2D_c58s7"] size = Vector2(46, 42) -[node name="RigidBody2D" type="RigidBody2D" groups=["box"]] +[node name="RigidBody2D" type="RigidBody2D" groups=["box", "shootable"]] position = Vector2(588, 292) rotation = 0.837162 metadata/_edit_group_ = true diff --git a/novembergame/scenes/bullet.tscn b/novembergame/scenes/bullet.tscn new file mode 100644 index 0000000..3ed39b7 --- /dev/null +++ b/novembergame/scenes/bullet.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=3 format=3 uid="uid://e4o5ja1w0gph"] + +[ext_resource type="Script" path="res://scripts/bullet.gd" id="1_mqe8j"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_y4ewo"] +size = Vector2(6, 2) + +[node name="Area2D" type="Area2D"] +script = ExtResource("1_mqe8j") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_y4ewo") +debug_color = Color(0.341018, 0.620642, 0.0617414, 0.42) + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/novembergame/scenes/character.tscn b/novembergame/scenes/character.tscn new file mode 100644 index 0000000..f6403a8 --- /dev/null +++ b/novembergame/scenes/character.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=3 format=3 uid="uid://b6vk2imhuhv0j"] + +[ext_resource type="Script" path="res://scripts/dudecontroller.gd" id="1_esbkk"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_drde1"] +radius = 23.0 + +[node name="CharacterBody2D" type="CharacterBody2D" groups=["player"]] +script = ExtResource("1_esbkk") +metadata/_edit_group_ = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +rotation = -0.0421956 +shape = SubResource("CircleShape2D_drde1") +debug_color = Color(0.459127, 0.454101, 0.981072, 0.42) + +[node name="RightRay" type="RayCast2D" parent="."] +target_position = Vector2(36, 0) + +[node name="LeftRay" type="RayCast2D" parent="."] +target_position = Vector2(-36, 0) + +[node name="RightTarget" type="Node2D" parent="."] +position = Vector2(23, -16) + +[node name="LeftTarget" type="Node2D" parent="."] +position = Vector2(-23, -16) diff --git a/novembergame/scenes/game.tscn b/novembergame/scenes/game.tscn index 614dd3a..1eb343e 100644 --- a/novembergame/scenes/game.tscn +++ b/novembergame/scenes/game.tscn @@ -1,21 +1,24 @@ -[gd_scene load_steps=8 format=3 uid="uid://dmk3hbsrqhgad"] +[gd_scene load_steps=9 format=3 uid="uid://dmk3hbsrqhgad"] [ext_resource type="PackedScene" uid="uid://flumvyk8tafw" path="res://scenes/box.tscn" id="1_ixp3c"] -[ext_resource type="Script" path="res://scripts/dudecontroller.gd" id="1_pin1i"] +[ext_resource type="Script" path="res://scripts/scene_manager.gd" id="1_sylse"] +[ext_resource type="PackedScene" uid="uid://b6vk2imhuhv0j" path="res://scenes/character.tscn" id="1_umdfo"] [ext_resource type="Script" path="res://scripts/trigger.gd" id="2_e4xab"] +[ext_resource type="PackedScene" uid="uid://e4o5ja1w0gph" path="res://scenes/bullet.tscn" id="4_7436f"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_mhewf"] size = Vector2(102, 12) -[sub_resource type="CircleShape2D" id="CircleShape2D_drde1"] -radius = 23.0 - [sub_resource type="RectangleShape2D" id="RectangleShape2D_0jo0r"] [sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_jsnkw"] [node name="Game" type="Node2D"] +[node name="SceneManager" type="Node" parent="."] +unique_name_in_owner = true +script = ExtResource("1_sylse") + [node name="Platform" type="StaticBody2D" parent="."] position = Vector2(584, 454) metadata/_edit_group_ = true @@ -51,15 +54,7 @@ metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="Platform5"] shape = SubResource("RectangleShape2D_mhewf") -[node name="CharacterBody2D" type="CharacterBody2D" parent="."] -position = Vector2(589, 426) -script = ExtResource("1_pin1i") -metadata/_edit_group_ = true - -[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D"] -rotation = -0.0421956 -shape = SubResource("CircleShape2D_drde1") -debug_color = Color(0.459127, 0.454101, 0.981072, 0.42) +[node name="CharacterBody2D" parent="." instance=ExtResource("1_umdfo")] [node name="Area2D" type="Area2D" parent="."] position = Vector2(576, 533) @@ -72,7 +67,7 @@ shape = SubResource("RectangleShape2D_0jo0r") debug_color = Color(0.774214, 0.233911, 0.917118, 0.42) [node name="RigidBody2D" parent="." instance=ExtResource("1_ixp3c")] -position = Vector2(627, 304) +position = Vector2(699, 304) [node name="RigidBody2D2" parent="." instance=ExtResource("1_ixp3c")] position = Vector2(586, 229) @@ -87,4 +82,7 @@ metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] shape = SubResource("WorldBoundaryShape2D_jsnkw") +[node name="Area2D2" parent="." instance=ExtResource("4_7436f")] +position = Vector2(207, 491) + [connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"] diff --git a/novembergame/scripts/bullet.gd b/novembergame/scripts/bullet.gd new file mode 100644 index 0000000..082d8de --- /dev/null +++ b/novembergame/scripts/bullet.gd @@ -0,0 +1,27 @@ +class_name Bullet extends Area2D + +var speed = 750 +# did I hit anyone? +signal hit(bullet, body) + +func setSpeed(speedValue): + speed = speedValue +func _physics_process(delta: float) -> void: + position += transform.x * speed * delta + + +func _on_body_entered(body: Node2D) -> void: + print("Bullet hit something") + if not body.is_in_group("player"): + hit.emit(self, body) + + + +# Called when the node enters the scene tree for the first time. +#func _ready() -> void: +# pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta: float) -> void: +# pass diff --git a/novembergame/scripts/dudecontroller.gd b/novembergame/scripts/dudecontroller.gd index 26a37eb..ce09a38 100644 --- a/novembergame/scripts/dudecontroller.gd +++ b/novembergame/scripts/dudecontroller.gd @@ -4,6 +4,18 @@ extends CharacterBody2D const SPEED = 300.0 const JUMP_VELOCITY = -400.0 const BUMP_FORCE = 50 +const PUSH_FORCE = 750 +@onready var right_ray: RayCast2D = $RightRay +@onready var left_ray: RayCast2D = $LeftRay + +var faceLeft = false + +var pushTarget +var pushLeftEnabled = false +var pushRightEnabled = false +@onready var right_target: Node2D = $RightTarget +@onready var left_target: Node2D = $LeftTarget + func _physics_process(delta: float) -> void: # Add the gravity. @@ -17,13 +29,59 @@ func _physics_process(delta: float) -> void: # 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 Input.is_action_just_pressed("shove") && pushRightEnabled && faceLeft == false: + print("shove a box") + pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 2) + pushRightEnabled = false + + if Input.is_action_just_pressed("shove") && faceLeft == true && pushLeftEnabled == true: + pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 2) + pushLeftEnabled = false + + if Input.is_action_just_pressed("shoot"): + print("shoot a bullet") + var mybullet = %SceneManager.bulletFactory() + if not faceLeft: + mybullet.transform = right_target.global_transform + mybullet.setSpeed(750) + if faceLeft: + mybullet.transform = left_target.global_transform + mybullet.setSpeed(-750) + if direction: velocity.x = direction * SPEED + if direction > 0: + faceLeft = false + if direction < 0: + faceLeft = true else: velocity.x = move_toward(velocity.x, 0, SPEED) move_and_slide() - + if right_ray.is_colliding(): + print("Something is on my right") + if not faceLeft: + var collider = right_ray.get_collider() + if collider is Node: + if collider.is_in_group("box"): + print("This is a pushable box") + pushTarget = collider + pushRightEnabled = true + else: + pushRightEnabled = false + + if left_ray.is_colliding(): + print("Something is on my left") + if faceLeft: + var collider = left_ray.get_collider() + if collider is Node: + if collider.is_in_group("box"): + print("This is a pushable box") + pushTarget = collider + pushLeftEnabled = true + else: + pushLeftEnabled = false + for i in get_slide_collision_count(): var c = get_slide_collision(i) if c.get_collider() is RigidBody2D: diff --git a/novembergame/scripts/scene_manager.gd b/novembergame/scripts/scene_manager.gd new file mode 100644 index 0000000..d3f63f8 --- /dev/null +++ b/novembergame/scripts/scene_manager.gd @@ -0,0 +1,31 @@ +extends Node + +var bulletsFiredTotal := 0 +var bulletsMadeTotal := 0 +var bulletArray:Array = [] + +var bullet = preload("res://scenes/bullet.tscn") + +func bulletFactory(): + print("Make a bullet at the factory") + var mybullet + + # How many bullet have been made + if bulletArray.size() < 4: + # make a new bullet + mybullet = bullet.instantiate() + mybullet.connect("hit", onBulletHit) + owner.add_child(mybullet) + else: + mybullet = bulletArray.pop_back() + bulletArray.push_front(mybullet) + bulletsMadeTotal += 1 + return mybullet + +func onBulletHit(bullet, body): + print("Scene Manager knows a bullet hit something") + bullet.setSpeed(0) + + if body.is_in_group("shootable"): + print("explode this thing") + body.queue_free()