Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from pathlib import Path
- from PIL import Image, ImageDraw
- FPS = 60
- WIDTH = 600
- HEIGHT = 400
- FULLSCREEN = False
- def pilImageToSurface(pilImage):
- return pygame.image.fromstring(
- pilImage.tobytes(), pilImage.size, pilImage.mode).convert()
- class Tile(pygame.sprite.Sprite):
- def __init__(self, pos_x, pos_y):
- if not hasattr(Tile, "group"):
- Tile.group = pygame.sprite.Group()
- Tile.tile_size = 50
- super().__init__(Tile.group)
- image = Image.open("data/box.png")
- this_image = pilImageToSurface(image)
- self.image = this_image
- self.rect = self.image.get_rect().move(
- Tile.tile_size * pos_x, Tile.tile_size * pos_y
- )
- def main(fps, width, height, fullscreen=False):
- pygame.init()
- if not fullscreen:
- screen = pygame.display.set_mode((width, height))
- else:
- screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
- clock = pygame.time.Clock()
- Tile(0, 0)
- running = True
- while running:
- screen.fill((255, 255, 255))
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- return
- Tile.group.draw(screen)
- pygame.display.flip()
- clock.tick(fps)
- pygame.quit()
- if __name__ == "__main__":
- main(FPS, WIDTH, HEIGHT, FULLSCREEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement