2024-08-31 14:58:41 +02:00
|
|
|
## FreeFTF
|
|
|
|
## Copyright (C) 2024 Interstellar Development
|
2024-08-02 22:38:08 +02:00
|
|
|
##
|
2024-08-31 14:58:41 +02:00
|
|
|
## This program is free software: you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published by
|
|
|
|
## the Free Software Foundation, either version 3 of the License, or
|
|
|
|
## (at your option) any later version.
|
2024-08-02 22:38:08 +02:00
|
|
|
##
|
2024-08-31 14:58:41 +02:00
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
2024-08-02 22:38:08 +02:00
|
|
|
##
|
2024-08-31 14:58:41 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
## along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2024-08-02 22:38:08 +02:00
|
|
|
|
2024-08-02 00:55:56 +02:00
|
|
|
extends CharacterBody3D
|
|
|
|
|
|
|
|
|
2024-08-11 19:43:03 +02:00
|
|
|
var jump_velocity = 4.5
|
2024-08-05 22:35:50 +02:00
|
|
|
var speed = 7
|
2024-08-02 00:55:56 +02:00
|
|
|
var zoom = 0
|
2024-08-02 20:13:42 +02:00
|
|
|
var player_no
|
2024-08-03 16:10:14 +02:00
|
|
|
var npc = false
|
2024-08-02 20:13:42 +02:00
|
|
|
var enabled = false
|
2024-08-03 16:10:14 +02:00
|
|
|
var caught = false
|
|
|
|
var captured_by
|
|
|
|
var position_pre
|
|
|
|
var got_person = false
|
2024-08-04 13:41:19 +02:00
|
|
|
var caught_body
|
|
|
|
var beast = false
|
|
|
|
var mouse_locked = true
|
|
|
|
var is_frozen = false
|
|
|
|
var hp = 100
|
2024-09-01 21:35:29 +02:00
|
|
|
var jump_debuff = 5
|
|
|
|
var jump_debuff_used = 5
|
2024-08-06 23:28:40 +02:00
|
|
|
var menu = preload("res://menus/game_menu.tscn")
|
2024-08-02 00:55:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
|
|
|
|
2024-08-02 20:13:42 +02:00
|
|
|
func _ready():
|
|
|
|
player_no = Game.players
|
2024-08-08 21:49:24 +02:00
|
|
|
$nametag.text = Game.player_list[Game.player_list.keys()[player_no]]
|
2024-08-02 20:13:42 +02:00
|
|
|
Game.players += 1
|
2024-08-08 21:49:24 +02:00
|
|
|
if Game.player_list.keys()[player_no] == multiplayer.get_unique_id():
|
2024-08-05 22:35:50 +02:00
|
|
|
if Game.settings["fps_counter"] == 1:
|
|
|
|
$fps_counter.show()
|
|
|
|
$health.show()
|
2024-08-02 20:13:42 +02:00
|
|
|
enabled = true
|
|
|
|
$cam_y/Camera3D.current = true
|
2024-08-05 22:35:50 +02:00
|
|
|
$nametag.hide()
|
2024-08-03 16:10:14 +02:00
|
|
|
else:
|
|
|
|
npc = true
|
2024-08-02 00:55:56 +02:00
|
|
|
|
|
|
|
func _physics_process(delta):
|
2024-08-02 20:13:42 +02:00
|
|
|
if enabled:
|
|
|
|
|
2024-08-11 19:43:03 +02:00
|
|
|
if Input.is_action_just_pressed("jump") and is_on_floor() and $jump_timeout.is_stopped():
|
|
|
|
if beast:
|
2024-09-01 21:35:29 +02:00
|
|
|
jump_debuff_used = jump_debuff
|
|
|
|
speed -= jump_debuff_used
|
2024-08-11 19:43:03 +02:00
|
|
|
$jump_timeout.start()
|
|
|
|
velocity.y = jump_velocity
|
|
|
|
|
2024-08-02 20:13:42 +02:00
|
|
|
if not is_on_floor():
|
|
|
|
velocity.y -= gravity * delta
|
2024-08-08 21:49:24 +02:00
|
|
|
|
2024-08-05 22:35:50 +02:00
|
|
|
|
|
|
|
if Input.is_action_just_pressed("crouch") and !beast:
|
|
|
|
if $collision.rotation.x == 0:
|
|
|
|
$collision.rotation.x = deg_to_rad(-90)
|
|
|
|
speed -= 3
|
|
|
|
$cam_y.position.y = 0
|
|
|
|
else :
|
|
|
|
$collision.rotation.x = 0
|
|
|
|
speed += 3
|
|
|
|
$cam_y.position.y = 0.5
|
|
|
|
position.y += 1
|
2024-08-06 23:28:40 +02:00
|
|
|
|
2024-08-11 19:43:03 +02:00
|
|
|
if Input.is_action_pressed("click") and $hammer.rotation_degrees.x > 0:
|
2024-08-13 20:43:54 +02:00
|
|
|
$hammer.rotation_degrees.x -= 10
|
2024-08-08 21:49:24 +02:00
|
|
|
for id in Game.player_list:
|
2024-08-13 22:12:37 +02:00
|
|
|
Client.rpc_id(id,"sync_hammer",$hammer.get_path(), $hammer.rotation)
|
2024-08-11 19:43:03 +02:00
|
|
|
elif $hammer.rotation_degrees.x < 90 and !Input.is_action_pressed("click"):
|
2024-08-13 20:43:54 +02:00
|
|
|
$hammer.rotation_degrees.x += 10
|
2024-08-08 21:49:24 +02:00
|
|
|
for id in Game.player_list:
|
2024-08-13 22:12:37 +02:00
|
|
|
Client.rpc_id(id,"sync_hammer",$hammer.get_path(), $hammer.rotation)
|
2024-08-02 00:55:56 +02:00
|
|
|
|
2024-08-02 20:13:42 +02:00
|
|
|
var input_dir = Input.get_vector("left", "right", "forwards", "backwards")
|
|
|
|
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
|
|
if direction:
|
2024-08-04 13:41:19 +02:00
|
|
|
velocity.x = direction.x * speed
|
|
|
|
velocity.z = direction.z * speed
|
2024-08-02 20:13:42 +02:00
|
|
|
else:
|
2024-08-04 13:41:19 +02:00
|
|
|
velocity.x = move_toward(velocity.x, 0, speed)
|
|
|
|
velocity.z = move_toward(velocity.z, 0, speed)
|
2024-08-11 19:43:03 +02:00
|
|
|
|
2024-08-02 20:13:42 +02:00
|
|
|
move_and_slide()
|
2024-08-02 00:55:56 +02:00
|
|
|
|
2024-08-04 13:41:19 +02:00
|
|
|
if !npc:
|
2024-08-08 21:49:24 +02:00
|
|
|
for id in Game.player_list:
|
2024-08-31 14:58:41 +02:00
|
|
|
Client.rpc_id(id,"sync_player",get_path(), position, rotation, $collision.rotation)
|
2024-08-06 23:28:40 +02:00
|
|
|
if mouse_locked and !has_node("./game_menu"):
|
2024-08-05 22:35:50 +02:00
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
2024-08-04 13:41:19 +02:00
|
|
|
else:
|
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
|
|
|
if Input.is_action_just_pressed("escape"):
|
2024-08-06 23:28:40 +02:00
|
|
|
if has_node("./game_menu"):
|
|
|
|
get_node("./game_menu").free()
|
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
|
|
|
else:
|
|
|
|
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
|
|
|
var instance = menu.instantiate()
|
|
|
|
add_child(instance)
|
2024-08-03 16:10:14 +02:00
|
|
|
|
|
|
|
|
2024-08-02 00:55:56 +02:00
|
|
|
func _input(event):
|
2024-08-03 16:10:14 +02:00
|
|
|
if !npc:
|
2024-09-01 21:35:29 +02:00
|
|
|
if event is InputEventMouseMotion and mouse_locked:
|
2024-08-31 14:58:41 +02:00
|
|
|
var camera_rotation = event.relative * 0.01 * Game.settings["sensitivity"]
|
2024-08-02 20:13:42 +02:00
|
|
|
if $cam_y.rotation.x <= 1.6 && camera_rotation.y <= 0:
|
|
|
|
$cam_y.rotate(Vector3.RIGHT, -camera_rotation.y)
|
|
|
|
elif $cam_y.rotation.x >= -1.6 && camera_rotation.y >= 0:
|
|
|
|
$cam_y.rotate(Vector3.RIGHT, -camera_rotation.y)
|
|
|
|
if $cam_y.rotation.x >= 1.6:
|
|
|
|
$cam_y.rotation.x = 1.6
|
|
|
|
elif $cam_y.rotation.x <= -1.6:
|
|
|
|
$cam_y.rotation.x = -1.6
|
|
|
|
rotate(Vector3.DOWN, camera_rotation.x)
|
2024-08-02 00:55:56 +02:00
|
|
|
|
2024-08-03 16:10:14 +02:00
|
|
|
|
|
|
|
func beast_init():
|
2024-08-06 23:28:40 +02:00
|
|
|
if !npc:
|
|
|
|
Game.is_beast = true
|
2024-09-01 21:35:29 +02:00
|
|
|
add_child(load("res://menus/ability_select.tscn").instantiate())
|
|
|
|
mouse_locked = false
|
2024-08-04 13:41:19 +02:00
|
|
|
beast = true
|
2024-09-01 21:35:29 +02:00
|
|
|
speed += 1
|
2024-08-11 19:43:03 +02:00
|
|
|
$hammer/CSGBox3D/detect_hit.monitoring = true
|
|
|
|
$hammer/CSGBox3D/detect_hit.monitorable = true
|
|
|
|
$hammer/CSGBox3D/detect_hit/CollisionShape3D.disabled = false
|
2024-08-06 23:28:40 +02:00
|
|
|
$hammer.show()
|
|
|
|
$bag.show()
|
2024-09-01 21:35:29 +02:00
|
|
|
|
2024-08-03 16:10:14 +02:00
|
|
|
|
|
|
|
func _on_detect_hit_body_entered(body):
|
|
|
|
if enabled and body is CharacterBody3D and !got_person:
|
2024-08-08 21:49:24 +02:00
|
|
|
for id in Game.player_list:
|
2024-08-13 22:12:37 +02:00
|
|
|
Client.rpc_id(id,"player_hit",body.get_path(), get_path())
|
2024-08-03 16:10:14 +02:00
|
|
|
|
2024-08-05 22:35:50 +02:00
|
|
|
func captured(beast2):
|
2024-08-13 22:12:37 +02:00
|
|
|
if !beast:
|
|
|
|
if !npc:
|
|
|
|
$in_bag.visible = true
|
|
|
|
$time_in_bag.start()
|
|
|
|
visible = false
|
|
|
|
enabled = false
|
|
|
|
caught = true
|
|
|
|
captured_by = beast2
|
|
|
|
position_pre = position
|
|
|
|
position = Vector3(10000, 10000, 10000)
|
2024-08-03 16:10:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
func got_one(target):
|
2024-08-13 22:12:37 +02:00
|
|
|
if !target.beast:
|
|
|
|
caught_body = target
|
|
|
|
got_person = true
|
|
|
|
$bag/CSGSphere3D.show()
|
2024-08-03 16:10:14 +02:00
|
|
|
|
|
|
|
func lost_one():
|
|
|
|
got_person = false
|
2024-08-06 23:28:40 +02:00
|
|
|
$bag/CSGSphere3D.hide()
|
2024-08-03 16:10:14 +02:00
|
|
|
|
2024-08-04 13:41:19 +02:00
|
|
|
func frozen():
|
2024-08-06 11:13:52 +02:00
|
|
|
visible = true
|
2024-08-04 13:41:19 +02:00
|
|
|
$in_bag.visible = false
|
|
|
|
is_frozen = true
|
2024-08-06 11:13:52 +02:00
|
|
|
enabled = false
|
2024-08-04 13:41:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
func unfreeze():
|
|
|
|
is_frozen = false
|
2024-08-06 11:13:52 +02:00
|
|
|
if !npc:
|
|
|
|
enabled = true
|
|
|
|
caught = false
|
2024-08-03 16:10:14 +02:00
|
|
|
|
|
|
|
func _on_time_in_bag_timeout():
|
|
|
|
visible = true
|
|
|
|
if !npc:
|
|
|
|
enabled = true
|
|
|
|
caught = false
|
|
|
|
captured_by.lost_one()
|
2024-08-11 19:43:03 +02:00
|
|
|
captured_by = null
|
2024-08-03 16:10:14 +02:00
|
|
|
position = position_pre
|
|
|
|
$in_bag.visible = false
|
2024-08-03 23:08:03 +02:00
|
|
|
|
|
|
|
func _on_show_fps_timeout():
|
2024-08-05 22:35:50 +02:00
|
|
|
$fps_counter.text = "FPS: "+str(Engine.get_frames_per_second())
|
|
|
|
$health.text = "HP: "+str(hp)
|
2024-08-04 13:41:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_jump_timeout_timeout():
|
2024-09-01 21:35:29 +02:00
|
|
|
speed += jump_debuff_used
|