work on new logic;

This commit is contained in:
Angelika Iskra 2022-04-10 20:28:50 +02:00
parent c1d05eb1d1
commit ac74280271
30 changed files with 299 additions and 319 deletions

View File

@ -1,34 +1,39 @@
GAME_TITLE = 'WMICraft' GAME_TITLE = 'WMICraft'
WINDOW_HEIGHT = 800 WINDOW_HEIGHT = 800
WINDOW_WIDTH = 1360 WINDOW_WIDTH = 1360
FPS_COUNT = 60
GRID_CELL_PADDING = 5 GRID_CELL_PADDING = 5
GRID_CELL_WIDTH = 36 GRID_CELL_SIZE = 36
GRID_CELL_HEIGHT = 36
ROWS = 19 ROWS = 19
COLUMNS = 24 COLUMNS = 24
BORDER_WIDTH = 10 BORDER_WIDTH = 10
BORDER_RADIUS = 5 BORDER_RADIUS = 5
FPS_COUNT = 60
KNIGHTS_SPAWN_WIDTH = 4 KNIGHTS_SPAWN_WIDTH = 4
KNIGHTS_SPAWN_HEIGHT = 7 KNIGHTS_SPAWN_HEIGHT = 7
LEFT_KNIGHTS_SPAWN_FIRST_ROW = 6 LEFT_KNIGHTS_SPAWN_FIRST_ROW = 6
LEFT_KNIGHTS_SPAWN_FIRST_COL = 0 LEFT_KNIGHTS_SPAWN_FIRST_COL = 0
RIGHT_KNIGHTS_SPAWN_FIRST_ROW = 6 RIGHT_KNIGHTS_SPAWN_FIRST_ROW = 6
RIGHT_KNIGHTS_SPAWN_FIRST_COL = 20 RIGHT_KNIGHTS_SPAWN_FIRST_COL = 20
NBR_OF_WATER = 10
NBR_OF_TREES = 16
CASTLE_SPAWN_WIDTH = 6 CASTLE_SPAWN_WIDTH = 6
# CASTLE_SPAWN_WIDTH = 0
CASTLE_SPAWN_HEIGHT = 5 CASTLE_SPAWN_HEIGHT = 5
# CASTLE_SPAWN_HEIGHT = 0
CASTLE_SPAWN_FIRST_ROW = 7 CASTLE_SPAWN_FIRST_ROW = 7
CASTLE_SPAWN_FIRST_COL = 9 CASTLE_SPAWN_FIRST_COL = 9
NBR_OF_WATER = 16
NBR_OF_TREES = 20
NBR_OF_MONSTERS = 2
TILES = [ TILES = [
'grass1.png', 'grass1.png',
'grass2.png', 'grass2.png',
'grass3.png', 'grass3.png',
# 'grass4.png', 'grass4.png',
# 'grass5.png',
# 'grass6.png',
'sand.png', 'sand.png',
'water.png', 'water.png',
'grass_with_tree.jpg', 'grass_with_tree.jpg',

15
helpers/debug.py Normal file
View File

@ -0,0 +1,15 @@
import pygame.display
from common.constants import GRID_CELL_PADDING, GRID_CELL_SIZE, COLUMNS, ROWS
def print_numbers():
display_surface = pygame.display.get_surface()
font = pygame.font.SysFont('Arial', 16)
for row_index in range(ROWS):
for col_index in range(COLUMNS):
x = (GRID_CELL_PADDING + GRID_CELL_SIZE) * col_index + GRID_CELL_PADDING + 7
y = (GRID_CELL_PADDING + GRID_CELL_SIZE) * row_index + GRID_CELL_PADDING + 16
display_surface.blit(font.render(f'[{col_index}, {row_index}]', True, (255, 0, 0)), (x, y))
pygame.display.update()

View File

@ -1,28 +0,0 @@
import pygame
from logic.exceptions import FieldNotWalkable
class Field(pygame.sprite.Sprite):
def __init__(self, texture_path, converted_texture, img, rect, row=0, column=0):
super().__init__()
self.texture_path = texture_path
self.converted_texture = converted_texture
self.image = img
self.row = row
self.column = column
self.rect = rect
self.busy = False
self.busy_detection()
def busy_detection(self):
if self.texture_path == 'water.png' or self.texture_path == 'grass_with_tree.jpg':
self.busy = True
def put_on(self, obj): # ustawia objekt na srodku pola
if not self.busy:
obj.rect = obj.rect.clamp(self.rect)
self.busy = True
obj.update()
else:
raise FieldNotWalkable

View File

@ -2,19 +2,14 @@ import sys
import pygame import pygame
from common.colors import FONT_DARK, WHITE
from common.constants import * from common.constants import *
from common.helpers import draw_text from helpers.debug import print_numbers
from logic.knights_queue import KnightsQueue from logic.level import Level
from models.castle import Castle
from models.knight import Knight
from models.monster import Monster
from ui.logs import Logs from ui.logs import Logs
from ui.screens.credits import Credits from ui.screens.credits import Credits
from ui.screens.main_menu import MainMenu
from ui.screens.options import Options from ui.screens.options import Options
from ui.stats import Stats from ui.stats import Stats
from .grid import Grid
from .spawner import Spawner
class Game: class Game:
@ -26,99 +21,24 @@ class Game:
self.screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT)) self.screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
self.clock = pygame.time.Clock() self.clock = pygame.time.Clock()
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))
self.bg = pygame.image.load("./resources/textures/bg.jpg") self.bg = pygame.image.load("./resources/textures/bg.jpg")
self.screens = {'credits': Credits(self.screen, self.clock), 'options': Options(self.screen, self.clock)} self.screens = {'credits': Credits(self.screen, self.clock), 'options': Options(self.screen, self.clock)}
click = False self.level = Level(self.screen)
def main_menu(self): def main_menu(self):
while True: menu = MainMenu(self.screen, self.clock, self.bg,
self.screen.blit(self.bg, (0, 0)) self.game,
self.screens['options'].display_screen,
pygame.draw.rect(self.screen, (255, 255, 255), pygame.Rect(800, 100, 400, 500), 0, 5) self.screens['credits'].display_screen)
draw_text('MAIN MENU', FONT_DARK, self.screen, 850, 150, 30, True) menu.display_screen()
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.screens['options'].display_screen()
if button_3.collidepoint((mx, my)):
if click:
self.screens['credits'].display_screen()
pygame.draw.rect(self.screen, (0, 191, 255), button_1, 0, 4)
draw_text('PLAY', WHITE, self.screen, 870, 255)
pygame.draw.rect(self.screen, (0, 191, 255), button_2, 0, 4)
draw_text('OPTIONS', WHITE, self.screen, 870, 355)
pygame.draw.rect(self.screen, (0, 191, 255), button_3, 0, 4)
draw_text('CREDITS', WHITE, self.screen, 870, 455)
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 game(self): def game(self):
running = True
grid = Grid(self.tiles)
stats = Stats() stats = Stats()
logs = Logs() logs = Logs()
knights_sprite_group = pygame.sprite.Group() print_numbers_flag = False
monsters_sprite_group = pygame.sprite.Group() running = True
castle_sprite_group = pygame.sprite.Group()
knights_left = self.generate_knights_team(knights_sprite_group)
knights_right = self.generate_knights_team(knights_sprite_group)
knights_queue = KnightsQueue(knights_left, knights_right)
spawn_left_team = Spawner(grid, knights_left, KNIGHTS_SPAWN_WIDTH, KNIGHTS_SPAWN_HEIGHT,
LEFT_KNIGHTS_SPAWN_FIRST_ROW, LEFT_KNIGHTS_SPAWN_FIRST_COL)
spawn_right_team = Spawner(grid, knights_right, KNIGHTS_SPAWN_WIDTH, KNIGHTS_SPAWN_HEIGHT,
RIGHT_KNIGHTS_SPAWN_FIRST_ROW,
RIGHT_KNIGHTS_SPAWN_FIRST_COL)
spawn_left_team.spawn()
spawn_right_team.spawn()
spawned_monsters = self.generate_monster(monsters_sprite_group)
monster_spawn = Spawner(grid, spawned_monsters, spawn_where_possible=True)
monster_spawn.spawn()
spawned_castle = self.generate_castle(castle_sprite_group)
castle_spawn = Spawner(grid, [spawned_castle], CASTLE_SPAWN_WIDTH, CASTLE_SPAWN_HEIGHT,
CASTLE_SPAWN_FIRST_ROW, CASTLE_SPAWN_FIRST_COL)
castle_spawn.spawn()
#grid.put_on_tile(0, 0, knights_left[0])
while running: while running:
self.screen.blit(self.bg, (0, 0)) self.screen.blit(self.bg, (0, 0))
@ -129,37 +49,16 @@ class Game:
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE: if event.key == pygame.K_ESCAPE:
running = False running = False
if event.key == 110: # clicked n letter on keyboard
print_numbers_flag = not print_numbers_flag
grid.update(self.screen)
stats.draw(self.screen) stats.draw(self.screen)
logs.draw(self.screen) logs.draw(self.screen)
knights_sprite_group.draw(self.screen) self.level.run()
monsters_sprite_group.draw(self.screen)
castle_sprite_group.draw(self.screen) if print_numbers_flag:
print_numbers()
pygame.display.update() pygame.display.update()
self.clock.tick(FPS_COUNT) self.clock.tick(FPS_COUNT)
@staticmethod
def generate_knights_team(knights_sprite_group):
knights = []
for i in range(4):
knight = Knight("./resources/textures/knight.png")
knights.append(knight)
knights_sprite_group.add(knight)
return knights
@staticmethod
def generate_monster(monsters_sprite_group):
monsters = []
for i in range(2):
monster = Monster()
monsters.append(monster)
monsters_sprite_group.add(monster)
return monsters
@staticmethod
def generate_castle(castle_sprite_group):
castle = Castle()
castle_sprite_group.add(castle)
return castle

