3
3
import random
4
4
import csv
5
5
import button
6
+ import pyautogui
6
7
7
8
pygame .init ()
8
9
9
-
10
10
SCREEN_WIDTH = 1080
11
11
SCREEN_HEIGHT = int (SCREEN_WIDTH * 0.8 )
12
12
programIcon = pygame .image .load ('img/favicon.png' )
39
39
shoot = False
40
40
grenade = False
41
41
grenade_thrown = False
42
+ molotov = False
43
+ molotov_thrown = False
42
44
43
45
44
46
58
60
Mkey = pygame .image .load ('img/icons/keyboard/Keyboard & Mouse/Light/M_Key_Light.png' ).convert_alpha ()
59
61
Ukey = pygame .image .load ('img/icons/keyboard/Keyboard & Mouse/Light/U_Key_Light.png' ).convert_alpha ()
60
62
Fkey = pygame .image .load ('img/icons/keyboard/Keyboard & Mouse/Light/F_Key_Light.png' ).convert_alpha ()
63
+ F5key = pygame .image .load ('img/icons/keyboard/Keyboard & Mouse/Light/F5_Key_Light.png' ).convert_alpha ()
61
64
62
65
63
66
# BACKGROUND IMAGES
80
83
bullet_zombie = pygame .image .load ('img/icons/bulletzombie.png' ).convert_alpha
81
84
82
85
grenade_img = pygame .image .load ('img/icons/grenade.png' ).convert_alpha ()
86
+ molotov_img = pygame .image .load ('img/icons/molotov.png' ).convert_alpha ()
83
87
84
88
health_box_img = pygame .image .load ('img/icons/health_box.png' ).convert_alpha ()
85
89
ammo_box_img = pygame .image .load ('img/icons/ammo_box.png' ).convert_alpha ()
86
- grenade_box_img = pygame .image .load (
87
- 'img/icons/grenade_box .png' ).convert_alpha ()
90
+ grenade_box_img = pygame .image .load ('img/icons/grenade_box.png' ). convert_alpha ()
91
+ molotov_box_img = pygame . image . load ( 'img/icons/molotov_box .png' ).convert_alpha ()
88
92
item_boxes = {
89
93
'Health' : health_box_img ,
90
94
'Ammo' : ammo_box_img ,
91
- 'Grenade' : grenade_box_img
95
+ 'Grenade' : grenade_box_img ,
92
96
}
93
97
94
98
# COLORS
95
- BG = (144 , 201 , 120 )
99
+ BG = (81 , 6 , 13 )
96
100
RED = (176 , 8 , 12 )
97
101
WHITE = (255 , 255 , 255 )
98
102
GREEN = (26 , 110 , 15 )
110
114
GRENADESOUND = pygame .mixer .Sound ('audio/grenade.mp3' )
111
115
GRENADESOUND .set_volume (1 )
112
116
117
+ MOLOTOVSOUND = pygame .mixer .Sound ('audio/molotov.wav' )
118
+ MOLOTOVSOUND .set_volume (1 )
119
+
113
120
PICK = pygame .mixer .Sound ('audio/grenadepick.mp3' )
114
121
PICK .set_volume (2 )
115
122
134
141
GAMEOVER = pygame .mixer .Sound ('audio/gameover.wav' )
135
142
GAMEOVER .set_volume (2 )
136
143
137
-
144
+ SCREENSHOT = pygame .mixer .Sound ('audio/takingphoto.wav' )
145
+ GAMEOVER .set_volume (5 )
138
146
139
147
# FONT
140
148
font = pygame .font .Font ("font/Futurot.ttf" , 20 )
143
151
YOUDIED = pygame .font .Font ("font/Futurot.ttf" , 110 )
144
152
JanKupczyk = pygame .font .Font ("font/Futurot.ttf" , 13 )
145
153
154
+ pausetimerevent = pygame .USEREVENT + 1
155
+ paused = False
156
+
146
157
def draw_text (text , font , text_col , x , y ):
147
158
img = font .render (text , True , text_col )
148
159
screen .blit (img , (x , y ))
@@ -198,7 +209,7 @@ def __init__(self, char_type, x, y, scale, speed, ammo, grenades):
198
209
self .vel_y = 0
199
210
self .jump = False
200
211
self .in_air = True
201
- self .flip = False
212
+ self .flip = True
202
213
self .animation_list = []
203
214
self .frame_index = 0
204
215
self .action = 0
@@ -310,7 +321,7 @@ def move(self, moving_left, moving_right):
310
321
def shoot (self ):
311
322
if self .shoot_cooldown == 0 and self .ammo > 0 :
312
323
self .shoot_cooldown = 15
313
- bullet = Bullet (self .rect .centerx + (0.80 *
324
+ bullet = Bullet (self .rect .centerx + (0.60 *
314
325
self .rect .size [0 ] * self .direction ), self .rect .centery , self .direction )
315
326
bullet_group .add (bullet )
316
327
SHOOT_SOUND .play ()
@@ -416,7 +427,7 @@ def process_data(self, data):
416
427
elif tile == 17 : # create ammo box
417
428
item_box = ItemBox (
418
429
'Ammo' , x * TILE_SIZE , y * TILE_SIZE )
419
- item_box_group .add (item_box )
430
+ item_box_group .add (item_box )
420
431
elif tile == 18 : # create grenade box
421
432
item_box = ItemBox (
422
433
'Grenade' , x * TILE_SIZE , y * TILE_SIZE )
@@ -513,12 +524,13 @@ def draw(self, health):
513
524
pygame .draw .rect (screen , RED , (self .x , self .y , 150 , 20 ))
514
525
pygame .draw .rect (screen , GREEN , (self .x , self .y , 150 * ratio , 20 ))
515
526
screen .blit (headhp , (- 4 , 2 ))
516
-
527
+ screen .blit (update_fps (), (1050 ,5 ))
528
+ draw_text ('FPS' , font , WHITE , 1010 , 5 )
517
529
518
530
class Bullet (pygame .sprite .Sprite ):
519
531
def __init__ (self , x , y , direction ):
520
532
pygame .sprite .Sprite .__init__ (self )
521
- self .speed = 10
533
+ self .speed = 11
522
534
self .image = bullet_img
523
535
self .rect = self .image .get_rect ()
524
536
self .rect .center = (x , y )
@@ -542,7 +554,11 @@ def update(self):
542
554
enemy .health -= 25
543
555
ZOMBIEATTACK .play ()
544
556
self .kill ()
545
-
557
+
558
+ def update_fps ():
559
+ fps = str (int (clock .get_fps ()))
560
+ fps_text = font .render (fps , 1 , pygame .Color ("white" ))
561
+ return fps_text
546
562
547
563
class Grenade (pygame .sprite .Sprite ):
548
564
def __init__ (self , x , y , direction ):
@@ -627,6 +643,11 @@ def update(self):
627
643
else :
628
644
self .image = self .images [self .frame_index ]
629
645
646
+ #TAKING SCREENSHOT
647
+ def screenshot (obj , file_name , position , size ):
648
+ img = pygame .Surface (size )
649
+ img .blit (obj , (0 , 0 ), (position , size ))
650
+ pygame .image .save (img , "screenshots/ss_.png" )
630
651
631
652
#BTNs
632
653
start_button = button .Button (
@@ -680,14 +701,16 @@ def update(self):
680
701
screen .blit (Akey , (100 , 450 ))
681
702
draw_text ('SHOOT' , font , WHITE , 210 , 512 )
682
703
screen .blit (SPkey , (125 , 480 ))
683
- draw_text ('NADE' , font , WHITE , 55 , 626 )
684
- screen .blit (Qkey , (5 , 610 ))
685
- draw_text ('MUTE MUSIC' , font , WHITE , 55 , 666 )
686
- screen .blit (Mkey , (5 , 650 ))
687
- draw_text ('UNMUTE MUSIC' , font , WHITE , 55 , 706 )
688
- screen .blit (Ukey , (5 , 690 ))
689
- draw_text ('FULLSCREEN' , font , WHITE , 55 , 746 )
690
- screen .blit (Fkey , (5 , 730 ))
704
+ draw_text ('NADE' , font , WHITE , 55 , 586 )
705
+ screen .blit (Qkey , (5 , 570 ))
706
+ draw_text ('MUTE MUSIC' , font , WHITE , 55 , 626 )
707
+ screen .blit (Mkey , (5 , 610 ))
708
+ draw_text ('UNMUTE MUSIC' , font , WHITE , 55 , 666 )
709
+ screen .blit (Ukey , (5 , 650 ))
710
+ draw_text ('FULLSCREEN' , font , WHITE , 55 , 706 )
711
+ screen .blit (Fkey , (5 , 690 ))
712
+ draw_text ('TAKE SCREENSHOT' , font , WHITE , 55 , 746 )
713
+ screen .blit (F5key , (5 , 730 ))
691
714
draw_text ('EXIT' , font , WHITE , 55 , 825 )
692
715
screen .blit (ESCkey , (5 , 810 ))
693
716
draw_text ('©2021 Jan Kupczyk' , JanKupczyk , WHITE , 905 , 845 )
@@ -710,6 +733,9 @@ def update(self):
710
733
draw_text ('GRENADES: ' , font , WHITE , 10 , 60 )
711
734
for x in range (player .grenades ):
712
735
screen .blit (grenade_img , (135 + (x * 15 ), 60 ))
736
+ draw_text ('MOLOTOVS: ' , font , WHITE , 10 , 85 )
737
+ for x in range (player .grenades ):
738
+ screen .blit (molotov_img , (140 + (x * 15 ), 90 ))
713
739
714
740
player .update ()
715
741
player .draw ()
@@ -805,12 +831,22 @@ def update(self):
805
831
player .jump = True
806
832
if event .key == pygame .K_ESCAPE :
807
833
run = False
834
+ MENUSELECT .play ()
808
835
if event .key == pygame .K_m :
809
836
pygame .mixer .music .pause ()
837
+ MENUSELECT .play ()
810
838
if event .key == pygame .K_u :
811
839
pygame .mixer .music .unpause ()
840
+ MENUSELECT .play ()
812
841
if event .key == pygame .K_f :
813
- pygame .display .toggle_fullscreen ()
842
+ pygame .display .set_mode ((1920 , 1080 ), pygame .FULLSCREEN )
843
+ MENUSELECT .play ()
844
+ if event .key == pygame .K_F5 :
845
+ screenshottaken = draw_text ('Screenshot taken!' , font , WHITE , 0 , 840 ,)
846
+ MENUSELECT .play ()
847
+ SCREENSHOT .play ()
848
+ screenshot (screen , "screenshots/screenshot.png" , (20 , 100 ), (1080 , 864 ))
849
+ print ("Screenshot taken" )
814
850
815
851
# KEYBOARDS SETT2
816
852
if event .type == pygame .KEYUP :
0 commit comments