File size: 4,011 Bytes
e13ec6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
class Girlfriend extends Character {
  constructor(gameState, girlfriendImg) {
    super(gameState, girlfriendImg);
    this.gameState = gameState;
    this.gameState.girlfriend = this;
    this.img = girlfriendImg;
    this.setCharacterPosition(this.gameState.map_data.girlfriend_start_pos);
    this.currentHidingSpot = null;
    this.stressLevel = 30;
    this.inventory = [];
  }

  draw(CELL_SIZE) {
    if (this.characterPos) {
      push();
      if (this.previousPos && this.characterPos.x > this.previousPos.x) {
        scale(-1, 1);
        image(
          this.img,
          -this.characterPos.x * CELL_SIZE - CELL_SIZE * 2,
          this.characterPos.y * CELL_SIZE,
          CELL_SIZE * 2,
          CELL_SIZE * 2
        );
      } else {
        if (this.getIsHiding()) {
          tint(255, 153);
          image(
            this.img,
            this.characterPos.x * CELL_SIZE,
            this.characterPos.y * CELL_SIZE,
            CELL_SIZE * 2,
            CELL_SIZE * 2
          );
        } else {
          image(
            this.img,
            this.characterPos.x * CELL_SIZE,
            this.characterPos.y * CELL_SIZE,
            CELL_SIZE * 2,
            CELL_SIZE * 2
          );
        }
      }
      pop();
    }
  }

  updateStressLevel(stressChange) {
    // Add or subtract the stress change while keeping within 0-100 range
    this.stressLevel = Math.max(
      0,
      Math.min(100, this.stressLevel + stressChange)
    );
  }

  handleAction(response) {
    switch (response.action) {
      case "go":
        this.moveToRoom(response.target);
        break;
      case "hide":
        this.hide(response.target);
        break;  
      case "exit":
        this.exit();
        break;
    }
  }

  getAvailableHidingSpots() {
    // Find the current room in map data
    const currentRoom = this.gameState.map_data.rooms.find(
      (room) => room.name === this.getCurrentRoom()
    );
    // Return hiding places for current room if found, otherwise empty array
    return currentRoom ? currentRoom.hiding_places : [];
  }

  getAvailableFurniture() {
    // Get current room
    const currentRoom = this.getCurrentRoom();
    if (!currentRoom) return [];

    // Filter furniture list to only include items in current room that are in use
    return this.gameState.map_data.furniture.filter(
      furniture => furniture.room === currentRoom && furniture.in_use === true
    );
  }

  getIsHiding() {
    const hidingSpots = this.getAvailableHidingSpots();
    if (!this.characterPos || hidingSpots.length === 0) return false;

    return hidingSpots.some(
      (spot) =>
        spot.position.x === this.characterPos.x &&
        spot.position.y === this.characterPos.y
    );
  }

  hide(hidingSpotName) {
    const currentRoom = this.getCurrentRoom();
    if (!currentRoom) return;

    // Find the room data from map_data
    const roomData = this.gameState.map_data.rooms.find(
      (room) => room.name === currentRoom
    );
    if (!roomData) return;

    // Find the specific hiding spot in the room by checking if names contain each other
    const hidingSpot = roomData.hiding_places.find(
      (spot) =>
        spot.name
          .toLowerCase()
          .trim()
          .includes(hidingSpotName.toLowerCase().trim()) ||
        hidingSpotName
          .toLowerCase()
          .trim()
          .includes(spot.name.toLowerCase().trim())
    );

    if (!hidingSpot) return;

    // Move to the hiding spot position
    this.moveToPosition(hidingSpot.position, () => {
      this.currentHidingSpot = hidingSpotName;
    });
  }

  exit() {
    let the_exit = this.gameState.getTheExit();
    let x = the_exit.pos.x;
    let y = the_exit.pos.y-1;
    let pos = {"x": x, "y": y};
    this.moveToPosition(pos, () => {
      if (!this.inventory || !this.inventory.includes("Key")) {
        addProgramaticMessage(the_exit.locked_message);
      } else  {
        addProgramaticMessage(the_exit.unlocked_message);
      }
      });
  }
}