View File

@ -1,86 +0,0 @@
import random
import numpy as np
import pygame
from common.constants import ROWS, COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, GRID_CELL_HEIGHT, BORDER_WIDTH, \
BORDER_RADIUS, NBR_OF_TREES, NBR_OF_WATER
from .exceptions import FieldNotWalkable
from .field import Field
class Grid:
def __init__(self, textures):
self.textures = textures
self.grid = []
self.free_fields = []
self.busy_fields = []
podkladka = np.zeros((ROWS, COLUMNS))
for drzewa in range(0, NBR_OF_TREES):
rzad = random.randint(0, ROWS - 1)
kolumna = random.randint(0, COLUMNS - 1)
if podkladka[rzad][kolumna] == 0:
podkladka[rzad][kolumna] = 1
else:
drzewa = drzewa - 1
for i in range(0, NBR_OF_WATER):
rzad = random.randint(0, ROWS - 1)
kolumna = random.randint(0, COLUMNS - 1)
if podkladka[rzad][kolumna] == 0:
podkladka[rzad][kolumna] = 2
else:
drzewa = drzewa - 1
for row in range(ROWS):
self.grid.append([])
for column in range(COLUMNS):
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]
if podkladka[row][column] == 1:
texture_path, converted_texture = self.textures[-1]
elif podkladka[row][column] == 2:
texture_path, converted_texture = self.textures[-2]
else:
texture_path, converted_texture = self.get_random_texture()
field = Field(
texture_path,
converted_texture,
pygame.transform.scale(converted_texture,
(GRID_CELL_WIDTH,
GRID_CELL_HEIGHT)),
pygame.Rect(box_rect),
row=row,
column=column
)
if field.busy:
self.busy_fields.append(field)
else:
self.free_fields.append(field)
self.grid[row].append(pygame.sprite.Group(field))
def update(self, screen):
self.draw(screen)
def get_random_texture(self):
texture_index = random.randint(0, len(self.textures) - 3)
return self.textures[texture_index]
def get_tile(self, row, column):
return pygame.sprite.Group.sprites(self.grid[row][column])[0] # iteruj kolumny i wiersze od 0
def put_on_tile(self, row, column, obj): # iteruj kolumny i wiersze od 0
try:
self.get_tile(row, column).put_on(obj)
except FieldNotWalkable:
print("Field busy")
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(5, 5, bg_width, bg_height), 0, BORDER_RADIUS)
for fields_row in self.grid:
for fields in fields_row:
fields.draw(screen)

