First Commit
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
|
||||
const SPEED:= 300.0
|
||||
const JUMP_VELOCITY:= 10.0
|
||||
|
||||
|
||||
@onready var animator = get_node("gobot_new/AnimationPlayer")
|
||||
@onready var hud_container: HBoxContainer = $hud/Hud_container
|
||||
|
||||
|
||||
|
||||
|
||||
@export var view : Node3D
|
||||
@export var health := 3
|
||||
@export var foot_damage:= 1
|
||||
@onready var immunity_cooldown = 1.5
|
||||
@onready var immunity_time = $immunity
|
||||
|
||||
var gravity = 0
|
||||
var moviment_velocity : Vector3
|
||||
var rotation_direction : float
|
||||
var knockbacked := false
|
||||
var coins := 0
|
||||
var is_dead := false
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func verfy_life():
|
||||
if health == 0:
|
||||
is_dead = true
|
||||
|
||||
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
sncy()
|
||||
handle_input(delta)
|
||||
# Add the gravity.
|
||||
apply_gravity(delta)
|
||||
jump(delta)
|
||||
handle_animations()
|
||||
|
||||
|
||||
var applied_velocity : Vector3
|
||||
applied_velocity = velocity.lerp(moviment_velocity, delta * 10)
|
||||
applied_velocity.y = -gravity
|
||||
|
||||
velocity = applied_velocity
|
||||
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func sncy():
|
||||
hud_container.update_life(health)
|
||||
func handle_input(delta):
|
||||
|
||||
if not is_dead:
|
||||
if Input.is_action_just_pressed("node_pause"):
|
||||
get_parent().get_node("Pause").visible = true
|
||||
get_tree().paused = true
|
||||
|
||||
if !knockbacked:
|
||||
var input := Vector3.ZERO
|
||||
input.x = Input.get_axis("move_left", "move_right")
|
||||
input.z = Input.get_axis("move_forward", "move_backward")
|
||||
|
||||
|
||||
velocity = input * SPEED * delta
|
||||
|
||||
if Vector2(velocity.z, velocity.x).length() > 0:
|
||||
rotation_direction = Vector2(velocity.z, velocity.x).angle()
|
||||
|
||||
rotation.y = lerp_angle(rotation.y, rotation_direction, delta * 10)
|
||||
func handle_animations():
|
||||
if not is_dead:
|
||||
if is_on_floor():
|
||||
if abs(velocity.x) > 1 or abs(velocity.z) > 1:
|
||||
animator.play("Run", 0.3)
|
||||
else:
|
||||
animator.play("Idle", 0.2)
|
||||
|
||||
if !is_on_floor() and gravity > 2:
|
||||
animator.play("Fall", 0.3)
|
||||
else:
|
||||
animator.play("Dead", 03)
|
||||
await animator.animation_finished
|
||||
get_parent().get_node("Game_over").visible = true
|
||||
get_tree().paused = true
|
||||
func apply_gravity(delta):
|
||||
if not is_on_floor():
|
||||
gravity += 25 * delta
|
||||
|
||||
func jump(_delta):
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
gravity = -JUMP_VELOCITY
|
||||
if gravity > 0 and is_on_floor():
|
||||
gravity = 0
|
||||
|
||||
func knockback(impact_point: Vector3, force: Vector3) -> void:
|
||||
force.y = abs(force.y)
|
||||
velocity = force.limit_length(9.0)
|
||||
|
||||
func _on_hurtbox_body_entered(body):
|
||||
#if health == 0:
|
||||
#is_dead = true
|
||||
|
||||
var body_collision = (body.global_position - global_position)
|
||||
var force = -body_collision
|
||||
force *= 10.0
|
||||
gravity = -5.0
|
||||
knockback(body_collision, force)
|
||||
knockbacked = true
|
||||
await get_tree().create_timer(0.3).timeout
|
||||
knockbacked = false
|
||||
|
||||
func collect_coin():
|
||||
coins += 1
|
||||
hud_container.update_coin(coins)
|
||||
|
||||
func damage_player(amount: int):
|
||||
health -= amount
|
||||
verfy_life()
|
||||
|
||||
|
||||
func _on_foot_area_entered(area: Area3D) -> void:
|
||||
if area.name == "damagem_box" :
|
||||
area.damage(foot_damage)
|
||||
@@ -0,0 +1 @@
|
||||
uid://0vdug42aihte
|
||||
@@ -0,0 +1,55 @@
|
||||
extends Node3D
|
||||
|
||||
#variaveis de propriedades
|
||||
@export_group("Properties")
|
||||
@export var target: Node3D
|
||||
|
||||
#variaveis de zoom
|
||||
@export_group("zoom")
|
||||
@export var zoom_minimum = 16
|
||||
@export var zoom_maximum = 4
|
||||
@export var zoom_speed = 10
|
||||
|
||||
#variaveis de rotação
|
||||
@export_group("Rotation")
|
||||
@export var rotation_speed = 120
|
||||
@export var min_rotation_x = -80
|
||||
@export var max_rotation_x = -10
|
||||
|
||||
var camera_rotation:Vector3
|
||||
var zoom = 10
|
||||
|
||||
#atribuição da camera
|
||||
@onready var Camera = $camera
|
||||
|
||||
#função
|
||||
func _ready():
|
||||
camera_rotation = rotation_degrees #inicia a rotação
|
||||
|
||||
func _physics_process(delta):
|
||||
self.position = self.position.lerp(target.position, delta * 4)
|
||||
rotation_degrees = rotation_degrees.lerp(camera_rotation, delta * 6)
|
||||
|
||||
Camera.position = Camera.position.lerp(Vector3(0, 0, zoom), 8 * delta)
|
||||
|
||||
handle_input(delta)
|
||||
|
||||
func handle_input(delta):
|
||||
#rotação
|
||||
var input := Vector3.ZERO
|
||||
|
||||
#seleção de inputs das teclas
|
||||
input.y = Input.get_axis("ui_left", "ui_right")
|
||||
input.x = Input.get_axis("ui_up", "ui_down")
|
||||
|
||||
camera_rotation += input * rotation_speed * delta
|
||||
camera_rotation.x = clamp(camera_rotation.x, min_rotation_x, max_rotation_x)
|
||||
|
||||
zoom += Input.get_axis("zoom_in", "zoom_out") * zoom_speed * delta
|
||||
zoom = clamp(zoom, zoom_maximum, zoom_minimum)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://bf5im32nygtgq
|
||||
@@ -0,0 +1,104 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
|
||||
const SPEED:= 300.0
|
||||
const JUMP_VELOCITY:= 10.0
|
||||
|
||||
|
||||
@onready var animator = get_node("gobot_new/AnimationPlayer")
|
||||
@onready var hud_container: HBoxContainer = $hud/Hud_container
|
||||
|
||||
|
||||
|
||||
|
||||
@export var view : Node3D
|
||||
@export var health := 3
|
||||
var gravity = 0
|
||||
var moviment_velocity : Vector3
|
||||
var rotation_direction : float
|
||||
var knockbacked := false
|
||||
var coins := 0
|
||||
var is_dead := false
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
if !knockbacked:
|
||||
handle_input(delta)
|
||||
# Add the gravity.
|
||||
apply_gravity(delta)
|
||||
jump(delta)
|
||||
handle_animations()
|
||||
|
||||
|
||||
var applied_velocity : Vector3
|
||||
applied_velocity = velocity.lerp(moviment_velocity, delta * 10)
|
||||
applied_velocity.y = -gravity
|
||||
|
||||
velocity = applied_velocity
|
||||
|
||||
|
||||
move_and_slide()
|
||||
|
||||
|
||||
func handle_input(delta):
|
||||
var input := Vector3.ZERO
|
||||
input.x = Input.get_axis("move_left", "move_right")
|
||||
input.z = Input.get_axis("move_forward", "move_backward")
|
||||
input = input.rotated(Vector3.UP, view.rotation.y).normalized()
|
||||
if !knockbacked:
|
||||
velocity = input * SPEED * delta
|
||||
|
||||
if Vector2(velocity.z, velocity.x).length() > 0:
|
||||
rotation_direction = Vector2(velocity.z, velocity.x).angle()
|
||||
|
||||
rotation.y = lerp_angle(rotation.y, rotation_direction, delta * 10)
|
||||
func handle_animations():
|
||||
if not is_dead:
|
||||
if is_on_floor():
|
||||
if abs(velocity.x) > 1 or abs(velocity.z) > 1:
|
||||
animator.play("Run", 0.3)
|
||||
else:
|
||||
animator.play("Idle", 0.2)
|
||||
|
||||
if !is_on_floor() and gravity > 2:
|
||||
animator.play("Fall", 0.3)
|
||||
else:
|
||||
animator.play("Dead", 03)
|
||||
await animator.animation_finished
|
||||
get_parent().get_node("Game_over").visible = true
|
||||
get_tree().paused = true
|
||||
func apply_gravity(delta):
|
||||
if not is_on_floor():
|
||||
gravity += 25 * delta
|
||||
|
||||
func jump(_delta):
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
gravity = -JUMP_VELOCITY
|
||||
if gravity > 0 and is_on_floor():
|
||||
gravity = 0
|
||||
|
||||
func knockback(impact_point: Vector3, force: Vector3) -> void:
|
||||
hud_container.update_life(health)
|
||||
|
||||
force.y = abs(force.y)
|
||||
velocity = force.limit_length(15.0)
|
||||
|
||||
func _on_hurtbox_body_entered(body):
|
||||
|
||||
if health == 0:
|
||||
is_dead = true
|
||||
print(health)
|
||||
var body_collision = (body.global_position - global_position)
|
||||
var force = -body_collision
|
||||
force *= 10.0
|
||||
gravity = -5.0
|
||||
knockback(body_collision, force)
|
||||
knockbacked = true
|
||||
await get_tree().create_timer(0.3).timeout
|
||||
knockbacked = false
|
||||
|
||||
func collect_coin():
|
||||
coins += 1
|
||||
hud_container.update_coin(coins)
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://difds0c6bi8nn
|
||||
@@ -0,0 +1,19 @@
|
||||
extends Area3D
|
||||
const ROTATION_SPEED := 45.0
|
||||
var start_pos := position.y
|
||||
var end_pos := position.y + 0.5
|
||||
|
||||
|
||||
func _ready():
|
||||
var coin_tween := create_tween().set_loops().set_ease(Tween.EASE_IN_OUT).set_trans(Tween.TRANS_SINE)
|
||||
coin_tween.tween_property(self, "position:y", end_pos, 1.0).from(start_pos)
|
||||
coin_tween.tween_property(self, "position:y", start_pos, 1.0).from(end_pos)
|
||||
|
||||
func _process(delta):
|
||||
rotate_y(deg_to_rad(ROTATION_SPEED * delta))
|
||||
|
||||
func _on_body_entered(body):
|
||||
if body.name == "player":
|
||||
body.collect_coin()
|
||||
queue_free()
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://dbfvho370q6cq
|
||||
@@ -0,0 +1,8 @@
|
||||
extends HBoxContainer
|
||||
@onready var coin_label = $coin_label
|
||||
@onready var life_label = $life_label
|
||||
|
||||
func update_life(health: int):
|
||||
life_label.text = "%d" % health
|
||||
func update_coin(amount: int):
|
||||
coin_label.text = "%d" % amount
|
||||
@@ -0,0 +1 @@
|
||||
uid://dp6vv8hjriuph
|
||||
@@ -0,0 +1,9 @@
|
||||
extends CollisionShape3D
|
||||
const LIFE_BODY:= 125
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
pass
|
||||
func _damage_in_body():
|
||||
|
||||
pass
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://bvulc20svkv6h
|
||||
@@ -0,0 +1,2 @@
|
||||
extends CollisionShape3D
|
||||
const ATTACK_DAMAGE = 1
|
||||
@@ -0,0 +1 @@
|
||||
uid://cfhrrjafe2emf
|
||||
@@ -0,0 +1,11 @@
|
||||
extends CanvasLayer
|
||||
|
||||
func _on_retry_button_pressed() -> void:
|
||||
get_tree().paused = false
|
||||
get_tree().reload_current_scene()
|
||||
# Replace with function body.
|
||||
|
||||
|
||||
func _on_quit_button_pressed() -> void:
|
||||
get_tree().quit()
|
||||
# Replace with function body.
|
||||
@@ -0,0 +1 @@
|
||||
uid://dsc7pk1wlo3lx
|
||||
@@ -0,0 +1,8 @@
|
||||
extends HBoxContainer
|
||||
@onready var life_label = $life_label
|
||||
|
||||
func _ready():
|
||||
life_label.text = str(3)
|
||||
|
||||
func update_life(health: int):
|
||||
life_label.text = "%d" % health
|
||||
@@ -0,0 +1 @@
|
||||
uid://ccjk8penaonow
|
||||
@@ -0,0 +1,18 @@
|
||||
extends CanvasLayer
|
||||
|
||||
|
||||
func _on_retry_button_pressed() -> void: # Retry_button
|
||||
print("retry pressionado")
|
||||
get_tree().paused = false
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
|
||||
func _on_quit_button_pressed() -> void: #Quit
|
||||
print("quity pressionado")
|
||||
get_tree().quit()
|
||||
|
||||
|
||||
func _on_continued_button_pressed() -> void:#continued
|
||||
print("continued pressionado")
|
||||
get_tree().paused = false
|
||||
get_parent().get_node("Pause").visible = false
|
||||
@@ -0,0 +1 @@
|
||||
uid://40tuulq1cqaj
|
||||
Reference in New Issue
Block a user