1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
class_name Player
extends Node3D
const PLAYER_SIZE: float = 0.4
const SPEED: float = 25.
var game: Game
var position_ = Vector2(0, 0)
var mesh = preload("res://scenes/player.tscn").instantiate()
var hand: Node3D = null
var _anim_angle: float = 0.0
const HAND_BASE_POSITION: Vector3 = Vector3(0, .25, .4)
@onready var character: Character = $Player/Character
func _init(_id: int, new_name: String, pos: Vector2, _character: int, new_game: Game):
add_child(mesh)
position_ = pos
name = new_name
game = new_game
func update_position(new_position: Vector2, new_rotation: float):
position_ = new_position
rotation_ = new_rotation
func set_item(i: Item):
i.owned_by = hand_base
if i == null:
push_error("tile is null")
hand = i
character.play_animation("hold")
func remove_item() -> Item:
var i = hand
if i == null:
push_error("holding nothing")
hand = null
character.play_animation("idle")
return i
func take_item(tile: Floor):
if hand != null:
push_error("already holding an item")
var i = tile.take_item()
if i == null:
push_error("tile is null")
hand = i
func put_item(tile: Floor):
var i = remove_item()
tile.put_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 = lerp(position_anim, position_, delta * 10)
rotation_anim = lerp_angle(rotation_anim, rotation_, delta * 10)
position.x = position_anim.x
position.z = position_anim.y
rotation.y = rotation_anim
|