def draw(self): pyxel.cls(0) super(Root, self).draw() if self.game_state.in_game_mode(): if not self.game_state.is_game_playing(): self.restart_text.draw(Point(0, 0)) elif self.game_state.paused: self.paused_text.draw(Point(0, 0))
def __init__(self, game_state, main_menu): super(Root, self).__init__(Size(255, 160)) self.caption = "Bi-onic" self.palette = PALETTE self.game_state = game_state # This line needs to come before any Pyxel imports are used, otherwise they can't # be imported pyxel.init(*self.size, caption=self.caption, palette=self.palette.get_palette()) pyxel.load(RESOURCE) self.character_display_window = CharacterDisplay() self.graph_area = GraphWindow(Point(0, 0), self.size) self.restart_text = TextSprite("Press R to Restart", 7) self.paused_text = TextSprite("Paused...", 7) self.game_windows = [self.character_display_window, self.graph_area] self.main_menu_windows = [main_menu] if DEBUG: self.debug_windows = [ ImageViewer(self.palette), Tiler(), PaletteViewer(), GraphImager(), TextImager() ] if len(self.debug_windows) != len(set(self.debug_windows)): print("debug windows with duplicate keys detected") quit()
def __init__(self): super(Tiler, self).__init__("Tiler", pyxel.KEY_T) self.sprite = Sprite(Point(1 * 8, 6 * 8), Size(5 * 8, 5 * 8), 0) self.source_size = self.sprite.source_size self.repetitions_x = 3 self.repetitions_y = 3 self.display_top_left = Vector(20, 20)
def draw_before_children(self): pyxel.rectb(*self.graph_tl, *self.graph_size, 7) pyxel.rectb(*self.graph_tl.br_of(Point(0, self.graph_size.y)), *self.graph_size.scale2D(Size(1, 2)), 7) self.draw_func_with_col(self.f, 8) self.draw_func_with_col(self.g, 9) self.draw_func_with_col(self.h, 10)
def draw(self, start): x = start.x # Draw backwards from the starting point for index in range(len(self.segments) - 1, -1, -1): if self.segments[index] < -self.high_bound: if index == len(self.segments) - 1: self.arrow_sprite.draw(Point(x, start.y - self.high_bound), Anchor.MIDDLE) else: pyxel.circ(x, start.y + self.segments[index], self.width, self.color) x -= 1
def __init__(self, start_game_interface): super(MainMenu, self).__init__(Point(0,0), Proportion2D(1,1)) self.start_game_interface = start_game_interface self.bg_col = 0 self.text_col = 7 self.selected_col = 14 self.character_sprite = Sprite(Point(0,0), Size(32,40), 0, 0) self.tutorial_menu_option = StatefulMainMenuOption("Tutorial: {}", "Yes", self.text_col, lambda main_menu: main_menu.update_tutorial_state()) self.options = [ MainMenuOption("Start Game", self.text_col, lambda main_menu: main_menu.start_game_interface.start_game()), #self.tutorial_menu_option, MainMenuOption("Quit", self.text_col, lambda main_menu: pyxel.quit()) ] self.num_options = len(self.options) self.current_option = 0 self.tutorial_active = True self.credit_text = TextSprite("By Robin McFarland: @RjmcfDev", 7) self.title = Sprite(Point(0,91), Size(67,23), 0, 0) self.animated_col = 10 self.animated_col_list = [11,9,8,8,9] self.current_animated_col_index = 0 self.frame_gap = 5
def __init__(self, length, low_border, high_border, low_bound, high_bound, color, width=0): self.length = length self.low_border = low_border self.high_border = high_border self.low_bound = low_bound self.high_bound = high_bound self.color = color self.width = width self.arrow_sprite = Sprite(Point(32, 0), Size(7, 8), 0, 0) # Record segments to be drawn as the heights they should be drawn at self.segments = []
class GraphImager(DebugWindow): def __init__(self): super(GraphImager, self).__init__("Graph Imager", pyxel.KEY_G) self.graph_tl = Point(10, 10) self.graph_size = Size(100, 70) self.cutoff = 0.9 def f(self, x): if x < self.cutoff: return self.up_curve(x / self.cutoff) return -self.up_curve((x - self.cutoff) / (1 - self.cutoff)) def up_curve(self, t): return t * (1 - t) def g(self, x): return x * (1 - x) def h(self, x): return -self.g(x) def draw_before_children(self): pyxel.rectb(*self.graph_tl, *self.graph_size, 7) pyxel.rectb(*self.graph_tl.br_of(Point(0, self.graph_size.y)), *self.graph_size.scale2D(Size(1, 2)), 7) self.draw_func_with_col(self.f, 8) self.draw_func_with_col(self.g, 9) self.draw_func_with_col(self.h, 10) def draw_func_with_col(self, func, col): for x in range(self.graph_size.x): current_y = self.graph_size.y * func(x / self.graph_size.x) current_y = self.graph_tl.y + self.graph_size.y - current_y current_x = self.graph_tl.x + x if x == 0: previous_y = current_y previous_x = current_x pyxel.line(previous_x, previous_y, current_x, current_y, col) previous_x = current_x previous_y = current_y
def __init__(self): super(GraphImager, self).__init__("Graph Imager", pyxel.KEY_G) self.graph_tl = Point(10, 10) self.graph_size = Size(100, 70) self.cutoff = 0.9
def __init__(self, title, toggle_key): super(DebugWindow, self).__init__(Point(0, 0), Proportion2D(1, 1)) self.title = title self.toggle_key = toggle_key
def draw(self): for window in self.windows: window.draw(Point(0, 0), self.size)