'Problem with self.width not being assigned a value
screen_width = 600
screen_height = 600
#Colors
bg = (215, 255, 200)
# game variables cols = columns \\ rows
cols = 6
rows = 6
With the wall class I have self_width = to screen_width // cols. screen_width and cols are both clearly defined variables but when I run my code, I get an error that says:
line 38, in create_wall
block_x = col * self.width
AttributeError: 'wall' object has no attribute 'width'"
I have no idea why the two variables aren't executing the math operation and being assigned to self.width so I can create a rect for a pygame.
#brick wall class
class wall():
def _init_(self):
self.width = screen_width // cols
self.height = 50
def create_wall(self):
self.block = []
#define an empty list for an individual block
block_individual = []
for row in range(rows):
#block row list
block_row = []
#iterate through each column in that row
for col in range(cols):
#generate rectangle based on values
block_x = col * self.width
block_y = row * self.height
rect = pygame.Rect(block_x, block_y, self.width, self.height)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
