forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] master from avinashkranjan:master #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
674a472
Fixed a Typo in the script
fc523c0
Merge pull request #1362 from anveshdange/master
avinashkranjan da47b54
Add files via upload
yashbhangale af0dba1
build(deps): bump tensorflow-gpu in /Traffic-Sign-Detection
dependabot[bot] fdf22b9
build(deps): bump tensorflow in /Traffic-Sign-Detection
dependabot[bot] 87bad9f
Merge pull request #1393 from yashbhangale/master
avinashkranjan 6f112e5
Merge pull request #1395 from avinashkranjan/dependabot/pip/Traffic-S...
avinashkranjan 19495cd
Merge pull request #1394 from avinashkranjan/dependabot/pip/Traffic-S...
avinashkranjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
pong-pygame/Assets/ball.png
Binary file added
pong-pygame/Assets/paddle.png
14 changes: 14 additions & 0 deletions
pong-pygame/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Pygame_pong | ||
|
||
useage: | ||
|
||
install python from ['https://www.python.org/downloads/'] | ||
|
||
>> pip install pygame | ||
|
||
``` | ||
python main.py | ||
``` | ||
|
||
|
||
 |
83 changes: 83 additions & 0 deletions
pong-pygame/pong.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import pygame | ||
# Initialize pygame | ||
|
||
pygame.init() # Initialize pygame | ||
|
||
# Set the window size | ||
screen = pygame.display.set_mode((600, 400)) # Set the window size | ||
|
||
# Set the title of the window | ||
pygame.display.set_caption("Pong") # Set the title of the window | ||
|
||
# Set up the game clock | ||
clock = pygame.time.Clock() # Set up the game clock | ||
|
||
# Load the images for the ball and paddles | ||
ball_image = pygame.image.load("Assets/ball.png") | ||
paddle_image = pygame.image.load("Assets/paddle.png") | ||
|
||
# Create the ball sprite | ||
ball = pygame.sprite.Sprite() # Create the ball sprite | ||
ball.image = ball_image # Load the ball image | ||
ball.rect = ball.image.get_rect() # Get the ball's rects | ||
|
||
# Create the paddles | ||
left_paddle = pygame.sprite.Sprite() # Create the left paddle | ||
left_paddle.image = paddle_image # Load the left paddle image | ||
left_paddle.rect = left_paddle.image.get_rect() # Get the left paddle's rect | ||
|
||
right_paddle = pygame.sprite.Sprite() # Create the right paddle | ||
right_paddle.image = paddle_image # Load the right paddle image | ||
right_paddle.rect = right_paddle.image.get_rect() # Get the right paddle's rect | ||
|
||
# Set the initial positions of the ball and paddles | ||
ball.rect.center = (300, 200) # Set the ball's initial position | ||
left_paddle.rect.left = 20 # Set the left paddle's initial position | ||
left_paddle.rect.centery = 200 # Set the left paddle's initial position | ||
right_paddle.rect.right = 580 # Set the right paddle's initial position | ||
right_paddle.rect.centery = 200 # Set the right paddle's initial position | ||
|
||
# Set the ball's initial velocity | ||
ball_vx = 5 # | ||
ball_vy = 5 # | ||
|
||
# Game loop | ||
while True: # | ||
# Handle events | ||
for event in pygame.event.get(): # Handle events | ||
if event.type == pygame.QUIT: # Handle the QUIT event | ||
pygame.quit() # Quit pygame | ||
exit() # Exit the program | ||
|
||
# Update game state | ||
ball.rect.x += ball_vx # Update the ball's x position | ||
ball.rect.y += ball_vy # Update the ball's y position | ||
|
||
# Update game state | ||
keys = pygame.key.get_pressed() # Get the keys that are pressed | ||
if keys[pygame.K_UP]: # Check if the up key is pressed | ||
right_paddle.rect.y -= 5 # Update the right paddle's y position | ||
if keys[pygame.K_DOWN]: # Check if the down key is pressed | ||
right_paddle.rect.y += 5 # Update the right paddle's y position | ||
if keys[pygame.K_w]: # Check if the w key is pressed | ||
left_paddle.rect.y -= 5 # Update the left paddle's y position | ||
if keys[pygame.K_s]: # Check if the s key is pressed | ||
left_paddle.rect.y += 5 # Update the left paddle's y position | ||
|
||
# Check for ball collision with paddles | ||
if ball.rect.colliderect(left_paddle.rect) or ball.rect.colliderect(right_paddle.rect): # Check for ball collision with paddles | ||
ball_vx = -ball_vx # Reverse the ball's x velocity | ||
|
||
# Check for ball collision with walls | ||
if ball.rect.top < 0 or ball.rect.bottom > 400: # Check for ball collision with walls | ||
ball_vy = -ball_vy # Reverse the ball's y velocity | ||
|
||
# Draw the screen | ||
screen.fill((0, 0, 0)) # Fill the screen with black | ||
screen.blit(ball.image, ball.rect) # Draw the ball | ||
screen.blit(left_paddle.image, left_paddle.rect) # Draw the left paddle | ||
screen.blit(right_paddle.image, right_paddle.rect) # Draw the right paddle | ||
pygame.display.flip() # Update the display | ||
|
||
# Limit the frame rate | ||
clock.tick(60) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.