# Hurry Curry! - a game about cooking # Copyright 2024 nokoe # Copyright 2024 metamuffin # Copyright 2024 tpart # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, version 3 of the License only. # # 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 Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # class_name Player extends Node3D const PLAYER_SIZE: float = 0.4 const SPEED: float = 25. var game: Game var rotation_ = 0. var rotation_anim = 0. var position_ = Vector2(0, 0) var position_anim = Vector2(0, 0) var boosting := false var walking := false var username: String var movement_base: Node3D = Node3D.new() var character: Character = preload("res://player/character/character.tscn").instantiate() var chat_bubble: ChatBubble = preload("res://player/chat_bubble.tscn").instantiate() var item_bubble: ItemBubble = preload("res://player/item_bubble.tscn").instantiate() var effect: Effect = preload("res://player/effect.tscn").instantiate() var marker: Marker = preload("res://player/marker.tscn").instantiate() var marker_target = Vector3(0, 0, 0) var clear_timer: Timer = Timer.new() var hand: Item = null var hand_base: Node3D = Node3D.new() var character_idx: int var _anim_angle: float = 0.0 const HAND_BASE_POSITION: Vector3 = Vector3(0, .25, .4) func _init(_id: int, new_name: String, pos: Vector2, new_character_idx: int, new_game: Game): add_child(movement_base) movement_base.add_child(character) position_ = pos position_anim = pos name = new_name game = new_game username = new_name hand_base.position = HAND_BASE_POSITION movement_base.add_child(hand_base) movement_base.add_child(chat_bubble) movement_base.add_child(item_bubble) movement_base.add_child(effect) clear_timer.one_shot = true clear_timer.wait_time = 5. add_child(clear_timer) marker.visible = false add_child(marker) character_idx = new_character_idx func _ready(): character.select_hairstyle(character_idx) clear_timer.timeout.connect(clear_message) update_username_tag() Global.settings_changed.connect(update_username_tag) func update_position(new_position: Vector2, new_rotation: float, new_boosting: bool): position_ = new_position rotation_ = new_rotation boosting = new_boosting func update_username_tag(): var tag: Label3D = character.username_tag tag.text = username tag.visible = Global.get_setting("usernames") func set_item(i: Item): i.owned_by = hand_base if hand != null: hand.queue_free() if i == null: push_error("tile is null") hand = i character.holding = true func remove_item() -> Item: var i = hand if i == null: push_error("holding nothing") hand = null character.holding = false return i func progress(p: float, warn: bool): if hand != null: hand.progress(p, warn) func finish(warn: bool): if hand != null: hand.finish(warn) func take_item(tile: Tile): if hand != null: push_error("already holding an item") var i = tile.take_item() i.take() set_item(i) func put_item(tile: Tile): var i = remove_item() i.put() tile.put_item(i) func pass_to(player: Player): var i = remove_item() if player.hand != null: push_error("target is already holding an item") player.set_item(i) func _process(delta): _anim_angle = fmod(_anim_angle + delta, TAU) hand_base.position.y = HAND_BASE_POSITION.y + 0.05 * sin(_anim_angle * 3) position_anim = G.interpolate(position_anim, position_, delta * 10) rotation_anim = G.interpolate_angle(rotation_anim, rotation_, delta * 10) movement_base.position.x = position_anim.x movement_base.position.z = position_anim.y movement_base.rotation.y = rotation_anim walking = walking or position_.distance_squared_to(position_anim) > 0.001 character.walking = walking character.boosting = boosting walking = false func clear_message(): item_bubble.remove_item() chat_bubble.remove_text() effect.clear_effect() func item_message(item_name: String, persist: bool): item_bubble.set_item(item_name) if persist: clear_timer.stop() else: clear_timer.start() func text_message(m: String, persist: bool): chat_bubble.set_text(m) if persist: clear_timer.stop() else: clear_timer.start() func effect_message(effect_name: String, persist: bool): effect.set_effect(effect_name) if persist: clear_timer.stop() else: clear_timer.start()