diff --git a/constants.py b/constants.py index 48b2d63..4023254 100644 --- a/constants.py +++ b/constants.py @@ -1,9 +1,31 @@ GAME_TITLE = 'WMICraft' -WINDOW_HEIGHT = 900 -WINDOW_WIDTH = 900 -GRID_CELL_PADDING = 3 -GRID_CELL_WIDTH = 42 -GRID_CELL_HEIGHT = 42 -ROWS = 20 -COLUMNS = 20 +WINDOW_HEIGHT = 800 +WINDOW_WIDTH = 1360 +GRID_CELL_PADDING = 5 +GRID_CELL_WIDTH = 54 +GRID_CELL_HEIGHT = 54 +ROWS = 13 +COLUMNS = 16 +BORDER_WIDTH = 15 FPS_COUNT = 60 +TILES = [ + 'grass1.png', + 'grass2.png', + 'grass3.png', + # 'grass4.png', + # 'grass5.png', + # 'grass6.png', + 'sand.png', + 'water.png', + # 'grass_with_tree.jpg', +] +OBJECTS = [ + { + 'name': 'tree', + 'location': 'tree1.png' + }, + { + 'name': 'knight', + 'location': 'knight.png' + } +] \ No newline at end of file diff --git a/game.py b/game.py index 3d8b24f..b800bf7 100644 --- a/game.py +++ b/game.py @@ -1,8 +1,10 @@ -import pygame +import pygame, sys from glob import glob from grid import Grid -from constants import GAME_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, FPS_COUNT +from constants import GAME_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, FPS_COUNT, TILES +from stats import Stats +from helpers import draw_text class Game: @@ -11,22 +13,114 @@ class Game: pygame.display.set_caption(GAME_TITLE) pygame.display.set_icon(pygame.image.load('resources/icons/sword.png')) - self.screen = pygame.display.set_mode((WINDOW_HEIGHT, WINDOW_WIDTH)) + self.screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) + self.font = pygame.font.SysFont(None, 30) self.clock = pygame.time.Clock() - self.textures = [] - for texture_path in glob('resources/textures/*.jpg'): - converted_texture = pygame.image.load(texture_path).convert_alpha() - self.textures.append((texture_path, converted_texture)) + self.tiles = [] + for tile_path in TILES: + converted_tile = pygame.image.load('resources/textures/' + tile_path).convert_alpha() + self.tiles.append((tile_path, converted_tile)) - def start(self): + self.bg = pygame.image.load("resources/textures/menu_bg2.jpg") + + click = False + + def main_menu(self): + while True: + self.screen.blit(self.bg, (0, 0)) + + pygame.draw.rect(self.screen, (255, 255, 255), pygame.Rect(800, 100, 400, 500), 0, 5) + draw_text('MAIN MENU', self.font, (0, 0, 0), self.screen, 850, 150) + + mx, my = pygame.mouse.get_pos() + + button_1 = pygame.Rect(850, 250, 300, 50) + button_2 = pygame.Rect(850, 350, 300, 50) + button_3 = pygame.Rect(850, 450, 300, 50) + if button_1.collidepoint((mx, my)): + if click: + self.game() + if button_2.collidepoint((mx, my)): + if click: + self.options() + if button_3.collidepoint((mx, my)): + if click: + self.credits() + pygame.draw.rect(self.screen, (0, 191, 255), button_1, 0, 4) + draw_text('PLAY', self.font, (255, 255, 255), self.screen, 870, 265) + + pygame.draw.rect(self.screen, (0, 191, 255), button_2, 0, 4) + draw_text('OPTIONS', self.font, (255, 255, 255), self.screen, 870, 365) + + pygame.draw.rect(self.screen, (0, 191, 255), button_3, 0, 4) + draw_text('CREDITS', self.font, (255, 255, 255), self.screen, 870, 465) + + click = False + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit() + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + pygame.quit() + sys.exit() + if event.type == pygame.MOUSEBUTTONDOWN: + if event.button == 1: + click = True + + pygame.display.update() + self.clock.tick(60) + + def options(self): running = True - grid = Grid(self.textures) while running: + self.screen.fill((0, 0, 0)) + + draw_text('options', self.font, (255, 255, 255), self.screen, 20, 20) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + running = False + + pygame.display.update() + self.clock.tick(60) + + def credits(self): + running = True + while running: + self.screen.fill((0, 0, 0)) + + draw_text('credits', self.font, (255, 255, 255), self.screen, 20, 20) + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + running = False + + pygame.display.update() + self.clock.tick(60) + + def game(self): + running = True + grid = Grid(self.tiles) + stats = Stats() + + while running: + self.screen.blit(self.bg, (0, 0)) + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit() + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_ESCAPE: + running = False + grid.draw(self.screen) + stats.draw(self.screen, self.font) pygame.display.update() self.clock.tick(FPS_COUNT) - pygame.quit() diff --git a/grid.py b/grid.py index 3359ff0..44093ef 100644 --- a/grid.py +++ b/grid.py @@ -2,7 +2,7 @@ import pygame import random from field import Field -from constants import ROWS, COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, GRID_CELL_HEIGHT +from constants import ROWS, COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, GRID_CELL_HEIGHT, BORDER_WIDTH class Grid: @@ -21,10 +21,14 @@ class Grid: return self.textures[texture_index] def draw(self, screen): + bg_width = (GRID_CELL_PADDING + GRID_CELL_WIDTH) * COLUMNS + BORDER_WIDTH + bg_height = (GRID_CELL_PADDING + GRID_CELL_HEIGHT) * ROWS + BORDER_WIDTH + pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(10, 8, bg_width, bg_height)) + for row in range(ROWS): for column in range(COLUMNS): - box_rect = [(GRID_CELL_PADDING + GRID_CELL_WIDTH) * column + GRID_CELL_PADDING, - (GRID_CELL_PADDING + GRID_CELL_HEIGHT) * row + GRID_CELL_PADDING, + box_rect = [(GRID_CELL_PADDING + GRID_CELL_WIDTH) * column + GRID_CELL_PADDING + 15, + (GRID_CELL_PADDING + GRID_CELL_HEIGHT) * row + GRID_CELL_PADDING + 13, GRID_CELL_WIDTH, GRID_CELL_HEIGHT] image = self.grid[row][column].converted_texture diff --git a/helpers.py b/helpers.py new file mode 100644 index 0000000..3d9a75a --- /dev/null +++ b/helpers.py @@ -0,0 +1,5 @@ +def draw_text(text, font, color, surface, x, y): + textobj = font.render(text, 1, color) + textrect = textobj.get_rect() + textrect.topleft = (x, y) + surface.blit(textobj, textrect) \ No newline at end of file diff --git a/main.py b/main.py index e31b37c..3cf2c8a 100644 --- a/main.py +++ b/main.py @@ -2,4 +2,4 @@ from game import Game if __name__ == '__main__': game = Game() - game.start() + game.main_menu() diff --git a/resources/textures/grass1.png b/resources/textures/grass1.png new file mode 100644 index 0000000..dd88981 Binary files /dev/null and b/resources/textures/grass1.png differ diff --git a/resources/textures/grass2.png b/resources/textures/grass2.png new file mode 100644 index 0000000..c07ab8f Binary files /dev/null and b/resources/textures/grass2.png differ diff --git a/resources/textures/grass3.png b/resources/textures/grass3.png new file mode 100644 index 0000000..4fac085 Binary files /dev/null and b/resources/textures/grass3.png differ diff --git a/resources/textures/grass4.png b/resources/textures/grass4.png new file mode 100644 index 0000000..74cb3d1 Binary files /dev/null and b/resources/textures/grass4.png differ diff --git a/resources/textures/grass5.png b/resources/textures/grass5.png new file mode 100644 index 0000000..d348b2d Binary files /dev/null and b/resources/textures/grass5.png differ diff --git a/resources/textures/grass6.png b/resources/textures/grass6.png new file mode 100644 index 0000000..fa788ab Binary files /dev/null and b/resources/textures/grass6.png differ diff --git a/resources/textures/grass_with_tree.jpg b/resources/textures/grass_with_tree.jpg new file mode 100644 index 0000000..56af6b8 Binary files /dev/null and b/resources/textures/grass_with_tree.jpg differ diff --git a/resources/textures/knight.png b/resources/textures/knight.png new file mode 100644 index 0000000..22c47bb Binary files /dev/null and b/resources/textures/knight.png differ diff --git a/resources/textures/menu_bg.jpg b/resources/textures/menu_bg.jpg new file mode 100644 index 0000000..69c8cc8 Binary files /dev/null and b/resources/textures/menu_bg.jpg differ diff --git a/resources/textures/menu_bg2.jpg b/resources/textures/menu_bg2.jpg new file mode 100644 index 0000000..c6825d8 Binary files /dev/null and b/resources/textures/menu_bg2.jpg differ diff --git a/resources/textures/sand.png b/resources/textures/sand.png new file mode 100644 index 0000000..51c072d Binary files /dev/null and b/resources/textures/sand.png differ diff --git a/resources/textures/tree1.png b/resources/textures/tree1.png new file mode 100644 index 0000000..48637da Binary files /dev/null and b/resources/textures/tree1.png differ diff --git a/resources/textures/tree2.png b/resources/textures/tree2.png new file mode 100644 index 0000000..2f8fa74 Binary files /dev/null and b/resources/textures/tree2.png differ diff --git a/resources/textures/water.png b/resources/textures/water.png new file mode 100644 index 0000000..28b45db Binary files /dev/null and b/resources/textures/water.png differ diff --git a/stats.py b/stats.py new file mode 100644 index 0000000..e93c559 --- /dev/null +++ b/stats.py @@ -0,0 +1,15 @@ +import pygame + +from constants import COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, BORDER_WIDTH +from helpers import draw_text + + +class Stats: + def __init__(self): + self.grid = [] + + def draw(self, screen, font): + x = (GRID_CELL_PADDING + GRID_CELL_WIDTH) * COLUMNS + BORDER_WIDTH + 20 + y = 8 + pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(x, y, 370, 782)) + draw_text('GAME STATS', font, (0, 0, 0), screen, x + 120, y + 30)