diff --git a/gears/geep.gd b/gears/geep.gd index fe59a81..b08f60a 100644 --- a/gears/geep.gd +++ b/gears/geep.gd @@ -9,23 +9,51 @@ func use_basis(): # multiplier of player's speed const speed = 2 +# how far the vehicle lifts the player off the ground +const lift = 2 +var box = null var driver = null var active = false -func on_use(player): +func init_driver(player): driver = player - if active: - active = false - position = Vector3.ZERO - driver.message("You are no longer driving a Geep") - return + if not box: + box = Vector3(driver.get_node("CollisionShape3D").shape.size) + +func mount(): active = true position = Vector3(-driver.get_node("Pivot/Container").position) - driver.message("You are now driving a Geep") + position.y += 1 + driver.message( + "Press [%s] to exit the Geep" + % Util.input_action_string("gear_use")) + driver.get_node("CameraGimbal").position.y += lift + driver.get_node("Pivot/Mesh").position.y += lift + driver.get_node("CollisionShape3D").shape.size = $GearMesh/Vehicle/CollisionShape3D.shape.size + driver.protected = true + driver.suspended = true + +func unmount(): + active = false + position = Vector3.ZERO + driver.message("") + driver.get_node("CameraGimbal").position = Vector3.ZERO + driver.get_node("Pivot/Mesh").position = Vector3.ZERO + driver.get_node("CollisionShape3D").shape.size = box + driver.protected = false + driver.suspended = false + +func on_use(player): + init_driver(player) + if active: + unmount() + else: + mount() func on_unequip(player): - active = false + init_driver(player) + unmount() func _physics_process(_delta): if not active: diff --git a/gears/geep.tscn b/gears/geep.tscn index b983d7b..481e2bb 100644 --- a/gears/geep.tscn +++ b/gears/geep.tscn @@ -1,31 +1,34 @@ [gd_scene load_steps=10 format=3 uid="uid://d3k7b6o56ue5k"] [ext_resource type="Script" uid="uid://fljad0m3jlt0" path="res://gears/geep.gd" id="1_8skgp"] - -[sub_resource type="BoxShape3D" id="BoxShape3D_8skgp"] -size = Vector3(3, 0.5, 6) - -[sub_resource type="BoxMesh" id="BoxMesh_rhiad"] -size = Vector3(3, 0.5, 6) +[ext_resource type="Material" uid="uid://dpacu3e7vsks5" path="res://gears/geep_body.tres" id="2_rhiad"] +[ext_resource type="Material" uid="uid://bt5aat64e478k" path="res://gears/geep_wheel.tres" id="3_lrfuo"] [sub_resource type="BoxShape3D" id="BoxShape3D_lrfuo"] -size = Vector3(0.5, 1.75, 6) +size = Vector3(3, 3, 6) + +[sub_resource type="BoxMesh" id="BoxMesh_rhiad"] +material = ExtResource("2_rhiad") +size = Vector3(3, 0.5, 6) [sub_resource type="BoxMesh" id="BoxMesh_kyikt"] +material = ExtResource("2_rhiad") size = Vector3(0.5, 1.75, 6) -[sub_resource type="BoxShape3D" id="BoxShape3D_vjakw"] -size = Vector3(3, 2, 2.5) - [sub_resource type="BoxMesh" id="BoxMesh_wm067"] +material = ExtResource("2_rhiad") size = Vector3(3, 2, 2.5) -[sub_resource type="BoxShape3D" id="BoxShape3D_rhiad"] -size = Vector3(3, 2, 0.5) - [sub_resource type="BoxMesh" id="BoxMesh_lrfuo"] +material = ExtResource("2_rhiad") size = Vector3(3, 2, 0.5) +[sub_resource type="CylinderMesh" id="CylinderMesh_lrfuo"] +material = ExtResource("3_lrfuo") +top_radius = 1.0 +bottom_radius = 1.0 +height = 0.25 + [node name="Gear" type="Node3D"] rotation_edit_mode = 2 script = ExtResource("1_8skgp") @@ -39,44 +42,46 @@ one_shot = true transform = Transform3D(1, 0, 0, 0, 1.0000001, 0, 0, 0, 1.0000001, 0, 0, 0) collision_layer = 4 -[node name="BaseShape" type="CollisionShape3D" parent="GearMesh/Vehicle"] -shape = SubResource("BoxShape3D_8skgp") +[node name="CollisionShape3D" type="CollisionShape3D" parent="GearMesh/Vehicle"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0) +shape = SubResource("BoxShape3D_lrfuo") [node name="BaseMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.9997004, 0) mesh = SubResource("BoxMesh_rhiad") -[node name="LeftSideShape" type="CollisionShape3D" parent="GearMesh/Vehicle"] -transform = Transform3D(1, 0, 0, 0, 0.9999999, 0, 0, 0, 0.9999999, -1.25, 1.1249999, 0) -shape = SubResource("BoxShape3D_lrfuo") - [node name="LeftSideMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"] -transform = Transform3D(1, 0, 0, 0, 0.9999999, 0, 0, 0, 0.9999999, -1.25, 1.1249999, 0) +transform = Transform3D(1, 0, 0, 0, 0.9999999, 0, 0, 0, 0.9999999, -1.25, 2.1247003, 0) mesh = SubResource("BoxMesh_kyikt") skeleton = NodePath("") -[node name="RightSideShape" type="CollisionShape3D" parent="GearMesh/Vehicle"] -transform = Transform3D(1, 0, 0, 0, 0.9999999, 0, 0, 0, 0.9999999, 1.25, 1.1249999, 0) -shape = SubResource("BoxShape3D_lrfuo") - [node name="RightSideMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"] -transform = Transform3D(1, 0, 0, 0, 0.9999999, 0, 0, 0, 0.9999999, 1.25, 1.1249999, 0) +transform = Transform3D(1, 0, 0, 0, 0.9999999, 0, 0, 0, 0.9999999, 1.25, 2.1247003, 0) mesh = SubResource("BoxMesh_kyikt") skeleton = NodePath("") -[node name="BonnetShape" type="CollisionShape3D" parent="GearMesh/Vehicle"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -1.75) -shape = SubResource("BoxShape3D_vjakw") - [node name="BonnetMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -1.75) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.9997005, -1.75) mesh = SubResource("BoxMesh_wm067") -[node name="TailgateShape" type="CollisionShape3D" parent="GearMesh/Vehicle"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 2.75) -shape = SubResource("BoxShape3D_rhiad") - [node name="TailgateMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 2.75) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.9997005, 2.75) mesh = SubResource("BoxMesh_lrfuo") +[node name="WheelFLMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"] +transform = Transform3D(-4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0, 1, 1.65, 1, 2) +mesh = SubResource("CylinderMesh_lrfuo") + +[node name="WheelFRMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"] +transform = Transform3D(-4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0, 1, -1.65, 1, 2) +mesh = SubResource("CylinderMesh_lrfuo") + +[node name="WheelBLMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"] +transform = Transform3D(-4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0, 1, 1.65, 1, -2) +mesh = SubResource("CylinderMesh_lrfuo") + +[node name="WheelBRMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"] +transform = Transform3D(-4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0, 1, -1.65, 1, -2) +mesh = SubResource("CylinderMesh_lrfuo") + [connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] diff --git a/main.tscn b/main.tscn index 5200292..cd73495 100644 --- a/main.tscn +++ b/main.tscn @@ -1,11 +1,10 @@ -[gd_scene load_steps=10 format=3 uid="uid://eiaw4xbs3suk"] +[gd_scene load_steps=9 format=3 uid="uid://eiaw4xbs3suk"] [ext_resource type="PackedScene" uid="uid://qb8cbljxgnub" path="res://world/killbrick.tscn" id="1_h2yge"] [ext_resource type="PackedScene" uid="uid://cfceg80unq0pe" path="res://player/player.tscn" id="1_ig7tw"] [ext_resource type="PackedScene" uid="uid://bcmrj6qkemrll" path="res://world/radiohead_cube.tscn" id="2_0xm2m"] [ext_resource type="PackedScene" uid="uid://of6tq8gpjxtu" path="res://gears/gear_pickup.tscn" id="3_lquwl"] -[ext_resource type="PackedScene" uid="uid://c117buhmmkvkt" path="res://gears/ball.tscn" id="5_7mycd"] -[ext_resource type="PackedScene" uid="uid://d3k7b6o56ue5k" path="res://gears/geep.tscn" id="6_272bh"] +[ext_resource type="PackedScene" uid="uid://bafl8q0r61xrg" path="res://gears/gear.tscn" id="4_7mycd"] [sub_resource type="BoxShape3D" id="BoxShape3D_7dm0k"] size = Vector3(100, 2, 100) @@ -19,6 +18,7 @@ albedo_color = Color(0.49454, 0.79, 0.4424, 1) [node name="Main" type="Node3D"] [node name="Player" parent="." instance=ExtResource("1_ig7tw")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0) [node name="Baseplate" type="StaticBody3D" parent="."] @@ -48,13 +48,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -12, 7, 0) [node name="Killbrick" parent="." instance=ExtResource("1_h2yge")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -40, 1.5, -40) -[node name="BallPickup" parent="." instance=ExtResource("3_lquwl")] +[node name="GearPickup" parent="." instance=ExtResource("3_lquwl")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -12, 2, -21) -[node name="Gear" parent="BallPickup" instance=ExtResource("5_7mycd")] - -[node name="GeepPickup" parent="." instance=ExtResource("3_lquwl")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.25, -20) -one_shot = true - -[node name="Gear" parent="GeepPickup" instance=ExtResource("6_272bh")] +[node name="Gear" parent="GearPickup" instance=ExtResource("4_7mycd")] +transform = Transform3D(1, 0, 0, 0, -0.012967386, 0.9999159, 0, -0.9999159, -0.012967386, 0, 0.5, 0) diff --git a/player/player.gd b/player/player.gd index ae6067b..4b712e6 100644 --- a/player/player.gd +++ b/player/player.gd @@ -10,6 +10,8 @@ const gear_slots = ["1", "2", "3"] var starting_gear = preload("res://gears/gear.tscn") +var dead = false +var protected = false var suspended = false var direction = Vector3.ZERO var target_velocity = Vector3.ZERO @@ -45,6 +47,8 @@ func message(string): # State functions func harm(hp): + if protected: + return assert(hp >= 0) _health -= hp make_hud() @@ -57,7 +61,8 @@ func heal(hp): func health(): return _health -func die(): +func _die(): + dead = true suspended = true visible = false $HUD.visible = false @@ -65,18 +70,24 @@ func die(): # strip gears for gear in $Backpack.get_children(): gear.queue_free() - $Pivot/Container/Gear.unequip(self) - $Pivot/Container/Gear.queue_free() + if has_node("Pivot/Container/Gear"): + $Pivot/Container/Gear.unequip(self) + $Pivot/Container/Gear.queue_free() $RespawnTimer.start() message("Le gone") +func die(): + if protected: + return + _die() + func respawn(): position = Vector3(spawn) $CameraGimbal.reset() _health = 100 visible = true - suspended = false + dead = false # add starting gear var gear = starting_gear.instantiate() @@ -184,16 +195,17 @@ func do_movement(delta): var mx = 0 var mz = 0 - if Input.is_action_pressed("move_forward"): - mz -= 1 - if Input.is_action_pressed("move_back"): - mz += 1 - if Input.is_action_pressed("move_left"): - mx -= 1 - if Input.is_action_pressed("move_right"): - mx += 1 - if Input.is_action_pressed("jump") and is_on_floor(): - target_velocity.y = jump_power + if not suspended: + if Input.is_action_pressed("move_forward"): + mz -= 1 + if Input.is_action_pressed("move_back"): + mz += 1 + if Input.is_action_pressed("move_left"): + mx -= 1 + if Input.is_action_pressed("move_right"): + mx += 1 + if Input.is_action_pressed("jump") and is_on_floor(): + target_velocity.y = jump_power if !(mx == 0 and mz == 0): move_player(mx, mz) @@ -226,12 +238,12 @@ func _ready(): respawn() func _physics_process(delta): - if health() < 1 or position.y <= -1000: - die() - - if suspended: + if dead: return + if health() < 1 or position.y <= -1000: + _die() + # Backpack keys do_backpack_keys() # Movement diff --git a/player/player.tscn b/player/player.tscn index 10a0f29..d87afa8 100644 --- a/player/player.tscn +++ b/player/player.tscn @@ -58,7 +58,9 @@ shape = SubResource("BoxShape3D_onrkg") [node name="Pivot" type="Node3D" parent="."] -[node name="PlayerMesh" type="MeshInstance3D" parent="Pivot"] +[node name="Mesh" type="Node3D" parent="Pivot"] + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Pivot/Mesh"] transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0, -100, 0) mesh = SubResource("ArrayMesh_sweqy") skeleton = NodePath("")