def main() -> None: screen_width = 64 screen_height = 35 tileset = tcod.tileset.load_tilesheet( get_app_path() + "/ceefax_teletext_6x10.png", 16, 16, tcod.tileset.CHARMAP_CP437) with tcod.context.new_terminal(screen_width * 2, screen_height * 2, tileset=tileset, title="Teletext", vsync=True, sdl_window_flags=tcod.context. SDL_WINDOW_BORDERLESS) as root_context: root_console = tcod.Console(screen_width, screen_height, order="F") engine = Engine() cycle = 0 while True: root_console.clear() engine.event_handler.on_render(root_console=root_console) root_context.present(root_console) engine.handle_events(root_context) cycle += 1 if cycle % 2 == 0: engine.update()
def update(self): if self.state == PageManagerState.SEARCHING_FOR_PAGE: if self.searching_for_page_progress >= int(self.active_page_key): self.state = PageManagerState.DISPLAYING_PAGE self.active_page = self.pages[self.active_page_key] self.tiles = self.active_page.tiles playsound(get_app_path() + "/sounds/arrive_at_page.wav", False) self.searching_for_page_progress += max( self.page_change_speed * self.engine.get_delta_time(), 1)
def clear(self): for i in range(0, num_digits): self.tiles[self.first_digit_pos[0] + i, self.first_digit_pos[1]]['graphic'][0] = ord(' ') self.num_digits = 0 self.selected_number = [0, 0, 0] playsound(get_app_path() + "/sounds/remote_button_press.wav", False)
def delete_number(self): if self.num_digits == 1: self.clear() elif self.num_digits == 2: self.num_digits = 1 self.selected_number[1] = 0 elif self.num_digits == 3: self.num_digits = 2 self.selected_number[2] = 0 playsound(get_app_path() + "/sounds/remote_button_press.wav", False)
def __init__(self, file: str): xp_file = gzip.open(get_app_path() + file) raw_data = xp_file.read() xp_file.close() self.tiles = np.full((40, 24), fill_value=tile_types.blank, order="F") xp_data = xp_loader.load_xp_string(raw_data) for h in range(0, 40): for w in range(0, 24): self.tiles[ h, w]['graphic'] = xp_data['layer_data'][0]['cells'][h][w]
def add_number(self, number: int): if self.num_digits == 0: if number != 0: self.num_digits = 1 self.selected_number[0] = number elif self.num_digits == 1: self.num_digits = 2 self.selected_number[1] = number elif self.num_digits == 2: self.num_digits = 3 self.selected_number[2] = number playsound(get_app_path() + "/sounds/remote_button_press.wav", False)
def change_page(self, page: str): if page in self.pages: self.active_page_key = page self.state = PageManagerState.SEARCHING_FOR_PAGE self.searching_for_page_progress = 100 playsound(get_app_path() + "/sounds/search.wav", False)
from sections.section import Section import numpy as np import xp_loader import gzip import tile_types from ui.completeUI import CompleteUI import os.path from application_path import get_app_path completion_panel_xp_file = get_app_path() + '/images/completePanel' class CompleteSection(Section): def __init__(self, engine, x, y, width, height): super().__init__(engine, x, y, width, height) self.animated_tiles = list() for i in range(0, 3): if os.path.isfile(completion_panel_xp_file + str(i + 1) + '.xp'): xp_file = gzip.open(completion_panel_xp_file + str(i + 1) + '.xp') raw_data = xp_file.read() xp_file.close() xp_data = xp_loader.load_xp_string(raw_data) self.animated_tiles.append( np.full((self.width, self.height), fill_value=tile_types.blank, order="F"))
def page_not_found(self): self.remote_error = RemoteErrors.PAGE_NOT_FOUND playsound(get_app_path() + "/sounds/page_not_found.wav", False)
from sections.section import Section import numpy as np import tile_types import tcod import xp_loader import gzip from ui.remoteUI import RemoteUI from enum import auto, Enum from threading import Timer from playsound import playsound from application_path import get_app_path remote_xp_file = get_app_path() + '/images/remote.xp' num_digits = 3 class RemoteErrors(Enum): NONE = auto() PAGE_NOT_FOUND = auto() class Remote(Section): def __init__(self, engine, x, y, width, height): super().__init__(engine, x, y, width, height) xp_file = gzip.open(remote_xp_file) raw_data = xp_file.read() xp_file.close() xp_data = xp_loader.load_xp_string(raw_data)
from sections.section import Section import numpy as np import xp_loader import gzip import tile_types from ui.answerUI import AnswersUI from effects.horizontal_wipe_effect import HorizontalWipeEffect, HorizontalWipeDirection from application_path import get_app_path answer_panel_xp_file = get_app_path() + '/images/answerPanel.xp' class Answers(Section): def __init__(self, engine, x,y,width, height): super().__init__(engine, x, y, width, height) xp_file = gzip.open(answer_panel_xp_file) raw_data = xp_file.read() xp_file.close() xp_data = xp_loader.load_xp_string(raw_data) self.tiles = np.full((self.width, self.height), fill_value=tile_types.blank, order="F") for h in range(0,self.height): for w in range(0,self.width): self.tiles[w,h]['graphic']= xp_data['layer_data'][0]['cells'][w][h] self.correct_colour = (0,255,0)
from sections.section import Section import numpy as np import xp_loader import gzip import tile_types from ui.menuUI import MenuUI import os.path from application_path import get_app_path menu_panel_xp_file = get_app_path() + '/images/menuPanel' class Menu(Section): def __init__(self, engine, x, y, width, height): super().__init__(engine, x, y, width, height) self.animated_tiles = list() for i in range(0, 3): if os.path.isfile(menu_panel_xp_file + str(i + 1) + '.xp'): xp_file = gzip.open(menu_panel_xp_file + str(i + 1) + '.xp') raw_data = xp_file.read() xp_file.close() xp_data = xp_loader.load_xp_string(raw_data) self.animated_tiles.append( np.full((self.width, self.height), fill_value=tile_types.blank, order="F"))