-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.js
212 lines (194 loc) · 6.28 KB
/
objects.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
class Box {
constructor(x, y, c = '', a = 0, str=null, str_c=0) {
this.x = X_(x);
this.y = Y_(y);
this.c = color(c);
this.a = a;
this.str = str;
this.str_c = str_c;
}
setColor() {
this.c.setAlpha(this.a)
fill(this.c)
if (this.str === null){
noStroke()
}
else {
strokeWeight(this.str)
stroke(this.str_c)
}
}
}
class Rect extends Box {
constructor(x, y, width, height, c, a, str=null, str_c=0, round=null){
super(x, y, c, a, str, str_c)
this.width = X_(width, false);
this.height = Y_(height);
this.round = round
}
boundingBox(debug=false) {
if (debug==true) {
fill(color('red'))
rect(this.x, this.y, this.width, this.height)
}
return(Math.abs(this.x + this.width/2 - mouseX) <= this.width/2 && Math.abs(this.y + this.height/2 - mouseY) <= this.height/2)
}
display() {
this.setColor()
rect(this.x, this.y, this.width, this.height, this.round)
}
}
class Circle extends Box {
constructor(x, y, diameter, c, a, str=null, str_c=0){
super(x, y, c, a, str, str_c)
this.diameter = X_(diameter, false);
}
boundingBox(debug=false) {
if (debug==true) {
fill(color('red'))
rect(this.x, this.y, this.diameter)
}
return(Math.abs(mouseX - this.x) <= this.diameter/2 && Math.abs(mouseY - this.y) <= this.diameter/2)
}
display() {
this.setColor()
circle(this.x, this.y, this.diameter)
}
}
class Ellipse extends Box {
constructor(x, y, width, height, c, a, str=null, str_c=0){
super(x, y, c, a, str, str_c)
this.width = X_(width, false);
this.height = Y_(height);
}
boundingBox(debug=false){
if (debug==true) {
fill(color('red'))
rect(this.x, this.y, this.width, this.height)
}
return(Math.abs(this.x - mouseX) <= this.width/2 && Math.abs(this.y - mouseY) <= this.height/2)
}
display() {
this.setColor()
ellipse(this.x, this.y, this.width, this.height)
}
}
class Polygon extends Box {
constructor(points, c, a, str=null, str_c=0) {
super(0, 0, c, a, str, str_c)
this.points = points
}
display() {
this.setColor()
beginShape()
for (let i = 0; i < this.points.length; i++) {
vertex(X_(this.points[i][0]), Y_(this.points[i][1]))
}
endShape(CLOSE)
}
}
class Img extends Box {
constructor(x, y, width, height, image=''){
super(x, y)
this.width = X_(width, false);
this.height = Y_(height);
this.image = image;
}
display() {
image(this.image, this.x, this.y, this.width, this.height)
}
}
class TextBox extends Box {
constructor(x, y, c='', a=255, txt='', style=NORMAL, width=1000, height=20) {
super(x, y, c, a)
this.width = width
this.heigh = height
this.txt = txt
this.style = style
}
display() {
this.setColor()
textStyle(this.style)
text(this.txt, this.x, this.y, this.width, this. height)
}
}
/// DEFINES AN OBJECT MADE OF MULTIPLE BOXES ///
class CompoundObject {
constructor(object_list, bounder_ind=null) {
this.object_list = object_list
this.bounder_ind = bounder_ind
}
// commented the following lines out because this wasn't working
// boundingBox() {
// this.object_list[this.bounder_ind].boundingBox()
// }
display() {
for (let i = 0; i < this.object_list.length; i++) {
this.object_list[i].display()
}
}
}
// SPECIAL FUNCTION FOR THE CANDLE SMOKE //
function snuffedOut(){
if (gameState.frameSnuffed == false){
gameState.frameSnuffed = frameCount
}
if ((frameCount - gameState.frameSnuffed) % 10 == 0 || frameCount == gameState.frameSnuffed) {
pts = []
for (let i = 0; i < 4; i++){
pts.push(X_(random(-7,7), adjust=false))
}
}
c = color('white')
c.setAlpha(80 + (gameState.frameSnuffed - frameCount)/10)
fill(c)
beginShape()
vertex(X_(450), Y_(510))
bezierVertex(X_(440) + pts[1], Y_(480), X_(460) + pts[2], Y_(450), X_(450), Y_(413))
bezierVertex(X_(460) + pts[3], Y_(380), X_(440) + pts[4], Y_(340), X_(450), Y_(200))
endShape()
}
/// GAME STATE OBJECT THAT HOLDS ALL GAME STATE VARIABLES ///
class GameState {
constructor(pickUp, settingsOpen, soundOn, bright_mod, clicks, frameSnuffed, emailOpen, inboxOrDrafts, lastPutDown, picZoom, plantZoom, letterFound, vialFound, letterPickUp, questionMenu, yes, no) {
this.anyZoomWindow = false;
this.pickUp = pickUp || false
this.settingsOpen = settingsOpen || false
this.soundOn = soundOn|| false
this.bright_mod = bright_mod || 0
this.clicks = clicks || 0
this.frameSnuffed = frameSnuffed || false
this.emailOpen = emailOpen || 1
this.inboxOrDrafts = inboxOrDrafts || 0
this.lastPutDown = lastPutDown || 0
this.picZoom = picZoom || false
this.plantZoom = plantZoom || false
this.letterFound = letterFound || false
this.vialFound = vialFound || false;
this.letterPickUp = letterPickUp || false;
this.questionMenu = questionMenu || false;
this.yes = yes || false;
this.no = no || false;
this.gameOver = false;
this.gameOverTime = 1000000;
}
}
/// COORDINATE ADJUSTMENT FUNCTIONS ///
function X_(input, adjust=true, coordWidth=1200, imageWidth=windowWidth*0.8) {
// imageWidth is the actual width of the image in pixels
// and coordWidth is the number input by the user for the
// coordinate system
xAdjust = (windowWidth - imageWidth)/2; // adjustment to center image
if (adjust == true) {
return input/coordWidth * imageWidth + xAdjust
}
else {
return input/coordWidth * imageWidth
}
}
function Y_(input, coordHeight=900, imAspect = 900/1200, imageWidth=windowWidth*0.8, imageHeight=imAspect*imageWidth) {
// imageHeight is the actual height of the image in pixels
// and coordHeight is the number input by the user for the
// coordinate system
return input/coordHeight * imageHeight
}