def init_app_config(self) -> None: map_model = get_map_by_title(app_config('map', 'title')) if not self.level: self.set_state(State.INIT) self.road = self self.bike or self.set_bike() if map_model and map_model.level == 'LevelOne': self.level = LevelOne(self, self.bike) Logger.info('Level was set successful!\n{}'.format(self.level)) if self.level: self.texture = self.level.road_texture self.total_way = self.level.total_way(self.level.map) # set background texture if self.parent: game_screen = ValidObject.screen(self.parent.parent) background = game_screen.ids['background'] if background and map_model: background.texture = image_texture(map_model.source) repeat_texture(self.texture, int(Window.width / self.texture.width))
def restart_game(self): Cache.remove(CACHE_NAME) screen_name = 'game' screen = ValidObject.screen(self.manager.get_screen(screen_name)) screen.ids['left_btn_wrap'].children[0].button_state_style() screen.ids['right_btn_wrap'].children[0].button_state_style() scene = screen.ids['scene'] road = screen.ids['road'] bike = screen.ids['bike'] if screen.ids.get('curtain'): scene.remove_widget(screen.ids['curtain']) road.bike = bike road.init_app_config() road.set_state(State.NONE) road.clear_widgets() road.landing_start() road.set_distance_traveled(0) bike.init_app_config() bike.collected_currency = 0 bike.y = 800 bike.canvas.remove_group("background") Curtain(font_size=FS.H1.value).add_to_game_screen(screen, scene) curtain = screen.ids['curtain'] if not curtain.text: curtain.do_start_timer() Clock.schedule_interval(scene.start_timer, 1) self.manager.current = screen_name
def set_app(self): BaseGameScreenGUITest.setdefaults_config() Cache.register(CACHE_NAME, limit=1000) self.manager = ScreenManager(transition=WipeTransition()) self.manager.add_widget(StartScreen(name='start')) self.manager.add_widget(GameScreen(name='game')) self.render(self.manager) screen = ValidObject.screen(self.manager.get_screen('game')) self.road = screen.ids['road'] self.bike = screen.ids['bike'] self.road.bike = self.bike self.bike.speed = 0
def screen(self): if hasattr(self.road, 'parent') and self.road.parent.parent: return ValidObject.screen(self.road.parent.parent)
def slider_map_max(self): if not self.road and self.parent: screen = ValidObject.screen(self.parent.parent.parent) self.road = ValidObject.road(screen.ids['road']) return self.road.total_way
def get_bike(self): if not self.bike: screen = ValidObject.screen(self.parent) self.bike = ValidObject.bike(screen.ids['bike']) return self.bike