From: Clifton Palmer Date: Sun, 15 Dec 2024 14:57:29 +0000 (+0200) Subject: Full collisions, hitboxes, walls appearing properly X-Git-Tag: 0.9.0~8 X-Git-Url: http://git.purplebirdman.com/lightcycles.git/commitdiff_plain/d9c42b6592d56cd8bf20cae59b2bf1d32219f9e0?ds=inline Full collisions, hitboxes, walls appearing properly --- diff --git a/map/world.gd b/map/world.gd index f3dc592..bd73e20 100644 --- a/map/world.gd +++ b/map/world.gd @@ -1,6 +1,5 @@ extends Node3D -@onready var _walls = $map var _player_wall_tscn = preload("res://player/player_wall.tscn") var _player_wall_map = {} @@ -23,7 +22,19 @@ func _process(_delta: float) -> void: func _player_add_wall(player: Player) -> void: var wall: PlayerWall = _player_wall_tscn.instantiate() + + # start new wall from origin position add_child(wall) wall.global_position = player.global_position wall.global_rotation = player.global_rotation + _player_wall_map[player] = wall + + +func _on_player_destroyed(player: Player) -> void: + print("Player \"" + player.name + "\" destroyed") + + +func _on_player_player_restart(player: Player) -> void: + print("Player \"" + player.name + "\" wants to restart") + get_tree().reload_current_scene() diff --git a/map/world.tscn b/map/world.tscn index ab2aaae..c392607 100644 --- a/map/world.tscn +++ b/map/world.tscn @@ -14,7 +14,7 @@ texture_filter = 0 material = SubResource("StandardMaterial3D_ul8mq") size = Vector2(50, 50) -[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_mhr6o"] +[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_t6tpe"] data = PackedVector3Array(25, 0, 25, -25, 0, 25, 25, 0, -25, -25, 0, 25, -25, 0, -25, 25, 0, -25) [node name="World" type="Node3D"] @@ -33,10 +33,12 @@ skeleton = NodePath("../..") [node name="StaticBody3D" type="StaticBody3D" parent="map/MeshInstance3D"] [node name="CollisionShape3D" type="CollisionShape3D" parent="map/MeshInstance3D/StaticBody3D"] -shape = SubResource("ConcavePolygonShape3D_mhr6o") +shape = SubResource("ConcavePolygonShape3D_t6tpe") [node name="player" parent="." instance=ExtResource("1_3tqxd")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -16) distance = 5.0 +[connection signal="playerDestroyed" from="player" to="." method="_on_player_destroyed"] +[connection signal="playerRestart" from="player" to="." method="_on_player_player_restart"] [connection signal="playerTurn" from="player" to="." method="_player_add_wall"] diff --git a/player/player.gd b/player/player.gd index 4378676..c71d952 100644 --- a/player/player.gd +++ b/player/player.gd @@ -3,30 +3,51 @@ extends CharacterBody3D signal playerTurn +signal playerDestroyed +signal playerRestart -@export_category("Movement") +@onready var _skin = $skin + + +@export_category("Movement") @export var speed = 5.0 @export_category("Camera") @export var distance = 3.0 + @onready var _springArm = $SpringArm3D +enum state {ALIVE, DEAD} +var _state = state.ALIVE func _ready() -> void: _springArm.spring_length = distance func _input(event: InputEvent) -> void: - if event.is_action_pressed("player_left"): - global_rotate(Vector3.UP, PI/2) - playerTurn.emit(self) - elif event.is_action_pressed("player_right"): - global_rotate(Vector3.UP, -PI/2) - playerTurn.emit(self) + if _state == state.ALIVE: + if event.is_action_pressed("player_left"): + global_rotate(Vector3.UP, PI/2) + playerTurn.emit(self) + elif event.is_action_pressed("player_right"): + global_rotate(Vector3.UP, -PI/2) + playerTurn.emit(self) + else: + if event.is_action_pressed("player_restart"): + playerRestart.emit(self) func _physics_process(_delta: float) -> void: - velocity = global_transform.basis.z * speed - move_and_slide() + if _state == state.ALIVE: + velocity = global_transform.basis.z * speed + move_and_slide() + if velocity.length() == 0: + _explode() + + +func _explode() -> void: + _skin.visible = false + _state = state.DEAD + playerDestroyed.emit(self) diff --git a/player/player.tscn b/player/player.tscn index 3404340..f86859d 100644 --- a/player/player.tscn +++ b/player/player.tscn @@ -3,8 +3,8 @@ [ext_resource type="Script" path="res://player/player.gd" id="1_kh0vu"] [ext_resource type="PackedScene" uid="uid://d13jnq5vpvhl0" path="res://skins/bike/bike.tscn" id="1_m3abw"] -[sub_resource type="BoxShape3D" id="BoxShape3D_vtbkq"] -size = Vector3(0.25116, 0.472717, 0.987427) +[sub_resource type="BoxShape3D" id="BoxShape3D_tm1pp"] +size = Vector3(0.158371, 0.45752, 0.144958) [node name="Player" type="CharacterBody3D"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.367284) @@ -14,14 +14,14 @@ script = ExtResource("1_kh0vu") unique_name_in_owner = true [node name="CollisionShape3D" type="CollisionShape3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00430298, 0.24234, 0.0166626) -shape = SubResource("BoxShape3D_vtbkq") +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00136566, 0.234772, 0.446018) +shape = SubResource("BoxShape3D_tm1pp") [node name="SpringArm3D" type="SpringArm3D" parent="."] -transform = Transform3D(-1, 0, -8.74228e-08, -2.26267e-08, 0.965926, 0.258819, 8.44439e-08, 0.258819, -0.965926, 0, 0.453074, 0) -spring_length = 5.0 +transform = Transform3D(-1, 0, -8.74228e-08, -2.26267e-08, 0.965926, 0.258819, 8.44439e-08, 0.258819, -0.965926, 0, 0.544421, 0.412464) +spring_length = 0.0 [node name="Camera3D" type="Camera3D" parent="SpringArm3D"] [node name="WallOrigin" type="Node3D" parent="." groups=["wall_origin"]] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.343644) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.544742) diff --git a/player/player_wall.tscn b/player/player_wall.tscn index ee9a0c7..dae979c 100644 --- a/player/player_wall.tscn +++ b/player/player_wall.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=4 format=3 uid="uid://6a20phajjwu8"] +[gd_scene load_steps=5 format=3 uid="uid://6a20phajjwu8"] [ext_resource type="Script" path="res://player/player_wall.gd" id="1_rj8im"] @@ -12,9 +12,17 @@ emission_energy_multiplier = 1.44 material = SubResource("StandardMaterial3D_sk1tc") size = Vector3(1, 0.01, 1) +[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_71bu6"] +data = PackedVector3Array(-0.5, 0.005, 0.5, 0.5, 0.005, 0.5, -0.5, -0.005, 0.5, 0.5, 0.005, 0.5, 0.5, -0.005, 0.5, -0.5, -0.005, 0.5, 0.5, 0.005, -0.5, -0.5, 0.005, -0.5, 0.5, -0.005, -0.5, -0.5, 0.005, -0.5, -0.5, -0.005, -0.5, 0.5, -0.005, -0.5, 0.5, 0.005, 0.5, 0.5, 0.005, -0.5, 0.5, -0.005, 0.5, 0.5, 0.005, -0.5, 0.5, -0.005, -0.5, 0.5, -0.005, 0.5, -0.5, 0.005, -0.5, -0.5, 0.005, 0.5, -0.5, -0.005, -0.5, -0.5, 0.005, 0.5, -0.5, -0.005, 0.5, -0.5, -0.005, -0.5, 0.5, 0.005, 0.5, -0.5, 0.005, 0.5, 0.5, 0.005, -0.5, -0.5, 0.005, 0.5, -0.5, 0.005, -0.5, 0.5, 0.005, -0.5, -0.5, -0.005, 0.5, 0.5, -0.005, 0.5, -0.5, -0.005, -0.5, 0.5, -0.005, 0.5, 0.5, -0.005, -0.5, -0.5, -0.005, -0.5) + [node name="PlayerWall" type="Node3D"] script = ExtResource("1_rj8im") [node name="MeshInstance3D" type="MeshInstance3D" parent="."] transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0, 1, 0, 0, 0.5) mesh = SubResource("BoxMesh_p4d0s") + +[node name="StaticBody3D" type="StaticBody3D" parent="MeshInstance3D"] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="MeshInstance3D/StaticBody3D"] +shape = SubResource("ConcavePolygonShape3D_71bu6") diff --git a/project.godot b/project.godot index 22564c7..a8253b7 100644 --- a/project.godot +++ b/project.godot @@ -17,8 +17,8 @@ config/icon="res://icon.svg" [display] -window/size/viewport_width=2304 -window/size/viewport_height=1296 +window/size/viewport_width=3456 +window/size/viewport_height=1944 [global_group] @@ -46,3 +46,8 @@ player_backward={ "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":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) ] } +player_restart={ +"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":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null) +] +}