-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_function.py
More file actions
1468 lines (1143 loc) · 38.2 KB
/
game_function.py
File metadata and controls
1468 lines (1143 loc) · 38.2 KB
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import pygame
import sys, os
from math import pi
from time import sleep
import requests
from multiprocessing import Process, Queue
from random import randint
from passlib.apps import custom_app_context as con_text
from analyze import Analyzer
from entity.explosion import Explosion
from entity.powerup import Powerup
from entity.bullets import Bullet
from entity.alien import Alien
from entity.tweeter import Tweeter
""" Username is a global var. Once we get the password we immediately auth w/ server """
# Data Relays to Thread_requests()
_relay_power = {'lazerup' : 0, 'bulletup' : 0, 'bombup' : 0, 'speedup' : 0}
_relay_score = {"points" : 0, "high_score" : 0, "multipliers" : 0}
_relay_other = {"dollars" : 0, "booster" : 0}
# unused currently
_offline = False
# This is the number of twits just blitted to the screen
total_twits = 0
# If acquired
get_lazer = False
get_bomb = False
# Timing constraints
laz_lok = 255
bom_lok = 255
bul_lok = 255
# List of literal indices i.e. [1,3] means we destroyed 0 and 2 ...
twits_list = []
# List of full tweets
all_tweets = []
# initial screen state
cur_scrn = 0
# logged in
flagged = 0
# No names
names = ''
# DEBUG
test = 0
# unique
twit_id = 0
# Always weapon states
powers = {'gun' : 0 , 'lazerup' : 0, 'bulletup' : 0, 'bombup' : 0, 'scoreup' : 0}
difficulty = 0
def stat_keeper(_relay_power, _relay_score, _relay_other):
""" Returns all data-trackers in a big ol' dict """
pass
def check_events(g_settings, screen, ship, aliens, stats, \
scores, projectiles):
global get_lazer
global laz_lok
""" Tracks player events while game_active == True """
# Used to ... ?
mousex, mousey = pygame.mouse.get_pos()
events = pygame.event.get()
""" Plugging in the Clock-Pipe here ? """
# Events : This wont run at the same time -event in events- occurs in textbox.update() via get_infoz
for event in events:
if event.type == pygame.QUIT:
print("Bye!")
return 'CE_QUIT'
if event.type == pygame.KEYDOWN:
keydown_event(event, g_settings, screen, ship, \
stats, scores, projectiles)
if event.key == pygame.K_SPACE:
g_settings.firing = True
# Handles bullets and bombs
fire_weapon(g_settings, screen, ship, projectiles[1], projectiles[0])
# if event.type == pygame.KEYUP:
# keyup_event(event, g_settings, stats)
elif event.type == pygame.KEYUP:
keyup_event(event, g_settings, stats)
# Fire lazer is separate because it does not use keyboard event
elif laz_lok >= 254 and event.type == pygame.MOUSEBUTTONDOWN:
if get_lazer:
# Acquire "the lazer"
lazers = projectiles[2]
# Get level of "the lazer"
laz_up = int(g_settings.lazer)
# Fire "the lazer"
fire_lazer(screen, g_settings, ship, lazers, laz_up)
# Get_lazer will become redundant for precision
return 0
return 0
# UNUSED
def menu_keys(event):
""" Only from main menu """
# jic
if not stats.game_active:
#
if event.key == pygame.K_b:
# Offline play
stats._current_screen = 3
# scores.start_game(mode=0)
##########
# ADD ALT+Z TO TURN OFF UI
##########
def keyup_event(event, g_settings, stats):
""" Keyups """
# More events
if stats.game_active:
if event.key == pygame.K_d:
g_settings.move_right = False
elif event.key == pygame.K_a:
g_settings.move_left = False
elif event.key == pygame.K_s:
g_settings.move_down = False
elif event.key == pygame.K_w:
g_settings.move_up = False
elif event.key == pygame.K_SPACE:
g_settings.firing = False
elif event.key == pygame.K_q:
g_settings.strafe_L = False
elif event.key == pygame.K_e:
g_settings.strafe_R = False
elif event.key == pygame.K_SPACE:
g_settings.firing = False
return False
def keydown_event(event, g_settings, screen, ship, stats,
scores, projectiles, is_lazer=False):
""" Keydowns """
if stats.game_active:
# Extra Boolean Falsey values will ease the transaction of multi keystrokeage
if event.key == pygame.K_d:
g_settings.move_left = False
g_settings.move_right = True
elif event.key == pygame.K_a:
g_settings.move_right = False
g_settings.move_left = True
elif event.key == pygame.K_s:
g_settings.move_up = False
g_settings.move_down = True
elif event.key == pygame.K_w:
g_settings.move_down = False
g_settings.move_up = True
return 0
def fire_weapon(g_settings, screen, ship, bullets, bombs):
# Tracks weapon levels
global powers
# Global restraints
global bom_lok
global get_bomb
# Update from dynamic settings
k_boom = powers['bombup'] = g_settings.bomb
k_bull = powers['bulletup'] = g_settings.bullets
# Fire upgraded bullets
if powers['bulletup']:
# Shuts off the starting gun
g_settings.default_gun = 0
powers['gun'] = 0
if len(bullets.sprites()) <= 15:
fire_bullets(screen, g_settings, ship, bullets, k_bull, v='bulletup')
# Fire bombs (also k_SPACE)
if powers['bombup'] and bom_lok >= 250:
# If not bomblock
if (len(bombs.sprites()) < 3 and k_boom == 1) or \
(len(bombs.sprites()) < 3 and k_boom == 2) or \
(len(bombs.sprites()) < 3 and k_boom == 3):
fire_bomb(screen, g_settings, ship, bombs, k_boom, v='bombup')
# Fire default gun
elif g_settings.default_gun:
# We have the gun until we touch any bulletup
powers['gun'] = 1
# Shoot if there are <= 16 bullets drawn to screen
if len(bullets.sprites()) <= 16:
new_bullet = Bullet(g_settings, screen, ship, power='gun', level=1)
bullets.add(new_bullet)
return 0
def fire_lazer(screen, g_settings, ship, lazers, lazer_up):
global laz_lok
if laz_lok >= 243:
new_lazer = Bullet(g_settings, screen, ship, power='lazerup', level=lazer_up)
lazers.add(new_lazer)
g_settings.lazer, g_settings.lazer_ammo = \
downgrade(g_settings.lazer, g_settings.lazer_ammo, mag=7, weap="laze")
laz_lok = 0
else:
return 0
def fire_bullets(screen, g_settings, ship, bullets, k, v=''):
global bul_lok
for num in range(0, (k*2)):
# k == 'bulletup' // v == v
new_bullet = Bullet(g_settings, screen, ship, power=str(v), \
level=int(k), \
b_offset=num)
bullets.add(new_bullet)
# Spend ammo & check if weapon downgrades
if k > 1:
g_settings.bullets, g_settings.bullets_ammo, = \
downgrade(g_settings.bullets, g_settings.bullets_ammo, mag=75, weap="bull")
if g_settings.bullets == 1:
num += 1
# or we get 3 bullets at lvl 1 instead of 2 ... design choice
if g_settings.bullets_ammo == 0:
g_settings.bullets_ammo == 75
return True
def fire_bomb(screen, g_settings, ship, bomb, k, v=''):
global bom_lok
if bom_lok >= 243:
for num in range(2):
new_bomb = Bullet(g_settings, screen, ship, power=str(v), \
level=int(k), \
b_offset=num)
bomb.add(new_bomb)
bom_lok = 0
if k > 1:
g_settings.bomb, g_settings.bomb_ammo, = \
downgrade(g_settings.bomb, g_settings.bomb_ammo, mag=10, weap='bomb')
if g_settings.bomb_ammo == 0:
g_settings.bomb_ammo == 10
def downgrade(weapon, ammo, mag=0, weap=''):
""" Discards spent ammo. weap is only for debugging """
if weapon > 1:
if ammo <= 0:
weapon -= 1
ammo = int(mag * weapon)
return (int(weapon), int(ammo))
else:
ammo -= 1
return (int(weapon), int(ammo))
else:
# Required
return 1, 0
def check_play_buttons(stats, textbox, buttons, cur_scrn=0, \
mousex=0, mousey=0):
"""
Enables user-click responses in any menu
Any True returned from here is to trigger textbox.update()
"""
global flagged
# Check which game button was clicked. Defaults to False
login_clicked = buttons[0].rect.collidepoint(mousex, mousey)
about_clicked = buttons[1].rect.collidepoint(mousex, mousey)
attack_clicked = buttons[2].rect.collidepoint(mousex, mousey)
to_pass_clicked = buttons[3].rect.collidepoint(mousex, mousey)
passed_clicked = buttons[4].rect.collidepoint(mousex, mousey)
"""
cur_scrn = stats._current_screen
0 : menu_mode
1 : login_mode
2 : pass_mode
3 : In-Game
4 : Logged in menu_mode
"""
if (login_clicked or attack_clicked \
or about_clicked or to_pass_clicked \
or passed_clicked) and not stats.game_active:
# Reset game stats
# stats.reset_all() ...It's in start_game
if login_clicked and cur_scrn == 0:
textbox.reset()
# Change
stats.login_mode()
# reset state
login_clicked = False
return True
if to_pass_clicked and cur_scrn == 1:
# Change
if not textbox.get_text():
return False
stats.pass_mode()
# Reset state
to_pass_clicked = False
return True
if passed_clicked and cur_scrn == 2:
# Need to auth before flagged = 1
if not len(textbox.get_text()):
# Dont peek at the pw
return False
# Reset state
passed_clicked = False
return True
elif (attack_clicked and textbox.get_text()) \
and not stats.game_active and (cur_scrn == 0 or cur_scrn == 4):
""" Fires when user clicks Attack w/ text entered """
print("Starting")
return True
elif about_clicked:
print("Try clicking harder")
return False
def end_game(g_settings, screen, stats, ship, powerups, projectiles, \
twits, scores, game_won=False, flagged=0):
global total_twits
global twits_list
global all_tweets
global twit_id
global powers
global get_lazer
global get_bomb
# Maybe I could reset globals at game start they could be used for score tracking
total_twits = 0
twits_list = []
all_tweets = []
twit_id = 0
default_gun = 1
get_lazer = False
get_bomb = False
# SHould reset at the beginning, not the end
powers = {'gun' : 0, 'lazerup' : 0, 'bulletup' : 0, 'bombup' : 0}
# Fuzz data from g_settings to Thread_requests()
# Only 1 pipe-stream should be sent from here to Thread_rqsts
for item in projectiles:
item.empty()
g_settings.set_special()
twits.empty()
powerups.empty()
get_high_score(stats, scores)
stats.reset_all()
scores.prep_score()
del(ship)
stats.game_active = False
# Flagged == User is logged in
stats.menu_mode(flagged=flagged)
def reset_army(screen, twits):
""" Place twits at the top of the screen """
screen_rect = screen.get_rect()
y = 1
for n, twit in enumerate(twits):
# print("n {}".format(n) )
if not n % 10:
y += 1
twit.rect.x = screen_rect.left + twit.rect.width * n
twit.rect.y = screen_rect.top + (twit.rect.height * y) + 20
def create_army(g_settings, screen, twits, all_tweets, \
start=0, act=2):
""" Blit 2 entire tweets to the screen """
from re import findall
global twit_list
global total_twits
global twit_id
# print(all_tweets)
re_palphaNum = r"^[a-zA-Z0-9'\"]+$"
total_twits = 0
dots = 0
end_char = 0
power = 0
available_x = int(get_cols(g_settings))
available_y = int(get_rows(g_settings))
generate_x = make_space(available_x)
generate_y = make_space(available_y)
row = next(generate_y)
# OPT does make sense to include in re_palphaNum then remove it by comparison?
punct = [",","\'","\"",".",":", ";", "?", "!"]
# Unused. Will need!
re_unicode = r"[^\u0000-\u007F]"
"""
Note : Row and column's incremental logic is 100% dissimilar
this supports dynamic twit allocation
"""
# OPT a better parsing method : for x in [i for i in tweet if i != re_palphaNum]
# ROW is now 0
for tweet in all_tweets[start:act]:
# RT's are usually empty
if "RT" in tweet or "rt" in tweet:
continue
# Assigns an ID unique to the whole tweet
twit_id = twit_id + 1
# That strange edgecase
if "..." in tweet:
tweet.remove("...")
# Almost bubble sort
tweet.append("...")
# Separate words
for word in tweet:
word = word.lower()
# Handles malformation
if word == "...":
word = "."
dots = 1
else:
dots = 0
# A (much too) thorough check
if (findall(re_palphaNum, word)) \
or dots:
# Determine sentiment
if word in Analyzer._neg_words:
sentiment = 0
else:
sentiment = 1
for n, letter in enumerate(word):
# Skip punct
if letter in punct:
continue
# Find if last letter
if n == len(word) - 1 or dots:
end_char = 1
else:
end_char = 0
# Determines if carrying powerup
try:
# Returns True if we just made the last char
make = assign_twit(g_settings, screen, twits, letter, sentiment, \
end_char, generate_x, row, twit_id)
if make or dots: # (Is the last char and >= position 40)
# Carriage return + newline
generate_x = make_space(available_x)
row = next(generate_y)
dots = 0
except StopIteration:
""" This more than likely wont incur from the above algo"""
row = next(generate_y)
position_x = make_space(available_x)
else:
continue
# Logical Grouping of all twits in a tweet
row = next(generate_y)
if len(all_tweets) >= 2:
# print("CASE 1")
# Destroy the first 2 tweets
x = all_tweets.pop(0)
x = all_tweets.pop(0)
x = ""
# Pop the last tweet if uneven total tweets were acquired
elif len(all_tweets):
x = all_tweets.pop(0)
x='done!'
return True
def assign_twit(g_settings, screen, twits, letter, sentiment, \
end_char, generate_x, row, twit_id, \
dots=0):
"""
- Construct an individual character and its properties to be blasted.
- 'dots' is a result of the Twitter API being handled by nltk tokenizer
- Returns True if we should start a newline.
- At the present, end_chars never contain power ups
"""
# Defaults
global total_twits
global twits_list
x_pos = next(generate_x)
# Is holding power up?
powers = {
'1' : 'bulletup', '2' : 'bombup', \
'3' : 'lazerup', '4' : 'speedup', \
'5' : 'scoreup', '6' : 'scoreup'
}
text_data = {}
# If last char of a word
text_data['end_char'] = int(end_char)\
# Literal alphabetic char
text_data['letter'] = str(letter.lower())
# Pos or Neg
text_data['sentiment'] = sentiment
# Twit sequence num
text_data['index'] = total_twits
# Each twit belongs to a group (id); that being its tweet
text_data['twit_id'] = int(twit_id)
if not dots:
character = Tweeter(g_settings, screen, \
text_data=text_data)
# Determine if carrying powerup
x = randint(1,6)
y = randint(1,12)
if y == 3:
character.power = powers[str(x)]
else:
# twit does not have a power
character.power = 0
# Acquire placement
give_twit_dimension(character, x_pos, row)
twits.add(character)
# Update globals
twits_list.append(total_twits)
total_twits += 1
# Only text-wrap after we've printed a whole word
if x_pos + 1 >= 40 and text_data["end_char"] == 1:
del(text_data)
return True
elif text_data["end_char"] == 1:
# Acquire the next location
x_pos = next(generate_x)
if letter == ".":
# Add "..." character when necessary
text_data["letter"] = "dots"
text_data["index"] = total_twits
# Create Twit
character = Tweeter(g_settings, screen, \
text_data=text_data)
give_twit_dimension(character, x_pos, row)
# Update globals
twits.add(character)
total_twits += 1
twits_list.append(total_twits)
del(text_data)
return False
else:
del(text_data)
return False
### ### ### ### ### ### ### ### Twit Placement ### ### ### ### ### ### ### ###
def give_twit_dimension(character, x_pos, row):
""" Positional awareness for each letter """
width = character.rect.width
character.x = width * x_pos
character.rect.x = character.x
character.rect.y = character.rect.height + (2 * (character.rect.height * row))
def make_space(columns):
""" Generator from 0 to total COLS """
for space in range(columns):
yield space
def get_cols(g_settings):
cols = int(g_settings.screen_width // int(g_settings.char_width))
avail_space = int(cols * g_settings.char_width - (2 * int(g_settings.char_width)))
return int(avail_space)
def get_rows(g_settings):
avail_space = float(g_settings.screen_height - (2 * int(g_settings.char_height)))
return avail_space
### ### ### ### ### ### ### ### ### Twitter mode Functions ### ### ### ### ###
def get_high_score(stats, scores):
""" Saves the high score """
if stats.score > stats.high_score:
stats.high_score = stats.score
scores.prep_high_score()
return 0
### ### ### ### ### ### ### ### ### I AM A CLASS ### ### ### ### ### ### ###
def send_data_TEST(name, q, url=0, hash='', u_name='', flag=0):
"""
flag = 0 = Access the Twitter API
flag = 1 = Authenticate user from client login (DISABLED)
"""
if not flag: # We are getting tweets
resp = []
url = "https://alyrist.herokuapp.com/twit?h=" + name
resp = requests.get(url)
return q.put(resp.json())
######## LOGIN #########
# elif flag: # We are logging the user in from menu
# ok = requests.post("https://alyrist.herokuapp.com/servauth", \
# data={'hash':hash, 'u_name': u_name})
# if ok:
# return 1
# else:
# print("BADNESS == {} - {}".\
# format(ok.status_code, ok.reason))
# return 12
def get_infoz(g_settings, screen, twits, stats, scores, reticle, \
textbox, buttons, cur_scrn=0, hide=0):
"""
Get user input // Call to Twitter // Conduct Sent. Analysis // Start Game
textbox.update() returns True if user presses Enter
"""
mousex, mousey = pygame.mouse.get_pos()
pygame.mouse.set_visible(False)
g_settings.set_special()
reticle.blitme(mousex, mousey)
events = pygame.event.get()
if not cur_scrn or cur_scrn == 4:
if mousex > 135 and mousey > 258 \
and mousex < 351 and mousey < 312:
# Login
buttons[0].create_button()
elif mousex > 827 and mousey > 258 \
and mousex < 1068 and mousey < 320:
# About
buttons[1].create_button()
elif mousex > 530 and mousey > 394 \
and mousex < 690 and mousey < 452:
# Attack
buttons[2].create_button()
""" In Main Menu """
x1 = textbox.update(events, stats, textbox, buttons, mousex, mousey, cur_scrn=cur_scrn, hide=0)
if x1 == 'TX_SEARCH':
# handle is the user's input
handle = textbox.get_text()
if handle.lower() == "realdonaldtrump" or handle.lower() == "@realdonaldtrump":
# Acquire Trump
g_settings.is_Trump = True
if handle.lower() == "yoshiyoshums" or handle.lower() == "@yoshiyoshums":
# Acquire the Poobah
g_settings.is_Yoshi = True
if not handle or handle == "":
return False
print("Getting tweets from @{}".format(handle))
try:
# Get Tweets from Twitter
q = Queue()
tweet_bot = Process(target=send_data_TEST, args=(handle, q), name="serv1", \
kwargs={'flag':0, 'url':0, 'hash':'', 'u_name':''}, \
daemon=None)
tweet_bot.start()
i = 0
# Loading Animation...
while tweet_bot.is_alive():
# OPT
i += 1
colors = [((0), (255 - (i % 200)), (255 - (i % 200))), \
((255 - (i % 200)), (0), (255 - (i % 200)))]
loading_wheel(screen, i, reticle, colors)
if i == 400:
i = 0
# Proc return
tweet_bot.join()
# The meat n' potatoes
user_tweets = q.get()
except: # Requests.exceptions or TimeoutError
# Trace server-side exception to stderr
print("Something went wrong - " \
"{}".format(sys.exc_info()[:-1]))
return 11
### ### ### ### ### ### ### ### Tweet Tweet ### ### ### ### ### ### ### ### ###
if user_tweets:
# nothing is sacred ...
global all_tweets
# If Twitter API respond, load sentiment files
positive = os.path.join(sys.path[0], \
"sentiments/positive-words.txt")
negative = os.path.join(sys.path[0], \
"sentiments/negative-words.txt")
# Sentiment Analyzer class
analyzer = Analyzer(positive, negative, stats)
# Create a list of analyzed tweets. Arbitrarily enumerated.
for i, tweet in enumerate(user_tweets):
"""
all_tweets looks like:
[["This", "is", "tweet", "one", "!"],["and", "two"]...etc]
"""
all_tweets.append(analyzer.analyze(tweet))
# Setup game scenario
global difficulty
difficulty = int(analyzer.get_difficulty())
create_army(g_settings, screen, twits, all_tweets)
# Clean up our textbox
textbox.reset()
# Go
scores.start_game(mode=1, handle=handle)
return True
# Or dont
else:
# Otherwise catch bad input
print("Unable to retrieve from server - " \
"{}".format(sys.exc_info()[:-1]))
textbox.reset()
""" INSERT OFFLINE GAME INSTEAD """
return 13
# Return signal to quit main program
elif x1 == 'TX_QUIT':
return 'TX_QUIT'
else:
# Display our text input field based on cur_scrn
screen.blit(textbox.get_surface(), \
((g_settings.screen_width//2) - 100, \
(g_settings.screen_height//2) + 80))
return False
### MENU BEHAVIORS ###
if cur_scrn == 1:
global names
""" In Username Menu """
# OPT for readability a function could position our elements per page
# Username Screen
if mousex > 530 and mousey > 300:
buttons[3].create_button()
x2 = textbox.update(events, stats, textbox, \
buttons, mousex, mousey, \
cur_scrn=cur_scrn, hide=0)
if x2 == 'TX_SEARCH':
names = textbox.get_text()
if not names:
return False
stats.pass_mode()
textbox.reset()
elif x2 == 'TX_QUIT':
return 'TX_QUIT'
else:
# Blit textbox on login screen
screen.blit(textbox.get_surface(), \
((g_settings.screen_width//2) - 100, \
(g_settings.screen_height//2) - 200))
return False
if cur_scrn == 2:
global flagged
""" In Password Menu """
if mousex > 530 and mousey > 300:
buttons[4].create_button()
x3 = textbox.update(events, stats, textbox, \
buttons, mousex, mousey, \
cur_scrn=cur_scrn, hide=1)
if x3 == 'TX_SEARCH':
x = textbox.get_text()
# je moet je wachtwoord verbergen
candy = textbox.hash_word()
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
### ### ### ### ###### ### ### ### ###### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
if con_text.verify(x, candy):
print("HASH COMPLETE ", candy)
textbox.reset()
# Send to server! WITH names
############
flagged = 1
# SAVE NAME and BLIT TO MENU "You are logged in as :"
#############
stats.menu_mode(flagged=flagged)
# update screen if auth
else:
return False
### ### ### ### ### ### ### ### ### ###### ### ### ### ###### ### ### ### ###### ### ### ### ###### ### ### ###
### ### ### ### ###### ### ### ### ###### ### ### ### ###### ### ### ### ###### ### ### ### ###### ### ### ### ###
elif x3 == 'TX_QUIT':
return 'TX_QUIT'
else:
# Blit textbox to password screen
screen.blit(textbox.get_surface(), \
((g_settings.screen_width//2) - 100, \
(g_settings.screen_height//2) - 200))
#### elif cur_scrn == 3: ABOUT PAGE
#
# screen.blit(textbox.get_surface(), \
# ((g_settings.screen_width//4)*3-32, \
# (g_settings.screen_height//6)*3-120))
return False
def loading_wheel(screen, i, reticle, colors):
""" PEP8 Pride """
mousex, mousey = pygame.mouse.get_pos()
reticle.blitme(mousex, mousey)
pygame.display.flip()
pygame.draw.aaline(screen, colors[0], [0, 560], [1200, 560], True)
if i < 50:
pygame.draw.aaline(screen, colors[i%2], [600, 560], [0, 550], True)
pygame.draw.aaline(screen, colors[i%2], [600, 560], [1200, 550], True)
elif i < 100:
pygame.draw.aaline(screen, colors[i%2], [520, 560], [0, 520], True)
pygame.draw.aaline(screen, colors[i%2], [680, 560], [1200, 520], True)
elif i < 150:
pygame.draw.aaline(screen, colors[i%2], [440, 560], [0, 490], True)
pygame.draw.aaline(screen, colors[i%2], [760, 560], [1200, 490], True)
elif i < 200:
pygame.draw.aaline(screen, colors[i%2], [360, 560], [0, 460], True)
pygame.draw.aaline(screen, colors[i%2], [840, 560], [1200, 460], True)
elif i < 250:
pygame.draw.aaline(screen, colors[i%2], [280, 560], [0, 430], True)
pygame.draw.aaline(screen, colors[i%2], [920, 560], [1200, 430], True)
elif i < 300:
pygame.draw.aaline(screen, colors[i%2], [200, 560], [0, 410], True)
pygame.draw.aaline(screen, colors[i%2], [1000, 560], [1200, 410], True)
elif i < 350:
pygame.draw.aaline(screen, colors[i%2], [120, 560], [0, 380], True)
pygame.draw.aaline(screen, colors[i%2], [1080, 560], [1200, 380], True)
elif i < 399:
pygame.draw.aaline(screen, colors[i%2], [40, 560], [0, 350], True)
pygame.draw.aaline(screen, colors[i%2], [1160, 560], [1200, 350], True)
else:
pygame.draw.aaline(screen, colors[i%2], [1, 560], [0, 350], True)
pygame.draw.aaline(screen, colors[i%2], [1199, 560], [1200, 350], True)
def check_twit_edges(g_settings, twits):
for twit in twits.sprites():
if twit.check_edges():
# Move these twits only
move = twit.twit_id
move_group = [t for t in twits.sprites() if t.twit_id == move]
change_army_direction(g_settings, move_group)
def change_army_direction(g_settings, move_group):
for i, twit in enumerate(move_group):
if twit.rect.x > 600:
# Edge buffer
twit.rect.x -= 20
elif twit.rect.x < 600:
# Edge buffer
twit.rect.x += 25
twit.twit_direction *= -1
twit.rect.y += g_settings.twit_drops
return 0
def check_twit_bottom(screen, twits):
screen_rect = screen.get_rect()
for twit in twits.sprites():
# Sprites in update_bullets() This might be useless <-- search "useless" to find all
if twit.rect.bottom >= screen_rect.bottom - 100:
twits.remove(twit)
return True
else:
return False
def update_twits(g_settings, screen, stats, ship, \
powerups, twits, scores, projectiles):
global test
global all_tweets
# active_ids = []
if test != len(twits.sprites()):
# DEBUGGING print tweets here
#print("ALL TWEETS {}".format(all_tweets))
test = len(twits.sprites())
twits.update()
# Check if twits touch edges
check_twit_edges(g_settings, twits)
if check_twit_bottom(screen, twits):