-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.gd
110 lines (99 loc) · 2.73 KB
/
Item.gd
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
extends RigidBody2D
class_name Item
var picked : bool = false
var just_dropped : bool = false
var playerPicker : CharacterBody2D = null
var a # way the vector goes, 1 right or -1 left
var dish : bool = true
var just_picked : bool = false
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
# Picking processing
if picked == true:
self.position = playerPicker.get_node("PickUpMarker").global_position
if just_picked == true:
just_picked = false
elif just_dropped:
if randi() % 2 == 0:
a = 1
else:
a = -1
apply_impulse(Vector2(), Vector2(400 * a,-400))
self.linear_velocity = Vector2(0,0)
self.position[1] -= 15
self.position[0] -= 15 * a
just_dropped = false
func _input(_event):
# Interaction processing
if Input.is_action_just_pressed("interact_1"):
if picked:
if playerPicker.name == "Character1":
# drop
picked = false
playerPicker.can_pick = true
playerPicker = null
just_dropped = true
else:
# pick
var bodies = $PickArea.get_overlapping_bodies()
for body in bodies:
if body.name == "Character1":
playerPicker= body
if playerPicker != null and playerPicker.can_pick:
picked = true
playerPicker.can_pick = false
just_picked = true
else:
playerPicker = null
if Input.is_action_just_pressed("interact_2"):
if picked:
if playerPicker.name == "Character2":
# drop
picked = false
playerPicker.can_pick = true
playerPicker = null
just_dropped = true
else:
# pick
var bodies = $PickArea.get_overlapping_bodies()
for body in bodies:
if body.name == "Character2":
playerPicker= body
if playerPicker != null and playerPicker.can_pick:
picked = true
playerPicker.can_pick = false
just_picked = true
else:
playerPicker = null
# Dash / throw item
if Input.is_action_just_pressed("dash_1"):
if picked == true:
if playerPicker.name == "Character1":
a = -1
if playerPicker.facing_left == true :
a= 1
picked = false
playerPicker.can_pick = true
playerPicker = null
self.linear_velocity = Vector2(0,0)
apply_central_impulse(Vector2(1000*a,-600))
self.position[1] -= 15
self.position[0] -= 15
if Input.is_action_just_pressed("dash_2"):
if picked == true:
if playerPicker.name == "Character2":
a = -1
if playerPicker.facing_left == true :
a= 1
picked = false
playerPicker.can_pick = true
playerPicker = null
self.linear_velocity = Vector2(0,0)
apply_central_impulse(Vector2(1000*a,-600))
self.position[1] -= 15
self.position[0] -= 15
func delete():
queue_free()