forked from StanislavPetrovV/Python-DOOM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawing.py
More file actions
164 lines (141 loc) · 7.11 KB
/
drawing.py
File metadata and controls
164 lines (141 loc) · 7.11 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
import pygame
from settings import *
from map import mini_map
from collections import deque
from random import randrange
import sys
class Drawing:
def __init__(self, sc, sc_map, player, clock):
self.sc = sc
self.sc_map = sc_map
self.player = player
self.clock = clock
self.font = pygame.font.SysFont('Arial', 36, bold=True)
self.font_win = pygame.font.Font('font/font.ttf', 144)
self.textures = {1: pygame.image.load('img/wall6.png').convert(),
2: pygame.image.load('img/wall5.png').convert(),
3: pygame.image.load('img/wall3.png').convert(),
4: pygame.image.load('img/wall7.png').convert(),
'S': pygame.image.load('img/sky0.png').convert(),
}
# menu
self.menu_trigger = True
self.menu_picture = pygame.image.load('img/bg.jpg').convert()
# weapon parameters
self.weapon_base_sprite = pygame.image.load('sprites/weapons/shotgun/base/0.png').convert_alpha()
self.weapon_shot_animation = deque([pygame.image.load(f'sprites/weapons/shotgun/shot/{i}.png')
.convert_alpha() for i in range(20)])
self.weapon_rect = self.weapon_base_sprite.get_rect()
self.weapon_pos = (HALF_WIDTH - self.weapon_rect.width // 2, HEIGHT - self.weapon_rect.height)
self.shot_length = len(self.weapon_shot_animation)
self.shot_length_count = 0
self.shot_animation_trigger = True
self.shot_animation_speed = 3
self.shot_animation_count = 0
self.shot_sound = pygame.mixer.Sound('sound/shotgun.wav')
# shot SFX
self.sfx = deque([pygame.image.load(f'sprites/weapons/sfx/{i}.png').convert_alpha() for i in range(9)])
self.sfx_length_count = 0
self.sfx_length = len(self.sfx)
def background(self):
sky_offset = -10 * math.degrees(self.player.angle) % WIDTH
self.sc.blit(self.textures['S'], (sky_offset, 0))
self.sc.blit(self.textures['S'], (sky_offset - WIDTH, 0))
self.sc.blit(self.textures['S'], (sky_offset + WIDTH, 0))
pygame.draw.rect(self.sc, DARKGRAY, (0, HALF_HEIGHT, WIDTH, HALF_HEIGHT))
def world(self, world_objects):
for obj in sorted(world_objects, key=lambda n: n[0], reverse=True):
if obj[0]:
_, object, object_pos = obj
self.sc.blit(object, object_pos)
def fps(self, clock):
display_fps = str(int(clock.get_fps()))
render = self.font.render(display_fps, 0, DARKORANGE)
self.sc.blit(render, FPS_POS)
def win(self):
render = self.font_win.render('YOU WIN!!!', 1, (randrange(40, 120), 0, 0))
rect = pygame.Rect(0, 0, 1000, 300)
rect.center = HALF_WIDTH, HALF_HEIGHT
pygame.draw.rect(self.sc, BLACK, rect, border_radius=50)
self.sc.blit(render, (rect.centerx - 430, rect.centery - 140))
pygame.display.flip()
self.clock.tick(15)
def mini_map(self):
self.sc_map.fill(BLACK)
map_x, map_y = self.player.x // MAP_SCALE, self.player.y // MAP_SCALE
pygame.draw.line(self.sc_map, YELLOW, (map_x, map_y), (map_x + 8 * math.cos(self.player.angle),
map_y + 8 * math.sin(self.player.angle)), 2)
pygame.draw.circle(self.sc_map, RED, (int(map_x), int(map_y)), 4)
for x, y in mini_map:
pygame.draw.rect(self.sc_map, DARKBROWN, (x, y, MAP_TILE, MAP_TILE))
self.sc.blit(self.sc_map, MAP_POS)
def player_weapon(self, shot_projections):
if self.player.shot:
if not self.shot_length_count:
self.shot_sound.play()
self.shot_projection = min(shot_projections)[1] // 2
self.bullet_sfx()
shot_sprite = self.weapon_shot_animation[0]
self.sc.blit(shot_sprite, self.weapon_pos)
self.shot_animation_count += 1
if self.shot_animation_count == self.shot_animation_speed:
self.weapon_shot_animation.rotate(-1)
self.shot_animation_count = 0
self.shot_length_count += 1
self.shot_animation_trigger = False
if self.shot_length_count == self.shot_length:
self.player.shot = False
# self.shot_animation_count = 0
self.shot_length_count = 0
self.sfx_length_count = 0
self.shot_animation_trigger = True
else:
self.sc.blit(self.weapon_base_sprite, self.weapon_pos)
def bullet_sfx(self):
if self.sfx_length_count < self.sfx_length:
sfx = pygame.transform.scale(self.sfx[0], (self.shot_projection, self.shot_projection))
sfx_rect = sfx.get_rect()
self.sc.blit(sfx, (HALF_WIDTH - sfx_rect.width // 2, HALF_HEIGHT - sfx_rect.height // 2))
self.sfx_length_count += 1
self.sfx.rotate(-1)
def menu(self):
x = 0
pygame.mixer.music.load('sound/win.mp3')
pygame.mixer.music.play()
button_font = pygame.font.Font('font/font.ttf', 72)
label_font = pygame.font.Font('font/font1.otf', 400)
start = button_font.render('START', 1, pygame.Color('lightgray'))
button_start = pygame.Rect(0, 0, 400, 150)
button_start.center = HALF_WIDTH, HALF_HEIGHT
exit = button_font.render('EXIT', 1, pygame.Color('lightgray'))
button_exit = pygame.Rect(0, 0, 400, 150)
button_exit.center = HALF_WIDTH, HALF_HEIGHT + 200
while self.menu_trigger:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
self.sc.blit(self.menu_picture, (0, 0), (x % WIDTH, HALF_HEIGHT, WIDTH, HEIGHT))
x += 1
pygame.draw.rect(self.sc, BLACK, button_start, border_radius=25, width=10)
self.sc.blit(start, (button_start.centerx - 130, button_start.centery - 70))
pygame.draw.rect(self.sc, BLACK, button_exit, border_radius=25, width=10)
self.sc.blit(exit, (button_exit.centerx - 85, button_exit.centery - 70))
color = randrange(40)
label = label_font.render('DOOMPy', 1, (color, color, color))
self.sc.blit(label, (15, -30))
mouse_pos = pygame.mouse.get_pos()
mouse_click = pygame.mouse.get_pressed()
if button_start.collidepoint(mouse_pos):
pygame.draw.rect(self.sc, BLACK, button_start, border_radius=25)
self.sc.blit(start, (button_start.centerx - 130, button_start.centery - 70))
if mouse_click[0]:
self.menu_trigger = False
elif button_exit.collidepoint(mouse_pos):
pygame.draw.rect(self.sc, BLACK, button_exit, border_radius=25)
self.sc.blit(exit, (button_exit.centerx - 85, button_exit.centery - 70))
if mouse_click[0]:
pygame.quit()
sys.exit()
pygame.display.flip()
self.clock.tick(20)