-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid-thing.py
44 lines (36 loc) · 1.3 KB
/
grid-thing.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pygame, sys, random as rd
pygame.init()
clock = pygame.time.Clock()
WIDTH, HEIGHT, TILESIZE = 500,500,20
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Tile Wave Effect")
class Tile(pygame.sprite.Sprite):
def __init__(self, x, y, color, outline="black"):
super().__init__()
self.color = color
self.outline = outline
self.image = pygame.Surface((TILESIZE,TILESIZE))
self.image.fill(outline)
self.image.fill(color, self.image.get_rect().inflate(-1,-1))
self.rect = self.image.get_rect(topleft=(x,y))
def changeColor(self, color):
self.image.fill(color, self.image.get_rect().inflate(-1,-1))
self.color = color
tiles = pygame.sprite.Group()
for indY in range(0,HEIGHT,TILESIZE):
for indX in range(0,WIDTH,TILESIZE):
tiles.add(Tile(indX,indY,"white"))
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
for tile in tiles.sprites():
if tile.rect.collidepoint(pygame.mouse.get_pos()):
tile.changeColor("red")
break
tiles.draw(screen)
pygame.display.flip()
clock.tick()
#not finished