88
logic/level.py Normal file
View File

@ -0,0 +1,88 @@
import random
import pygame
from common.constants import *
from logic.spawner import Spawner
from models.castle import Castle
from models.knight import Knight
from models.monster import Monster
from models.tile import Tile
class Level:
def __init__(self, screen):
self.screen = screen
# sprite group setup
self.sprites = pygame.sprite.Group()
self.create_map()
def generate_map(self):
map = [[' ' for x in range(COLUMNS)] for y in range(ROWS)]
spawner = Spawner(map)
spawner.spawn_where_possible(['w' for x in range(NBR_OF_WATER)])
spawner.spawn_where_possible(['t' for x in range(NBR_OF_TREES)])
spawner.spawn_in_area(['k' for x in range(4)], LEFT_KNIGHTS_SPAWN_FIRST_ROW, LEFT_KNIGHTS_SPAWN_FIRST_COL,
KNIGHTS_SPAWN_WIDTH, KNIGHTS_SPAWN_HEIGHT)
spawner.spawn_in_area(['k' for x in range(4)], RIGHT_KNIGHTS_SPAWN_FIRST_ROW, RIGHT_KNIGHTS_SPAWN_FIRST_COL,
KNIGHTS_SPAWN_WIDTH, KNIGHTS_SPAWN_HEIGHT)
spawner.spawn_in_area(['c'], CASTLE_SPAWN_FIRST_ROW, CASTLE_SPAWN_FIRST_COL, CASTLE_SPAWN_WIDTH,
CASTLE_SPAWN_HEIGHT, 2)
spawner.spawn_where_possible(['m' for x in range(NBR_OF_MONSTERS)])
return map
def create_map(self):
map = self.generate_map()
textures = []
for texture_path in TILES:
converted_texture = pygame.image.load('resources/textures/' + texture_path).convert_alpha()
converted_texture = pygame.transform.scale(converted_texture, (40, 40))
textures.append((texture_path, converted_texture))
castle_count = 0 # TODO: find some smarter method to print castle
for row_index, row in enumerate(map):
print(row)
for col_index, col in enumerate(row):
x = (GRID_CELL_PADDING + GRID_CELL_SIZE) * col_index + GRID_CELL_PADDING + 7
y = (GRID_CELL_PADDING + GRID_CELL_SIZE) * row_index + GRID_CELL_PADDING + 7
# add base tiles, e.g. water, tree, grass
if col == "w":
texture_index = 5
texture_surface = textures[texture_index][1]
Tile((x, y), texture_surface, self.sprites, 'w')
elif col == "t":
texture_index = 6
texture_surface = textures[texture_index][1]
Tile((x, y), texture_surface, self.sprites, 't')
else:
texture_index = random.randint(0, 4)
texture_surface = textures[texture_index][1]
Tile((x, y), texture_surface, self.sprites)
# add objects, e.g. knights, monsters, castle
if col == "k":
map[row_index][col_index] = Knight((x, y), self.sprites)
elif col == "m":
map[row_index][col_index] = Monster((x, y), self.sprites)
elif col == "c":
castle_count += 1
if castle_count == 4:
map[row_index][col_index] = Castle((x, y), self.sprites)
def run(self):
bg_width = (GRID_CELL_PADDING + GRID_CELL_SIZE) * COLUMNS + BORDER_WIDTH
bg_height = (GRID_CELL_PADDING + GRID_CELL_SIZE) * ROWS + BORDER_WIDTH
pygame.draw.rect(self.screen, (255, 255, 255), pygame.Rect(5, 5, bg_width, bg_height), 0, BORDER_RADIUS)
# update and draw the game
self.sprites.draw(self.screen)

View File

@ -1,36 +1,33 @@
import random import random
from common.constants import GRID_CELL_PADDING, GRID_CELL_WIDTH, GRID_CELL_HEIGHT from common.constants import COLUMNS, ROWS
class Spawner: class Spawner:
def __init__(self, grid, objs_to_spawn_list: list, spawn_area_width=0, spawn_area_height=0, spawn_area_pos_row=0, def __init__(self, map):
spawn_area_pos_column=0, spawn_where_possible=False): # kolumny i wiersze liczymy od 0; self.map = map
self.objs_to_spawn_list = objs_to_spawn_list
self.spawn_area_width = spawn_area_width
self.spawn_area_height = spawn_area_height
self.spawn_area_pos_row = spawn_area_pos_row
self.spawn_area_pos_column = spawn_area_pos_column
self.grid = grid
self.spawn_where_possible = spawn_where_possible
def spawn(self): def __is_free_field(self, field):
if self.spawn_where_possible: return field == ' '
possible_fields = self.grid.free_fields
else:
possible_fields = []
for field in self.grid.free_fields:
if (self.spawn_area_pos_column <= field.column < (self.spawn_area_width + self.spawn_area_pos_column)) \
and (self.spawn_area_pos_row <= field.row < (self.spawn_area_height + self.spawn_area_pos_row)):
possible_fields.append(field)
for obj in self.objs_to_spawn_list: def spawn_in_area(self, objects: list, spawn_area_pos_row=0, spawn_area_pos_column=0, spawn_area_width=0,
ran_index = random.randint(0, len(possible_fields)-1) spawn_area_height=0, size=1):
ran_field = possible_fields[ran_index] spawned_objects_count = 0
ran_field.busy = True
obj.rect = obj.rect.clamp(ran_field) while spawned_objects_count != len(objects):
self.grid.busy_fields.append(ran_field) x = random.randint(0, spawn_area_height) + spawn_area_pos_row
if ran_field in self.grid.free_fields: y = random.randint(0, spawn_area_width) + spawn_area_pos_column
self.grid.free_fields.remove(ran_field) if x < ROWS-1 and y < COLUMNS-1 and self.__is_free_field(self.map[x][y]):
if ran_field in possible_fields: for i in range(size):
possible_fields.remove(ran_field) for j in range(size):
obj.update() self.map[x-i][y-j] = objects[spawned_objects_count]
spawned_objects_count += 1
def spawn_where_possible(self, objects: list):
spawned_objects_count = 0
while spawned_objects_count != len(objects):
x = random.randint(0, ROWS-1)
y = random.randint(0, COLUMNS-1)
if self.__is_free_field(self.map[x][y]):
self.map[x][y] = objects[spawned_objects_count]
spawned_objects_count += 1

