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
|
@ -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
|
||||
|
@ -41,10 +43,14 @@ func create_game():
|
|||
if error:
|
||||
return error
|
||||
multiplayer.multiplayer_peer = peer
|
||||
|
||||
@rpc("authority", "call_remote", "reliable")
|
||||
func sync_playerlist(text):
|
||||
get_tree().root.get_node("create/player_list/list").text = text
|
||||
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
@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…
Add table
Add a link
Reference in a new issue