Skip to content
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

Sourcery refactored master branch #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 18 additions & 26 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
enemyY_change = []
num_of_enemies = 6

for i in range(num_of_enemies):
for _ in range(num_of_enemies):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 40-40 refactored with the following changes:

enemyImg.append(pg.image.load("real enemy.png"))
enemyX.append(rd.randint(0, 735)) # 335
enemyY.append(rd.randint(50, 150)) # 2
Expand Down Expand Up @@ -69,7 +69,7 @@
over_font = pg.font.Font('freesansbold.ttf', 64)

def show_score(x, y):
score = font.render("Score :" + str(score_value), True, (255, 255, 255))
score = font.render(f"Score :{str(score_value)}", True, (255, 255, 255))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function show_score refactored with the following changes:

screen.blit(score, (x, y))

def game_over_text():
Expand All @@ -90,10 +90,7 @@ def fire_bullet(x, y):

def isCollision(enemyX, enemyY, bulletX, bulletY):
distance = mt.sqrt((mt.pow(enemyX-bulletX-28, 2)) + (mt.pow(enemyY-bulletY, 2)))
if distance < 27:
return True
else:
return False
return distance < 27
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function isCollision refactored with the following changes:



# Game Loop
Expand All @@ -116,25 +113,22 @@ def isCollision(enemyX, enemyY, bulletX, bulletY):
playerX_change = -5
if event.key == pg.K_RIGHT:
playerX_change = 5
if event.key == pg.K_KP_ENTER:
if bullet_state is 'ready':
# Get the current x cordinate of the spaceship
bulletX = playerX
fire_bullet(bulletX, bulletY)
if event.key == pg.K_SPACE:
if bullet_state is 'ready':
# Get the current x cordinate of the spaceship
bullet_sound = mixer.Sound("laser.wav")
bullet_sound.set_volume(0.2)
bullet_sound.play()
bulletX = playerX
fire_bullet(bulletX, bulletY)
if event.key == pg.KMOD_ALT or event.key == pg.K_F4:
if event.key == pg.K_KP_ENTER and bullet_state is 'ready':
# Get the current x cordinate of the spaceship
bulletX = playerX
fire_bullet(bulletX, bulletY)
if event.key == pg.K_SPACE and bullet_state is 'ready':
# Get the current x cordinate of the spaceship
bullet_sound = mixer.Sound("laser.wav")
bullet_sound.set_volume(0.2)
bullet_sound.play()
bulletX = playerX
fire_bullet(bulletX, bulletY)
if event.key in [pg.KMOD_ALT, pg.K_F4]:
running = False

if event.type == pg.KEYUP:
if event.key == pg.K_LEFT or event.key == pg.K_RIGHT:
playerX_change = 0
if event.type == pg.KEYUP and event.key in [pg.K_LEFT, pg.K_RIGHT]:
playerX_change = 0
Comment on lines -119 to +131
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 119-170 refactored with the following changes:

This removes the following comments ( why? ):

# Collision



# Checking for boundaries of spaceship so it doesn't go out of bounds
Expand Down Expand Up @@ -165,9 +159,7 @@ def isCollision(enemyX, enemyY, bulletX, bulletY):
enemyX_change[i] = -2
enemyY[i] += enemyY_change[i]

# Collision
collision = isCollision(enemyX[i], enemyY[i], bulletX, bulletY)
if collision:
if collision := isCollision(enemyX[i], enemyY[i], bulletX, bulletY):
explosion_sound = mixer.Sound("explosion.wav")
explosion_sound.set_volume(0.15)
explosion_sound.play()
Expand Down