View File

@ -2,14 +2,9 @@ import pygame.image
class Castle(pygame.sprite.Sprite): class Castle(pygame.sprite.Sprite):
images = [] def __init__(self, position, group):
super().__init__(group)
def __init__(self): self.image = pygame.image.load("./resources/textures/castle.png").convert_alpha()
super().__init__()
self.image = pygame.image.load("./resources/textures/castle.png")
self.image = pygame.transform.scale(self.image, (78, 78)) self.image = pygame.transform.scale(self.image, (78, 78))
self.images.append(self.image) self.rect = self.image.get_rect(center=position)
self.rect = self.image.get_rect()
castle_list = pygame.sprite.Group()
self.health = 80 self.health = 80

View File

@ -1,17 +1,48 @@
import pygame.image import pygame.image
import random import random
from common.constants import GRID_CELL_SIZE
def load_knight_textures():
random_index = random.randint(1, 4)
states = [
pygame.image.load(f'resources/textures/knight_{random_index}_up.png').convert_alpha(), # up = 0
pygame.image.load(f'resources/textures/knight_{random_index}_right.png').convert_alpha(), # right = 1
pygame.image.load(f'resources/textures/knight_{random_index}_down.png').convert_alpha(), # down = 2
pygame.image.load(f'resources/textures/knight_{random_index}_left.png').convert_alpha(), # left = 3
]
return states
class Knight(pygame.sprite.Sprite): class Knight(pygame.sprite.Sprite):
def __init__(self, img):
super().__init__() def __init__(self, position, group):
self.images = [] super().__init__(group)
self.image = pygame.image.load("./resources/textures/knight.png")
self.image = pygame.transform.scale(self.image, (40, 40)) self.direction = 2
self.images.append(self.image) self.states = load_knight_textures()
self.rect = self.image.get_rect()
self.image = self.states[self.direction]
self.rect = self.image.get_rect(topleft=position)
self.health = random.randint(7, 12) self.health = random.randint(7, 12)
self.attack = random.randint(4, 7) self.attack = random.randint(4, 7)
self.defense = random.randint(1,4) self.defense = random.randint(1, 4)
self.points = 1 self.points = 1
# direction arg = -1 to rotate left
# direction arg = 1 to rotate right
def rotate(self, direction):
self.direction = (self.direction + direction) % 4
self.image = self.states[self.direction]
def step_forward(self):
if self.direction == 0:
self.rect.y = self.rect.y - GRID_CELL_SIZE
elif self.direction == 1:
self.rect.x = self.rect.x + GRID_CELL_SIZE
elif self.direction == 2:
self.rect.y = self.rect.y + GRID_CELL_SIZE
else:
self.rect.x = self.rect.x - GRID_CELL_SIZE

