Hi everyone, basically im just trying to make this grid of stars for something and I just cant see a logical reason for an AttributeError…
import sys
import pygame
from pygame.sprite import Sprite
from sett import Settings
class Stars(Sprite):
"""A class to represent a sky full of rotating stars"""
def __init__(self):
"""Configure program attributes"""
pygame.init()
self.screen = pygame.display.set_mode(self.sett.screen_width, self.sett.screen_height)
pygame.display.set_caption("Starz")
self.image = pygame.image.load("star1(1).bmp")
self.rect = self.image.get_rect()
self.stars = pygame.sprite.Group()
self._create_sky()
def _create_sky(self):
"""configure space for stars"""
star_width, star_height = self.rect.size
available_space_x = self.screen_width - (2 * star_width)
available_space_y = self.screen_height - (2 * star_height)
number_rows = available_space_y // (2 * star_height)
number_stars_x = available_space_x // (2 * star_width)
#Create the full fleet of aliens.
for row_number in range(number_rows):
for star_number in range(number_stars_x):
self._create_star(star_number, row_number)
def _create_star(self, star_number, row_number):
"""create stars"""
star_width, star_height = self.rect.size
self.x = star_width + 2 * star_width * star_number
self.rect.x = star.x
self.rect.y = star_height + 2 * self.rect.height * row_number
self.queens.add(star)
if __name__ == '__main__':
si = Stars()
si.run_game()
other than this I just have one module named sett.py which contains the settings but i cant import the sett module…
python just comes back with:
Traceback (most recent call last):
File "C:\Users\jacob\OneDrive\Desktop\New folder (3)\star.py", line 48, in <module>
si = Stars()
File "C:\Users\jacob\OneDrive\Desktop\New folder (3)\star.py", line 13, in __init__
self.screen = pygame.display.set_mode(self.sett.screen_width, self.sett.screen_height)
AttributeError: 'Stars' object has no attribute 'sett'