Cleanup
This commit is contained in:
+32
-3
@@ -9,6 +9,9 @@ extends CharacterBody3D
|
||||
@export var dash_action := "dash"
|
||||
@export var bomb_action := "bomp"
|
||||
|
||||
@export var coloring_sprite_path : NodePath
|
||||
@export var coloring_bomb_sprite_path : NodePath
|
||||
|
||||
@onready var geometry = $Geometry
|
||||
|
||||
signal bomb_triggered
|
||||
@@ -16,15 +19,27 @@ signal bomb_triggered
|
||||
var angle = 0
|
||||
var is_dashing = false
|
||||
var dash_time = 0
|
||||
var bomb_time = 0
|
||||
var coloring_sprite : Sprite2D
|
||||
var coloring_bomb_sprite : Sprite2D
|
||||
|
||||
const SPEED = 5.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
const DASH_SPEED: float = 20
|
||||
const DASH_DURATION: float = 0.2
|
||||
const BOMB_DURATION: float = 0.1
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
func _ready():
|
||||
coloring_sprite = get_node(coloring_sprite_path)
|
||||
coloring_bomb_sprite = get_node(coloring_bomb_sprite_path)
|
||||
coloring_sprite.modulate = color
|
||||
coloring_sprite.visible = true
|
||||
coloring_bomb_sprite.modulate = color
|
||||
coloring_bomb_sprite.visible = false
|
||||
|
||||
func _physics_process(delta):
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
@@ -34,8 +49,15 @@ func _physics_process(delta):
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
if Input.is_action_just_pressed(bomb_action):
|
||||
emit_signal("bomb_triggered", self)
|
||||
if bomb_time > 0:
|
||||
bomb_time -= delta
|
||||
if bomb_time <= 0:
|
||||
coloring_bomb_sprite.visible = false
|
||||
bomb_time = 0
|
||||
else:
|
||||
if Input.is_action_just_pressed(bomb_action):
|
||||
coloring_bomb_sprite.visible = true;
|
||||
bomb_time = BOMB_DURATION
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
@@ -51,7 +73,7 @@ func _physics_process(delta):
|
||||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
||||
geometry.global_basis = Basis.from_euler(Vector3(0, -angle, 0))
|
||||
|
||||
if Input.is_action_just_pressed("dash_p1"):
|
||||
if Input.is_action_just_pressed(dash_action):
|
||||
is_dashing = true;
|
||||
dash_time = DASH_DURATION
|
||||
|
||||
@@ -66,3 +88,10 @@ func _physics_process(delta):
|
||||
is_dashing = false
|
||||
|
||||
move_and_slide()
|
||||
|
||||
coloring_sprite.global_position = calc_coloring_position()
|
||||
coloring_bomb_sprite.global_position = coloring_sprite.global_position
|
||||
|
||||
func calc_coloring_position():
|
||||
var result = Vector2 (global_position.x * 10 + 500, global_position.z * 10 + 500)
|
||||
return result;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bfyjtfdko3l7o"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/Player.gd" id="1_w5gy0"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_yle83"]
|
||||
size = Vector3(0.24, 0.75, 0.24)
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_rwgp3"]
|
||||
height = 0.75
|
||||
radius = 0.15
|
||||
|
||||
[node name="Player1" type="CharacterBody3D"]
|
||||
collision_layer = 5
|
||||
collision_mask = 7
|
||||
script = ExtResource("1_w5gy0")
|
||||
move_right_action = "move_right_p1"
|
||||
move_left_action = "move_left_p1"
|
||||
move_down_action = "move_down_p1"
|
||||
move_up_action = "move_up_p1"
|
||||
dash_action = "dash_p1"
|
||||
bomb_action = "bomb_p1"
|
||||
|
||||
[node name="Geometry" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.472544, 0)
|
||||
mesh = SubResource("BoxMesh_yle83")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.496337, 0)
|
||||
shape = SubResource("CylinderShape3D_rwgp3")
|
||||
Reference in New Issue
Block a user