View File

@ -1,47 +1,36 @@
import pygame.image import pygame.image
import random import random
monster_images = [
pygame.image.load("./resources/textures/dragon2.png"),
pygame.image.load("./resources/textures/birb.png"),
pygame.image.load("./resources/textures/wolfart.png"),
pygame.image.load("./resources/textures/goblin.png"),
]
class Monster(pygame.sprite.Sprite): class Monster(pygame.sprite.Sprite):
monster_images = [] def __init__(self, position, group):
super().__init__(group)
def __init__(self): self.image = random.choice(monster_images)
super().__init__() self.image = pygame.transform.scale(self.image, (40, 40))
self.rect = self.image.get_rect(topleft=position)
self.monster_image1 = pygame.image.load("./resources/textures/dragon2.png")
self.monster_image1 = pygame.transform.scale(self.monster_image1, (40, 40))
self.monster_image2 = pygame.image.load("./resources/textures/birb.png")
self.monster_image2 = pygame.transform.scale(self.monster_image2, (40, 40))
self.monster_image3 = pygame.image.load("./resources/textures/wolfart.png")
self.monster_image3 = pygame.transform.scale(self.monster_image3, (40, 40))
self.monster_image4 = pygame.image.load("./resources/textures/goblin.png")
self.monster_image4 = pygame.transform.scale(self.monster_image4, (40, 40))
self.monster_images.append(self.monster_image1)
self.monster_images.append(self.monster_image2)
self.monster_images.append(self.monster_image3)
self.monster_images.append(self.monster_image4)
#self.images.append(self.image1)
self.image = random.choice(self.monster_images)
self.rect = self.image.get_rect()
monster_list = pygame.sprite.Group()
self.health = random.randrange(15, 25) self.health = random.randrange(15, 25)
self.attack = random.randrange(2, 10) self.attack = random.randrange(2, 10)
if self.image == self.monster_images[0]: if self.image == monster_images[0]:
self.health = 20 self.health = 20
self.attack = 9 self.attack = 9
self.points = 10 self.points = 10
elif self.image == self.monster_images[1]: elif self.image == monster_images[1]:
self.health = 15 self.health = 15
self.attack = 7 self.attack = 7
self.points = 7 self.points = 7
elif self.image == self.monster_images[2]: elif self.image == monster_images[2]:
self.health = 10 self.health = 10
self.attack = 4 self.attack = 4
self.points = 4 self.points = 4
elif self.image == self.monster_images[3]: elif self.image == monster_images[3]:
self.health = 7 self.health = 7
self.attack = 2 self.attack = 2
self.points = 2 self.points = 2

