-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.js
111 lines (96 loc) · 2.52 KB
/
player.js
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
111
function checkForNPC(player_character)
{
if (!playerVsFloor.hit || !playerVsNPC.hit || playerVsTrigger) {
//To prevent the player from moving, subtract its velocity from its position
player.x -= player.vx;
player.y -= player.vy;
player.vx = 0;
player.vy = 0;
}
let tempItem = null; //set up tempItem (catches NPC quest if NPC has a quest)
//if collided with an NPC...
if (!playerVsNPC.hit)
{
//checks if collided with Quest NPC
var i = 0;
var qFound = false;
while (i < questNPCArray.length && !qFound)
{
//compares index of collision object with index of quest sprite
if (playerVsNPC.index === questNPCArray[i].object.index)
{
tempItem = questNPCArray[i].interact();
qFound = true;
// Make sure the NPC has an active quest
if (questNPCArray[i].quest.getState() === QUEST_ACTIVE)
{
console.log("check for receive");
// Check that the player has the quest item in inventory
questNPCArray[i].receive();
}
setupDialogueScene(questNPCArray[i]);
dispDialogue();
}
i++;
}
//catches Quest NPC's quest and adds to quest array
if (tempItem != null)
{
questArray.push(tempItem);
console.log("quest added to array");
}
//checks if collided with Regular NPC
i = 0;
var rFound = false;
while (i < regNPCArray.length && !rFound)
{
//compares index of collision boject with index of regular sprite
if (playerVsNPC.index === regNPCArray[i].object.index)
{
console.log(regNPCArray[i].name);
regNPCArray[i].interact(); //interact with NPC
rFound = true;
setupDialogueScene(regNPCArray[i]);
dispDialogue();
}
i++;
}
}
tempItem = null;
}
// checks for collision with item on the map and calls pickUpItem if there is a collision
function checkForItem(player_character)
{
if (!playerVsItem.hit) {
console.log("found item");
//To prevent the player from moving, subtract its velocity from its position
player.x -= player.vx;
player.y -= player.vy;
player.vx = 0;
player.vy = 0;
pickUpItem();
}
//pickUpItem(item);
}
// is called by checkForItem
// checks to see which item is hit and adds it to the inventory if it is not there
function pickUpItem()
{
let current_item;
for (let i = 0; i < itemArray.length; i++)
{
if (itemArray[i].object != null && playerVsItem.index === itemArray[i].object.index)
{
current_item = itemArray[i];
}
}
if (inventory.includes(current_item))
{
console.log("already in list");
}
else
{
inventory.push(current_item);
g.remove(current_item.object);
}
}