Compare commits
22 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 54967e570b | |||
| 35a17c04b6 | |||
| ee44810636 | |||
| d00cee752e | |||
| 79fa813571 | |||
| b11655a8fe | |||
| e16f87cbfa | |||
| 20d1f62a7d | |||
| bc88fed830 | |||
| 7ba423e6c5 | |||
| 5b7ab7811e | |||
| 1e4aeddbb5 | |||
| f22364ce39 | |||
| 907508c4eb | |||
| 10dd8ce719 | |||
| f16e26c981 | |||
| fced905bae | |||
| cf14e5d398 | |||
| c78368c89e | |||
| db0aa2ad9e | |||
| eac591cf29 | |||
| 1017920ee0 |
15 changed files with 376 additions and 110 deletions
|
|
@ -2,8 +2,6 @@ class_name Ball extends "gear.gd"
|
|||
|
||||
func gear_name():
|
||||
return "Ball"
|
||||
func gear_id():
|
||||
return 1
|
||||
func continuous():
|
||||
return false
|
||||
|
||||
|
|
|
|||
|
|
@ -1,43 +1,47 @@
|
|||
@icon("./gear.png")
|
||||
class_name Gear extends Node3D
|
||||
|
||||
var idle_basis = Basis(
|
||||
Vector3(1, 0, 0),
|
||||
Vector3(0, 1, 0),
|
||||
Vector3(0, 0, 1))
|
||||
var use_basis = Basis(
|
||||
Vector3(1, 0, 0),
|
||||
Vector3(0, 0, -1),
|
||||
Vector3(0, 1, 0))
|
||||
var pickup_basis = idle_basis
|
||||
|
||||
func gear_name():
|
||||
return "Gear"
|
||||
func gear_id():
|
||||
return 0
|
||||
func model_file():
|
||||
return "hammer.glb"
|
||||
func continuous():
|
||||
return false
|
||||
func idle_basis():
|
||||
return Basis(
|
||||
Vector3(1, 0, 0),
|
||||
Vector3(0, 1, 0),
|
||||
Vector3(0, 0, 1))
|
||||
func use_basis():
|
||||
return Basis(
|
||||
Vector3(1, 0, 0),
|
||||
Vector3(0, 0, -1),
|
||||
Vector3(0, 1, 0))
|
||||
func pickup_basis():
|
||||
return idle_basis()
|
||||
|
||||
# this can be redefined to make a custom
|
||||
# gear mesh, e.g. a SphereMesh
|
||||
func use(player):
|
||||
basis = use_basis
|
||||
basis = use_basis()
|
||||
$Timer.start()
|
||||
on_use(player)
|
||||
|
||||
func unequip(player):
|
||||
on_unequip(player)
|
||||
|
||||
func on_use(_player):
|
||||
pass
|
||||
|
||||
func on_unequip(_player):
|
||||
pass
|
||||
|
||||
func on_ready():
|
||||
pass
|
||||
|
||||
func _on_timer_timeout():
|
||||
basis = idle_basis
|
||||
basis = idle_basis()
|
||||
|
||||
func _ready():
|
||||
basis = idle_basis
|
||||
basis = idle_basis()
|
||||
if get_parent() is GearPickup:
|
||||
basis = pickup_basis
|
||||
basis = pickup_basis()
|
||||
on_ready()
|
||||
|
|
|
|||
62
gears/geep.gd
Normal file
62
gears/geep.gd
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
class_name Geep extends "gear.gd"
|
||||
|
||||
func gear_name():
|
||||
return "Geep"
|
||||
func continuous():
|
||||
return false
|
||||
func use_basis():
|
||||
return idle_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 init_driver(player):
|
||||
driver = player
|
||||
if not box:
|
||||
box = Vector3(driver.get_node("CollisionShape3D").shape.size)
|
||||
|
||||
func mount():
|
||||
active = true
|
||||
position = Vector3(-driver.get_node("Pivot/Container").position)
|
||||
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):
|
||||
init_driver(player)
|
||||
unmount()
|
||||
|
||||
func _physics_process(_delta):
|
||||
if not active:
|
||||
return
|
||||
|
||||
driver.move_player(0, -speed)
|
||||
87
gears/geep.tscn
Normal file
87
gears/geep.tscn
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
[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"]
|
||||
[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(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="BoxMesh" id="BoxMesh_wm067"]
|
||||
material = ExtResource("2_rhiad")
|
||||
size = Vector3(3, 2, 2.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")
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[node name="GearMesh" type="Node3D" parent="."]
|
||||
|
||||
[node name="Vehicle" type="StaticBody3D" parent="GearMesh"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1.0000001, 0, 0, 0, 1.0000001, 0, 0, 0)
|
||||
collision_layer = 4
|
||||
|
||||
[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="LeftSideMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"]
|
||||
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="RightSideMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"]
|
||||
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="BonnetMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.9997005, -1.75)
|
||||
mesh = SubResource("BoxMesh_wm067")
|
||||
|
||||
[node name="TailgateMesh" type="MeshInstance3D" parent="GearMesh/Vehicle"]
|
||||
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"]
|
||||
4
gears/geep_body.tres
Normal file
4
gears/geep_body.tres
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[gd_resource type="StandardMaterial3D" load_steps=0 format=3 uid="uid://dpacu3e7vsks5"]
|
||||
|
||||
[resource]
|
||||
albedo_color = Color(0.99607843, 0.99607843, 0.99607843, 1)
|
||||
4
gears/geep_wheel.tres
Normal file
4
gears/geep_wheel.tres
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[gd_resource type="StandardMaterial3D" load_steps=0 format=3 uid="uid://bt5aat64e478k"]
|
||||
|
||||
[resource]
|
||||
albedo_color = Color(0.1254902, 0.1254902, 0.1254902, 1)
|
||||
65
main.tscn
65
main.tscn
|
|
@ -1,23 +1,49 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://eiaw4xbs3suk"]
|
||||
[gd_scene load_steps=17 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="Texture2D" uid="uid://dnt0vfav03ris" path="res://world/textures/grass.jpg" id="2_272bh"]
|
||||
[ext_resource type="PackedScene" uid="uid://of6tq8gpjxtu" path="res://gears/gear_pickup.tscn" id="3_lquwl"]
|
||||
[ext_resource type="PackedScene" uid="uid://bafl8q0r61xrg" path="res://gears/gear.tscn" id="4_7mycd"]
|
||||
[ext_resource type="PackedScene" uid="uid://c117buhmmkvkt" path="res://gears/ball.tscn" id="6_5vw27"]
|
||||
[ext_resource type="PackedScene" uid="uid://d3k7b6o56ue5k" path="res://gears/geep.tscn" id="7_kek77"]
|
||||
[ext_resource type="Texture2D" uid="uid://bl4yvm44o6gcf" path="res://world/textures/sky.hdr" id="8_5vw27"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_7dm0k"]
|
||||
size = Vector3(100, 2, 100)
|
||||
size = Vector3(1000, 2, 1000)
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_ig7tw"]
|
||||
size = Vector3(100, 2, 100)
|
||||
size = Vector3(1000, 2, 1000)
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ig7tw"]
|
||||
albedo_color = Color(0.49454, 0.79, 0.4424, 1)
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_272bh"]
|
||||
albedo_color = Color(0, 1, 0, 1)
|
||||
albedo_texture = ExtResource("2_272bh")
|
||||
uv1_scale = Vector3(300, 300, 300)
|
||||
|
||||
[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_272bh"]
|
||||
panorama = ExtResource("8_5vw27")
|
||||
|
||||
[sub_resource type="Sky" id="Sky_7mycd"]
|
||||
sky_material = SubResource("PanoramaSkyMaterial_272bh")
|
||||
|
||||
[sub_resource type="Environment" id="Environment_7mycd"]
|
||||
background_mode = 2
|
||||
sky = SubResource("Sky_7mycd")
|
||||
sky_rotation = Vector3(6.2831855, 0, 0)
|
||||
glow_enabled = true
|
||||
glow_intensity = 0.1
|
||||
glow_bloom = 0.02
|
||||
glow_blend_mode = 0
|
||||
glow_hdr_luminance_cap = 0.0
|
||||
|
||||
[sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_272bh"]
|
||||
|
||||
[sub_resource type="Compositor" id="Compositor_5vw27"]
|
||||
|
||||
[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="."]
|
||||
|
||||
|
|
@ -26,11 +52,7 @@ shape = SubResource("BoxShape3D_7dm0k")
|
|||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Baseplate"]
|
||||
mesh = SubResource("BoxMesh_ig7tw")
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_ig7tw")
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(0.7071068, -0.49999994, 0.49999994, 0, 0.7071067, 0.7071067, -0.7071068, -0.49999994, 0.49999994, 50, 50, 50)
|
||||
shadow_enabled = true
|
||||
surface_material_override/0 = SubResource("StandardMaterial3D_272bh")
|
||||
|
||||
[node name="radiohead cube" parent="." instance=ExtResource("2_0xm2m")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -16, 3, 0)
|
||||
|
|
@ -47,8 +69,23 @@ 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="GearPickup" parent="." instance=ExtResource("3_lquwl")]
|
||||
[node name="BallPickup" parent="." instance=ExtResource("3_lquwl")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -12, 2, -21)
|
||||
|
||||
[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)
|
||||
[node name="Gear" parent="BallPickup" instance=ExtResource("6_5vw27")]
|
||||
|
||||
[node name="GeepPickup" parent="." instance=ExtResource("3_lquwl")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8, 1.75, -30)
|
||||
|
||||
[node name="Gear" parent="GeepPickup" instance=ExtResource("7_kek77")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.75, 0)
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_7mycd")
|
||||
camera_attributes = SubResource("CameraAttributesPractical_272bh")
|
||||
compositor = SubResource("Compositor_5vw27")
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(0.70710665, 0.5, -0.5, 0, 0.7071067, 0.7071067, 0.7071069, -0.49999988, 0.49999988, -500, 200, 500)
|
||||
light_color = Color(1, 0.87058824, 0.12941177, 1)
|
||||
shadow_enabled = true
|
||||
|
|
|
|||
87
player/camera.gd
Normal file
87
player/camera.gd
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
class_name CameraGimbal extends Node3D
|
||||
|
||||
@export var rotation_speed = (PI / 180) * 120
|
||||
@export var default_zoom = 8
|
||||
|
||||
# is mouse captured by game permanently?
|
||||
# (i.e. not just holding right click)
|
||||
var locked = false
|
||||
var mouse_velocity = Vector2.ZERO
|
||||
|
||||
var current_zoom = default_zoom
|
||||
var zoom_min = 4
|
||||
var zoom_max = 80
|
||||
var zoom_speed = 20
|
||||
|
||||
func _lock():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
func _unlock():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
mouse_velocity = Vector2.ZERO
|
||||
|
||||
func lock():
|
||||
_lock()
|
||||
locked = true
|
||||
|
||||
# optional API function for nodes that want
|
||||
# to unlock the mouse for a period of time
|
||||
func unlock():
|
||||
_unlock()
|
||||
locked = false
|
||||
|
||||
func reset():
|
||||
basis = Basis()
|
||||
$InnerGimbal.basis = Basis()
|
||||
current_zoom = default_zoom
|
||||
|
||||
# y is before x because the outer gimbal is
|
||||
# in charge of rotating the y axis
|
||||
func rotate_camera(delta):
|
||||
var y = 0
|
||||
var x = 0
|
||||
|
||||
if mouse_velocity.x > 5 or mouse_velocity.x < -5:
|
||||
y -= clamp(mouse_velocity.x / 12.5, -10, 10)
|
||||
if mouse_velocity.y > 5 or mouse_velocity.y < -5:
|
||||
x -= clamp(mouse_velocity.y / 12.5, -10, 10)
|
||||
|
||||
rotate_object_local(Vector3.UP, y * rotation_speed * delta)
|
||||
$InnerGimbal.rotate_object_local(
|
||||
Vector3.RIGHT, x * rotation_speed * delta)
|
||||
$InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x, -0.8, 0.7)
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseMotion:
|
||||
mouse_velocity = event.relative
|
||||
elif event.is_action_pressed("cam_zoom_out"):
|
||||
current_zoom += 1
|
||||
elif event.is_action_pressed("cam_zoom_in"):
|
||||
current_zoom -= 1
|
||||
|
||||
current_zoom = clamp(current_zoom, zoom_min, zoom_max)
|
||||
|
||||
func _process(delta):
|
||||
# rotate camera
|
||||
if locked:
|
||||
rotate_camera(delta)
|
||||
else:
|
||||
if Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
|
||||
_lock()
|
||||
rotate_camera(delta)
|
||||
else:
|
||||
_unlock()
|
||||
|
||||
# zoom in/out
|
||||
var pos = Vector3($InnerGimbal/Camera3D.position)
|
||||
pos.y = lerp(pos.y, float(current_zoom), zoom_speed * delta)
|
||||
pos.z = lerp(pos.z, float(current_zoom), zoom_speed * delta)
|
||||
|
||||
$InnerGimbal/Camera3D.position = pos
|
||||
|
||||
# reset camera
|
||||
if Input.is_action_pressed("cam_reset"):
|
||||
reset()
|
||||
|
||||
func _ready():
|
||||
lock()
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
class_name CameraGimbal extends Node3D
|
||||
|
||||
@export var rotation_speed = (PI / 180) * 120
|
||||
|
||||
func reset():
|
||||
basis = Basis()
|
||||
$InnerGimbal.basis = Basis()
|
||||
|
||||
func rotate_camera_y(y, delta):
|
||||
rotate_object_local(Vector3.UP, y * rotation_speed * delta)
|
||||
func rotate_camera_x(x, delta):
|
||||
$InnerGimbal.rotate_object_local(
|
||||
Vector3.RIGHT, x * rotation_speed * delta)
|
||||
$InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x,-0.8,0.7)
|
||||
|
||||
func _process(delta):
|
||||
# rotate outer gimbal around y axis
|
||||
var y = 0
|
||||
if Input.is_action_pressed("cam_left"):
|
||||
y += 1
|
||||
if Input.is_action_pressed("cam_right"):
|
||||
y -= 1
|
||||
rotate_camera_y(y, delta)
|
||||
|
||||
# rotate inner gimbal around x axis
|
||||
var x = 0
|
||||
if Input.is_action_pressed("cam_up"):
|
||||
x -= 1
|
||||
if Input.is_action_pressed("cam_down"):
|
||||
x += 1
|
||||
rotate_camera_x(x, delta)
|
||||
|
||||
# reset gimbals
|
||||
if Input.is_action_pressed("cam_reset"):
|
||||
reset()
|
||||
|
|
@ -8,8 +8,10 @@ const gear_slots = ["1", "2", "3"]
|
|||
|
||||
@onready var spawn = Vector3(position)
|
||||
|
||||
var starting_gear = preload("res://gears/ball.tscn")
|
||||
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,17 +70,24 @@ func die():
|
|||
# strip gears
|
||||
for gear in $Backpack.get_children():
|
||||
gear.queue_free()
|
||||
$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()
|
||||
|
|
@ -103,6 +115,7 @@ func use_backpack_slot(n):
|
|||
# place current gear in first free slot
|
||||
var slot = find_free_slot()
|
||||
if slot:
|
||||
old.unequip(self)
|
||||
old.name = slot
|
||||
old.reparent($Backpack, false)
|
||||
get_node(gear_node).reparent($Pivot/Container, false)
|
||||
|
|
@ -111,7 +124,8 @@ func use_backpack_slot(n):
|
|||
return
|
||||
# couldn't find a free slot, so replace
|
||||
# the new slot with the current gear
|
||||
get_node(gear_node).reparent($Pivot/Container, false)
|
||||
get_node(gear_node).reparent($Pivot/Container, false)
|
||||
old.unequip(self)
|
||||
old.reparent($Backpack, false)
|
||||
old.name = n
|
||||
get_node("Pivot/Container/" + n).name = "Gear"
|
||||
|
|
@ -119,6 +133,8 @@ func use_backpack_slot(n):
|
|||
return
|
||||
|
||||
func equip(gear: Gear):
|
||||
if suspended:
|
||||
return
|
||||
var gear_name = gear.gear_name()
|
||||
# do we have the gear equipped?
|
||||
if gear_name == $Pivot/Container/Gear.gear_name():
|
||||
|
|
@ -135,6 +151,7 @@ func equip(gear: Gear):
|
|||
# place current gear in first free slot
|
||||
var slot = find_free_slot()
|
||||
if slot:
|
||||
old.unequip(self)
|
||||
old.name = slot
|
||||
old.reparent($Backpack, false)
|
||||
new_gear = gear.duplicate()
|
||||
|
|
@ -180,16 +197,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)
|
||||
|
|
@ -222,12 +240,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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=8 format=4 uid="uid://cfceg80unq0pe"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://djeyfi7vm2vw0" path="res://player/player.gd" id="1_onrkg"]
|
||||
[ext_resource type="Script" uid="uid://oi6sint7jkc6" path="res://player/camera_gimbal.gd" id="2_onrkg"]
|
||||
[ext_resource type="Script" uid="uid://oi6sint7jkc6" path="res://player/camera.gd" id="2_onrkg"]
|
||||
[ext_resource type="Texture2D" uid="uid://cfb0gbwm57hm4" path="res://models/player_0.png" id="3_hqtel"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_onrkg"]
|
||||
|
|
@ -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("")
|
||||
|
|
|
|||
|
|
@ -42,26 +42,6 @@ jump={
|
|||
"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":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_left={
|
||||
"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":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_right={
|
||||
"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":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_up={
|
||||
"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":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_down={
|
||||
"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":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_reset={
|
||||
"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":79,"physical_keycode":0,"key_label":0,"unicode":111,"location":0,"echo":false,"script":null)
|
||||
|
|
@ -87,9 +67,23 @@ backpack_3={
|
|||
"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":51,"physical_keycode":0,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_zoom_in={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
cam_zoom_out={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"canceled":false,"pressed":false,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
3d_physics/layer_1="World"
|
||||
3d_physics/layer_2="Player"
|
||||
3d_physics/layer_3="Object"
|
||||
|
||||
[physics]
|
||||
|
||||
3d/physics_interpolation/scene_traversal="Legacy"
|
||||
|
|
|
|||
4
util/util.gd
Normal file
4
util/util.gd
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
class_name Util extends Node
|
||||
|
||||
static func input_action_string(action):
|
||||
return InputMap.action_get_events(action)[0].as_text()
|
||||
BIN
world/textures/grass.jpg
Normal file
BIN
world/textures/grass.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
BIN
world/textures/sky.hdr
Normal file
BIN
world/textures/sky.hdr
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue