{"id":39,"date":"2024-09-26T14:09:37","date_gmt":"2024-09-26T14:09:37","guid":{"rendered":"https:\/\/theroyalscode.com\/students\/l_rankins\/?p=39"},"modified":"2024-10-04T14:06:12","modified_gmt":"2024-10-04T14:06:12","slug":"blog-two-maddness-ensues","status":"publish","type":"post","link":"https:\/\/theroyalscode.com\/students\/l_rankins\/2024\/09\/26\/blog-two-maddness-ensues\/","title":{"rendered":"BLOG TWO: MADDNESS ENSUES"},"content":{"rendered":"\n<p>Today I used a tutorial to make ALL of flappy bird<\/p>\n\n\n\n<p>THIS IS THE CODE<\/p>\n\n\n\n<p>import pygame<\/p>\n\n\n\n<p>from pygame.locals import *<\/p>\n\n\n\n<p>import random<\/p>\n\n\n\n<p>pygame.init()<\/p>\n\n\n\n<p>clock = pygame.time.Clock()<\/p>\n\n\n\n<p>fps = 60<\/p>\n\n\n\n<p>screen_width = 864<\/p>\n\n\n\n<p>screen_height = 936<\/p>\n\n\n\n<p>screen = pygame.display.set_mode((screen_width, screen_height))<\/p>\n\n\n\n<p>pygame.display.set_caption(&#8216;POLLUTION BIRD&#8217;)<\/p>\n\n\n\n<p>#define font<\/p>\n\n\n\n<p>font = pygame.font.SysFont(&#8216;Bauhaus 93&#8217;, 60)<\/p>\n\n\n\n<p>#define colours<\/p>\n\n\n\n<p>white = (255, 255, 255)<\/p>\n\n\n\n<p>#define game variables<\/p>\n\n\n\n<p>ground_scroll = 0<\/p>\n\n\n\n<p>scroll_speed = 4<\/p>\n\n\n\n<p>flying = False<\/p>\n\n\n\n<p>game_over = False<\/p>\n\n\n\n<p>pipe_gap = 150<\/p>\n\n\n\n<p>pipe_frequency = 1500 #milliseconds<\/p>\n\n\n\n<p>last_pipe = pygame.time.get_ticks() &#8211; pipe_frequency<\/p>\n\n\n\n<p>score = 0<\/p>\n\n\n\n<p>pass_pipe = False<\/p>\n\n\n\n<p>#load images<\/p>\n\n\n\n<p>bg = pygame.image.load(&#8216;bg.png&#8217;)<\/p>\n\n\n\n<p>ground_img = pygame.image.load(&#8216;ground.png&#8217;)<\/p>\n\n\n\n<p>button_img = pygame.image.load(&#8216;restart.png&#8217;)<\/p>\n\n\n\n<p>#function for outputting text onto the screen<\/p>\n\n\n\n<p>def draw_text(text, font, text_col, x, y):<\/p>\n\n\n\n<p>&nbsp; &nbsp; img = font.render(text, True, text_col)<\/p>\n\n\n\n<p>&nbsp; &nbsp; screen.blit(img, (x, y))<\/p>\n\n\n\n<p>def reset_game():<\/p>\n\n\n\n<p>&nbsp; &nbsp; pipe_group.empty()<\/p>\n\n\n\n<p>&nbsp; &nbsp; flappy.rect.x = 100<\/p>\n\n\n\n<p>&nbsp; &nbsp; flappy.rect.y = int(screen_height \/ 2)<\/p>\n\n\n\n<p>&nbsp; &nbsp; score = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; return score<\/p>\n\n\n\n<p>class Bird(pygame.sprite.Sprite):<\/p>\n\n\n\n<p>&nbsp; &nbsp; def __init__(self, x, y):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; pygame.sprite.Sprite.__init__(self)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.images = []<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.index = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.counter = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; for num in range (1, 4):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; img = pygame.image.load(f&#8221;bird{num}.png&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.images.append(img)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.image = self.images[self.index]<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.rect = self.image.get_rect()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.rect.center = [x, y]<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.vel = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.clicked = False<\/p>\n\n\n\n<p>&nbsp; &nbsp; def update(self):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if flying == True:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #apply gravity<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.vel += 0.5<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if self.vel &gt; 8:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.vel = 8<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if self.rect.bottom &lt; 768:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.rect.y += int(self.vel)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if game_over == False:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #jump<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.clicked = True<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.vel = -10<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if pygame.mouse.get_pressed()[0] == 0:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.clicked = False<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #handle the animation<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flap_cooldown = 5<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.counter += 1<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if self.counter &gt; flap_cooldown:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.counter = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.index += 1<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if self.index &gt;= len(self.images):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.index = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.image = self.images[self.index]<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #rotate the bird<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.image = pygame.transform.rotate(self.images[self.index], self.vel * -2)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; else:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #point the bird at the ground<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.image = pygame.transform.rotate(self.images[self.index], -90)<\/p>\n\n\n\n<p>class Pipe(pygame.sprite.Sprite):<\/p>\n\n\n\n<p>&nbsp; &nbsp; def __init__(self, x, y, position):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; pygame.sprite.Sprite.__init__(self)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.image = pygame.image.load(&#8220;pipe.png&#8221;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.rect = self.image.get_rect()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; #position variable determines if the pipe is coming from the bottom or top<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; #position 1 is from the top, -1 is from the bottom<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if position == 1:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.image = pygame.transform.flip(self.image, False, True)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.rect.bottomleft = [x, y &#8211; int(pipe_gap \/ 2)]<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; elif position == -1:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.rect.topleft = [x, y + int(pipe_gap \/ 2)]<\/p>\n\n\n\n<p>&nbsp; &nbsp; def update(self):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.rect.x -= scroll_speed<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if self.rect.right &lt; 0:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.kill()<\/p>\n\n\n\n<p>class Button():<\/p>\n\n\n\n<p>&nbsp; &nbsp; def __init__(self, x, y, image):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.image = image<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.rect = self.image.get_rect()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.rect.topleft = (x, y)<\/p>\n\n\n\n<p>&nbsp; &nbsp; def draw(self):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; action = False<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; #get mouse position<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; pos = pygame.mouse.get_pos()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; #check mouseover and clicked conditions<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if self.rect.collidepoint(pos):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if pygame.mouse.get_pressed()[0] == 1:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action = True<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; #draw button<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; screen.blit(self.image, (self.rect.x, self.rect.y))<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; return action<\/p>\n\n\n\n<p>pipe_group = pygame.sprite.Group()<\/p>\n\n\n\n<p>bird_group = pygame.sprite.Group()<\/p>\n\n\n\n<p>flappy = Bird(100, int(screen_height \/ 2))<\/p>\n\n\n\n<p>bird_group.add(flappy)<\/p>\n\n\n\n<p>#create restart button instance<\/p>\n\n\n\n<p>button = Button(screen_width \/\/ 2 &#8211; 50, screen_height \/\/ 2 &#8211; 100, button_img)<\/p>\n\n\n\n<p>run = True<\/p>\n\n\n\n<p>while run:<\/p>\n\n\n\n<p>&nbsp; &nbsp; clock.tick(fps)<\/p>\n\n\n\n<p>&nbsp; &nbsp; #draw background<\/p>\n\n\n\n<p>&nbsp; &nbsp; screen.blit(bg, (0,0))<\/p>\n\n\n\n<p>&nbsp; &nbsp; pipe_group.draw(screen)<\/p>\n\n\n\n<p>&nbsp; &nbsp; bird_group.draw(screen)<\/p>\n\n\n\n<p>&nbsp; &nbsp; bird_group.update()<\/p>\n\n\n\n<p>&nbsp; &nbsp; #draw and scroll the ground<\/p>\n\n\n\n<p>&nbsp; &nbsp; screen.blit(ground_img, (ground_scroll, 768))<\/p>\n\n\n\n<p>&nbsp; &nbsp; #check the score<\/p>\n\n\n\n<p>&nbsp; &nbsp; if len(pipe_group) &gt; 0:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if bird_group.sprites()[0].rect.left &gt; pipe_group.sprites()[0].rect.left\\<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and bird_group.sprites()[0].rect.right &lt; pipe_group.sprites()[0].rect.right\\<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and pass_pipe == False:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pass_pipe = True<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if pass_pipe == True:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if bird_group.sprites()[0].rect.left &gt; pipe_group.sprites()[0].rect.right:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; score += 1<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pass_pipe = False<\/p>\n\n\n\n<p>&nbsp; &nbsp; draw_text(str(score), font, white, int(screen_width \/ 2), 20)<\/p>\n\n\n\n<p>&nbsp; &nbsp; #look for collision<\/p>\n\n\n\n<p>&nbsp; &nbsp; if pygame.sprite.groupcollide(bird_group, pipe_group, False, False) or flappy.rect.top &lt; 0:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; game_over = True<\/p>\n\n\n\n<p>&nbsp; &nbsp; #once the bird has hit the ground it&#8217;s game over and no longer flying<\/p>\n\n\n\n<p>&nbsp; &nbsp; if flappy.rect.bottom &gt;= 768:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; game_over = True<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; flying = False<\/p>\n\n\n\n<p>&nbsp; &nbsp; if flying == True and game_over == False:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; #generate new pipes<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; time_now = pygame.time.get_ticks()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if time_now &#8211; last_pipe &gt; pipe_frequency:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pipe_height = random.randint(-100, 100)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; btm_pipe = Pipe(screen_width, int(screen_height \/ 2) + pipe_height, -1)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top_pipe = Pipe(screen_width, int(screen_height \/ 2) + pipe_height, 1)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pipe_group.add(btm_pipe)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pipe_group.add(top_pipe)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last_pipe = time_now<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; pipe_group.update()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; ground_scroll -= scroll_speed<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if abs(ground_scroll) &gt; 35:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ground_scroll = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; #check for game over and reset<\/p>\n\n\n\n<p>&nbsp; &nbsp; if game_over == True:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if button.draw():<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; game_over = False<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; score = reset_game()<\/p>\n\n\n\n<p>&nbsp; &nbsp; for event in pygame.event.get():<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if event.type == pygame.QUIT:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; run = False<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if event.type == pygame.MOUSEBUTTONDOWN and flying == False and game_over == False:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flying = True<\/p>\n\n\n\n<p>&nbsp; &nbsp; pygame.display.update()<\/p>\n\n\n\n<p>pygame.quit()<\/p>\n\n\n\n<p>bg = pygame.image.load(&#8216;bg.png&#8217;)<\/p>\n\n\n\n<p>ground_img = pygame.image.load(&#8216;ground.png&#8217;)<\/p>\n\n\n\n<p>class Bird(pygame.sprite.Sprite):<\/p>\n\n\n\n<p>&nbsp; &nbsp; def __init__(self, x, y):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; pygame.sprite.Sprite.__init__(self)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.images = []<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.index = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.counter = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; for num in range(1, 4):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; img = pygame.image.load(f&#8217;bird{num}.png&#8217;)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.images.append(img)<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.image = self.images[self.index]<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.rect = self.image.get_rect()<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.rect.center = [x, y]<\/p>\n\n\n\n<p>&nbsp; &nbsp; def update(self):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; #handle the animation<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.counter += 1<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; flap_cooldown = 5<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if self.counter &gt; flap_cooldown:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.counter = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.index += 1<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if self.index &gt;= len(self.images):<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.index = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; self.image = self.images[self.index]<\/p>\n\n\n\n<p>bird_group = pygame.sprite.Group()<\/p>\n\n\n\n<p>flappy = Bird(100, int(screen_height \/ 2))<\/p>\n\n\n\n<p>bird_group.add(flappy)<\/p>\n\n\n\n<p>run = True<\/p>\n\n\n\n<p>while run:<\/p>\n\n\n\n<p>&nbsp; &nbsp; clock.tick(fps)<\/p>\n\n\n\n<p>&nbsp; &nbsp; #draw background<\/p>\n\n\n\n<p>&nbsp; &nbsp; screen.blit(bg, (0,0))<\/p>\n\n\n\n<p>&nbsp; &nbsp; bird_group.draw(screen)<\/p>\n\n\n\n<p>&nbsp; &nbsp; bird_group.update()<\/p>\n\n\n\n<p>&nbsp; &nbsp; #draw and scroll the ground<\/p>\n\n\n\n<p>&nbsp; &nbsp; screen.blit(ground_img, (ground_scroll, 768))<\/p>\n\n\n\n<p>&nbsp; &nbsp; ground_scroll -= scroll_speed<\/p>\n\n\n\n<p>&nbsp; &nbsp; if abs(ground_scroll) &gt; 35:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; ground_scroll = 0<\/p>\n\n\n\n<p>&nbsp; &nbsp; for event in pygame.event.get():<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if event.type == pygame.QUIT:<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; run = False<\/p>\n\n\n\n<p>&nbsp; &nbsp; pygame.display.update()<\/p>\n\n\n\n<p>pygame.quit()<\/p>\n\n\n\n<p>you will need a few images<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"864\" height=\"768\" src=\"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/bg.png\" alt=\"\" class=\"wp-image-40\" srcset=\"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/bg.png 864w, https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/bg-300x267.png 300w, https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/bg-768x683.png 768w\" sizes=\"auto, (max-width: 864px) 100vw, 864px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"168\" src=\"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/ground.png\" alt=\"\" class=\"wp-image-41\" srcset=\"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/ground.png 900w, https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/ground-300x56.png 300w, https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/ground-768x143.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"51\" height=\"36\" src=\"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/bird1.png\" alt=\"\" class=\"wp-image-42\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"51\" height=\"36\" src=\"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/bird2.png\" alt=\"\" class=\"wp-image-43\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"51\" height=\"36\" src=\"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/bird3-1.png\" alt=\"\" class=\"wp-image-45\" style=\"width:49px;height:auto\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"78\" height=\"560\" src=\"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/pipe-1.png\" alt=\"\" class=\"wp-image-49\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"120\" height=\"42\" src=\"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-content\/uploads\/2024\/09\/restart-1.png\" alt=\"\" class=\"wp-image-50\"\/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I used a tutorial to make ALL of flappy bird THIS IS THE CODE import pygame from pygame.locals import [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":2,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":51,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/posts\/39\/revisions\/51"}],"wp:attachment":[{"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theroyalscode.com\/students\/l_rankins\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}