1
Fork 0
mirror of https://github.com/Steffo99/cinnos.git synced 2024-11-25 17:44:21 +00:00
This commit is contained in:
Lorenzo Rossi 2023-11-25 14:15:38 +01:00
commit c005ba4e8a
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 43733C54D7B7BD75
5 changed files with 128 additions and 26 deletions

12
GameTimer.gd Normal file
View file

@ -0,0 +1,12 @@
extends Node
class_name GameTimer
var current_time := 0.0
@onready var parent: Label = get_parent()
func _process(delta):
current_time += delta
parent.text = "%0.2f" % current_time

View file

@ -1,31 +1,54 @@
extends CharacterBody3D
class_name Player
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
@export var input_accel: float = 1.0
@onready var current_input_accel = input_accel
@onready var gravity_accel: Vector3 = ProjectSettings.get_setting("physics/3d/default_gravity") * ProjectSettings.get_setting("physics/3d/default_gravity_vector")
@export var jump_impulse: Vector3 = Vector3.UP * 5;
@export var max_jumps = 1
@onready var current_jumps = max_jumps
@export var collision_normal_max_y_for_floor: float = 0.9
func refill_jumps():
current_jumps = max_jumps
func do_jump():
current_jumps -= 1
velocity += jump_impulse
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y -= gravity * delta
# Refilla salto
if is_on_floor():
refill_jumps()
# Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Rileva salto
if Input.is_action_just_pressed("jump") and current_jumps > 0:
do_jump()
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
# Applica gravità
velocity += gravity_accel * delta
# Applica input
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
var input_change = input_dir * input_accel
velocity.x += input_change.x * delta
velocity.z += input_change.y * delta
move_and_slide()
# Gestisci collisioni
for collision_idx in range(get_slide_collision_count()):
var collision = get_slide_collision(collision_idx)
if collision.get_normal().y > collision_normal_max_y_for_floor:
continue
print("bonk")

View file

@ -1,24 +1,36 @@
[gd_scene load_steps=8 format=3 uid="uid://4whij2hmts0t"]
[gd_scene load_steps=11 format=3 uid="uid://4whij2hmts0t"]
[ext_resource type="Script" path="res://Player.gd" id="1_wt4gx"]
[ext_resource type="Material" uid="uid://dondfiavgo2ws" path="res://Unshaded.material" id="2_upp15"]
[ext_resource type="Script" path="res://GameTimer.gd" id="3_y362g"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_castg"]
[sub_resource type="CapsuleMesh" id="CapsuleMesh_pnmjt"]
material = ExtResource("2_upp15")
[sub_resource type="BoxShape3D" id="BoxShape3D_kpyw3"]
size = Vector3(1, 0.1, 3)
[sub_resource type="BoxMesh" id="BoxMesh_4tnse"]
material = ExtResource("2_upp15")
size = Vector3(1, 0.1, 3)
[sub_resource type="PlaneMesh" id="PlaneMesh_opk07"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_1au4d"]
shading_mode = 0
albedo_color = Color(0, 0.541176, 0, 1)
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_tpbxa"]
[sub_resource type="PlaneMesh" id="PlaneMesh_opk07"]
material = SubResource("StandardMaterial3D_1au4d")
size = Vector2(200, 200)
[sub_resource type="BoxShape3D" id="BoxShape3D_2bm1d"]
size = Vector3(200, 4, 200)
[node name="Root" type="Node3D"]
[node name="Player" type="CharacterBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.927202, 0)
script = ExtResource("1_wt4gx")
[node name="Man" type="CollisionShape3D" parent="Player"]
@ -40,11 +52,34 @@ skeleton = NodePath("../..")
[node name="Plane" type="StaticBody3D" parent="."]
[node name="MeshInstance3D" type="MeshInstance3D" parent="Plane"]
transform = Transform3D(100, 0, 0, 0, 1, 0, 0, 0, 100, 0, 0, 0)
mesh = SubResource("PlaneMesh_opk07")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Plane"]
shape = SubResource("WorldBoundaryShape3D_tpbxa")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0)
shape = SubResource("BoxShape3D_2bm1d")
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.955149, 0.296125, 0, -0.296125, 0.955149, 0, 2.66196, 3.33182)
[node name="Control" type="Control" parent="."]
layout_mode = 3
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -40.0
offset_bottom = 40.0
grow_horizontal = 0
[node name="Label" type="Label" parent="Control"]
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -81.0
offset_bottom = 26.0
grow_horizontal = 0
text = "Garasauto"
horizontal_alignment = 2
[node name="GameTimer" type="Node" parent="Control/Label"]
script = ExtResource("3_y362g")

BIN
Unshaded.material Normal file

Binary file not shown.

View file

@ -14,3 +14,35 @@ config/name="cisio"
run/main_scene="res://Root.tscn"
config/features=PackedStringArray("4.1", "Forward Plus")
config/icon="res://icon.svg"
[input]
jump={
"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":32,"key_label":0,"unicode":32,"echo":false,"script":null)
]
}
move_up={
"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":87,"key_label":0,"unicode":119,"echo":false,"script":null)
, 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":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
move_down={
"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":83,"key_label":0,"unicode":115,"echo":false,"script":null)
, 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":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
move_left={
"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":65,"key_label":0,"unicode":97,"echo":false,"script":null)
, 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":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
move_right={
"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":68,"key_label":0,"unicode":100,"echo":false,"script":null)
, 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":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}