2018-03-24 21:24:11 +00:00
|
|
|
"""
|
|
|
|
Author: freezed <freezed@users.noreply.github.com> 2018-02-11
|
|
|
|
Version: 0.1
|
|
|
|
Licence: `GNU GPL v3` GNU GPL v3: http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
This file is part of [_ocp3_ project](https://github.com/freezed/ocp3)
|
|
|
|
"""
|
|
|
|
|
|
|
|
# CONFIGURATION
|
|
|
|
ELEMENT_LIST = [
|
|
|
|
{'symbol': 'n', 'name': 'needle', 'cross': True, 'ressurect': False, 'collect': True, 'tile': 'img/3-blue-transp-30.png'},
|
|
|
|
{'symbol': 't', 'name': 'tube', 'cross': True, 'ressurect': False, 'collect': True, 'tile': 'img/1-blue-transp-30.png'},
|
|
|
|
{'symbol': 'e', 'name': 'ether', 'cross': True, 'ressurect': False, 'collect': True, 'tile': 'img/2-blue-transp-30.png'},
|
|
|
|
{'symbol': 'E', 'name': 'exit', 'cross': False, 'ressurect': False, 'collect': False, 'tile': 'img/g-orange-transp-30.png'},
|
|
|
|
{'symbol': ' ', 'name': 'void', 'cross': True, 'ressurect': True, 'collect': False, 'tile': 'img/blue-white-30.png'},
|
|
|
|
{'symbol': '.', 'name': 'wall', 'cross': False, 'ressurect': False, 'collect': False, 'tile': 'img/transp-30.png'},
|
|
|
|
{'symbol': 'X', 'name': 'player', 'cross': False, 'ressurect': False, 'collect': False, 'tile': 'img/player-30.png'},
|
|
|
|
{'symbol': '\n', 'name': 'nlin', 'cross': False, 'ressurect': False, 'collect': False, 'tile': False},
|
|
|
|
]
|
|
|
|
|
|
|
|
# Possible returns of a move, keep the «ok» at the end
|
2018-03-26 13:34:07 +00:00
|
|
|
MOVE_STATUS = ['looser', 'wall', 'winner', 'collect', 'ok']
|
2018-03-24 21:24:11 +00:00
|
|
|
MOVE_STATUS_MSG = {
|
2018-03-26 13:34:07 +00:00
|
|
|
'looser': "Vous vous êtes fait assommé! Pour endormir le garde, il manqait: {}.\nPerdu!",
|
2018-03-24 21:24:11 +00:00
|
|
|
'wall': "Le déplacement est stoppé par un mur.",
|
2018-03-26 13:34:07 +00:00
|
|
|
'winner': "Gagné! Vous avez endormis le garde avec votre seringue.",
|
2018-03-24 22:38:54 +00:00
|
|
|
'collect': "Vous ramassez l'objet «{}»",
|
2018-03-24 21:24:11 +00:00
|
|
|
'ok': "Jusqu'ici, tout va bien…"
|
|
|
|
}
|
|
|
|
|
|
|
|
CELL_SIZE_PX = 30 # Size of the tiles, in pixels
|
|
|
|
MAZE_SIZE_TIL = 15 # Size of a map, in tiles
|
2018-03-27 00:39:40 +00:00
|
|
|
BLACK = (0, 0, 0)
|
|
|
|
BLUE = (0, 0, 128)
|
|
|
|
GREEN = (0, 255, 0)
|
|
|
|
WHITE = (255, 255, 255)
|
2018-03-24 21:24:11 +00:00
|
|
|
|
|
|
|
# Messages
|
2018-03-27 00:39:40 +00:00
|
|
|
CAPTION = "OCP3, a pygame maze"
|
2018-03-24 21:24:11 +00:00
|
|
|
ERR_MAP = "ERR_MAP: «{}»"
|
|
|
|
MSG_START_GAME = "Welcome in OCP3.\nUse arrow keys to play, any other key to quit."
|
|
|
|
|
|
|
|
# Files
|
|
|
|
BACKGROUND_IMG = 'img/zebra-800.png'
|
|
|
|
MAP_FILE = '01.map'
|
|
|
|
UNKNOWN_TILE = 'img/unknown-30.png'
|
|
|
|
|
|
|
|
|
|
|
|
# FUNCTIONS
|
|
|
|
|
|
|
|
|
|
|
|
def elmt_val(kval, ksel, vsel, nline=False):
|
|
|
|
"""
|
|
|
|
Return value(s) from ELEMENT_LIST
|
|
|
|
|
|
|
|
:param str kval: key of the value returned
|
|
|
|
:param str ksel: key of the selection criteria
|
|
|
|
:param str vsel: value of the selection criteria
|
|
|
|
:param bool/int nline: Default False, return value(s) in a list,
|
|
|
|
use a int() to return the `n` value from the list
|
|
|
|
|
|
|
|
:return str/bool/…:
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
if nline is False:
|
|
|
|
return (element[kval] for element in ELEMENT_LIST if element[ksel] == vsel)
|
|
|
|
else:
|
|
|
|
return [element[kval] for element in ELEMENT_LIST if element[ksel] == vsel][nline]
|
|
|
|
except IndexError:
|
|
|
|
return False
|
2018-03-26 23:23:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def maze_draw(WINDOW, map_string):
|
|
|
|
""" Take a map string and generate a graphic maze """
|
|
|
|
import pygame
|
|
|
|
back_tiles = []
|
|
|
|
for cell, element in enumerate(map_string):
|
|
|
|
img = elmt_val('tile', 'symbol', element, 0)
|
|
|
|
|
|
|
|
if img is False:
|
|
|
|
back_tiles.append(pygame.image.load(UNKNOWN_TILE).convert())
|
|
|
|
else:
|
|
|
|
back_tiles.append(pygame.image.load(img).convert_alpha())
|
|
|
|
|
|
|
|
x = (cell % MAZE_SIZE_TIL) * CELL_SIZE_PX
|
2018-03-27 00:39:40 +00:00
|
|
|
y = (cell // MAZE_SIZE_TIL) * CELL_SIZE_PX + (2 * CELL_SIZE_PX)
|
2018-03-26 23:23:46 +00:00
|
|
|
WINDOW.blit(back_tiles[cell], (x, y))
|
|
|
|
|
|
|
|
# Refresh
|
|
|
|
pygame.display.flip()
|