finished UI layout;

This commit is contained in:
Angelika Iskra 2022-03-08 14:50:48 +01:00
parent 358107a046
commit 96a86cf4ce
33 changed files with 271 additions and 41 deletions

6
colors.py Normal file
View File

@ -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)

View File

@ -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',
]

30
game.py
View File

@ -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)

View File

@ -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

View File

@ -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)
surface.blit(textobj, textrect)

25
logs.py Normal file
View File

@ -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)

93
resources/fonts/OFL.txt Normal file
View File

@ -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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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:
<a href="http://www.freepik.com">Designed by vectorpocket / Freepik</a>
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.

View File

@ -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.

View File

Before

Width:  |  Height:  |  Size: 256 KiB

After

Width:  |  Height:  |  Size: 256 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -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)