fevzi02

Тимур ЛОХ

Jan 24th, 2022 (edited)
574
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame, sys, random
  2. import numpy as np
  3.  
  4. class Main:
  5.     def __init__(self, fps=60, screen_resolution=()):
  6.         self.fps = fps
  7.         pygame.init()
  8.         self.screen = pygame.display.set_mode((1080,720))
  9.         self.clock = pygame.time.Clock()
  10.         self.display_width, self.display_height = pygame.display.Info().current_w, pygame.display.Info().current_h
  11.         self.bool_pos = 0
  12.         self.x = 5
  13.         self.conter = 0
  14.         #0 - Левое Крыло; 2 - Правое крыло; 1 - Основа; 3 - Заднее Левое Крыло; 4 - Заднее Правое Крыло
  15.         self.list_0_coordinates = [[215, 100], [255, 100],
  16.                                     [365, 307], [265, 310]]
  17.         self.list_2_coordinates = [[215, 560], [255, 560],
  18.                                     [365, 353], [265, 350]]
  19.         self.list_3_coordinates = [[0, 250], [20, 250],
  20.                                     [90, 330], [30, 330]]
  21.         self.list_4_coordinates = [[0, 410], [20, 410],
  22.                                     [90, 330], [30, 330]]
  23.         self.list_1_coordinates = [[505, 330], [495, 345], [480, 360],
  24.                                     [50, 345], [30, 330],
  25.                                     [50, 315], [480, 300],[495, 315]]
  26.         self.p_list = [self.list_0_coordinates, self.list_1_coordinates, self.list_2_coordinates, self.list_3_coordinates, self.list_4_coordinates]
  27.         #Тут Отрисовка перед циклом
  28.  
  29.     def run_while(self):
  30.         while True:
  31.             self.conter += 1
  32.             if not self.bool_pos:
  33.                 self.drawing_in_a_loop()
  34.             self.event_handler()
  35.             pygame.display.flip()
  36.             self.clock.tick(self.fps)
  37.  
  38.     def event_handler(self):
  39.         for event in pygame.event.get():
  40.             if event.type == pygame.QUIT:
  41.                 pygame.quit()
  42.                 sys.exit()
  43.             if event.type == pygame.KEYDOWN :
  44.                 if event.key == pygame.K_ESCAPE:
  45.                     pygame.quit()
  46.                     sys.exit()
  47.                 elif event.key == pygame.K_SPACE:
  48.                     self.bool_pos = 0
  49.             if event.type == pygame.MOUSEBUTTONDOWN :
  50.                 self.pos = event.pos
  51.                 for p in self.p_list:
  52.                     if self.point_in_polygon(p, self.pos):
  53.                         self.fire()
  54.                         self.bool_pos = not self.bool_pos
  55.                         break
  56.                 #print(self.pos)
  57.                 #if self.pos
  58.  
  59.     def drawing_in_a_loop(self):
  60.         if self.list_4_coordinates[0][0] >=  pygame.display.Info().current_w:
  61.             self.list_0_coordinates = [[-290, 100], [-250, 100], [-140, 307], [-240, 310]]
  62.             self.list_2_coordinates = [[-290, 560], [-250, 560], [-140, 353], [-240, 350]]
  63.             self.list_3_coordinates = [[-505, 250], [-485, 250], [-415, 330], [-475, 330]]
  64.             self.list_4_coordinates = [[-505, 410], [-485, 410], [-415, 330], [-475, 330]]
  65.             self.list_1_coordinates = [[0, 330], [-10, 345], [-25, 360], [-455, 345],
  66.                                     [-475, 330], [-455, 315], [-25, 300], [-10, 315]]
  67.             self.p_list = [self.list_0_coordinates, self.list_1_coordinates, self.list_2_coordinates, self.list_3_coordinates, self.list_4_coordinates]
  68.  
  69.         self.screen.fill((125,249,255))
  70.         for i in range(len(self.list_0_coordinates)):
  71.             self.list_0_coordinates[i][0] += self.x
  72.         for i in range(len(self.list_1_coordinates)):
  73.             self.list_1_coordinates[i][0] += self.x
  74.         for i in range(len(self.list_2_coordinates)):
  75.             self.list_2_coordinates[i][0] += self.x
  76.         for i in range(len(self.list_3_coordinates)):
  77.             self.list_3_coordinates[i][0] += self.x
  78.         for i in range(len(self.list_4_coordinates)):
  79.             self.list_4_coordinates[i][0] += self.x
  80.  
  81.         pygame.draw.lines(self.screen, "black", True, self.list_0_coordinates, 5)
  82.         pygame.draw.lines(self.screen, "black", True, self.list_2_coordinates, 5)
  83.         pygame.draw.polygon(self.screen, (181,184,187), self.list_0_coordinates)
  84.         pygame.draw.polygon(self.screen, (181,184,187), self.list_2_coordinates)
  85.         pygame.draw.polygon(self.screen, (181,184,187), self.list_3_coordinates)
  86.         pygame.draw.polygon(self.screen, (181,184,187), self.list_4_coordinates)
  87.         pygame.draw.aalines(self.screen, "black", True, self.list_3_coordinates, 5)
  88.         pygame.draw.aalines(self.screen, "black", True, self.list_4_coordinates, 5)
  89.         pygame.draw.polygon(self.screen, (181,184,187), self.list_1_coordinates)
  90.         pygame.draw.aalines(self.screen, "black", True, self.list_1_coordinates, 5)
  91.  
  92.     def point_in_polygon(self, p, point):
  93.         result = False
  94.         size = len(p)
  95.         j = size - 1
  96.         for i in range(size):
  97.             if (p[i][1] < point[1] and p[j][1] >= point[1] or p[j][1] < point[1]
  98.             and p[i][1] >= point[1]) and (p[i][0] + (point[1] - p[i][1]) / (p[j][1] - p[i][1]) * (p[j][0] - p[i][0]) < point[0]):
  99.                 result = not result
  100.             j = i
  101.         return result
  102.  
  103.     def fire(self):
  104.         pygame.draw.circle(self.screen, "red", self.pos, 3)
  105.         pygame.draw.circle(self.screen, "red", self.pos, 7, 1)
  106.         pygame.draw.circle(self.screen, "red", self.pos, 9, 1)
  107.  
  108. Main(24).run_while()
  109.  
RAW Paste Data Copied