9
models/tile.py Normal file
View File

@ -0,0 +1,9 @@
import pygame
class Tile(pygame.sprite.Sprite):
def __init__(self, position, image, group, tile_type=' '):
super().__init__(group)
self.image = image
self.rect = self.image.get_rect(topleft=position)
self.tile_type = tile_type

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1,7 +1,7 @@
import pygame import pygame
from common.colors import FONT_DARK, ORANGE, WHITE from common.colors import FONT_DARK, ORANGE, WHITE
from common.constants import COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, BORDER_WIDTH, BORDER_RADIUS from common.constants import COLUMNS, GRID_CELL_PADDING, GRID_CELL_SIZE, BORDER_WIDTH, BORDER_RADIUS
from common.helpers import draw_text from common.helpers import draw_text
@ -10,7 +10,7 @@ class Logs:
self.grid = [] self.grid = []
def draw(self, screen): def draw(self, screen):
x = (GRID_CELL_PADDING + GRID_CELL_WIDTH) * COLUMNS + BORDER_WIDTH + 15 x = (GRID_CELL_PADDING + GRID_CELL_SIZE) * COLUMNS + BORDER_WIDTH + 15
y = 470 y = 470
# background # background

66
ui/screens/main_menu.py Normal file
View File

@ -0,0 +1,66 @@
import sys
import pygame
from common.colors import WHITE, FONT_DARK
from common.helpers import draw_text
from ui.screens.credits import Credits
from ui.screens.options import Options
from ui.screens.screen import Screen
class MainMenu(Screen):
def __init__(self, screen, clock, bg, btn_play_action, btn_options_action, btn_credits_action):
super().__init__('main_menu', screen, clock)
self.click = False
self.bg = bg
self.btn_play_action = btn_play_action
self.btn_options_action = btn_options_action
self.btn_credits_action = btn_credits_action
def display_screen(self):
running = True
while running:
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', FONT_DARK, self.screen, 850, 150, 30, True)
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 self.click:
self.btn_play_action()
if button_2.collidepoint((mx, my)):
if self.click:
self.btn_options_action()
if button_3.collidepoint((mx, my)):
if self.click:
self.btn_credits_action()
pygame.draw.rect(self.screen, (0, 191, 255), button_1, 0, 4)
draw_text('PLAY', WHITE, self.screen, 870, 255)
pygame.draw.rect(self.screen, (0, 191, 255), button_2, 0, 4)
draw_text('OPTIONS', WHITE, self.screen, 870, 355)
pygame.draw.rect(self.screen, (0, 191, 255), button_3, 0, 4)
draw_text('CREDITS', WHITE, self.screen, 870, 455)
self.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:
self.click = True
pygame.display.update()
self.clock.tick(60)

View File

@ -1,7 +1,7 @@
import pygame import pygame
from common.colors import FONT_DARK, ORANGE, WHITE, RED from common.colors import FONT_DARK, ORANGE, WHITE, RED
from common.constants import COLUMNS, GRID_CELL_PADDING, GRID_CELL_WIDTH, BORDER_WIDTH, BORDER_RADIUS from common.constants import COLUMNS, GRID_CELL_PADDING, GRID_CELL_SIZE, BORDER_WIDTH, BORDER_RADIUS
from common.helpers import draw_text from common.helpers import draw_text
@ -10,7 +10,7 @@ class Stats:
self.grid = [] self.grid = []
def draw(self, screen): def draw(self, screen):
x = (GRID_CELL_PADDING + GRID_CELL_WIDTH) * COLUMNS + BORDER_WIDTH + 15 x = (GRID_CELL_PADDING + GRID_CELL_SIZE) * COLUMNS + BORDER_WIDTH + 15
y = 5 y = 5
# background # background