-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.py
27 lines (24 loc) · 1001 Bytes
/
object.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pygame
class Block(pygame.sprite.Sprite):
def __init__(self,x,y):
super().__init__()
self.image = pygame.Surface((3,3))
self.image.fill((255, 200, 210))
self.rect = self.image.get_rect(topleft = (x,y))
grid = [
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1],
[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
]
class Object:
def __init__(self,x,y):
self.blocks_group = pygame.sprite.Group()
for row in range(len(grid)):
for column in range(len(grid[0])):
if grid[row][column] == 1:
pos_x = x + column * 3
pos_y = y + row * 3 # them x voi y de doi vi tri block duoc hen
block = Block(pos_x,pos_y)
self.blocks_group.add(block)