From bed39e9c4431e686e670f401e5c419a505db1e0a Mon Sep 17 00:00:00 2001 From: korzepadawid Date: Fri, 4 Mar 2022 16:45:30 +0100 Subject: [PATCH] feat: added basic 2d grid --- .gitignore | 2 +- README.md | 2 ++ main.py | 45 +++++++++++++++++++++++++++++++++++---------- 3 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index fe33a8e..f73443c 100644 --- a/.gitignore +++ b/.gitignore @@ -149,4 +149,4 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +.idea/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3c86f3f --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# 🏰 WMICraft + diff --git a/main.py b/main.py index b6dc926..6538ccf 100644 --- a/main.py +++ b/main.py @@ -1,18 +1,43 @@ import pygame -# game init pygame.init() -# screen size -pygame.display.set_mode((800, 800)) +GAME_TITLE = 'WMICraft' +WINDOW_HEIGHT = 900 +WINDOW_WIDTH = 900 +GRID_CELL_PADDING = 3 +GRID_CELL_WIDTH = 42 +GRID_CELL_HEIGHT = 42 +GREEN = (0, 255, 0) -# title and icon -pygame.display.set_caption('WMICraft') +screen = pygame.display.set_mode((WINDOW_HEIGHT, WINDOW_WIDTH)) +pygame.display.set_caption(GAME_TITLE) icon = pygame.image.load('resources/icons/sword.png') pygame.display.set_icon(icon) -running = True -while running: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - running = False + +def draw_grid(): + for row in range(20): + for column in range(20): + box_rect = [(GRID_CELL_PADDING + GRID_CELL_WIDTH) * column + GRID_CELL_PADDING, + (GRID_CELL_PADDING + GRID_CELL_HEIGHT) * row + GRID_CELL_PADDING, + GRID_CELL_WIDTH, + GRID_CELL_HEIGHT] + pygame.draw.rect(screen, GREEN, box_rect) + + +def main(): + running = True + + while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + draw_grid() + pygame.display.update() + + pygame.quit() + + +if __name__ == '__main__': + main()