-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcrewStatus.py
342 lines (236 loc) · 14.1 KB
/
crewStatus.py
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 22 13:02:17 2020
The Crew Status viewer for Ironseed.
Here you can see XP, crew bio readouts, their profile etc.
@author: Nuke Bloodaxe
"""
import buttons, pygame, os
import global_constants as g
import helper_functions as h
# Main class for the Crew Status screen, which is yet another minigame.
class CrewStatus(object):
def __init__(self, theCrew):
self.crew = theCrew
self.systemState = 13
self.musicState = False
self.crewStatusStage = 0 # Setup/interaction stage.
self.pulseColourCycle = 255 # for Ego Bio Status line. Red Pulse.
self.currentCrewMember = 0
self.crewPointer = "placeholder" # For Sanity.
self.crewPositions = ["", "PSYCHOMETRY", "ENGINEERING", "SCIENCE", "SECURITY", "ASTROGATION", "MEDICAL"]
# Graphics related
self.crewInterface = pygame.image.load(os.path.join('Graphics_Assets', 'char2.png'))
self.crewInterfaceScaled = pygame.transform.scale(self.crewInterface, (g.width, g.height))
self.crewInterfaceScaled.set_colorkey(g.BLACK)
self.frameCount = 0 # For keeping track of animation frames.
self.titleFrameCount = 0 # For keeping track of title frames.
self.pseudoTextCount1 = 0 # For keeping track of pseudo text frames.
self.pseudoTextCount2 = 1 # For keeping track of pseudo text frames.
# Create individual graphical elements.
# left, top, width, height
# Handle display area of the crew heartbeat line.
self.pulseDisplayArea = pygame.Rect((int((g.width/320)*16),
int((g.height/200)*14)),
(int((g.width/320)*180),
int((g.height/200)*76)))
# Handle display area of horizontal pulse line.
self.pulseLineArea = pygame.Rect((int((g.width/320)*42),
int((g.height/200)*122)),
(int((g.width/320)*38),
int((g.height/200)*2)))
# Handle display area of the sanity bar; red.
self.sanityBarArea = pygame.Rect((int((g.width/320)*309),
int((g.height/200)*26)),
(int((g.width/320)*2),
int((g.height/200)*68)))
# Handle the blanking area to clear texture elements.
self.blankDisplayArea = pygame.Rect((int((g.width/320)*5),
int((g.height/200)*130)),
(int((g.width/320)*259),
int((g.height/200)*67)))
# Location of green crew pips when crewmember selected.
self.greenCrewLEDLocation = [(303, 142),(303, 145),(303, 148),
(310, 142),(310, 145),(310, 148)]
self.currentGreenLED = pygame.Rect((int((g.width/320)*303),
int((g.height/200)*142)),
(int((g.width/320)*2),
int((g.height/200)*2)))
# Tuple list for the Sanity bar.
self.sanityBar = h.colourGradient(self.sanityBarArea.height, g.RED)
# Tuple list for micro pulse line.
self.pulseLine = h.colourGradient(self.pulseLineArea.width, g.RED)
# Animation array for text displayed in window above buttons.
self.titleText = []
self.pseudoText = []
self.titleTextDraw = pygame.Rect((int((g.width/320)*273),
int((g.height/200)*121)),
(int((g.width/320)*38),
int((g.height/200)*9)))
self.pseudoTextDraw1 = pygame.Rect((int((g.width/320)*273),
int((g.height/200)*132)),
(int((g.width/320)*18),
int((g.height/200)*9)))
self.pseudoTextDraw2 = pygame.Rect((int((g.width/320)*292),
int((g.height/200)*132)),
(int((g.width/320)*18),
int((g.height/200)*9)))
# formatted (x,y)(width,height)(columns,rows)
self.textTitleLocations = ((9, 144), (39, 10), (3, 2))
self.pseudoTextLocations = ((129, 145), (20, 8), (2, 4))
# Scaled animation arrays for screen text.
self.scaledTitleText = []
self.scaledPseudoText = []
# Load in above textures.
self.prepareAnimationFrames()
# Scale above textures
self.scaleAnimationFrames()
# Define button positions scaled from a 320x200 screen.
# Note: expect this to be very buggy! Placeholder class in effect.
# Button positions and handler objects.
# Positional buttons for the screen options.
self.exit = buttons.Button(int((g.height/200)*14),
int((g.width/320)*9),
(int((g.width/320)*302),
int((g.height/200)*155)))
self.up = buttons.Button(int((g.height/200)*14),
int((g.width/320)*17),
(int((g.width/320)*280),
int((g.height/200)*146)))
self.down = buttons.Button(int((g.height/200)*14),
int((g.width/320)*17),
(int((g.width/320)*280),
int((g.height/200)*162)))
# Prepare all animation frames from the screen graphic.
def prepareAnimationFrames(self):
self.titleText = h.prepareAnimationArray(self.crewInterface,
self.textTitleLocations,
False)
self.pseudoText = h.prepareAnimationArray(self.crewInterface,
self.pseudoTextLocations,
False)
# Scale animation frames to current resolution.
def scaleAnimationFrames(self):
self.scaledTitleText = h.resizeGraphicArray(self.titleText)
self.scaledPseudoText = h.resizeGraphicArray(self.pseudoText)
# Reset the Crew Status system back to default starting values.
def resetCrewStatus(self):
self.crewStatusStage = -1 # Forces reset when we return.
self.pulseColourCycle = 255
self.musicState = False
# Update loop.
# Note: This is one of the basics of polymorphism, where functions
# have common names across diffrent classes. The idea being to simplify
# overall coding.
def update(self, displaySurface):
return self.crewInterfaceLoop(displaySurface)
# Mouse handling routines, handles all button press logic.
def interact(self, mouseButton):
currentPosition = pygame.mouse.get_pos()
if self.up.within(currentPosition):
self.currentCrewMember += 1
if self.currentCrewMember > 5:
self.currentCrewMember = 0
self.crewPointer = self.crew.crew[self.currentCrewMember] # For Sanity.
self.currentGreenLED = pygame.Rect((int((g.width/320)*self.greenCrewLEDLocation[self.currentCrewMember][0]),
int((g.height/200)*self.greenCrewLEDLocation[self.currentCrewMember][1])),
(int((g.width/320)*2),
int((g.height/200)*2)))
elif self.down.within(currentPosition):
self.currentCrewMember -= 1
if self.currentCrewMember < 0:
self.currentCrewMember = 5
self.crewPointer = self.crew.crew[self.currentCrewMember] # For Sanity.
self.currentGreenLED = pygame.Rect((int((g.width/320)*self.greenCrewLEDLocation[self.currentCrewMember][0]),
int((g.height/200)*self.greenCrewLEDLocation[self.currentCrewMember][1])),
(int((g.width/320)*2),
int((g.height/200)*2)))
elif self.exit.within(currentPosition):
self.resetCrewStatus()
self.systemState = 10
# Reset crew status stage and enter command deck state.
return self.systemState
# Interface drawing routine.
def drawInterface(self, displaySurface):
displaySurface.fill(g.BLACK)
displaySurface.blit(self.crewInterfaceScaled, (0, 0))
# Render heartbeat pulse line in red.
self.crewPointer.drawStatusLine(displaySurface, self.pulseDisplayArea, 0)
# Render small pulse line in red.
pulse = h.createBar(self.pulseLine, len(self.pulseLine), self.pulseLineArea.height)
displaySurface.blit(pulse, self.pulseLineArea)
# Make pulse rotate right after each frame.
self.pulseLine = h.shiftArrayRight(self.pulseLine)
# Render crewmember image.
displaySurface.blit(self.crewPointer.resizedImage,
((g.width/320)*220, (g.height/200)*16))
# Render green LED for selected crew member.
displaySurface.fill(g.GREEN, self.currentGreenLED)
# Calculate sanity bar length
sanityBarLength = int((self.sanityBarArea.height/100)*self.crewPointer.sanity)
# Create sanity bar tuple list.
sanityBar = h.colourGradient(sanityBarLength, g.RED)
# Render sanity bar for selected crew member.
adjustedSanityBar = h.createBar(sanityBar,
sanityBarLength,
self.sanityBarArea.height)
rotatedSanityBar = pygame.transform.rotate(adjustedSanityBar, -90)
scaledSanityBar = pygame.transform.scale(rotatedSanityBar,
(self.sanityBarArea.width,
sanityBarLength))
displaySurface.blit(scaledSanityBar, self.sanityBarArea)
# Render pretty graphics in mini-monitor for ambiance.
displaySurface.blit(self.scaledTitleText[self.titleFrameCount],
self.titleTextDraw)
displaySurface.blit(self.scaledPseudoText[self.pseudoTextCount1],
self.pseudoTextDraw1)
displaySurface.blit(self.scaledPseudoText[self.pseudoTextCount2],
self.pseudoTextDraw2)
# Adjust frame counters and timers.
if self.frameCount >= 20:
self.titleFrameCount += 1
if self.titleFrameCount >= len(self.scaledTitleText):
self.titleFrameCount = 0
self.frameCount = 0
elif self.frameCount in [0, 5, 10, 15, 20]:
self.pseudoTextCount1 += 1
self.pseudoTextCount2 += 1
if self.pseudoTextCount1 >= len(self.scaledPseudoText):
self.pseudoTextCount1 = 0
if self.pseudoTextCount2 >= len(self.scaledPseudoText):
self.pseudoTextCount2 = 0
self.frameCount += 1
# Clear text area.
displaySurface.fill(g.BLACK, self.blankDisplayArea)
# Render Bio column of text.
h.renderText(self.crewPointer.bio, g.font, displaySurface, g.WHITE, 15, (g.width/320)*6, (g.height/200)*131)
# Render Character Level text.
h.renderText([str(self.crewPointer.level)], g.font, displaySurface, g.WHITE, 15, (g.width/320)*154, (g.height/200)*120)
# Render Character Experience points.
h.renderText([str(self.crewPointer.experience)], g.font, displaySurface, g.WHITE, 15, (g.width/320)*190, (g.height/200)*120)
# Render Character Name. Note, using 180 for x as is centre of text field.
h.renderText([str(self.crewPointer.name)], g.font, displaySurface, g.WHITE, 15, (g.width/320)*180, (g.height/200)*103, True)
# Our main interface loop, here we run all setup and stage checks.
def crewInterfaceLoop(self, displaySurface):
# Preparation routine
if self.crewStatusStage == 0:
# We need to ensure our system state is set.
self.systemState = 13
self.crewPointer = self.crew.crew[self.currentCrewMember] # For Sanity.
# Start main intro music
if self.musicState == False:
pygame.mixer.music.load(os.path.join('sound', 'CREWCOMM.OGG'))
pygame.mixer.music.play()
self.musicState = True
self.crewStatusStage += 1
elif self.crewStatusStage == 1:
# rewind and start music playing again if track end reached.
if not pygame.mixer.music.get_busy():
pygame.mixer.music.play()
self.drawInterface(displaySurface)
# Run slow!
pygame.time.wait(50)
if self.systemState != 13:
self.crewStatusStage = 0
self.musicState = False
return self.systemState