Added changes from week 2 videoa

This commit is contained in:
Kevin O Gorman 2025-01-19 21:04:07 -05:00
parent 90bdd35020
commit 3b09af598b
7 changed files with 156 additions and 29 deletions

View File

@ -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)
]
}

17
scenes/bullet.tscn Normal file
View File

@ -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"]

View File

@ -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"]

27
scenes/player.tscn Normal file
View File

@ -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)

14
scripts/bullet.gd Normal file
View File

@ -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.

View File

@ -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

View File

@ -1,6 +1,6 @@
extends Node2D
var boxTotal = 4
var boxTotal = 3
var timer:= Timer.new()
@export var secondCount= 15