diff --git a/colors.py b/colors.py new file mode 100644 index 0000000..8a8f41b --- /dev/null +++ b/colors.py @@ -0,0 +1,6 @@ +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +ORANGE = (249, 141, 42) +RED = (255, 58, 58) + +FONT_DARK = (37, 37, 37) diff --git a/constants.py b/constants.py index 4023254..7c7cb50 100644 --- a/constants.py +++ b/constants.py @@ -2,11 +2,12 @@ GAME_TITLE = 'WMICraft' 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 +GRID_CELL_WIDTH = 36 +GRID_CELL_HEIGHT = 36 +ROWS = 19 +COLUMNS = 24 +BORDER_WIDTH = 10 +BORDER_RADIUS = 5 FPS_COUNT = 60 TILES = [ 'grass1.png', @@ -17,15 +18,5 @@ TILES = [ # 'grass6.png', 'sand.png', 'water.png', - # 'grass_with_tree.jpg', -] -OBJECTS = [ - { - 'name': 'tree', - 'location': 'tree1.png' - }, - { - 'name': 'knight', - 'location': 'knight.png' - } + 'grass_with_tree.jpg', ] \ No newline at end of file diff --git a/game.py b/game.py index b800bf7..5cedc6d 100644 --- a/game.py +++ b/game.py @@ -1,10 +1,12 @@ -import pygame, sys -from glob import glob +import pygame +import sys -from grid import Grid +from colors import FONT_DARK, WHITE from constants import GAME_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, FPS_COUNT, TILES -from stats import Stats +from grid import Grid from helpers import draw_text +from logs import Logs +from stats import Stats class Game: @@ -14,7 +16,6 @@ class Game: pygame.display.set_icon(pygame.image.load('resources/icons/sword.png')) self.screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) - self.font = pygame.font.SysFont(None, 30) self.clock = pygame.time.Clock() self.tiles = [] @@ -22,7 +23,7 @@ class Game: converted_tile = pygame.image.load('resources/textures/' + tile_path).convert_alpha() self.tiles.append((tile_path, converted_tile)) - self.bg = pygame.image.load("resources/textures/menu_bg2.jpg") + self.bg = pygame.image.load("resources/textures/bg.jpg") click = False @@ -31,7 +32,7 @@ class Game: 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) + draw_text('MAIN MENU', FONT_DARK, self.screen, 850, 150, 30, True) mx, my = pygame.mouse.get_pos() @@ -48,13 +49,13 @@ class Game: 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) + draw_text('PLAY', WHITE, self.screen, 870, 255) pygame.draw.rect(self.screen, (0, 191, 255), button_2, 0, 4) - draw_text('OPTIONS', self.font, (255, 255, 255), self.screen, 870, 365) + draw_text('OPTIONS', WHITE, self.screen, 870, 355) pygame.draw.rect(self.screen, (0, 191, 255), button_3, 0, 4) - draw_text('CREDITS', self.font, (255, 255, 255), self.screen, 870, 465) + draw_text('CREDITS', WHITE, self.screen, 870, 455) click = False for event in pygame.event.get(): @@ -77,7 +78,7 @@ class Game: while running: self.screen.fill((0, 0, 0)) - draw_text('options', self.font, (255, 255, 255), self.screen, 20, 20) + draw_text('options', WHITE, self.screen, 20, 20, 30) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False @@ -93,7 +94,7 @@ class Game: while running: self.screen.fill((0, 0, 0)) - draw_text('credits', self.font, (255, 255, 255), self.screen, 20, 20) + draw_text('credits', WHITE, self.screen, 20, 20, 30) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False @@ -108,6 +109,7 @@ class Game: running = True grid = Grid(self.tiles) stats = Stats() + logs = Logs() while running: self.screen.blit(self.bg, (0, 0)) @@ -121,6 +123,8 @@ class Game: running = False grid.draw(self.screen) - stats.draw(self.screen, self.font) + stats.draw(self.screen) + logs.draw(self.screen) + pygame.display.update() self.clock.tick(FPS_COUNT) diff --git a/grid.py b/grid.py index 44093ef..891c618 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, BORDER_WIDTH +from constants import ROWS, COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, GRID_CELL_HEIGHT, BORDER_WIDTH, BORDER_RADIUS class Grid: @@ -23,12 +23,12 @@ class Grid: 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)) + pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(5, 5, bg_width, bg_height), 0, BORDER_RADIUS) for row in range(ROWS): for column in range(COLUMNS): - box_rect = [(GRID_CELL_PADDING + GRID_CELL_WIDTH) * column + GRID_CELL_PADDING + 15, - (GRID_CELL_PADDING + GRID_CELL_HEIGHT) * row + GRID_CELL_PADDING + 13, + box_rect = [(GRID_CELL_PADDING + GRID_CELL_WIDTH) * column + GRID_CELL_PADDING + 7, + (GRID_CELL_PADDING + GRID_CELL_HEIGHT) * row + GRID_CELL_PADDING + 7, GRID_CELL_WIDTH, GRID_CELL_HEIGHT] image = self.grid[row][column].converted_texture diff --git a/helpers.py b/helpers.py index 3d9a75a..63238b6 100644 --- a/helpers.py +++ b/helpers.py @@ -1,5 +1,12 @@ -def draw_text(text, font, color, surface, x, y): +import pygame + + +def draw_text(text, color, surface, x, y, text_size=30, is_bold=False): + if is_bold: + font = pygame.font.Font('resources/fonts/Poppins-SemiBold.ttf', text_size) + else: + font = pygame.font.Font('resources/fonts/Poppins-Regular.ttf', text_size) textobj = font.render(text, 1, color) textrect = textobj.get_rect() textrect.topleft = (x, y) - surface.blit(textobj, textrect) \ No newline at end of file + surface.blit(textobj, textrect) diff --git a/logs.py b/logs.py new file mode 100644 index 0000000..beaff27 --- /dev/null +++ b/logs.py @@ -0,0 +1,25 @@ +import pygame + +from colors import FONT_DARK, ORANGE, WHITE, RED +from constants import COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, BORDER_WIDTH, BORDER_RADIUS +from helpers import draw_text + + +class Logs: + def __init__(self): + self.grid = [] + + def draw(self, screen): + x = (GRID_CELL_PADDING + GRID_CELL_WIDTH) * COLUMNS + BORDER_WIDTH + 15 + y = 470 + + # background + pygame.draw.rect(screen, WHITE, pygame.Rect(x, y, 340, 323), 0, BORDER_RADIUS) + + # title + draw_text('LOGS', FONT_DARK, screen, x + 120, y + 10, 36) + pygame.draw.rect(screen, ORANGE, pygame.Rect(x, y + 65, 340, 3)) + + # texts + draw_text('AI Blue: Zniszczyła fortecę (4, 8).', FONT_DARK, screen, x + 35, y + 90, 16) + draw_text('AI Red: Zniszczyła fortecę (12, 5).', FONT_DARK, screen, x + 35, y + 120, 16) diff --git a/resources/fonts/OFL.txt b/resources/fonts/OFL.txt new file mode 100644 index 0000000..76df3b5 --- /dev/null +++ b/resources/fonts/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2020 The Poppins Project Authors (https://github.com/itfoundry/Poppins) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/resources/fonts/Poppins-Black.ttf b/resources/fonts/Poppins-Black.ttf new file mode 100644 index 0000000..71c0f99 Binary files /dev/null and b/resources/fonts/Poppins-Black.ttf differ diff --git a/resources/fonts/Poppins-BlackItalic.ttf b/resources/fonts/Poppins-BlackItalic.ttf new file mode 100644 index 0000000..7aeb58b Binary files /dev/null and b/resources/fonts/Poppins-BlackItalic.ttf differ diff --git a/resources/fonts/Poppins-Bold.ttf b/resources/fonts/Poppins-Bold.ttf new file mode 100644 index 0000000..00559ee Binary files /dev/null and b/resources/fonts/Poppins-Bold.ttf differ diff --git a/resources/fonts/Poppins-BoldItalic.ttf b/resources/fonts/Poppins-BoldItalic.ttf new file mode 100644 index 0000000..e61e8e8 Binary files /dev/null and b/resources/fonts/Poppins-BoldItalic.ttf differ diff --git a/resources/fonts/Poppins-ExtraBold.ttf b/resources/fonts/Poppins-ExtraBold.ttf new file mode 100644 index 0000000..df70936 Binary files /dev/null and b/resources/fonts/Poppins-ExtraBold.ttf differ diff --git a/resources/fonts/Poppins-ExtraBoldItalic.ttf b/resources/fonts/Poppins-ExtraBoldItalic.ttf new file mode 100644 index 0000000..14d2b37 Binary files /dev/null and b/resources/fonts/Poppins-ExtraBoldItalic.ttf differ diff --git a/resources/fonts/Poppins-ExtraLight.ttf b/resources/fonts/Poppins-ExtraLight.ttf new file mode 100644 index 0000000..e76ec69 Binary files /dev/null and b/resources/fonts/Poppins-ExtraLight.ttf differ diff --git a/resources/fonts/Poppins-ExtraLightItalic.ttf b/resources/fonts/Poppins-ExtraLightItalic.ttf new file mode 100644 index 0000000..89513d9 Binary files /dev/null and b/resources/fonts/Poppins-ExtraLightItalic.ttf differ diff --git a/resources/fonts/Poppins-Italic.ttf b/resources/fonts/Poppins-Italic.ttf new file mode 100644 index 0000000..12b7b3c Binary files /dev/null and b/resources/fonts/Poppins-Italic.ttf differ diff --git a/resources/fonts/Poppins-Light.ttf b/resources/fonts/Poppins-Light.ttf new file mode 100644 index 0000000..bc36bcc Binary files /dev/null and b/resources/fonts/Poppins-Light.ttf differ diff --git a/resources/fonts/Poppins-LightItalic.ttf b/resources/fonts/Poppins-LightItalic.ttf new file mode 100644 index 0000000..9e70be6 Binary files /dev/null and b/resources/fonts/Poppins-LightItalic.ttf differ diff --git a/resources/fonts/Poppins-Medium.ttf b/resources/fonts/Poppins-Medium.ttf new file mode 100644 index 0000000..6bcdcc2 Binary files /dev/null and b/resources/fonts/Poppins-Medium.ttf differ diff --git a/resources/fonts/Poppins-MediumItalic.ttf b/resources/fonts/Poppins-MediumItalic.ttf new file mode 100644 index 0000000..be67410 Binary files /dev/null and b/resources/fonts/Poppins-MediumItalic.ttf differ diff --git a/resources/fonts/Poppins-Regular.ttf b/resources/fonts/Poppins-Regular.ttf new file mode 100644 index 0000000..9f0c71b Binary files /dev/null and b/resources/fonts/Poppins-Regular.ttf differ diff --git a/resources/fonts/Poppins-SemiBold.ttf b/resources/fonts/Poppins-SemiBold.ttf new file mode 100644 index 0000000..74c726e Binary files /dev/null and b/resources/fonts/Poppins-SemiBold.ttf differ diff --git a/resources/fonts/Poppins-SemiBoldItalic.ttf b/resources/fonts/Poppins-SemiBoldItalic.ttf new file mode 100644 index 0000000..3e6c942 Binary files /dev/null and b/resources/fonts/Poppins-SemiBoldItalic.ttf differ diff --git a/resources/fonts/Poppins-Thin.ttf b/resources/fonts/Poppins-Thin.ttf new file mode 100644 index 0000000..03e7366 Binary files /dev/null and b/resources/fonts/Poppins-Thin.ttf differ diff --git a/resources/fonts/Poppins-ThinItalic.ttf b/resources/fonts/Poppins-ThinItalic.ttf new file mode 100644 index 0000000..e26db5d Binary files /dev/null and b/resources/fonts/Poppins-ThinItalic.ttf differ diff --git a/resources/textures/License free.txt b/resources/textures/License free.txt new file mode 100644 index 0000000..c2c3c1b --- /dev/null +++ b/resources/textures/License free.txt @@ -0,0 +1,45 @@ +IMPORTANT NOTICE: This license only applies if you downloaded this content as +an unsubscribed user. If you are a premium user (ie, you pay a subscription) +you are bound to the license terms described in the accompanying file +"License premium.txt". + +--------------------- + +You must attribute the image to its author: + +In order to use a content or a part of it, you must attribute it to vectorpocket / Freepik, +so we will be able to continue creating new graphic resources every day. + + +How to attribute it? + +For websites: + +Please, copy this code on your website to accredit the author: +Designed by vectorpocket / Freepik + +For printing: + +Paste this text on the final work so the authorship is known. +- For example, in the acknowledgements chapter of a book: +"Designed by vectorpocket / Freepik" + + +You are free to use this image: + +- For both personal and commercial projects and to modify it. +- In a website or presentation template or application or as part of your design. + +You are not allowed to: + +- Sub-license, resell or rent it. +- Include it in any online or offline archive or database. + +The full terms of the license are described in section 7 of the Freepik +terms of use, available online in the following link: + + http://www.freepik.com/terms_of_use + +The terms described in the above link have precedence over the terms described +in the present document. In case of disagreement, the Freepik Terms of Use +will prevail. diff --git a/resources/textures/License premium.txt b/resources/textures/License premium.txt new file mode 100644 index 0000000..c6cd87a --- /dev/null +++ b/resources/textures/License premium.txt @@ -0,0 +1,30 @@ +IMPORTANT NOTICE: This license only applies if you downloaded this content as +a subscribed (or "premium") user. If you are an unsubscribed user (or "free" +user) you are bound to the license terms described in the accompanying file +"License free.txt". + +--------------------- + +You can download from your profile in Freepik a personalized license stating +your right to use this content as a "premium" user: + + https://profile.freepik.com/my_downloads + +You are free to use this image: + +- For both personal and commercial projects and to modify it. +- In a website or presentation template or application or as part of your design. + +You are not allowed to: + +- Sub-license, resell or rent it. +- Include it in any online or offline archive or database. + +The full terms of the license are described in sections 7 and 8 of the Freepik +terms of use, available online in the following link: + + http://www.freepik.com/terms_of_use + +The terms described in the above link have precedence over the terms described +in the present document. In case of disagreement, the Freepik Terms of Use +will prevail. diff --git a/resources/textures/menu_bg2.jpg b/resources/textures/bg.jpg similarity index 100% rename from resources/textures/menu_bg2.jpg rename to resources/textures/bg.jpg diff --git a/resources/textures/knight.png b/resources/textures/knight.png index 22c47bb..0024f64 100644 Binary files a/resources/textures/knight.png and b/resources/textures/knight.png differ diff --git a/resources/textures/menu_bg.jpg b/resources/textures/menu_bg.jpg deleted file mode 100644 index 69c8cc8..0000000 Binary files a/resources/textures/menu_bg.jpg and /dev/null differ diff --git a/resources/textures/shield_blue.png b/resources/textures/shield_blue.png new file mode 100644 index 0000000..2fab665 Binary files /dev/null and b/resources/textures/shield_blue.png differ diff --git a/resources/textures/shield_red.png b/resources/textures/shield_red.png new file mode 100644 index 0000000..686eb4f Binary files /dev/null and b/resources/textures/shield_red.png differ diff --git a/stats.py b/stats.py index e93c559..f1e9994 100644 --- a/stats.py +++ b/stats.py @@ -1,6 +1,7 @@ import pygame -from constants import COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, BORDER_WIDTH +from colors import FONT_DARK, ORANGE, WHITE, RED +from constants import COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, BORDER_WIDTH, BORDER_RADIUS from helpers import draw_text @@ -8,8 +9,36 @@ 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) + def draw(self, screen): + x = (GRID_CELL_PADDING + GRID_CELL_WIDTH) * COLUMNS + BORDER_WIDTH + 15 + y = 5 + + # background + pygame.draw.rect(screen, WHITE, pygame.Rect(x, y, 340, 450), 0, BORDER_RADIUS) + + # title + draw_text('STATS', FONT_DARK, screen, x + 120, y + 10, 36) + pygame.draw.rect(screen, ORANGE, pygame.Rect(x, y + 65, 340, 3)) + + # shields + shield_blue = pygame.image.load('resources/textures/shield_blue.png') + shield_red = pygame.image.load('resources/textures/shield_red.png') + screen.blit(shield_blue, (x + 20, y + 80)) + screen.blit(shield_red, (x + 200, y + 80)) + draw_text('VS', FONT_DARK, screen, x + 150, y + 120, 36) + + # HP bars + pygame.draw.rect(screen, RED, pygame.Rect(x + 30, y + 210, 100, 15), 0, 4) + pygame.draw.rect(screen, RED, pygame.Rect(x + 210, y + 210, 100, 15), 0, 4) + + # texts + draw_text('Rycerze: 2', FONT_DARK, screen, x + 35, y + 240, 18) + draw_text('Fortece: 1', FONT_DARK, screen, x + 35, y + 270, 18) + + draw_text('Rycerze: 4', FONT_DARK, screen, x + 215, y + 240, 18) + draw_text('Fortece: 0', FONT_DARK, screen, x + 215, y + 270, 18) + + # points + pygame.draw.rect(screen, ORANGE, pygame.Rect(x, y + 390, 340, 3)) + draw_text('PUNKTY: 10', FONT_DARK, screen, x + 35, y + 408, 18, True) + draw_text('PUNKTY: 10', FONT_DARK, screen, x + 215, y + 408, 18, True) \ No newline at end of file