forked from interstellar_development/freeftf
Milestone 3: Freezer
The freezer is now implemented, just as it worked in the original. There are also a few fixes here and there in preparation for Milestonr 4.
This commit is contained in:
parent
d40c3ce1ab
commit
a92202b536
14 changed files with 199 additions and 114 deletions
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://2qsccmko8yl8"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://2qsccmko8yl8"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://4mhcwvn365ki" path="res://objects/computer.tscn" id="2_28qhl"]
|
||||
[ext_resource type="PackedScene" uid="uid://bldbqjmabjemn" path="res://objects/freezer.tscn" id="2_ty8su"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_34oyu"]
|
||||
size = Vector3(50, 1, 50)
|
||||
|
@ -42,3 +43,6 @@ transform = Transform3D(1, 0, 0, 0, 0.984808, 0.173648, 0, -0.173648, 0.984808,
|
|||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_3mjgt")
|
||||
|
||||
[node name="freezer" parent="." instance=ExtResource("2_ty8su")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -18.6627, 3.5, -10.4457)
|
||||
|
|
|
@ -40,6 +40,17 @@ layout_mode = 2
|
|||
theme_override_font_sizes/font_size = 32
|
||||
placeholder_text = "Name"
|
||||
|
||||
[node name="ip" type="TextEdit" parent="player_customization"]
|
||||
custom_minimum_size = Vector2(256, 64)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 32
|
||||
placeholder_text = "IP Address"
|
||||
|
||||
[node name="join" type="Button" parent="player_customization"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 32
|
||||
text = "Join Game"
|
||||
|
||||
[node name="start" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 3
|
||||
|
@ -53,8 +64,11 @@ grow_horizontal = 0
|
|||
grow_vertical = 0
|
||||
|
||||
[node name="start" type="Button" parent="start"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 32
|
||||
disabled = true
|
||||
text = "Start Game"
|
||||
|
||||
[connection signal="pressed" from="player_customization/join" to="." method="_on_join_pressed"]
|
||||
[connection signal="pressed" from="start/start" to="." method="_on_start_pressed"]
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://bh1ptr4bepla6"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/join.gd" id="1_evkiv"]
|
||||
|
||||
[node name="Join" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_evkiv")
|
||||
|
||||
[node name="player_customization" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -128.0
|
||||
offset_top = -32.0
|
||||
offset_right = 128.0
|
||||
offset_bottom = 32.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="name" type="TextEdit" parent="player_customization"]
|
||||
custom_minimum_size = Vector2(256, 64)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 32
|
||||
placeholder_text = "Name"
|
||||
|
||||
[node name="ip" type="TextEdit" parent="player_customization"]
|
||||
custom_minimum_size = Vector2(256, 64)
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 32
|
||||
placeholder_text = "IP Address"
|
||||
|
||||
[node name="join" type="Button" parent="player_customization"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 32
|
||||
text = "Join Game"
|
||||
|
||||
[node name="Timer" type="Timer" parent="player_customization"]
|
||||
one_shot = true
|
||||
|
||||
[connection signal="pressed" from="player_customization/join" to="." method="_on_join_pressed"]
|
||||
[connection signal="timeout" from="player_customization/Timer" to="." method="_on_timer_timeout"]
|
|
@ -59,7 +59,7 @@ grow_vertical = 0
|
|||
[node name="Label" type="Label" parent="ver_string"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 32
|
||||
text = "Milestone 2"
|
||||
text = "Milestone 3"
|
||||
|
||||
[connection signal="pressed" from="main_content/create" to="." method="_on_create_pressed"]
|
||||
[connection signal="pressed" from="main_content/join" to="." method="_on_join_pressed"]
|
||||
|
|
42
objects/freezer.tscn
Normal file
42
objects/freezer.tscn
Normal file
|
@ -0,0 +1,42 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://bldbqjmabjemn"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/freezer.gd" id="1_nmqkg"]
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_pkxhd"]
|
||||
height = 6.0
|
||||
radius = 2.0
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_uvwqt"]
|
||||
size = Vector3(5, 5, 5)
|
||||
|
||||
[node name="freezer" type="StaticBody3D"]
|
||||
script = ExtResource("1_nmqkg")
|
||||
|
||||
[node name="CSGCylinder3D" type="CSGCylinder3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2.5, 0)
|
||||
radius = 2.0
|
||||
height = 1.0
|
||||
|
||||
[node name="CSGCylinder3D2" type="CSGCylinder3D" parent="."]
|
||||
transparency = 0.25
|
||||
radius = 1.5
|
||||
height = 4.0
|
||||
|
||||
[node name="CSGCylinder3D3" type="CSGCylinder3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.5, 0)
|
||||
radius = 2.0
|
||||
height = 1.0
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CylinderShape3D_pkxhd")
|
||||
|
||||
[node name="Area3D" type="Area3D" parent="."]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"]
|
||||
shape = SubResource("BoxShape3D_uvwqt")
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
autostart = true
|
||||
|
||||
[connection signal="body_entered" from="Area3D" to="." method="_on_area_3d_body_entered"]
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
|
@ -63,8 +63,14 @@ wait_time = 30.0
|
|||
one_shot = true
|
||||
|
||||
[node name="show_fps" type="Timer" parent="."]
|
||||
wait_time = 10.0
|
||||
autostart = true
|
||||
|
||||
[node name="jump_timeout" type="Timer" parent="."]
|
||||
wait_time = 2.0
|
||||
one_shot = true
|
||||
|
||||
[connection signal="body_entered" from="detect_hit" to="." method="_on_detect_hit_body_entered"]
|
||||
[connection signal="timeout" from="time_in_bag" to="." method="_on_time_in_bag_timeout"]
|
||||
[connection signal="timeout" from="show_fps" to="." method="_on_show_fps_timeout"]
|
||||
[connection signal="timeout" from="jump_timeout" to="." method="_on_jump_timeout_timeout"]
|
||||
|
|
|
@ -66,6 +66,11 @@ escape={
|
|||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
mouse_lock={
|
||||
"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":76,"key_label":0,"unicode":108,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ func _ready():
|
|||
Game.computers += 1
|
||||
|
||||
func _on_computer_tick_timeout():
|
||||
if multiplayer.is_server():
|
||||
if Server.is_server:
|
||||
current += (pc_occupied[0] + pc_occupied[1] + pc_occupied[2])
|
||||
Server.sync_computers.rpc(name, current)
|
||||
if current >= TARGET:
|
||||
|
@ -32,19 +32,19 @@ func _on_computer_tick_timeout():
|
|||
|
||||
|
||||
func _on_pc_1_area_body_entered(body):
|
||||
if pc_occupied[0] == 0:
|
||||
if pc_occupied[0] == 0 and !body.beast:
|
||||
pc_occupied[0] = 1
|
||||
pc_body[0] = body
|
||||
|
||||
|
||||
func _on_pc_2_area_body_entered(body):
|
||||
if pc_occupied[1] == 0:
|
||||
if pc_occupied[1] == 0 and !body.beast:
|
||||
pc_occupied[1] = 1
|
||||
pc_body[1] = body
|
||||
|
||||
|
||||
func _on_pc_3_area_body_entered(body):
|
||||
if pc_occupied[2] == 0:
|
||||
if pc_occupied[2] == 0 and !body.beast:
|
||||
pc_occupied[2] = 1
|
||||
pc_body[2] = body
|
||||
|
||||
|
|
|
@ -8,15 +8,36 @@
|
|||
|
||||
extends Control
|
||||
|
||||
|
||||
func _ready():
|
||||
Server.create_game()
|
||||
if Server.is_server:
|
||||
$player_customization/ip.hide()
|
||||
$player_customization/ip.text = "localhost"
|
||||
$player_customization/ip.editable = false
|
||||
$start/start.show()
|
||||
$start/start.disabled = false
|
||||
$player_list/list.text = " "
|
||||
|
||||
func _process(delta):
|
||||
if Server.is_server:
|
||||
Server.sync_playerlist.rpc($player_list/list.text)
|
||||
|
||||
func _on_start_pressed():
|
||||
Server.send_playerinfo(get_tree().root.get_node("create/player_customization/name").text, multiplayer.get_unique_id())
|
||||
Server.start_game.rpc(Server.players)
|
||||
|
||||
func _input(event):
|
||||
if Input.is_action_just_pressed("escape"):
|
||||
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
||||
|
||||
|
||||
func _on_join_pressed():
|
||||
if $player_customization/name.text != "" and $player_customization/ip.text != "":
|
||||
if !Server.is_server:
|
||||
Server.join_game($player_customization/ip.text)
|
||||
$player_customization/join.hide()
|
||||
$player_customization/join.disabled = true
|
||||
$player_customization/name.editable = false
|
||||
$player_customization/ip.editable = false
|
||||
while $player_list/list.text == "":
|
||||
await get_tree().create_timer(0.001).timeout
|
||||
Server.send_playerinfo.rpc($player_customization/name.text, multiplayer.get_unique_id())
|
||||
|
||||
|
|
30
scripts/freezer.gd
Normal file
30
scripts/freezer.gd
Normal file
|
@ -0,0 +1,30 @@
|
|||
extends StaticBody3D
|
||||
|
||||
var trapped_body
|
||||
var occupied = false
|
||||
var living = true
|
||||
|
||||
func _process(delta):
|
||||
if occupied:
|
||||
trapped_body.position = position
|
||||
if occupied and trapped_body.hp == 0:
|
||||
living = false
|
||||
|
||||
func _on_area_3d_body_entered(body):
|
||||
if body is StaticBody3D:
|
||||
pass
|
||||
elif body.beast and body.got_person and !occupied:
|
||||
trapped_body = body.caught_body
|
||||
occupied = true
|
||||
living = true
|
||||
body.lost_one()
|
||||
trapped_body.frozen()
|
||||
elif !body.beast and occupied and living and body != trapped_body:
|
||||
trapped_body.unfreeze()
|
||||
trapped_body._on_time_in_bag_timeout()
|
||||
occupied = false
|
||||
trapped_body = null
|
||||
|
||||
func _on_timer_timeout():
|
||||
if occupied and living:
|
||||
trapped_body.hp -= 2
|
|
@ -1,27 +0,0 @@
|
|||
## Copyright (C) 2024 Patrick_Pluto
|
||||
##
|
||||
## 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, version 3.
|
||||
##
|
||||
## 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.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
extends Control
|
||||
|
||||
|
||||
|
||||
func _on_join_pressed():
|
||||
if $player_customization/name.text != "" or $player_customization/ip.text != "":
|
||||
Server.join_game($player_customization/ip.text)
|
||||
$player_customization/join.hide()
|
||||
$player_customization/join.disabled = true
|
||||
$player_customization/Timer.start()
|
||||
|
||||
|
||||
func _on_timer_timeout():
|
||||
Server.send_playerinfo.rpc($player_customization/name.text, multiplayer.get_unique_id())
|
||||
|
||||
|
||||
func _input(event):
|
||||
if Input.is_action_just_pressed("escape"):
|
||||
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
|
@ -20,9 +20,11 @@ func _process(delta):
|
|||
|
||||
|
||||
func _on_create_pressed():
|
||||
Server.create_game()
|
||||
Server.is_server = true
|
||||
get_tree().change_scene_to_file("res://menus/create.tscn")
|
||||
|
||||
|
||||
func _on_join_pressed():
|
||||
get_tree().change_scene_to_file("res://menus/join.tscn")
|
||||
get_tree().change_scene_to_file("res://menus/create.tscn")
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
|
||||
const SPEED = 5.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
var jump_velocity = 6
|
||||
var speed = 10.0
|
||||
var zoom = 0
|
||||
var player_no
|
||||
var npc = false
|
||||
|
@ -19,6 +19,11 @@ var caught = false
|
|||
var captured_by
|
||||
var position_pre
|
||||
var got_person = false
|
||||
var caught_body
|
||||
var beast = false
|
||||
var mouse_locked = true
|
||||
var is_frozen = false
|
||||
var hp = 100
|
||||
|
||||
|
||||
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
@ -33,17 +38,6 @@ func _ready():
|
|||
npc = true
|
||||
|
||||
func _physics_process(delta):
|
||||
if $cam_y/Camera3D.position.z == 0:
|
||||
$cam_y.position.y = 1
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
else:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
$cam_y.position.y = 0
|
||||
if Input.is_action_just_pressed("escape"):
|
||||
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
||||
Game.reset()
|
||||
Server.reset()
|
||||
|
||||
if enabled:
|
||||
|
||||
if not is_on_floor():
|
||||
|
@ -52,22 +46,41 @@ func _physics_process(delta):
|
|||
|
||||
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
if beast:
|
||||
speed -= 6
|
||||
$jump_timeout.start()
|
||||
velocity.y = jump_velocity
|
||||
|
||||
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:
|
||||
velocity.x = direction.x * SPEED
|
||||
velocity.z = direction.z * SPEED
|
||||
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)
|
||||
velocity.x = move_toward(velocity.x, 0, speed)
|
||||
velocity.z = move_toward(velocity.z, 0, speed)
|
||||
|
||||
move_and_slide()
|
||||
Server.sync_player.rpc(name, position, rotation)
|
||||
|
||||
if caught and !npc:
|
||||
if !npc:
|
||||
print(hp)
|
||||
Server.sync_player.rpc(name, position, rotation)
|
||||
if $cam_y/Camera3D.position.z == 0:
|
||||
$cam_y.position.y = 1
|
||||
if mouse_locked:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
else:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
else:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
$cam_y.position.y = 0
|
||||
if Input.is_action_just_pressed("escape"):
|
||||
get_tree().change_scene_to_file("res://menus/main_menu.tscn")
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
Game.reset()
|
||||
Server.reset()
|
||||
if Input.is_action_just_pressed("mouse_lock"):
|
||||
mouse_locked = !mouse_locked
|
||||
|
||||
|
||||
func _input(event):
|
||||
|
@ -86,7 +99,7 @@ func _input(event):
|
|||
rotate(Vector3.DOWN, camera_rotation.x)
|
||||
|
||||
func _unhandled_input(event):
|
||||
if !npc:
|
||||
if !npc and !beast:
|
||||
if event.is_action_pressed("zoom_in") && $cam_y/Camera3D.position.z > 0:
|
||||
zoom = -1
|
||||
$cam_y/Camera3D.position.z += zoom
|
||||
|
@ -97,7 +110,10 @@ func _unhandled_input(event):
|
|||
zoom = 0
|
||||
|
||||
func beast_init():
|
||||
beast = true
|
||||
speed += 1
|
||||
position.y += 10
|
||||
$cam_y/Camera3D.position.z = 0
|
||||
$detect_hit.monitoring = true
|
||||
$detect_hit.monitorable = true
|
||||
$detect_hit/CollisionShape3D.disabled = false
|
||||
|
@ -120,6 +136,7 @@ func captured(beast):
|
|||
|
||||
|
||||
func got_one(target):
|
||||
caught_body = target
|
||||
got_person = true
|
||||
$hammer_bag/CSGCylinder3D/CSGSphere3D.visible = true
|
||||
|
||||
|
@ -127,6 +144,13 @@ func lost_one():
|
|||
got_person = false
|
||||
$hammer_bag/CSGCylinder3D/CSGSphere3D.visible = false
|
||||
|
||||
func frozen():
|
||||
$in_bag.visible = false
|
||||
is_frozen = true
|
||||
|
||||
|
||||
func unfreeze():
|
||||
is_frozen = false
|
||||
|
||||
func _on_time_in_bag_timeout():
|
||||
visible = true
|
||||
|
@ -139,4 +163,8 @@ func _on_time_in_bag_timeout():
|
|||
|
||||
|
||||
func _on_show_fps_timeout():
|
||||
print(Engine.get_frames_per_second())
|
||||
print("FPS: "+str(Engine.get_frames_per_second()))
|
||||
|
||||
|
||||
func _on_jump_timeout_timeout():
|
||||
speed += 6
|
||||
|
|
|
@ -17,12 +17,14 @@ var players_numbered = []
|
|||
var label
|
||||
var map
|
||||
var character = preload("res://objects/player.tscn")
|
||||
var is_server = false
|
||||
|
||||
func reset():
|
||||
players = {}
|
||||
players_numbered = []
|
||||
label = null
|
||||
map = null
|
||||
is_server = false
|
||||
character = preload("res://objects/player.tscn")
|
||||
if multiplayer != null:
|
||||
multiplayer.multiplayer_peer = null
|
||||
|
@ -42,9 +44,13 @@ func create_game():
|
|||
return error
|
||||
multiplayer.multiplayer_peer = peer
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
@rpc("authority", "call_remote", "reliable")
|
||||
func sync_playerlist(text):
|
||||
get_tree().root.get_node("create/player_list/list").text = text
|
||||
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func send_playerinfo(name, id):
|
||||
if multiplayer.is_server():
|
||||
if Server.is_server:
|
||||
var done = 0
|
||||
players[id] = name
|
||||
label = get_tree().root.get_node("create/player_list/list")
|
||||
|
@ -72,7 +78,7 @@ func start_game(server_players):
|
|||
i += 1
|
||||
player.position.z = -i*2.5
|
||||
map.add_child(player)
|
||||
if multiplayer.is_server():
|
||||
if Server.is_server:
|
||||
var random = randi() % Server.players.size()
|
||||
sync_beast.rpc(random)
|
||||
|
||||
|
@ -89,6 +95,8 @@ func sync_computers(node_name, current):
|
|||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func sync_beast(player):
|
||||
while !get_tree().root.has_node("./map/player"+str(player)):
|
||||
await get_tree().create_timer(0.001).timeout
|
||||
var current_character = get_tree().root.get_node("./map/player"+str(player))
|
||||
current_character.beast_init()
|
||||
|
||||
|
@ -96,6 +104,7 @@ func sync_beast(player):
|
|||
func player_hit(target, beast):
|
||||
target = get_tree().root.get_node("./map/"+target)
|
||||
beast = get_tree().root.get_node("./map/"+beast)
|
||||
target.captured(beast)
|
||||
beast.got_one(target)
|
||||
if !target.is_frozen:
|
||||
target.captured(beast)
|
||||
beast.got_one(target)
|
||||
|
||||
|
|
Loading…
Reference in a new issue