def __init__(self, screen, text, Group, x, y, size=(256, 64), setting=False): super().__init__(Group) super().__init__() pygame.sprite.Sprite.__init__(self) self.Setting_button = setting self.screen = screen self.text = text self.size = size self.x = x + 10 self.y = y + 10 self.image = pygame.Surface(self.size) self.Button1 = pygame.transform.scale( load_image('Main_menu/Buttons/Button1.png'), self.size) self.Button2 = pygame.transform.scale( load_image('Main_menu/Buttons/Button1.1.png'), self.size) self.Button3 = pygame.transform.scale( load_image('Main_menu/Buttons/Button1.2.png'), self.size) self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y self.font = pygame.font.Font('static/fonts/19888.ttf', 40) self.text = self.font.render(f'{text}', True, (255, 255, 255)) self.screen.blit(self.text, (self.x, self.y))
def __init__(self, pos, goal, LastPose, group): super().__init__(group) super().__init__() pygame.sprite.Sprite.__init__(self) self.image = pygame.transform.scale( load_image('For Fire/Red_bullet1.png'), (16, 16)) self.rect = self.image.get_rect() self.LastPose = LastPose if self.LastPose == 'R': self.rect.centerx = pos[0] + 50 self.rect.centery = pos[1] - 50 else: self.rect.centerx = pos[0] - 50 self.rect.centery = pos[1] - 50 self.pistol_pos = pos self.goal = goal self.speed = 15 if self.LastPose == 'L' and self.speed > 0 or \ self.LastPose == 'R' and self.speed < 0: self.speed = -1 * self.speed
def __init__(self, GunType, x, y): super().__init__(Guns) super().__init__() pygame.sprite.Sprite.__init__(self) self.GunType = GunType if self.GunType == 'AR': self.image = load_image('details/AR.png') elif self.GunType == 'shootgun': self.image = load_image('details/Shootgun.png') self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y Guns.add(self)
def LogoInit(self): Logo = pygame.sprite.Sprite() Logo.image = pygame.transform.scale( load_image('Logo/logo_for_menu.png'), (850, 450)) Logo.rect = Logo.image.get_rect() Logo.rect.x = 300 Logo.rect.y = 100 self.all_sprites.add(Logo)
def __init__(self, ArrowType, ArrowType2, screen): pygame.sprite.Sprite.__init__(self) self.screen = screen self.mouse_sprite1 = pygame.sprite.Group() self.mouse_sprite2 = pygame.sprite.Group() self.sprite = pygame.sprite.Sprite() self.sprite2 = pygame.sprite.Sprite() self.sprite2.image = pygame.transform.scale(load_image(ArrowType2), (64, 64)) self.sprite.image = pygame.transform.scale(load_image(ArrowType), (64, 64)) self.sprite.rect = self.sprite.image.get_rect() self.sprite2.rect = self.sprite2.image.get_rect() self.mouse_sprite1.add(self.sprite) self.mouse_sprite2.add(self.sprite2) pygame.mouse.set_visible(False) self.sprite.rect.centerx = screen.get_size()[0] // 2 self.sprite.rect.centery = screen.get_size()[1] // 2 self.sprite2.rect.centerx = screen.get_size()[0] // 2 self.sprite2.rect.centery = screen.get_size()[1] // 2
def __init__(self, screen, clock): self.screen = screen self.clock = clock self.mouse = Mouse('Arrows/Arrow1.png', 'Arrows/Arrow1.1.png', screen) spaces = [i for i in os.listdir('sprites/Main_menu/spaces')] space = '/'.join(['Main_menu/spaces', choice(spaces)]) self.BG = pygame.transform.scale(load_image(space), st.ResolutionInt) self.all_sprites = pygame.sprite.Group() self.HerosInit() self.LogoInit() self.MusicInit()
def __init__(self, screen, x, y, Group): super().__init__(Group) super().__init__() pygame.sprite.Sprite.__init__(self) self.screen = screen self.image = pygame.transform.scale(load_image('Main_menu/Circle.png'), (40, 40)) self.rect = self.image.get_rect() self.rectangle_pos = (x, y) self.rect.x = x self.rect.y = y + 7 self.percent = 50
def __init__(self, screen, start_pos=(500, 600)): self.left_sprites = pygame.sprite.Group() self.right_sprites = pygame.sprite.Group() self.stand_sprites_R = pygame.sprite.Group() self.stand_sprites_L = pygame.sprite.Group() self.bite_sprites_R = pygame.sprite.Group() self.bite_sprites_L = pygame.sprite.Group() self.screen = screen # Speed from 2 --> 5, HP from 20 --> 50, Visibility from 250 --> 500 self.Difficulty = st.Difficulty if self.Difficulty == 1: self.Strench = choice(range(40, 60)) elif self.Difficulty == 2: self.Strench = choice(range(60, 80)) elif self.Difficulty == 3: self.Strench = choice(range(80, 101)) self.Speed = int(0.05 * self.Strench) self.HeatPoints = int(0.5 * self.Strench) self.zS = 80 / self.HeatPoints self.Visibility = (6.25 * self.Strench) Man_start_pos = start_pos self.Man_stand_R = AnimatedSprite( load_image('Зомби/Зомби_stand_R_ALL.png'), 8, 1, *Man_start_pos, self.stand_sprites_R) self.Man_stand_L = AnimatedSprite( load_image('Зомби/Зомби_stand_L_ALL.png'), 8, 1, *Man_start_pos, self.stand_sprites_L, 1) self.Man_Go_R = AnimatedSprite(load_image('Зомби/Зомби_run_R_ALL.png'), 8, 1, *Man_start_pos, self.right_sprites) self.Man_Go_L = AnimatedSprite(load_image('Зомби/Зомби_run_L_ALL.png'), 8, 1, *Man_start_pos, self.left_sprites, 1) self.Man_Bite_R = AnimatedSprite( load_image('Зомби/Зомби_bite_R_ALL.png'), 8, 1, *Man_start_pos, self.bite_sprites_R, 1) self.Man_Bite_L = AnimatedSprite( load_image('Зомби/Зомби_bite_L_ALL.png'), 8, 1, *Man_start_pos, self.bite_sprites_L, 1) self.All_sprites_DRAW = [ self.left_sprites, self.right_sprites, self.stand_sprites_R, self.stand_sprites_L, self.bite_sprites_L, self.bite_sprites_R ] self.All_sprites = [ self.Man_stand_R, self.Man_stand_L, self.Man_Go_R, self.Man_Go_L, self.Man_Bite_R, self.Man_Bite_L ] self.LastPose = 'R' self.IsAlive = True self.Last_Move = '' self.IsBiting = False
def __init__(self, x, y): super().__init__(Bullets_group) super().__init__() pygame.sprite.Sprite.__init__(self) self.pos = (x, y) self.image = load_image('details/bullets.png') self.rect = self.image.get_rect() self.rect.centerx, self.rect.centery = self.pos[0], self.pos[1] self.i = 0 self.speedx, self.speedy = choice([-4, 4]), choice([-4, 4]) Bullets_group.add(self)
def __init__(self, x, y): super().__init__(Experience) super().__init__() pygame.sprite.Sprite.__init__(self) self.pos = (x, y) self.image = load_image('details/XP.png') self.rect = self.image.get_rect() self.rect.centerx, self.rect.centery = self.pos[0], self.pos[1] self.xp = choice(range(10, 30)) self.i = 0 self.speedx, self.speedy = choice([-4, 4]), choice([-4, 4]) Experience.add(self)
def __init__(self, screen, mouse, typeofgun, ammo=10): self.mouse = mouse self.type = typeofgun self.Taken = False self.InHands = False self.Ammo = ammo if self.type == 'pistol': self.Damage = 3 self.frames = [23] self.gunR = 'guns/pistol/Default_pistol_R.png' self.gunL = 'guns/pistol/Default_pistol_L.png' elif self.type == 'AR': self.Damage = 10 self.frames = [11, 23] self.gunR = 'guns/assault_rifle/assault_rifle_R.png' self.gunL = 'guns/assault_rifle/assault_rifle_L.png' elif self.type == 'shootgun': self.Damage = 7 self.frames = [23] self.gunR = 'guns/shootgun/shootguns_R.png' self.gunL = 'guns/shootgun/shootguns_L.png' self.left_sprites = pygame.sprite.Group() self.right_sprites = pygame.sprite.Group() self.screen = screen self.pos = (248, 244) if self.type == 'AR': self.Pistol_R = AnimatedSprite(load_image(self.gunR), 8, 1, *self.pos, self.right_sprites) self.Pistol_L = AnimatedSprite(load_image(self.gunL), 8, 1, *self.pos, self.left_sprites, 1) elif self.type == 'shootgun': self.Pistol_R = AnimatedSprite(load_image(self.gunR), 8, 1, *self.pos, self.right_sprites) self.Pistol_L = AnimatedSprite(load_image(self.gunL), 8, 1, *self.pos, self.left_sprites, 1) elif self.type == 'pistol': self.Pistol_R = AnimatedSprite( pygame.transform.scale(load_image(self.gunR), (512, 64)), 8, 1, *self.pos, self.right_sprites) self.Pistol_L = AnimatedSprite( pygame.transform.scale(load_image(self.gunL), (512, 64)), 8, 1, *self.pos, self.left_sprites, 1) self.FireSound = pygame.mixer.Sound( 'static/audio/firing/laser_pistol.mp3')
def __init__(self, group): super().__init__(group) super().__init__() pygame.sprite.Sprite.__init__(self) self.Group = group types = ['Hero_b', 'Hero_s', 'Zombie'] path = f'Main_menu/Floating_heroes/{choice(types)}.png' self.original_image = load_image(path) self.image = self.original_image self.rect = self.image.get_rect() self.pos = (choice(range(200, 1720)), choice(range(200, 880))) self.rect.x = self.pos[0] self.rect.y = self.pos[1] self.speedx = choice([-1, 1]) self.speedy = choice([-1, 1]) self.position = pygame.math.Vector2(*self.pos) self.i = 0 self.rotateleft = choice([True, False])
def Change_gun(self, GunType): self.type = GunType if self.type == 'pistol': self.Damage = 5 self.frames = [23] self.gunR = 'guns/pistol/Default_pistol_R.png' self.gunL = 'guns/pistol/Default_pistol_L.png' elif self.type == 'AR': self.Damage = 10 self.frames = [11, 23] self.gunR = 'guns/assault_rifle/assault_rifle_R.png' self.gunL = 'guns/assault_rifle/assault_rifle_L.png' elif self.type == 'shootgun': self.Damage = 7 self.frames = [23] self.gunR = 'guns/shootgun/shootguns_R.png' self.gunL = 'guns/shootgun/shootguns_L.png' self.Pistol_R.kill() self.Pistol_L.kill() if self.type == 'AR': self.Pistol_R = AnimatedSprite(load_image(self.gunR), 8, 1, *self.pos, self.right_sprites) self.Pistol_L = AnimatedSprite(load_image(self.gunL), 8, 1, *self.pos, self.left_sprites, 1) elif self.type == 'shootgun': self.Pistol_R = AnimatedSprite(load_image(self.gunR), 8, 1, *self.pos, self.right_sprites) self.Pistol_L = AnimatedSprite(load_image(self.gunL), 8, 1, *self.pos, self.left_sprites, 1) elif self.type == 'pistol': self.Pistol_R = AnimatedSprite( pygame.transform.scale(load_image(self.gunR), (512, 64)), 8, 1, *self.pos, self.right_sprites) self.Pistol_L = AnimatedSprite( pygame.transform.scale(load_image(self.gunL), (512, 64)), 8, 1, *self.pos, self.left_sprites, 1)
from Fuctions import load_image pygame.init() size = st.Change_Resolution() screen = pygame.display.set_mode(size) clock = pygame.time.Clock() Game_menu = MMC.Main_menu(screen, clock) # ----------------------Menu---------------------- # Playing = Game_menu.Menu_cycle() if not Playing: exit() # ----------------------Game---------------------- # FT = pygame.transform.scale(load_image('Main_menu\Fast_Tutorial.png'), (1800, 980)) running = True while running: screen.blit(FT, (-30, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: quit() pressed_key = pygame.key.get_pressed() if pressed_key[pygame.K_SPACE]: running = False pygame.display.flip() clock.tick(st.FPS)
def SpritesINIT(self, PlayersColor): Man_start_pos = (500, 500) # ----------------ASSAULT RIFLE------------------ # self.left_sprites = pygame.sprite.Group() self.right_sprites = pygame.sprite.Group() self.left_back_sprites = pygame.sprite.Group() self.right_back_sprites = pygame.sprite.Group() self.stand_sprites_R = pygame.sprite.Group() self.stand_sprites_L = pygame.sprite.Group() self.Man_stand_R = AnimatedSprite( load_image(f'Космонавт/{PlayersColor}/Космонавт_stand_R_ALL.png'), 8, 1, *Man_start_pos, self.stand_sprites_R) self.Man_stand_L = AnimatedSprite( load_image(f'Космонавт/{PlayersColor}/Космонавт_stand_L_ALL.png'), 8, 1, *Man_start_pos, self.stand_sprites_L, 1) self.Man_Go_R = AnimatedSprite( load_image(f'Космонавт/{PlayersColor}/Космонавт_run_R_ALL.png'), 8, 1, *Man_start_pos, self.right_sprites) self.Man_Go_L = AnimatedSprite( load_image(f'Космонавт/{PlayersColor}/Космонавт_run_L_ALL.png'), 8, 1, *Man_start_pos, self.left_sprites, 1) self.Man_Go_L_Back = AnimatedSprite( load_image(f'Космонавт/{PlayersColor}/Космонавт_run_L_ALL.png'), 8, 1, *Man_start_pos, self.left_back_sprites) self.Man_Go_R_Back = AnimatedSprite( load_image(f'Космонавт/{PlayersColor}/Космонавт_run_R_ALL.png'), 8, 1, *Man_start_pos, self.right_back_sprites, 1) self.default_sprites_DRAW = [ self.stand_sprites_R, self.stand_sprites_L, self.right_sprites, self.left_sprites, self.right_back_sprites, self.left_back_sprites ] # ----------------С ПИСТОЛЕТОМ------------------ # self.left_sprites_P = pygame.sprite.Group() self.right_sprites_P = pygame.sprite.Group() self.left_back_sprites_P = pygame.sprite.Group() self.right_back_sprites_P = pygame.sprite.Group() self.stand_sprites_R_P = pygame.sprite.Group() self.stand_sprites_L_P = pygame.sprite.Group() path = f'Космонавт/{PlayersColor}/С_пистолетом/' self.Man_stand_R_P = AnimatedSprite( load_image(path + 'Космонавт_stand_R_ALL_P.png'), 8, 1, *Man_start_pos, self.stand_sprites_R_P) self.Man_stand_L_P = AnimatedSprite( load_image(path + 'Космонавт_stand_L_ALL_P.png'), 8, 1, *Man_start_pos, self.stand_sprites_L_P, 1) self.Man_Go_R_P = AnimatedSprite( load_image(path + 'Космонавт_run_R_ALL_P.png'), 8, 1, *Man_start_pos, self.right_sprites_P) self.Man_Go_L_P = AnimatedSprite( load_image(path + 'Космонавт_run_L_ALL_P.png'), 8, 1, *Man_start_pos, self.left_sprites_P, 1) self.Man_Go_L_Back_P = AnimatedSprite( load_image(path + 'Космонавт_run_L_ALL_P.png'), 8, 1, *Man_start_pos, self.left_back_sprites_P) self.Man_Go_R_Back_P = AnimatedSprite( load_image(path + 'Космонавт_run_R_ALL_P.png'), 8, 1, *Man_start_pos, self.right_back_sprites_P, 1) self.pistol_sprites_DRAW = [ self.stand_sprites_R_P, self.stand_sprites_L_P, self.right_sprites_P, self.left_sprites_P, self.right_back_sprites_P, self.left_back_sprites_P ] # ------------------ВСЕ СПРАЙТЫ В СПИСКАХ---------------- # self.ALL_sprites_RECT = [ self.Man_stand_R_P, self.Man_stand_L_P, self.Man_Go_R_P, self.Man_Go_L_P, self.Man_Go_L_Back_P, self.Man_Go_R_Back_P, self.Man_stand_R, self.Man_stand_L, self.Man_Go_R, self.Man_Go_L, self.Man_Go_L_Back, self.Man_Go_R_Back ] self.ALL_sprites_DRAW = [ self.default_sprites_DRAW, self.pistol_sprites_DRAW ]