add sprites and refactor
This commit is contained in:
parent
2ea0e3b27d
commit
ff3f344fca
@ -38,8 +38,10 @@ class GridDraw():
|
||||
self.background = background if background != None else Colors.BLACK
|
||||
|
||||
self.sprites = {
|
||||
'VACUUM': pygame.transform.scale(pygame.image.load('media/sprites/robot_vacuum.png'), (self.tile_width, self.tile_height)),
|
||||
'VACUUM': pygame.transform.scale(pygame.image.load('media/sprites/vacuum.png'), (self.tile_width, self.tile_height)),
|
||||
'WALL': pygame.transform.scale(pygame.image.load('media/sprites/wall.png'), (self.tile_width, self.tile_height)),
|
||||
'TILE': pygame.transform.scale(pygame.image.load('media/sprites/tile.jpeg'), (self.tile_width, self.tile_height)),
|
||||
'PEEL': pygame.transform.scale(pygame.image.load('media/sprites/peel.webp'), (self.tile_width, self.tile_height)),
|
||||
}
|
||||
|
||||
pygame.init()
|
||||
@ -75,14 +77,14 @@ class GridDraw():
|
||||
def circle(self, x, y, radius, color = None):
|
||||
pygame.draw.circle(self.screen, color, (x, y), radius)
|
||||
|
||||
def draw_vacuum(self, tile_x, tile_y):
|
||||
def draw_sprite(self, tile_x, tile_y, sprite):
|
||||
self.screen.blit(
|
||||
self.sprites['VACUUM'],
|
||||
self.sprites[sprite],
|
||||
(tile_x * self.tile_width, tile_y * self.tile_height)
|
||||
)
|
||||
|
||||
def draw_wall(self, tile_x, tile_y):
|
||||
self.screen.blit(
|
||||
self.sprites['WALL'],
|
||||
(tile_x * self.tile_width, tile_y * self.tile_height)
|
||||
)
|
||||
def fill_grid_with_sprite(self, sprite):
|
||||
for tile_x in range(self.tiles_x):
|
||||
for tile_y in range(self.tiles_y):
|
||||
self.draw_sprite(tile_x, tile_y, sprite)
|
||||
|
||||
|
@ -1,23 +1,35 @@
|
||||
from Interface.grid_draw import GridDraw, Colors
|
||||
import sys
|
||||
import pygame
|
||||
from random import randint
|
||||
|
||||
GRID_SIZE_X = 10
|
||||
GRID_SIZE_Y = 10
|
||||
|
||||
# dummy function
|
||||
def initial_draw():
|
||||
grid = GridDraw(500, 500, GRID_SIZE_X, GRID_SIZE_Y)
|
||||
grid = GridDraw(800, 800, GRID_SIZE_X, GRID_SIZE_Y)
|
||||
|
||||
x = 2
|
||||
y = 2
|
||||
|
||||
peels = []
|
||||
for _ in range(10):
|
||||
temp_x = randint(0, GRID_SIZE_X)
|
||||
temp_y = randint(0, GRID_SIZE_Y)
|
||||
peels.append((temp_x, temp_y))
|
||||
|
||||
|
||||
while True:
|
||||
grid.start_draw()
|
||||
# grid.draw_vacuum(x, y)
|
||||
grid.fill_grid_with_sprite('TILE')
|
||||
grid.board()
|
||||
|
||||
grid.draw_wall(0, 0)
|
||||
grid.draw_vacuum(x, y)
|
||||
for peel in peels:
|
||||
grid.draw_sprite(peel[0], peel[1], "PEEL")
|
||||
|
||||
grid.draw_sprite(x, y, "VACUUM")
|
||||
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
|
BIN
media/sprites/peel.webp
Normal file
BIN
media/sprites/peel.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 328 KiB |
BIN
media/sprites/tile.jpeg
Normal file
BIN
media/sprites/tile.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 87 KiB |
BIN
media/sprites/vacuum.png
Normal file
BIN
media/sprites/vacuum.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 122 KiB |
Loading…
Reference in New Issue
Block a user