-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game_2.py
1429 lines (1009 loc) · 43.5 KB
/
Game_2.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
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 cv2
import numpy as np
import os
import Face_to_array as fr
from pygame.locals import *
import random
import sys
from menu import *
pygame.init()
camera = cv2.VideoCapture(0)
pygame.display.set_caption("OpenCV camera stream on Pygame")
camera.set(3,200)
camera.set(4,200)
CURR_PATH = os.path.dirname(os.path.realpath(__file__));
OUTPUT_DIRECTORY = str(CURR_PATH) + "/Input";
#costanti globali
# V. Colori
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
BLUE_PLATFORM1 = (51, 153, 255)
BLUE_PLATFORM2 = (12, 50, 100)
BACKGROUND = (231, 229, 205)
PUNTO = (255,102,51)
YELLOW = (255,128,0)
PLATFORM_GREY = (105,104,104)
COIN_COLOR = (251,135,5)
RED_HEARTH =(219,32,39)
# Dimensione Schermo
SCREEN_WIDTH = 1024
SCREEN_HEIGHT = 576
global P_R, P_B, P_G, PLAYER_COLOR
P_R = 0
P_G = 204
P_B = 0
PLAYER_COLOR = (P_R,P_G,P_B)
global MOOD, COMP_COLOR
MOOD = "ANGRY"
COMP_COLOR = RED
global P_R, P_B, P_G, PLAYER_COLOR
P_R = 0
P_G = 204
P_B = 0
PLAYER_COLOR = (P_R,P_G,P_B)
global MOOD, COMP_COLOR
MOOD = "ANGRY"
COMP_COLOR = RED
full = (SCREEN_WIDTH,SCREEN_HEIGHT)
global DIFFICULTY
DIFFICULTY = 1.0;
class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.MORTAL = True
self.image = pygame.image.load('assets/sprites/player.png').convert_alpha()
self.image = pygame.transform.scale(self.image, (20, 20))
# Riferimento rect
self.rect = self.image.get_rect()
# Vel. player
self.change_x = 0
self.change_y = 0
# Lista variabili
self.level = None
self.attempt = 1
self.total_points = 0
## Changed -- tagged --
self.life = 10
self.mixer = pygame.mixer.pre_init(frequency=22050, size=-16, channels=2, buffer=4096)
self.pick_coin = pygame.mixer.Sound('assets/audio/point.ogg')
self.die = pygame.mixer.Sound('assets/audio/hit.ogg')
def update(self):
#Aggiorno le variabili e muovo il player
if self.life < 1:
game_over()
# Severity
self.calc_grav()
# Muovo a sinistra e a destra
self.rect.x += self.change_x
#---------------pick coin--------------------------------------------
coin_hit = pygame.sprite.spritecollide(self,self.level.coin_list,True)
for block in coin_hit:
self.total_points +=1
self.pick_coin.play(maxtime =850,fade_ms = 0)
#----------------------coin--------------------------------------------
# spritecollide platform, se muovo a destra collido, cambio direzione
block_hit_list = pygame.sprite.spritecollide(self, self.level.platform_list,False)
for block in block_hit_list:
if self.change_x > 0:
self.rect.right = block.rect.left
self.die.play(maxtime =550,fade_ms = 0)
#se collido in X con gli obstacles game over
#-----------------------GAME OVER---------------------#
if (self.MORTAL):
## CHANGED -- tagged --
if self.level.obstacles_list.has(block):
#vado a y 550 e riavvio
self.attempt +=1
self.life -= 1
self.life += 1
self.rect.x = -5
self.rect.y = 550
#-----------------------GAME OVER---------------------#
#Muovo su e giu
self.rect.y += self.change_y
# spritecollide su e giu
block_hit_list = pygame.sprite.spritecollide(self, self.level.platform_list, False)
for block in block_hit_list:
# Resetto la posizione dell'oggetto sopra e sotto
if self.change_y > 0:
self.rect.bottom = block.rect.top
if (self.MORTAL):
## CHANGED -- tagged --
#If I collide in y with the obstacles game over
if self.level.obstacles_list.has(block):
#I go to y 510 and restart
self.attempt +=1
self.life -= 1
self.life += 1
self.rect.x = -5
self.rect.y = 550
if self.change_y < 0:
self.rect.bottom = block.rect.top
# Movimento Veritcale a 0
self.change_y = 0
#-------------------------------------------------------------SE SCONTRO CON I BLOCCHI points--------------------------
def calc_grav(self):
#def gravità
if self.change_y == 0:
self.change_y = 1
else:
self.change_y += .55
# Pav
if self.rect.y >= SCREEN_HEIGHT - self.rect.height and self.change_y >= 0:
self.change_y = 0
self.rect.y = SCREEN_HEIGHT - self.rect.height
def jump(self):
# Definition jumping
self.rect.y += 3
platform_hit_list = pygame.sprite.spritecollide(self, self.level.platform_list, False)
self.rect.y -= 3
for platform in platform_hit_list:
if self.change_y < 0:
self.rect.bottom = platform.rect.top
print("top it")
## -- tagged --
# If I jump and collide with the platform shut down the player
if self.rect.bottom >= SCREEN_HEIGHT or (len(platform_hit_list) > 0):
self.change_y = -9
# Movimento left, right , stop
def go_left(self):
self.change_x = -5
def go_right(self):
global DIFFICULTY
self.change_x = 5 #* DIFFICULTY
def stop(self):
self.change_x = 0
#class Proiettili(pygame.sprite.Sprite):
# def __init__(self):
# pygame.sprite.Sprite.__init__(self)
# self.image = pygame.Surface([10,4])
# self.image.fill(BLACK)
# self.rect = self.image.get_rect()
# def update(self):
# self.rect.x += 10
class Platform(pygame.sprite.Sprite):
def __init__(self, width, height):
# -- tagged --
global DIFFICULTY
self.width = width
self.height = height
width = min((int)(width * DIFFICULTY), 10000)
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface([width, height])
self.image.fill(WHITE)
self.rect = self.image.get_rect()
class obstacles_1(Platform):
def __init__(self, width, height):
# -- tagged --
## global DIFFICULTY
##
## width = (int)(width * DIFFICULTY)
self.width = width
self.height = height
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('assets/sprites/ostacolo_1.png').convert_alpha()
self.image = pygame.transform.smoothscale(self.image, (width, height))
self.rect = self.image.get_rect()
class obstacles_2(Platform):
def __init__(self, width, height):
# -- tagged --
## global DIFFICULTY
##
## width = (int)(width * DIFFICULTY)
self.width = width
self.height = height
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('assets/sprites/ostacolo_2.png').convert_alpha()
self.image = pygame.transform.smoothscale(self.image, (width, height))
self.rect = self.image.get_rect()
class obstacles_3(Platform):
def __init__(self, width, height):
# -- tagged --
## global DIFFICULTY
##
## width = (int)(width * DIFFICULTY)
self.width = width
self.height = height
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('assets/sprites/ostacolo_3.png').convert_alpha()
self.image = pygame.transform.smoothscale(self.image, (width, height))
self.rect = self.image.get_rect()
class points_1(Platform):
def __init__(self,x,y):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('assets/sprites/gemma1.png')
self.image = pygame.transform.smoothscale(self.image, (31, 28))
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
def update(self):
pass
class points_2(Platform):
def __init__(self,x,y):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('assets/sprites/gemma2.png')
self.image = pygame.transform.smoothscale(self.image, (31, 28))
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
def update(self):
pass
class points_3(Platform):
def __init__(self,x,y):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load('assets/sprites/gemma3.png')
self.image = pygame.transform.smoothscale(self.image, (31, 28))
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y
def update(self):
pass
class Level(object):
#Super class che controlla i livelli
def __init__(self, player):
#al costruttore passo come paramentro il player e le relative variabili
self.platform_list = pygame.sprite.Group()
self.proiettili_lista = pygame.sprite.Group()
self.player = player
self.coin_list = pygame.sprite.Group()
self.obstacles_list = pygame.sprite.Group()
# Background
self.background = None
self.world_shift = 0
self.level_limit = -1000
#POSIZIONE PLAYER--------------------------
self.player.rect.x = 50
self.player.rect.y = 400 - self.player.rect.height
# Update livelli
def update(self):
self.platform_list.update()
def draw(self, screen):
#Disegno su schermo
# background
screen.fill(BACKGROUND)
screen.blit(self.background,(self.world_shift // 3,0))
# Tutti gli sprite delle liste plat e coin
self.platform_list.draw(screen)
self.coin_list.draw(screen)
def shift_world(self,shift_x):
self.world_shift += shift_x
#per tutti gli sprite nella lista sposto
for platform in self.platform_list:
platform.rect.x += shift_x
#per tutti gli sprite nella lista sposto
for coin in self.coin_list:
coin.rect.x += shift_x
# Classi figlie di "level"
class Level_01(Level):
def __init__(self, player):
# Richiamo il costruttore
Level.__init__(self, player)
self.level_limit = -3000
#CARICO LO SFONDO
self.background = pygame.image.load('assets/sprites/background_lvl_1.png').convert()
# Array that passes class parameters width, height, x and y
self.level = level = [[10, 600, -100, 0], #lato sinistro
[2400, 1, 0, 400],#1
[300, 1, 500, 350],
[31, 2, 1500, 360],
[31, 2, 1650, 330],
[31, 2, 1850, 330],
[31, 2, 2040, 330],
## -- tagged --
#[10000, 1, 0, 350],
[31, 2, 2210, 330],
#MOD. LVL 1
[31, 2, 2350, 290],
[31, 2, 2500, 250],
[31, 2, 2650, 210],
[30, 2, 2750, 250],
[100, 2, 2790, 170],
[100, 2, 2820, 310],
[50, 2, 3000, 290],
[30, 2, 3170, 250],
[40, 2, 3330, 250],
[1000, 1, 3480, 250]
]
obstacles = [[30, 30 , 450, 370],
[30, 30, 550, 370],
[30, 30, 650, 320],#sopra
[30, 30, 750,370],
[30, 30, 850, 370],
[30, 30, 1450, 370],
[30, 30, 1550, 370],
[30, 30, 1650, 370],
[30, 30, 1750, 370],
[30, 30, 1850, 370],
[30, 30, 1950, 370],
[30, 30, 2050, 370],
[30, 30, 2200, 370],
[30, 30, 2350, 370],
[30, 30, 1750, 300],
[30, 30, 1960, 300],
[30, 30, 2140, 300],
#MOD. LVL 1 obstacles
[30, 30, 2355, 300],
[30, 30, 2505, 270],
[30, 30, 2655, 240],
[30, 30, 2890, 280]
]
coins = [[30,30,300,320],
[30,30, 650, 250],
[30,30, 1000, 360],
[30,30, 1100, 320],
[30, 30, 1200, 360],
[30, 30, 1300, 360],
[30, 30, 1750, 240],
[30, 30, 1960, 240],
[30, 30, 2140, 240],
[30, 30, 2600, 150],
[30, 30, 2810, 110],
[30, 30, 3250, 170],
[30, 30, 3410, 170]
]
# ciclo for che grabba i dati dall'array
for coin in coins:
block = points_1(coin[0], coin[1])
block.rect.x = coin[2]
block.rect.y = coin[3]
block.player = self.player
self.coin_list.add(block)
# ciclo for che grabba i dati dall'array
for platform in level:
block = Platform(platform[0], platform[1])
block.rect.x = platform[2]
block.rect.y = platform[3]
block.player = self.player
self.platform_list.add(block)
# ciclo for che grabba i dati dall'array
for ost in obstacles:
#obstacles---------------
block = obstacles_1(ost[0],ost[1])
block.rect.x = ost[2]
block.rect.y = ost[3]
block.player = self.player
self.platform_list.add(block)
self.obstacles_list.add(block)
class Level_02(Level):
def __init__(self, player):
Level.__init__(self, player)
#CARICO LO SFONDO
self.background = pygame.image.load('assets/sprites/background_lvl_2.png').convert()
#psozione player
self.player.rect.x = 80
self.player.rect.y = 300
self.level_limit = -3000
# Array che passa i parametri della classe width, height, x e y
self.level = level = [[10000, 0, -200, 550],#sotto
[10, 600, -100, 0], #lato sinistro
## -- tagged --
#[10000, 1, 0, 350],
#PIATTAFORME
[400, 1.5, 50, 420],#1
[110, 1.5, 520, 350],#2
[110, 1.5, 650, 280],
[350, 1.5, 790, 210],
#scalinata scesa
[30, 30, 1200, 250],
[30, 30, 1310, 300],
[30, 30, 1420, 350],
[30, 30, 1530, 400],
[30, 30, 1640, 450],
[30, 30, 1850, 500],
#scalinata salita
[70, 2, 1940, 450],
[70, 2, 2090, 400],
[400, 2, 2250, 350],
# paltform vari
[60, 2, 2700, 300],
[60, 2, 2800, 370],
[60, 2, 3000, 370],
[60, 2, 3200, 370],
[1000, 2, 3350, 300]]
obstacles = [[30,30, 850,180],
[30,30, 1050,180],
[30,30, 2350,320],
[30,30, 2500, 320],
[30,30, 3400, 270]
]
coins = [[30,30,300,350],
[30,30, 900, 120],
[30, 30, 1200, 210],
[30, 30, 1530, 300],
[30, 30, 1740, 380],
[30, 30, 2250, 320],
[30, 30, 2415, 280],
[30, 30, 2600, 320],
[30, 30, 2915, 270],
[30, 30, 3115, 270],
[30, 30, 3350, 260]
]
# ciclo for che grabba i dati dall'array
for coin in coins:
block = points_2(coin[0], coin[1])
block.rect.x = coin[2]
block.rect.y = coin[3]
block.player = self.player
self.coin_list.add(block)
#For che grabba i dati dall'array
for platform in level:
block = Platform(platform[0], platform[1])
block.rect.x = platform[2]
block.rect.y = platform[3]
block.player = self.player
self.platform_list.add(block)
# ciclo for che grabba i dati dall'array
for ost in obstacles:
#obstacles---------------
block = obstacles_2(ost[0],ost[1])
block.rect.x = ost[2]
block.rect.y = ost[3]
block.player = self.player
self.platform_list.add(block)
self.obstacles_list.add(block)
class Level_03(Level):
def __init__(self, player):
Level.__init__(self, player)
self.level_limit = -3000
self.background = pygame.image.load('assets/sprites/background_lvl_3.png').convert()
# Array che passa i parametri della classe width, height, x e y
self.level = level = [[10000, 0, -100, 550],#sotto
[10, 600, -100, 0], #lato sinistro
#PIATTAFORME
[320,1, -10, 420],#1
[50, 1, 450, 400],#2
[50, 1, 650, 400],
[50, 1, 850, 400],
[50, 20, 950, 460],
[50, 1, 1080, 400],
[50, 20, 1180, 460],
[50, 1, 1310, 400],
[50, 20, 1450, 350],
[30, 30, 1550, 410],
[30, 30, 1650, 460],
[140, 1, 1730, 500],
#scalinata salita
[50, 20, 1940, 460],
[50, 20, 2090, 410],
[400, 1, 2250, 360],
# paltform vari
[50, 1, 2700, 310],
[50, 1, 2800, 380],
[50, 20, 2910, 440],
[50, 1, 3020, 380],
[50, 20, 3110, 440],
[50, 1, 3240, 370],
[500, 1, 3370, 340]]
obstacles = [[30,30, 560,370],
[30,30, 760,370],
[30,30, 960,360],
[30,30, 1210, 340],
[20,20, 1740, 420],
[20,20, 1770, 420],
[20,20, 1800, 420],
[20,20, 1830, 420],
[30,30, 2300, 330],
[30,30, 2600, 330],
[30,30, 2920, 350],
[30,30, 3130, 340],
[30,30, 3480, 310]
]
coins = [[30,30, 560,320],
[30,30, 760,320],
[30,30, 960,420],
[30,30, 1190, 420],
[30,30, 1550, 370],
[20,20, 1750, 470],
[20,20, 1820, 470],
[30,30, 2400, 330],
[30,30, 2500, 330],
[30,30, 2920, 410],
[30,30, 3130, 410],
[30,30, 3420, 310]
]
# ciclo for che grabba i dati dall'array
for coin in coins:
block = points_3(coin[0], coin[1])
block.rect.x = coin[2]
block.rect.y = coin[3]
block.player = self.player
self.coin_list.add(block)
# ciclo for che grabba i dati dall'array
for ost in obstacles:
#obstacles---------------
block = obstacles_3(ost[0],ost[1])
block.rect.x = ost[2]
block.rect.y = ost[3]
block.player = self.player
self.platform_list.add(block)
self.obstacles_list.add(block)
# Grabbo i dati dall'array
for platform in level:
block = Platform(platform[0], platform[1])
block.rect.x = platform[2]
block.rect.y = platform[3]
block.player = self.player
self.platform_list.add(block)
def game_over():
size = [SCREEN_WIDTH, SCREEN_HEIGHT]
screen = pygame.display.set_mode((size),pygame.DOUBLEBUF | pygame.HWSURFACE )
pygame.display.set_caption("Endless - Block")
background_menu = pygame.image.load('assets/sprites/Game_over.png').convert()
screen.blit(background_menu,(0,0))
player = Player()
font3 = pygame.font.Font('KGPrimaryWhimsy.ttf',30)
text = font3.render(" Lifes Used "+str(player.life), True, WHITE)
screen.blit(text, [420, 415])
pygame.display.flip()
menu = cMenu(20, 00, 100, 20, 'horizontal', 100, screen,
[('MENU', 1, None),
('EXIT',2, None)])
menu.set_center(True, True)
menu.set_alignment('center', 'center')
state = 0
prev_state = 1
rect_list = []
while 1:
if prev_state != state:
pygame.event.post(pygame.event.Event(EVENT_CHANGE_STATE, key = 0))
prev_state = state
e = pygame.event.wait()
if e.type == pygame.KEYDOWN or e.type == EVENT_CHANGE_STATE:
if state == 0:
rect_list, state = menu.update(e, state)
elif state == 1:
main()
state = 0
else:
print ('Exit!')
pygame.quit()
sys.exit()
if e.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update(rect_list)
def main():
size = [SCREEN_WIDTH, SCREEN_HEIGHT]
screen = pygame.display.set_mode((size),pygame.DOUBLEBUF | pygame.HWSURFACE )
pygame.display.set_caption("Endless - Block")
background_menu = pygame.image.load('assets/sprites/Intro_BG_desktop.png').convert()
screen.blit(background_menu,(0,0))
pygame.display.flip()
tick_speed = 1
menu = cMenu(20, 00, 100, 28, 'vertical', 100, screen,
[('PLAY', 1, None),
('How To Play',2, None),
('QUIT',3, None),])
menu.set_center(True, True)
menu.set_alignment('center', 'center')
state = 0
prev_state = 1
rect_list = []
BG_1 = pygame.image.load('assets/sprites/background_lvl_1.png').convert()
BG_1i = pygame.image.load('assets/sprites/background_lvl_1_invert.png').convert()
while 1:
if prev_state != state:
pygame.event.post(pygame.event.Event(EVENT_CHANGE_STATE, key = 0))
prev_state = state
e = pygame.event.wait()
if e.type == pygame.KEYDOWN or e.type == EVENT_CHANGE_STATE:
if state == 0:
rect_list, state = menu.update(e, state)
elif state == 1:
#-----------------------------------------------------------------------LOOP GAME------------------------------------------------------
size = [SCREEN_WIDTH, SCREEN_HEIGHT]
screen = pygame.display.set_mode((size),pygame.DOUBLEBUF | pygame.HWSURFACE )
pygame.display.set_caption("Endless - Block")
attempt = 1
joysticks = []
# Creo il player
player = Player()
#Carico le font
font1 = pygame.font.Font('KGPrimaryWhimsy.ttf', 30)
font2 = pygame.font.Font('KGPrimaryWhimsy.ttf', 40)
#Creo i livelli
level_list = []
level_list.append( Level_01(player) )
level_list.append( Level_02(player) )
level_list.append( Level_03(player) )
#Setto il livello corrente
current_level_no = 0
current_level = level_list[current_level_no]
active_sprite_list = pygame.sprite.Group()
player.level = current_level
active_sprite_list.add(player)
#-------------------------------------------JOYPAD-----------------------------
joystick_count = pygame.joystick.get_count()
print ("Ho trovato", joystick_count, "joystick/s")
if joystick_count == 0:
print ("Error, I did not find anything")
else:
my_joystick = pygame.joystick.Joystick(0)
my_joystick.init()
#-------------------------------------------JOYPAD-----------------------------
global OUTPUT_DIRECTORY
clock = pygame.time.Clock()
#cam_clock = pygame.time.Clock()
done = False
time_elapsed = 0
ret, frame = camera.read()
#screen.fill([0,0,0])
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame = np.rot90(frame)
frame = pygame.surfarray.make_surface(frame)
while not done:
global P_R, P_B, P_G, PLAYER_COLOR
PLAYER_COLOR = (P_R,P_G,P_B)
player.image.fill(PLAYER_COLOR)
if (P_R < 100):
P_R += 1
elif (P_G < 100):
P_G += 1
elif (P_B < 100):
P_B += 1
else:
P_R -= 1
P_G -= 1
P_B -= 1
global OUTPUT_DIRECTORY
# Capture frame-by-frame
dt = clock.tick()
time_elapsed += dt
if time_elapsed > 1000:
time_elapsed = 0
ret, frame = camera.read()
cv2.imwrite(OUTPUT_DIRECTORY + "/face.jpg", frame)
local_result = fr.main()
if (local_result == "Angry" or local_result == "Fear"):
MOOD = "ANGRY"
if (player.level.background != BG_1i):
player.level.background = BG_1i #pygame.image.load('assets/sprites/background_lvl_1_invert.png').convert()
screen.blit(player.level.background,(0,0))
elif (local_result == "Happy" or local_result == "Surprise"):
MOOD = "HAPPY"
if (player.level.background != BG_1):
player.level.background = BG_1 #pygame.image.load('assets/sprites/background_lvl_1_invert.png').convert()
screen.blit(player.level.background,(0,0))
else:
MOOD = "NEUTRAL"
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame = np.rot90(frame)
frame = pygame.surfarray.make_surface(frame)
#screen.blit(frame, (SCREEN_WIDTH - 144,SCREEN_HEIGHT - 144))
pygame.display.update()
# Our operations on the frame come here
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
#cv2.imshow('frame', frame) cv2.imwrite(output_directory + "/face_" + str(i) + ".jpg", all_faces[i]);
if cv2.waitKey(1) & 0xFF == ord('q'):
break
global MOOD, COMP_COLOR
if MOOD == "ANGRY":
COMP_COLOR = RED
elif MOOD == "SAD":
COMP_COLOR = BLUE
else:
COMP_COLOR = GREEN
if (PLAYER_COLOR[0] != COMP_COLOR[0]):
if (P_R < COMP_COLOR[0]):
P_R += 1
else:
P_R -= 1
if (PLAYER_COLOR[1] != COMP_COLOR[1]):
if (P_G < COMP_COLOR[1]):
P_G += 1
else:
P_G -= 1
if (PLAYER_COLOR[2] != COMP_COLOR[2]):
if (P_B < COMP_COLOR[2]):
P_B += 1
else:
P_B -= 1