File size: 4,989 Bytes
2a6d2b0
 
 
 
 
 
 
 
 
 
c8e039e
 
2a6d2b0
 
 
 
 
 
 
 
 
 
 
 
 
 
9fd3a67
0bb733c
9fd3a67
2a6d2b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9fd3a67
2a6d2b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
class Clown extends Character {
  constructor(gameState, clownImg) {
    super(gameState, clownImg);
    this.isChasing = false;
    this.targetGirlfriend = null;
    this.gameState.clown = this;
    this.startAutonomousBehavior();
    this.setCharacterPosition(this.gameState.map_data.clown_start_pos);

    // Add initial speed properties
    this.baseSpeed = 900; // Starting movement delay in milliseconds
    this.minSpeed = 300; // Fastest possible speed
    this.speedIncreaseInterval = 150000; // Speed increases every 30 seconds
    this.speedIncreaseAmount = 100; // How much to decrease delay each time

    // Start the speed increase timer
    this.startSpeedIncrease();
  }

  startAutonomousBehavior() {
    if (this.behaviorInterval) {
      clearInterval(this.behaviorInterval);
    }

    this.behaviorInterval = setInterval(() => {
      this.decideBehavior();
     playSound(Math.random() < 0.5 ? 'clownSound1' : 'clownSound2');

    }, 6000);
  }

  decideBehavior() {
    if (!this.isMoving) {
      const roomEntries = this.gameState.map_data.rooms;

      if (this.targetGirlfriend && !this.gameState.girlfriend.isHiding) {
        const girlfriendPos = this.targetGirlfriend.getCharacterPosition();
        if (girlfriendPos) {
          this.path = this.findPath(this.characterPos, girlfriendPos);
          if (this.path.length > 0) {
            this.isChasing = true;
            this.moveCharacterAlongPath();
            return;
          }
        }
      }

      this.isChasing = false;
      this.targetGirlfriend = null;

      const randomRoom =
        roomEntries[Math.floor(Math.random() * roomEntries.length)];
      if (randomRoom) {
        this.path = this.findPath(this.characterPos, randomRoom.label_position);
        if (this.path.length > 0) {
          this.moveCharacterAlongPath();
        }
      }
    }
  }

  checkForGirlfriend(girlfriend) {
    // First check if girlfriend exists and has a position
    if (
      !this.gameState.girlfriend ||
      !this.characterPos ||
      this.gameState.girlfriend.isHiding || // Check if girlfriend is hiding
      this.gameState.girlfriend.getIsHiding() // Also check using the getter method
    ) {
      this.targetGirlfriend = null;
      this.isChasing = false; // Stop chasing if was chasing before
      return;
    }

    const girlfriendPos = this.gameState.girlfriend.getCharacterPosition();
    if (!girlfriendPos) return;

    // First check if in same room
    const clownRoom = this.getCurrentRoom();
    const girlfriendRoom = this.gameState.girlfriend.getCurrentRoom();

    if (clownRoom && girlfriendRoom && clownRoom === girlfriendRoom) {
      // Check if within 3 cells in any direction
      const xDistance = Math.abs(this.characterPos.x - girlfriendPos.x);
      const yDistance = Math.abs(this.characterPos.y - girlfriendPos.y);

      if (xDistance <= 3 && yDistance <= 3) {
        this.targetGirlfriend = girlfriend;
        // Immediately update path to chase
        if (!this.isChasing) {
          this.path = this.findPath(this.characterPos, girlfriendPos);
          if (this.path.length > 0) {
            this.isChasing = true;
            playSound('clownSeesYou');
            this.moveCharacterAlongPath();
          }
        }
      }
    } else {
      // Not in same room, stop chasing
      this.isChasing = false;
      this.targetGirlfriend = null;
    }
  }

  draw(CELL_SIZE) {
    if (this.characterPos) {
      const newSize = CELL_SIZE * 3; // Increased from 2x to 3x for 50% bigger
      const offset = (newSize - CELL_SIZE) / 2;
      push();
      if (this.previousPos && this.characterPos.x > this.previousPos.x) {
        scale(-1, 1);
        image(
          this.img,
          -this.characterPos.x * CELL_SIZE - newSize + offset,
          this.characterPos.y * CELL_SIZE - offset,
          newSize,
          newSize
        );
      } else {
        image(
          this.img,
          this.characterPos.x * CELL_SIZE - offset,
          this.characterPos.y * CELL_SIZE - offset,
          newSize,
          newSize
        );
      }
      pop();
    }
  }

  moveCharacterAlongPath() {
    if (this.path && this.path.length > 0) {
      this.isMoving = true;
      const nextPos = this.path.shift();
      this.previousPos = { ...this.characterPos };
      this.characterPos = nextPos;

      // Use the current speed for movement delay
      setTimeout(() => {
        this.isMoving = false;
        if (this.path.length > 0) {
          this.moveCharacterAlongPath();
        }
      }, this.baseSpeed);
    }
  }

  startSpeedIncrease() {
    // Increase speed every 30 seconds
    setInterval(() => {
      if (this.baseSpeed > this.minSpeed) {
        this.baseSpeed = Math.max(
          this.baseSpeed - this.speedIncreaseAmount,
          this.minSpeed
        );
        console.log(
          `Clown speed increased! Current delay: ${this.baseSpeed}ms`
        );
      }
    }, this.speedIncreaseInterval);
  }
}