import pygame import sys from pygame import * import cv2 import random pygame.init() clock = pygame.time.Clock() max_fps = 60 screen_width = 864 screen_height = 936 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("blappy fird") #define font font = pygame.font.Font("SCRIPTIN.ttf", 60) # define colors white = (255,255,255) #defien tgame varibvales ground_scroll = 0 scroll_speed = 4 flying = False game_over = False pipe_gap = 230 pipe_frequency = 1500 #milliseconds last_pipe = pygame.time.get_ticks() - pipe_frequency score = 0 pass_pipe = False jump_sound = pygame.mixer.Sound("jumpsound.mp3") pygame.mixer.music.load("mainmusic.mp3") pygame.mixer.music.play(-1) # T plays main menu MOVIE = cv2.VideoCapture("gameover1.mp4") success, video_image = MOVIE.read() subwaysurfer = cv2.VideoCapture("subwaysurfer.mp4") success2, video_image2 = subwaysurfer.read() subway = False robloxstory = cv2.VideoCapture("robloxsadstory.mp4") success3, video_image3 = robloxstory.read() roblox = False # Load Images bg = pygame.image.load("bg1.jpg") ground_img = pygame.image.load("img/ground.png") def draw_text(text, font, text_col, x, y): img = font.render(text, True, text_col) screen.blit(img, (x,y)) class Bird(pygame.sprite.Sprite): def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) self.images = [] self.index = 0 self.count = 0 for num in range(1, 4): img = pygame.image.load(f'img/bird{num}.png') self.images.append(img) self.image = self.images[self.index] self.rect = self.image.get_rect() self.rect.center = [x, y] self.vel = 0 self.clicked = False def update(self): global subway, video2_x, video2_y if flying == True: self.vel += 0.5 if self.vel > 8: self.vel = 8 if self.rect.bottom < 768: self.rect.y += int(self.vel) if game_over == False: # jump if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False: self.clicked = True self.vel = -10 jump_sound.stop() jump_sound.set_volume(0.2) jump_sound.play() randomnum = random.randint(1,10) if randomnum == 10 and subway == False: video2_x = random.randint(0, 800) video2_y = random.randint(10, 500) subway = True if pygame.mouse.get_pressed()[0] == 0: self.clicked = False # handle animation self.count += 1 # Change 'self.counter' to 'self.count' flap_cooldown = 5 if self.count > flap_cooldown: self.count = 0 self.index += 1 if self.index >= len(self.images): self.index = 0 self.image = self.images[self.index] #rotate the bird self.image = pygame.transform.rotate(self.images[self.index], self.vel * -12) #thing that makes it funny spin class Pipe(pygame.sprite.Sprite): def __init__(self, x, y, position): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load('img/birdpipe.png') self.rect = self.image.get_rect() # posotion 1 is from th e top, -1 is for the bottom if position == 1: self.image = pygame.transform.flip(self.image, False, True) self.rect.bottomleft = [x,y - int(pipe_gap / 2)] if position == -1: self.rect.topleft = [x,y + int(pipe_gap / 2)] def update(self): self.rect.x -= scroll_speed if self.rect.right < 0: self.kill() bird_group = pygame.sprite.Group() pipe_group = pygame.sprite.Group() flappy = Bird(100, int(screen_height / 2)) bird_group.add(flappy) run = True while run: #draw bacground screen.blit(bg, (0, 0)) bird_group.draw(screen) bird_group.update() pipe_group.draw(screen) # draw the ground screen.blit(ground_img, (ground_scroll, 768)) # check the scire if len(pipe_group) > 0: if bird_group.sprites()[0].rect.left > pipe_group.sprites()[0].rect.left\ and bird_group.sprites()[0].rect.right < pipe_group.sprites()[0].rect.right\ and pass_pipe == False: pass_pipe = True if pass_pipe == True: if bird_group.sprites()[0].rect.left > pipe_group.sprites()[0].rect.right: score += 1 pass_pipe = False draw_text(str(score), font, white, int(screen_width) / 2, 20) #look for colisin if pygame.sprite.groupcollide(bird_group, pipe_group, False, False) or flappy.rect.top < 0: if not game_over: game_over = True flying = False MOVIE.set(cv2.CAP_PROP_POS_FRAMES, 0) # Restart video from the beginning #chec kif bird game over :( if flappy.rect.bottom >= 768 and game_over == False: game_over = True flying = False MOVIE.set(cv2.CAP_PROP_POS_FRAMES, 0) # Restart video from the beginning if game_over == False: #generate new puipes time_now = pygame.time.get_ticks() if time_now - last_pipe > pipe_frequency and flying == True: pipe_height = random.randint(-100, 100) btm_pipe = Pipe(screen_width, int(screen_height / 2) + pipe_height, -1) top_pipe = Pipe(screen_width, int(screen_height / 2) + pipe_height, 1) pipe_group.add(btm_pipe) pipe_group.add(top_pipe) last_pipe = time_now if flying == True: #draw bad tegesikk tge griybd ground_scroll -= scroll_speed if abs(ground_scroll) > 35: ground_scroll = 0 pipe_group.update() if game_over and score < 1: pygame.mixer.music.stop() if not robloxstory.isOpened(): # Check if the video file opened properly print("Error: Video file could not be opened") else: screen1 = pygame.display.set_mode((1280, 720)) sadstory = pygame.mixer.Sound('robloxsadstory.mp3') sadstory.play() while robloxstory.isOpened(): success3, video_image3 = robloxstory.read() if not success3: pygame.QUIT() sys.exit() # Convert OpenCV image to Pygame surface video_surf3 = pygame.image.frombuffer(video_image3.tobytes(), video_image3.shape[1::-1], "BGR") # Blit and update display screen1.blit(video_surf3, (0, 0)) pygame.display.update() clock.tick(max_fps) # Event handling (blocks quitting) for event in pygame.event.get(): if event.type == pygame.QUIT: print("nah") robloxstory.release() # Release video when done if game_over == True and score >=1: pygame.mixer.music.stop() pygame.mixer.Sound('deathsound.mp3').play() success, video_image = MOVIE.read() if success: video_width = 225 video_height = 225 video_surf = pygame.image.frombuffer(video_image.tobytes(), video_image.shape[1::-1], "BGR") video_surf = pygame.transform.scale(video_surf, (video_width, video_height)) video_surf1 = pygame.image.frombuffer(video_image.tobytes(), video_image.shape[1::-1], "BGR") video_x = 10 video_y = 10 screen.blit(video_surf1, (0,0)) screen.blit(video_surf, (video_x, video_y)) else: # End the game once the video finishes print(score) pygame.quit() sys.exit() if subway == True and game_over == False: success2, video_image2 = subwaysurfer.read() if success2: if 'start_time2' not in locals() or current_time2 - start_time2 >= 10000: start_time2 = pygame.time.get_ticks() video_surf2 = pygame.image.frombuffer(video_image2.tobytes(), video_image2.shape[1::-1], "BGR") orig_width, orig_height = video_image2.shape[1], video_image2.shape[0] target_width = 250 aspect_ratio = orig_width / orig_height target_height = int(target_width / aspect_ratio) scaled_video_surf2 = pygame.transform.scale(video_surf2, (target_width, target_height)) current_time2 = pygame.time.get_ticks() if current_time2 - start_time2 >= 10000: subway = False else: screen.blit(scaled_video_surf2, (video2_x, video2_y)) else: subway = False for event in pygame.event.get(): if event.type == pygame.QUIT: print(score) pygame.quit() sys.exit() run = False if event.type == pygame.MOUSEBUTTONDOWN and flying == False and game_over == False: flying = True # Restart game if event.type == pygame.MOUSEBUTTONDOWN and game_over == True: game_over = False flying = False flappy.rect.center = (100, screen_height // 2) flappy.vel = 0 pygame.display.update() clock.tick(max_fps)