First deadline
BIN
Font/lb1.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lb2.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lb3.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lb4.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lb5.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lb6.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lb7.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lb8.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lb9.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lr1.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lr2.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lr3.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lr4.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lr5.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lr6.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lr7.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lr8.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/lr9.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rb0.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rb1.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rb2.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rb3.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rb4.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rb5.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rb6.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rb7.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rb8.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rb9.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rr0.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rr1.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rr2.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rr3.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rr4.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rr5.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rr6.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rr7.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rr8.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Font/rr9.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/A_door.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/A_icon.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/A_key.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/A_moves.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/A_open_door.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/A_time.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/B_door.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/B_icon.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/B_key.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/B_moves.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/B_open_door.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/B_time.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/Empty.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Icons/Wall.png
Normal file
After Width: | Height: | Size: 6.5 KiB |
63
config.py
Normal file
@ -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()
|
19
gamemodes.py
Normal file
@ -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)
|
42
grid.py
Normal file
@ -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))
|
22
main.py
Normal file
@ -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()
|
82
menu.py
Normal file
@ -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)
|
72
templates.py
Normal file
@ -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],
|
||||||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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
|