commit 37d1265b98fd3fc3c6fb50b44d233b20513bc6d9 Author: Szymon Komosinski Date: Mon Apr 27 11:38:36 2020 +0200 First deadline diff --git a/Font/lb1.png b/Font/lb1.png new file mode 100644 index 0000000..f92e9f7 Binary files /dev/null and b/Font/lb1.png differ diff --git a/Font/lb2.png b/Font/lb2.png new file mode 100644 index 0000000..6522dfe Binary files /dev/null and b/Font/lb2.png differ diff --git a/Font/lb3.png b/Font/lb3.png new file mode 100644 index 0000000..8185872 Binary files /dev/null and b/Font/lb3.png differ diff --git a/Font/lb4.png b/Font/lb4.png new file mode 100644 index 0000000..4117f79 Binary files /dev/null and b/Font/lb4.png differ diff --git a/Font/lb5.png b/Font/lb5.png new file mode 100644 index 0000000..ca2a3c5 Binary files /dev/null and b/Font/lb5.png differ diff --git a/Font/lb6.png b/Font/lb6.png new file mode 100644 index 0000000..85b275f Binary files /dev/null and b/Font/lb6.png differ diff --git a/Font/lb7.png b/Font/lb7.png new file mode 100644 index 0000000..612c80b Binary files /dev/null and b/Font/lb7.png differ diff --git a/Font/lb8.png b/Font/lb8.png new file mode 100644 index 0000000..deb37c0 Binary files /dev/null and b/Font/lb8.png differ diff --git a/Font/lb9.png b/Font/lb9.png new file mode 100644 index 0000000..687daee Binary files /dev/null and b/Font/lb9.png differ diff --git a/Font/lr1.png b/Font/lr1.png new file mode 100644 index 0000000..8a5a140 Binary files /dev/null and b/Font/lr1.png differ diff --git a/Font/lr2.png b/Font/lr2.png new file mode 100644 index 0000000..53ccb38 Binary files /dev/null and b/Font/lr2.png differ diff --git a/Font/lr3.png b/Font/lr3.png new file mode 100644 index 0000000..288c713 Binary files /dev/null and b/Font/lr3.png differ diff --git a/Font/lr4.png b/Font/lr4.png new file mode 100644 index 0000000..79d5449 Binary files /dev/null and b/Font/lr4.png differ diff --git a/Font/lr5.png b/Font/lr5.png new file mode 100644 index 0000000..55c0533 Binary files /dev/null and b/Font/lr5.png differ diff --git a/Font/lr6.png b/Font/lr6.png new file mode 100644 index 0000000..c229fcb Binary files /dev/null and b/Font/lr6.png differ diff --git a/Font/lr7.png b/Font/lr7.png new file mode 100644 index 0000000..961db14 Binary files /dev/null and b/Font/lr7.png differ diff --git a/Font/lr8.png b/Font/lr8.png new file mode 100644 index 0000000..e62e7c4 Binary files /dev/null and b/Font/lr8.png differ diff --git a/Font/lr9.png b/Font/lr9.png new file mode 100644 index 0000000..251c545 Binary files /dev/null and b/Font/lr9.png differ diff --git a/Font/rb0.png b/Font/rb0.png new file mode 100644 index 0000000..095f330 Binary files /dev/null and b/Font/rb0.png differ diff --git a/Font/rb1.png b/Font/rb1.png new file mode 100644 index 0000000..5c7c2fe Binary files /dev/null and b/Font/rb1.png differ diff --git a/Font/rb2.png b/Font/rb2.png new file mode 100644 index 0000000..c7bee10 Binary files /dev/null and b/Font/rb2.png differ diff --git a/Font/rb3.png b/Font/rb3.png new file mode 100644 index 0000000..a70d4ce Binary files /dev/null and b/Font/rb3.png differ diff --git a/Font/rb4.png b/Font/rb4.png new file mode 100644 index 0000000..2c50466 Binary files /dev/null and b/Font/rb4.png differ diff --git a/Font/rb5.png b/Font/rb5.png new file mode 100644 index 0000000..1bc609e Binary files /dev/null and b/Font/rb5.png differ diff --git a/Font/rb6.png b/Font/rb6.png new file mode 100644 index 0000000..9d90cb1 Binary files /dev/null and b/Font/rb6.png differ diff --git a/Font/rb7.png b/Font/rb7.png new file mode 100644 index 0000000..a59561c Binary files /dev/null and b/Font/rb7.png differ diff --git a/Font/rb8.png b/Font/rb8.png new file mode 100644 index 0000000..6a072b9 Binary files /dev/null and b/Font/rb8.png differ diff --git a/Font/rb9.png b/Font/rb9.png new file mode 100644 index 0000000..8e9764f Binary files /dev/null and b/Font/rb9.png differ diff --git a/Font/rr0.png b/Font/rr0.png new file mode 100644 index 0000000..469ae40 Binary files /dev/null and b/Font/rr0.png differ diff --git a/Font/rr1.png b/Font/rr1.png new file mode 100644 index 0000000..0d0047d Binary files /dev/null and b/Font/rr1.png differ diff --git a/Font/rr2.png b/Font/rr2.png new file mode 100644 index 0000000..a265033 Binary files /dev/null and b/Font/rr2.png differ diff --git a/Font/rr3.png b/Font/rr3.png new file mode 100644 index 0000000..86fb6d8 Binary files /dev/null and b/Font/rr3.png differ diff --git a/Font/rr4.png b/Font/rr4.png new file mode 100644 index 0000000..6128546 Binary files /dev/null and b/Font/rr4.png differ diff --git a/Font/rr5.png b/Font/rr5.png new file mode 100644 index 0000000..23cf7be Binary files /dev/null and b/Font/rr5.png differ diff --git a/Font/rr6.png b/Font/rr6.png new file mode 100644 index 0000000..f221229 Binary files /dev/null and b/Font/rr6.png differ diff --git a/Font/rr7.png b/Font/rr7.png new file mode 100644 index 0000000..48f1893 Binary files /dev/null and b/Font/rr7.png differ diff --git a/Font/rr8.png b/Font/rr8.png new file mode 100644 index 0000000..7f87c8c Binary files /dev/null and b/Font/rr8.png differ diff --git a/Font/rr9.png b/Font/rr9.png new file mode 100644 index 0000000..84df8c8 Binary files /dev/null and b/Font/rr9.png differ diff --git a/Icons/A_door.png b/Icons/A_door.png new file mode 100644 index 0000000..ea7dcc1 Binary files /dev/null and b/Icons/A_door.png differ diff --git a/Icons/A_icon.png b/Icons/A_icon.png new file mode 100644 index 0000000..aea5224 Binary files /dev/null and b/Icons/A_icon.png differ diff --git a/Icons/A_key.png b/Icons/A_key.png new file mode 100644 index 0000000..18fe6fd Binary files /dev/null and b/Icons/A_key.png differ diff --git a/Icons/A_moves.png b/Icons/A_moves.png new file mode 100644 index 0000000..da25606 Binary files /dev/null and b/Icons/A_moves.png differ diff --git a/Icons/A_open_door.png b/Icons/A_open_door.png new file mode 100644 index 0000000..8e53bb7 Binary files /dev/null and b/Icons/A_open_door.png differ diff --git a/Icons/A_time.png b/Icons/A_time.png new file mode 100644 index 0000000..04cd7a5 Binary files /dev/null and b/Icons/A_time.png differ diff --git a/Icons/B_door.png b/Icons/B_door.png new file mode 100644 index 0000000..969ca3f Binary files /dev/null and b/Icons/B_door.png differ diff --git a/Icons/B_icon.png b/Icons/B_icon.png new file mode 100644 index 0000000..f2eb341 Binary files /dev/null and b/Icons/B_icon.png differ diff --git a/Icons/B_key.png b/Icons/B_key.png new file mode 100644 index 0000000..5996a43 Binary files /dev/null and b/Icons/B_key.png differ diff --git a/Icons/B_moves.png b/Icons/B_moves.png new file mode 100644 index 0000000..d9d2eff Binary files /dev/null and b/Icons/B_moves.png differ diff --git a/Icons/B_open_door.png b/Icons/B_open_door.png new file mode 100644 index 0000000..609b5cd Binary files /dev/null and b/Icons/B_open_door.png differ diff --git a/Icons/B_time.png b/Icons/B_time.png new file mode 100644 index 0000000..4a3c404 Binary files /dev/null and b/Icons/B_time.png differ diff --git a/Icons/Empty.png b/Icons/Empty.png new file mode 100644 index 0000000..fdb8443 Binary files /dev/null and b/Icons/Empty.png differ diff --git a/Icons/Wall.png b/Icons/Wall.png new file mode 100644 index 0000000..ce92bca Binary files /dev/null and b/Icons/Wall.png differ diff --git a/config.py b/config.py new file mode 100644 index 0000000..fc101d2 --- /dev/null +++ b/config.py @@ -0,0 +1,63 @@ +import sys +import pygame as pg + +# Display dimensions: +tile_size = 40 +map_height = 18 +map_width = 32 +legend_height = 1 + +# Game display: + +gameDisplay = pg.display.set_mode((tile_size * map_width, tile_size * (map_height + legend_height))) +display_width = map_width * tile_size +display_height = (map_height + legend_height) * tile_size +clock = pg.time.Clock() + +# Accessible floors for both players: +ground = 0 +red_key = 2 +blue_key = 3 + +# Inaccessible floor for both players: +wall = 1 + +# Accessible floor for player #1: +red_open_door = 4 + +# Inaccessible floor for player #1: +red_closed_door = 6 + +# Accessible floors for player #2: +blue_open_door = 5 + +# Inaccessible floor for player #1: +blue_closed_door = 7 + +# Linking floors with matching textures: +textures = { + ground: pg.image.load('Icons/Empty.png'), + red_key: pg.image.load('Icons/A_key.png'), + blue_key: pg.image.load('Icons/B_key.png'), + red_open_door: pg.image.load('Icons/A_open_door.png'), + blue_open_door: pg.image.load('Icons/B_open_door.png'), + red_closed_door: pg.image.load('Icons/A_door.png'), + blue_closed_door: pg.image.load('Icons/B_door.png'), + wall: pg.image.load('Icons/Wall.png') +} + +# Colors: +black = (0, 0, 0) +purple = (138, 43, 226) +white = (255, 255, 255) + +def events(): + # Letting the user quit + for event in pg.event.get(): + if event.type == pg.QUIT: + pg.quit() + sys.exit() + if event.type == pg.KEYDOWN: + if event.key == pg.K_ESCAPE or pg.K_q: + pg.quit() + sys.exit() \ No newline at end of file diff --git a/gamemodes.py b/gamemodes.py new file mode 100644 index 0000000..6ab9de6 --- /dev/null +++ b/gamemodes.py @@ -0,0 +1,19 @@ +from grid import * +from config import * + + +def singlePlayer(): + global pause + gameExit = False + a = Grid() + a.generate_map() + while not gameExit: + + for event in pg.event.get(): + if event.type == pg.QUIT: + pg.quit() + quit() + + a.display_map() + pg.display.update() + clock.tick(60) \ No newline at end of file diff --git a/grid.py b/grid.py new file mode 100644 index 0000000..abf185b --- /dev/null +++ b/grid.py @@ -0,0 +1,42 @@ +from config import * +from templates import * + + +class Grid: + + def __init__(self): + # Creating a new drawing surface + self.floor = [[0 for x in range(map_width)] for y in range(map_height)] + self.surface = pg.display.set_mode((tile_size * map_width, tile_size * (map_height + legend_height))) + + # Making a mouse cursor invisible + pg.mouse.set_visible(True) + + # Elements of the legend bar beneath the map + self.time = 0 + + + def generate_map(self): + # Generating an empty map and filling it with floors of a randomly chosen type + A = random_part() + for i in range(16): + for j in range(9): + self.floor[j][i] = A[j][i] + B = random_part() + for i in range(16, 32): + for j in range(9): + self.floor[j][i] = B[j][i - 16] + C = random_part() + for i in range(16): + for j in range(9, 18): + self.floor[j][i] = C[j - 9][i] + D = random_part() + for i in range(16, 32): + for j in range(9, 18): + self.floor[j][i] = D[j - 9][i - 16] + + def display_map(self): + for x in range(map_width): + for y in range(map_height): + self.surface.blit(textures[self.floor[y][x]], + (x * tile_size, y * tile_size)) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..2108ad8 --- /dev/null +++ b/main.py @@ -0,0 +1,22 @@ +from config import * +from grid import Grid +from templates import * +from menu import * + +# initializing PyGame module +pg.init() + +pg.display.set_caption('Key Star AI Race') + +pause = False + + +def main(): + game_intro() + singlePlayer() + pg.quit() + quit() + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/menu.py b/menu.py new file mode 100644 index 0000000..d1b6a36 --- /dev/null +++ b/menu.py @@ -0,0 +1,82 @@ +import pygame as pg +from config import * +from gamemodes import * + + +def text_objects(text, font): + textSurface = font.render(text, True, purple) + return textSurface, textSurface.get_rect() + + +def button(msg, x, y, w, h, action=None): + + mouse = pg.mouse.get_pos() + click = pg.mouse.get_pressed() + + font = pg.font.SysFont("ubuntumono", 80) + + if x+w > mouse[0] > x and y+h > mouse[1] > y: + textSurface = font.render(msg, True, purple) + + if click[0] == 1 and action != None: + action() + else: + textSurface = font.render(msg, True, black) + + textRectangle = textSurface.get_rect() + textRectangle.center = ((x + (w / 2)), (y + (h / 2))) + gameDisplay.blit(textSurface, textRectangle) + + +def quitgame(): + pg.quit() + quit() + + +def unpause(): + global pause + pause = False + + +def paused(): + largeText = pg.font.SysFont("ubuntumono", 160) + TextSurf, TextRect = text_objects("Paused", largeText) + TextRect.center = ((display_width / 2), (display_height / 2)) + gameDisplay.blit(TextSurf, TextRect) + + while pause: + for event in pg.event.get(): + # print(event) + if event.type == pg.QUIT: + pg.quit() + quit() + + # gameDisplay.fill(white) + + button("Continue", 150, 450, 100, 50, unpause) + button("Quit", 550, 450, 100, 50, quitgame) + + pg.display.update() + + +def game_intro(): + + intro = True + + while intro: + for event in pg.event.get(): + if event.type == pg.QUIT: + pg.quit() + quit() + gameDisplay.fill(white) + largeText = pg.font.SysFont("ubuntumono", 160) + TextSurf, TextRect = text_objects("Key *Star Race", largeText) + TextRect.center = ((display_width / 2), (display_height / 4)) + gameDisplay.blit(TextSurf, TextRect) + + button("Singleplayer", 720, 360, 450, 100, singlePlayer) + button("Multiplayer", 738, 480, 450, 100) + button("Quit", 874, 600, 450, 100, quitgame) + + pg.display.update() + clock.tick(15) diff --git a/templates.py b/templates.py new file mode 100644 index 0000000..321839d --- /dev/null +++ b/templates.py @@ -0,0 +1,72 @@ +from numpy import array, flipud, fliplr +from random import randint + +A = [[0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0], + [0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1], + [0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1], + [1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0], + [1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0], + [0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0], + [1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1], + [0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0]] + +B = [[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0], + [0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0], + [1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0], + [0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1], + [1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0], + [0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0]] + +C = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0], + [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], + [1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1], + [0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0], + [0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0]] + +D = [[0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + [0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0], + [0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1], + [0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0], + [0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] + + +def create_n_fill_matrix(x, y): + A = [[0 for i in range(x)] for j in range(y)] + for i in range(x): + for j in range(y): + print("x: {}, y: {}\n".format(i, j)) + a = input("value: ") + A[j][i] = a + return A + + +def random_part(): + n = randint(1, 4) + if n == 1: + X = A + if n == 2: + X = B + if n == 3: + X = C + if n == 4: + X = D + X = array(X) + m = randint(0, 1) + if m == 1: + X = flipud(X) + o = randint(0, 1) + if o == 1: + X = fliplr(X) + return X