enter image description here
The stars in the first column of each row appear to be misaligned or have a different background color compared to the rest of the stars in the grid.
The issue seems specific to the first star in each row, as the rest of the stars align correctly.
here is the relevant code,
import pygame
import sys
from star import Star
from random import randint
def check_events():
"""Check events in main module such as mouse and keyboard movement"""
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
def draw_star(star):
"""Draw the star on the screen top left corner"""
star.blitme()
def get_number_star(star_width):
"""Number of stars in a row"""
available_x = 800 - (2 * star_width)
no_x = int(available_x / (2 * star_width))
return no_x
def get_number_rows(star):
"""Number of rows of stars"""
star_height = star.rect.height
available_y = 600 - 3 * star_height
number_rows = int(available_y / (2 * star_height))
return number_rows
def create_star(number_x, screen, stars, row_number):
"""Create and add a star at a specific position"""
star = Star(screen)
star_width = star.rect.width
star_height = star.rect.height
# Position calculation
star.rect.x = star_width * number_x
star.rect.y = star_height * row_number
stars.add(star)
def create_grid(screen, star, stars):
"""Create a grid of stars"""
number_stars_x = get_number_star(star.rect.width)
number_rows_y = get_number_rows(star)
for row_number in range(number_rows_y):
for number_x in range(number_stars_x):
create_star(number_x, screen, stars, row_number)
What did I try?
= Checked for any initialization issues or positioning anomalies.
New contributor
Celestial_Lord is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.