diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 5008ddf..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..af61997 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: prateekiiest +patreon: # Replace with a single Patreon username +open_collective: prateekiiest +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: https://opencollective.com/codepython/contribute diff --git a/.gitignore b/.gitignore index 894a44c..0630d69 100644 --- a/.gitignore +++ b/.gitignore @@ -72,6 +72,9 @@ target/ # Jupyter Notebook .ipynb_checkpoints +# VS Code +.vscode/ + # pyenv .python-version @@ -102,3 +105,5 @@ venv.bak/ # mypy .mypy_cache/ + +.DS_Store diff --git a/Code-Sleep-Python/Bird_migration/code.py b/Code-Sleep-Python/Bird_migration/code.py index 30f0e61..98c6a74 100644 --- a/Code-Sleep-Python/Bird_migration/code.py +++ b/Code-Sleep-Python/Bird_migration/code.py @@ -1,3 +1,12 @@ +import pandas as pd +import matplotlib.pyplot as plt +import numpy as np + +# Import bird data +birddata = pd.read_csv('https://d37djvu3ytnwxt.cloudfront.net/assets/' +'courseware/v1/c72498a54a4513c2eb4ec005adc0010c/' +'asset-v1:HarvardX+PH526x+3T2016+type@asset+block/bird_tracking.csv') + # First, use `groupby` to group up the data. grouped_birds = birddata.groupby("bird_name") @@ -5,7 +14,9 @@ mean_speeds = grouped_birds.speed_2d.mean() # The `head` method prints the first 5 lines of each bird. -grouped_birds.head() +# This is useful if you are running this in ipython and need to see some data. +# Call this only on pandas data frame. +# mean_speeds.head() # Find the mean `altitude` for each bird. # Assign this to `mean_altitudes`. @@ -13,16 +24,14 @@ mean_altitudes = grouped_birds.altitude.mean() - - # Convert birddata.date_time to the `pd.datetime` format. birddata.date_time = pd.to_datetime(birddata.date_time) # Create a new column of day of observation birddata["date"] = birddata.date_time.dt.date -# Check the head of the column. -birddata.date.head() +# If you're in ipython and want to check the head of the column run: +# birddata.date.head() grouped_bydates = birddata.groupby("date") mean_altitudes_perday = grouped_bydates.altitude.mean() @@ -33,8 +42,8 @@ grouped_birdday = birddata.groupby(["bird_name","date"]) mean_altitudes_perday = grouped_birdday.altitude.mean() -# look at the head of `mean_altitudes_perday`. -mean_altitudes_perday.head() +# If you're in ipython and want to look at the head of `mean_altitudes_perday` run: +# mean_altitudes_perday.head() grouped_birdday = birddata.groupby(["bird_name","date"]) @@ -48,4 +57,5 @@ sanne_daily_speed.plot(label="Sanne") nico_daily_speed.plot(label="Nico") plt.legend(loc="upper left") +plt.ylabel("2D mean speed (m/s)") plt.show() diff --git a/Code-Sleep-Python/Bird_migration/requirements.txt b/Code-Sleep-Python/Bird_migration/requirements.txt new file mode 100644 index 0000000..a225a6b --- /dev/null +++ b/Code-Sleep-Python/Bird_migration/requirements.txt @@ -0,0 +1,9 @@ +cycler==0.10.0 +kiwisolver==1.1.0 +matplotlib==3.1.1 +numpy==1.22.0 +pandas==0.25.2 +pyparsing==2.4.2 +python-dateutil==2.8.0 +pytz==2019.3 +six==1.12.0 diff --git a/Code-Sleep-Python/Caesar-cipher/code.py b/Code-Sleep-Python/Caesar-cipher/code.py index 36994ab..ff5a988 100644 --- a/Code-Sleep-Python/Caesar-cipher/code.py +++ b/Code-Sleep-Python/Caesar-cipher/code.py @@ -1,23 +1,23 @@ import string -string.ascii_lowercase +import argparse +string.ascii_lowercase # We will consider the alphabet to be these letters, along with a space. # create `letters` here! - - -## alphabet = string.ascii_lowercase + " " letters = dict(enumerate(alphabet)) -# define `coded_message` here! - +p = argparse.ArgumentParser(description="Implement Caesar Cipher Algorithm") +p.add_argument("-e", "-encription_key", help="encription key") +p.add_argument("-m", "-message", help="message") +args = p.parse_args() ################## -message = raw_input("Enter a string: ") +message = args.m def caesar(mee, encryption_key): @@ -45,7 +45,7 @@ def caesar(mee, encryption_key): return encoded_mess -encryption_key=input("Enter a number: ") +encryption_key = args.e encoded_message = (caesar(message,encryption_key)) print(encoded_message) diff --git a/Code-Sleep-Python/Classification/requirements.txt b/Code-Sleep-Python/Classification/requirements.txt index 3922f12..2c970b0 100644 --- a/Code-Sleep-Python/Classification/requirements.txt +++ b/Code-Sleep-Python/Classification/requirements.txt @@ -1,4 +1,4 @@ -numpy==1.13.3 +numpy==1.22.0 pandas==0.21.0 matplotlib==2.1.0 scikit-learn==0.19.1 \ No newline at end of file diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/blue1.png b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/blue1.png new file mode 100644 index 0000000..d82802a Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/blue1.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/blue2.png b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/blue2.png new file mode 100644 index 0000000..034b76c Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/blue2.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/blue3.png b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/blue3.png new file mode 100644 index 0000000..900d012 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/blue3.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/red1.png b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/red1.png new file mode 100644 index 0000000..e853b95 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/red1.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/red2.png b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/red2.png new file mode 100644 index 0000000..a915f7e Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/red2.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/red3.png b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/red3.png new file mode 100644 index 0000000..f9ed856 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/red3.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/yellow1.png b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/yellow1.png new file mode 100644 index 0000000..e9e1c77 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/yellow1.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/yellow2.png b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/yellow2.png new file mode 100644 index 0000000..2ca3c2d Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/yellow2.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/yellow3.png b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/yellow3.png new file mode 100644 index 0000000..2f693da Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Grumpy/yellow3.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Score/0.png b/Code-Sleep-Python/Flappy Bird/Assets/Score/0.png new file mode 100644 index 0000000..ad522b9 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Score/0.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Score/1.png b/Code-Sleep-Python/Flappy Bird/Assets/Score/1.png new file mode 100644 index 0000000..55d7c89 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Score/1.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Score/2.png b/Code-Sleep-Python/Flappy Bird/Assets/Score/2.png new file mode 100644 index 0000000..6a3af46 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Score/2.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Score/3.png b/Code-Sleep-Python/Flappy Bird/Assets/Score/3.png new file mode 100644 index 0000000..13d88bf Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Score/3.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Score/4.png b/Code-Sleep-Python/Flappy Bird/Assets/Score/4.png new file mode 100644 index 0000000..51cbbc3 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Score/4.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Score/5.png b/Code-Sleep-Python/Flappy Bird/Assets/Score/5.png new file mode 100644 index 0000000..b5055ab Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Score/5.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Score/6.png b/Code-Sleep-Python/Flappy Bird/Assets/Score/6.png new file mode 100644 index 0000000..dbc4c00 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Score/6.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Score/7.png b/Code-Sleep-Python/Flappy Bird/Assets/Score/7.png new file mode 100644 index 0000000..04658ad Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Score/7.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Score/8.png b/Code-Sleep-Python/Flappy Bird/Assets/Score/8.png new file mode 100644 index 0000000..f053e38 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Score/8.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/Score/9.png b/Code-Sleep-Python/Flappy Bird/Assets/Score/9.png new file mode 100644 index 0000000..3bd0412 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/Score/9.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/background-day.png b/Code-Sleep-Python/Flappy Bird/Assets/background-day.png new file mode 100644 index 0000000..afcb5ec Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/background-day.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/background-night.png b/Code-Sleep-Python/Flappy Bird/Assets/background-night.png new file mode 100644 index 0000000..e2a2b89 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/background-night.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/base.png b/Code-Sleep-Python/Flappy Bird/Assets/base.png new file mode 100644 index 0000000..c374f2b Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/base.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/flappybird.png b/Code-Sleep-Python/Flappy Bird/Assets/flappybird.png new file mode 100644 index 0000000..d74f2cf Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/flappybird.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/gameover.png b/Code-Sleep-Python/Flappy Bird/Assets/gameover.png new file mode 100644 index 0000000..b1df7f5 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/gameover.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/pipe-green.png b/Code-Sleep-Python/Flappy Bird/Assets/pipe-green.png new file mode 100644 index 0000000..4664401 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/pipe-green.png differ diff --git a/Code-Sleep-Python/Flappy Bird/Assets/pipe-red.png b/Code-Sleep-Python/Flappy Bird/Assets/pipe-red.png new file mode 100644 index 0000000..ab6e065 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Assets/pipe-red.png differ diff --git a/Code-Sleep-Python/Flappy Bird/README.md b/Code-Sleep-Python/Flappy Bird/README.md new file mode 100644 index 0000000..e4d44d6 --- /dev/null +++ b/Code-Sleep-Python/Flappy Bird/README.md @@ -0,0 +1,39 @@ +# Flappy Bird + +[](https://forthebadge.com) +[](https://forthebadge.com) +[](https://forthebadge.com) + +Flappy Bird is an implementation of the famous flappy bird game in pygame. The game is specifically meant to run on pydroid3 on android, It may not work properly in desktop. + +Install pydroid3 on Android from here : [pydroid3 playstore](https://play.google.com/store/apps/details?id=ru.iiec.pydroid3&hl=en_IN&gl=US) + + + +## How to Download + +Download this project from here [Download Flappy Bird](https://downgit.github.io/#/home?url=https://github.com/pyGuru123/Python-Games/tree/master/Flappy%20Bird) + +## Requirements + +Use the package manager [pip](https://pip.pypa.io/en/stable/) to install following packages :- +* Pygame + +```bash +pip install pygame +``` + +pygame is already installed in pydroid3, no installation required. + +## Usage + +Navigate and click main.py to open the game in pydroid3, tap anywhere to start the game. The objective of the game is jump and pass through the poles without touching them. + +Controls: +* Tap on the screen to make the bird jump. + +## Contributing + +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. + +Please make sure to update tests as appropriate. \ No newline at end of file diff --git a/Code-Sleep-Python/Flappy Bird/Sounds/die.wav b/Code-Sleep-Python/Flappy Bird/Sounds/die.wav new file mode 100644 index 0000000..9b79fbd Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Sounds/die.wav differ diff --git a/Code-Sleep-Python/Flappy Bird/Sounds/hit.wav b/Code-Sleep-Python/Flappy Bird/Sounds/hit.wav new file mode 100644 index 0000000..9d9b77c Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Sounds/hit.wav differ diff --git a/Code-Sleep-Python/Flappy Bird/Sounds/point.wav b/Code-Sleep-Python/Flappy Bird/Sounds/point.wav new file mode 100644 index 0000000..9cf19fe Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Sounds/point.wav differ diff --git a/Code-Sleep-Python/Flappy Bird/Sounds/swoosh.wav b/Code-Sleep-Python/Flappy Bird/Sounds/swoosh.wav new file mode 100644 index 0000000..bcae63e Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Sounds/swoosh.wav differ diff --git a/Code-Sleep-Python/Flappy Bird/Sounds/wing.wav b/Code-Sleep-Python/Flappy Bird/Sounds/wing.wav new file mode 100644 index 0000000..9ae2c67 Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/Sounds/wing.wav differ diff --git a/Code-Sleep-Python/Flappy Bird/app.webp b/Code-Sleep-Python/Flappy Bird/app.webp new file mode 100644 index 0000000..67672ad Binary files /dev/null and b/Code-Sleep-Python/Flappy Bird/app.webp differ diff --git a/Code-Sleep-Python/Flappy Bird/main.py b/Code-Sleep-Python/Flappy Bird/main.py new file mode 100644 index 0000000..ab54e93 --- /dev/null +++ b/Code-Sleep-Python/Flappy Bird/main.py @@ -0,0 +1,160 @@ +import pygame +import random + +from objects import Grumpy, Pipe, Base, Score + +# Setup ******************************************* + +pygame.init() +SCREEN = WIDTH, HEIGHT = 288, 512 +display_height = 0.80 * HEIGHT +info = pygame.display.Info() +width = info.current_w +height = info.current_h + +if width >= height: + win = pygame.display.set_mode(SCREEN, pygame.NOFRAME) +else: + win = pygame.display.set_mode( + SCREEN, pygame.NOFRAME | pygame.SCALED | pygame.FULLSCREEN) + +clock = pygame.time.Clock() +FPS = 60 + +# COLORS + +RED = (255, 0, 0) +WHITE = (255, 255, 255) +BLACK = (0, 0, 0) + +# Backgrounds + +bg1 = pygame.image.load('Assets/background-day.png') +bg2 = pygame.image.load('Assets/background-night.png') + +bg = random.choice([bg1, bg2]) +im_list = [pygame.image.load('Assets/pipe-green.png'), + pygame.image.load('Assets/pipe-red.png')] +pipe_img = random.choice(im_list) + +gameover_img = pygame.image.load('Assets/gameover.png') +flappybird_img = pygame.image.load('Assets/flappybird.png') +flappybird_img = pygame.transform.scale(flappybird_img, (200, 80)) + +# Sounds & fx + + +die_fx = pygame.mixer.Sound('Sounds/die.wav') +hit_fx = pygame.mixer.Sound('Sounds/hit.wav') +point_fx = pygame.mixer.Sound('Sounds/point.wav') +swoosh_fx = pygame.mixer.Sound('Sounds/swoosh.wav') +wing_fx = pygame.mixer.Sound('Sounds/wing.wav') + +# Objects + +pipe_group = pygame.sprite.Group() +base = Base(win) +score_img = Score(WIDTH // 2, 50, win) +grumpy = Grumpy(win) + +# Variables + +base_height = 0.80 * HEIGHT +speed = 0 +game_started = False +game_over = False +restart = False +score = 0 +start_screen = True +pipe_pass = False +pipe_frequency = 1600 + +running = True +while running: + win.blit(bg, (0, 0)) + + if start_screen: + speed = 0 + grumpy.draw_flap() + base.update(speed) + win.blit(flappybird_img, (40, 50)) + else: + + if game_started and not game_over: + + next_pipe = pygame.time.get_ticks() + if next_pipe - last_pipe >= pipe_frequency: + y = display_height // 2 + pipe_pos = random.choice(range(-100, 100, 4)) + height = y + pipe_pos + + top = Pipe(win, pipe_img, height, 1) + bottom = Pipe(win, pipe_img, height, -1) + pipe_group.add(top) + pipe_group.add(bottom) + last_pipe = next_pipe + + pipe_group.update(speed) + base.update(speed) + grumpy.update() + score_img.update(score) + + if (pygame.sprite.spritecollide(grumpy, pipe_group, False) or + grumpy.rect.top <= 0): + game_started = False + if grumpy.alive: + hit_fx.play() + die_fx.play() + grumpy.alive = False + grumpy.theta = grumpy.vel * -2 + + if grumpy.rect.bottom >= display_height: + speed = 0 + game_over = True + + if len(pipe_group) > 0: + p = pipe_group.sprites()[0] + if (grumpy.rect.left > p.rect.left and + grumpy.rect.right < p.rect.right and not pipe_pass + and grumpy.alive): + pipe_pass = True + + if pipe_pass: + if grumpy.rect.left > p.rect.right: + pipe_pass = False + score += 1 + point_fx.play() + + if not grumpy.alive: + win.blit(gameover_img, (50, 200)) + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE or \ + event.key == pygame.K_q: + running = False + if event.type == pygame.MOUSEBUTTONDOWN: + if start_screen: + game_started = True + speed = 2 + start_screen = False + + game_over = False + last_pipe = pygame.time.get_ticks() - pipe_frequency + next_pipe = 0 + pipe_group.empty() + + speed = 2 + score = 0 + + if game_over: + start_screen = True + grumpy = Grumpy(win) + pipe_img = random.choice(im_list) + bg = random.choice([bg1, bg2]) + + clock.tick(FPS) + pygame.display.update() +pygame.quit() diff --git a/Code-Sleep-Python/Flappy Bird/objects.py b/Code-Sleep-Python/Flappy Bird/objects.py new file mode 100644 index 0000000..8c0d813 --- /dev/null +++ b/Code-Sleep-Python/Flappy Bird/objects.py @@ -0,0 +1,153 @@ +import pygame +import random + +SCREEN = WIDTH, HEIGHT = 288, 512 +display_height = 0.80 * HEIGHT + +pygame.mixer.init() +wing_fx = pygame.mixer.Sound('Sounds/wing.wav') + + +class Grumpy: + def __init__(self, win): + self.win = win + + self.im_list = [] + bird_color = random.choice(['red', 'blue', 'yellow']) + for i in range(1, 4): + img = pygame.image.load(f'Assets/Grumpy/{bird_color}{i}.png') + self.im_list.append(img) + + self.reset() + + def update(self): + # gravity + self.vel += 0.3 + if self.vel >= 8: + self.vel = 8 + if self.rect.bottom <= display_height: + self.rect.y += int(self.vel) + + if self.alive: + + # jump + if pygame.mouse.get_pressed()[0] == 1 and not self.jumped: + wing_fx.play() + self.jumped = True + self.vel = -6 + if pygame.mouse.get_pressed()[0] == 0: + self.jumped = False + + self.flap_counter() + + self.image = pygame.transform.rotate( + self.im_list[self.index], self.vel * -2) + else: + if self.rect.bottom <= display_height: + self.theta -= 2 + self.image = pygame.transform.rotate( + self.im_list[self.index], self.theta) + + self.win.blit(self.image, self.rect) + + def flap_counter(self): + self.counter += 1 + if self.counter > 5: + self.counter = 0 + self.index += 1 + if self.index >= 3: + self.index = 0 + + def draw_flap(self): + self.flap_counter() + if self.flap_pos <= -10 or self.flap_pos > 10: + self.flap_inc *= -1 + self.flap_pos += self.flap_inc + self.rect.y += self.flap_inc + self.rect.x = WIDTH // 2 - 20 + self.image = self.im_list[self.index] + self.win.blit(self.image, self.rect) + + def reset(self): + self.index = 0 + self.image = self.im_list[self.index] + self.rect = self.image.get_rect() + self.rect.x = 60 + self.rect.y = int(display_height) // 2 + self.counter = 0 + self.vel = 0 + self.jumped = False + self.alive = True + self.theta = 0 + self.mid_pos = display_height // 2 + self.flap_pos = 0 + self.flap_inc = 1 + + +class Base: + def __init__(self, win): + self.win = win + + self.image1 = pygame.image.load('Assets/base.png') + self.image2 = self.image1 + self.rect1 = self.image1.get_rect() + self.rect1.x = 0 + self.rect1.y = int(display_height) + self.rect2 = self.image2.get_rect() + self.rect2.x = WIDTH + self.rect2.y = int(display_height) + + def update(self, speed): + self.rect1.x -= speed + self.rect2.x -= speed + + if self.rect1.right <= 0: + self.rect1.x = WIDTH - 5 + if self.rect2.right <= 0: + self.rect2.x = WIDTH - 5 + + self.win.blit(self.image1, self.rect1) + self.win.blit(self.image2, self.rect2) + + +class Pipe(pygame.sprite.Sprite): + def __init__(self, win, image, y, position): + super(Pipe, self).__init__() + + self.win = win + self.image = image + self.rect = self.image.get_rect() + pipe_gap = 100 // 2 + x = WIDTH + + if position == 1: + self.image = pygame.transform.flip(self.image, False, True) + self.rect.bottomleft = (x, y - pipe_gap) + elif position == -1: + self.rect.topleft = (x, y + pipe_gap) + + def update(self, speed): + self.rect.x -= speed + if self.rect.right < 0: + self.kill() + self.win.blit(self.image, self.rect) + + +class Score: + def __init__(self, x, y, win): + self.score_list = [] + for score in range(10): + img = pygame.image.load(f'Assets/Score/{score}.png') + self.score_list.append(img) + self.x = x + self.y = y + + self.win = win + + def update(self, score): + score = str(score) + for index, num in enumerate(score): + self.image = self.score_list[int(num)] + self.rect = self.image.get_rect() + self.rect.topleft = self.x - 15 * len(score) + 30 * index, self.y + self.win.blit(self.image, self.rect) diff --git a/Code-Sleep-Python/Link Shortener/README.md b/Code-Sleep-Python/Link Shortener/README.md new file mode 100644 index 0000000..ea51e58 --- /dev/null +++ b/Code-Sleep-Python/Link Shortener/README.md @@ -0,0 +1,23 @@ + + +
+ Python Application | 5 lines of code
+
+
+