Week 2 Learnings: Week 1 recap (bodies, area trigger), raycasts, dynamic instantiation (spawning things)
This commit is contained in:
parent
91dc632faf
commit
68a092aa68
@ -1,13 +1,16 @@
|
||||
[gd_scene format=3 uid="uid://dvg70drsbendq"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://u1ubij2eih4r" path="res://Scripts/bullet.gd" id="1_xjght"]
|
||||
[ext_resource type="Script" uid="uid://lt4ob78t6q2a" path="res://Scripts/bullet.gd" id="1_xjght"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4mw4s"]
|
||||
size = Vector2(10, 4)
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_oov8j"]
|
||||
size = Vector2(13, 2)
|
||||
|
||||
[node name="Bullet" type="Area2D" unique_id=1549351635]
|
||||
[node name="Area2D" type="Area2D" unique_id=945283574]
|
||||
script = ExtResource("1_xjght")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=687436499]
|
||||
shape = SubResource("RectangleShape2D_4mw4s")
|
||||
debug_color = Color(0.9064841, 0.22817236, 0.5106338, 0.41960785)
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=2014630273]
|
||||
shape = SubResource("RectangleShape2D_oov8j")
|
||||
debug_color = Color(0.33554953, 0.61683553, 0.2469708, 0.41960785)
|
||||
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
|
||||
@ -3,15 +3,13 @@
|
||||
[ext_resource type="Script" uid="uid://bwyucgbes44rd" path="res://Scripts/trigger.gd" id="1_ebmjs"]
|
||||
[ext_resource type="Script" uid="uid://cvrssvw6p8myl" path="res://Scripts/game.gd" id="1_wrm1d"]
|
||||
[ext_resource type="Script" uid="uid://bfh1ec3bb5oki" path="res://Scripts/scene_manager.gd" id="2_3dryh"]
|
||||
[ext_resource type="Script" uid="uid://cq2vf132xjtli" path="res://Scripts/player.gd" id="2_qxrlw"]
|
||||
[ext_resource type="PackedScene" uid="uid://b5y6rb2t0eaqr" path="res://Scenes/crate.tscn" id="3_wowpa"]
|
||||
[ext_resource type="PackedScene" uid="uid://en40721f6qwj" path="res://Scenes/player.tscn" id="4_wowpa"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2poj3"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_2poj3"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_ebmjs"]
|
||||
|
||||
[node name="Game" type="Node2D" unique_id=1651082265]
|
||||
script = ExtResource("1_wrm1d")
|
||||
|
||||
@ -19,8 +17,8 @@ script = ExtResource("1_wrm1d")
|
||||
script = ExtResource("2_3dryh")
|
||||
|
||||
[node name="Floor" type="StaticBody2D" parent="." unique_id=1930890804]
|
||||
position = Vector2(558, 453)
|
||||
scale = Vector2(3.880005, 1)
|
||||
position = Vector2(490, 453)
|
||||
scale = Vector2(10, 1)
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Floor" unique_id=208628971]
|
||||
@ -53,23 +51,16 @@ metadata/_edit_group_ = true
|
||||
shape = SubResource("CircleShape2D_2poj3")
|
||||
debug_color = Color(0.47473383, 0.5864115, 0.1707469, 0.41960785)
|
||||
|
||||
[node name="Player" type="CharacterBody2D" parent="." unique_id=1131424030]
|
||||
position = Vector2(538.00006, 420)
|
||||
scale = Vector2(1.64, 1.64)
|
||||
script = ExtResource("2_qxrlw")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Player" unique_id=628686782]
|
||||
shape = SubResource("CircleShape2D_ebmjs")
|
||||
debug_color = Color(0.6308279, 0.36922106, 0.95607406, 0.41960785)
|
||||
|
||||
[node name="Crates" type="Node2D" parent="." unique_id=799685623]
|
||||
|
||||
[node name="Crate" parent="Crates" unique_id=38246509 instance=ExtResource("3_wowpa")]
|
||||
[node name="Crate" parent="Crates" unique_id=38246509 groups=["pushables"] instance=ExtResource("3_wowpa")]
|
||||
position = Vector2(683, 406)
|
||||
|
||||
[node name="Crate2" parent="Crates" unique_id=1259430642 instance=ExtResource("3_wowpa")]
|
||||
position = Vector2(716, 382)
|
||||
[node name="Crate2" parent="Crates" unique_id=1259430642 groups=["pushables"] instance=ExtResource("3_wowpa")]
|
||||
position = Vector2(476, 420.99997)
|
||||
|
||||
[node name="Player" parent="." unique_id=478864706 instance=ExtResource("4_wowpa")]
|
||||
position = Vector2(553, 419)
|
||||
|
||||
[connection signal="areaTriggerSignal" from="Trigger" to="." method="_on_trigger"]
|
||||
[connection signal="body_entered" from="Trigger" to="Trigger" method="_on_body_entered"]
|
||||
|
||||
@ -13,14 +13,14 @@ metadata/_edit_group_ = true
|
||||
shape = SubResource("CircleShape2D_ebmjs")
|
||||
debug_color = Color(0.6308279, 0.36922106, 0.95607406, 0.41960785)
|
||||
|
||||
[node name="RightCast" type="RayCast2D" parent="." unique_id=448970826]
|
||||
target_position = Vector2(17.073172, 0)
|
||||
[node name="RightRay" type="RayCast2D" parent="." unique_id=1765430818]
|
||||
target_position = Vector2(15.853659, 0)
|
||||
|
||||
[node name="LeftCast" type="RayCast2D" parent="." unique_id=1038607459]
|
||||
target_position = Vector2(-17.073172, 0)
|
||||
[node name="LeftRay" type="RayCast2D" parent="." unique_id=1817550679]
|
||||
target_position = Vector2(-15.854, 0)
|
||||
|
||||
[node name="RightSpawn" type="Marker2D" parent="." unique_id=1358832037]
|
||||
position = Vector2(11.585366, -8.536586)
|
||||
[node name="MarkerRight" type="Node2D" parent="." unique_id=592182633]
|
||||
position = Vector2(12, -5)
|
||||
|
||||
[node name="LeftSpawn" type="Marker2D" parent="." unique_id=1880777693]
|
||||
position = Vector2(-12.195123, -8.536585)
|
||||
[node name="MarkerLeft" type="Node2D" parent="." unique_id=1552465162]
|
||||
position = Vector2(-12, -5)
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
class_name Bullet extends Area2D
|
||||
var speed:float = 700
|
||||
signal bulletHitSignal(body, bullet)
|
||||
func setSpeed(value)->void:
|
||||
speed = value
|
||||
extends Area2D
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var speed := 700
|
||||
signal hit(bullet, body)
|
||||
|
||||
func setSpeed(speedValue):
|
||||
speed = speedValue
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# delta - time passed between physics process being called, think FPS
|
||||
position += transform.x * speed * delta
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body is Crate:
|
||||
bulletHitSignal.emit(body,self)
|
||||
print("I HIT SMTHING")
|
||||
|
||||
@ -1 +1 @@
|
||||
uid://u1ubij2eih4r
|
||||
uid://lt4ob78t6q2a
|
||||
|
||||
@ -25,7 +25,6 @@ func countdown() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func _on_trigger(body: Variant, trigger: Variant) -> void:
|
||||
print("Game controller knows trigger fired")
|
||||
body.queue_free()
|
||||
|
||||
@ -3,7 +3,21 @@ extends CharacterBody2D
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
const PUSH_FORCE = 700
|
||||
|
||||
var faceLeft = false
|
||||
# Can I push right / left
|
||||
var pushLeftEnabled = false
|
||||
var pushRightEnabled = false
|
||||
|
||||
@onready var right_ray: RayCast2D = $RightRay
|
||||
@onready var left_ray: RayCast2D = $LeftRay
|
||||
@onready var marker_right: Node2D = $MarkerRight
|
||||
@onready var marker_left: Node2D = $MarkerLeft
|
||||
|
||||
var pushTarget
|
||||
|
||||
var bullet = preload("res://Scenes/bullet.tscn")
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
@ -14,9 +28,35 @@ func _physics_process(delta: float) -> void:
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
if Input.is_action_just_pressed("Shove") && pushLeftEnabled && faceLeft:
|
||||
print("shove box on the left")
|
||||
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 1.5)
|
||||
pushLeftEnabled = false
|
||||
|
||||
if Input.is_action_just_pressed("Shove") && pushRightEnabled && not faceLeft:
|
||||
print("shove box on the right")
|
||||
pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 1.5)
|
||||
pushRightEnabled = false
|
||||
|
||||
if Input.is_action_just_pressed("Shoot"):
|
||||
print("will shoot")
|
||||
var myBullet = bullet.instantiate()
|
||||
if faceLeft:
|
||||
print("shoot left")
|
||||
myBullet.setSpeed(-700)
|
||||
myBullet.transform = marker_left.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:
|
||||
@ -30,3 +70,23 @@ func _physics_process(delta: float) -> void:
|
||||
#is this bonkable? reverse normal
|
||||
if c.get_collider() is RigidBody2D:
|
||||
c.get_collider().apply_central_impulse(-c.get_normal() * 100)
|
||||
|
||||
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
|
||||
|
||||
@ -12,9 +12,22 @@ config_version=5
|
||||
|
||||
config/name="CatGame"
|
||||
run/main_scene="uid://bportqr2j3d7s"
|
||||
config/features=PackedStringArray("4.6", "Forward Plus")
|
||||
config/features=PackedStringArray("4.7", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[input]
|
||||
|
||||
Shove={
|
||||
"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":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
Shoot={
|
||||
"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":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[physics]
|
||||
|
||||
3d/physics_engine="Jolt Physics"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user