Ejemplo n.º 1
0
    def set_distance_traveled(self, val: Optional[int] = None) -> None:
        if val is not None:
            self.distance_traveled = val

        self.distance_traveled += self.get_distance_traveled()
        set_texture_uvpos(
            self,
            self.texture.uvpos[0] + self.bike.speed / self.texture.size[0],
            self.texture.uvpos[1])
        ValidObject.scene(self.parent).define_and_add_map_elements()
Ejemplo n.º 2
0
    def on_press(self, *args, **kwargs):
        _screen = self._current_screen()
        menu_screen = ValidObject.menu_screen(_screen.manager.get_screen('menu'))
        bikes_screen = ValidObject.bikes_screen(_screen.manager.get_screen('bikes'))
        maps_screen = ValidObject.maps_screen(_screen.manager.get_screen('maps'))
        shop_screen = ValidObject.shop_screen(_screen.manager.get_screen('shop'))
        screens = [menu_screen, bikes_screen, maps_screen, shop_screen]

        if 'BikesScreen' == _screen.__class__.__name__:
            if not app_config('bike', 'title'):
                bike_model = get_bike_by_title(bikes_screen.ids['title'].text)
                rest_rm = calc_rest_rm(bike_model.price)

                if Bike.buy(bike_model):
                    RightPanelBtn.change_rm(screens, rest_rm)
                    RightPanelBtn.change_character_wrap(bikes_screen.ids['character_wrap_price'], bike_model.price)
                    RightPanelBtn.change_character_wrap(bikes_screen.ids['character_wrap_power'], bike_model.power)
                    RightPanelBtn.change_character_wrap(bikes_screen.ids['character_wrap_speed'], bike_model.speed)
                    RightPanelBtn.change_character_wrap(bikes_screen.ids['character_wrap_acceleration'], bike_model.acceleration)
                    RightPanelBtn.change_character_wrap(bikes_screen.ids['character_wrap_agility'], bike_model.agility)
                    RightPanelBtn.cancel_animation_button(screens, 'left_panel_menu_bikes')

                    self.init_item(menu_screen.init_bike)
                    RightPanelBtn.change_bottom_right_btn(menu_screen)
                    bikes_screen.ids['title'].color = UColor.hex(UColor.WHITE)
                else:
                    Clock.schedule_once(self._create_animation_fail, 0)
                    Clock.schedule_once(self._clear_animation, .5)

        elif 'MapsScreen' == _screen.__class__.__name__:
            if not app_config('map', 'title'):
                map_model = get_map_by_title(maps_screen.ids['title'].text)
                rest_rm = calc_rest_rm(map_model.price)

                if BaseLevel.buy(map_model):
                    RightPanelBtn.change_rm(screens, rest_rm)
                    RightPanelBtn.change_character_wrap(maps_screen.ids['character_wrap_price'], map_model.price)
                    RightPanelBtn.change_character_wrap(maps_screen.ids['character_wrap_record'], '/dev/')
                    RightPanelBtn.change_character_wrap(maps_screen.ids['character_wrap_level'], map_model.level)
                    RightPanelBtn.change_character_wrap(maps_screen.ids['character_wrap_map'], map_model.map)
                    RightPanelBtn.change_character_wrap(maps_screen.ids['character_wrap_total_way'], map_model.total_way)
                    RightPanelBtn.cancel_animation_button(screens, 'left_panel_menu_maps')

                    self.init_item(menu_screen.init_map)
                    RightPanelBtn.change_bottom_right_btn(menu_screen)
                    maps_screen.ids['title'].color = UColor.hex(UColor.WHITE)
                else:
                    Clock.schedule_once(self._create_animation_fail, 0)
                    Clock.schedule_once(self._clear_animation, .5)
Ejemplo n.º 3
0
 def set_title(self, value):
     if self.parent:
         screen = ValidObject.maps_screen(self._screen())
         if screen.ids['title']:
             if screen.ids:
                 screen.ids['title'].text = value
                 return
Ejemplo n.º 4
0
 def tools(self):
     try:
         tools = self.road.parent and GetObject.get_child(
             self.road.parent.parent.parent, 'Tools')
         return ValidObject.tools(tools)
     except AttributeError:
         return None
Ejemplo n.º 5
0
    def on_index(self, *args, **kwargs):
        super(BikeMenuCarousel, self).on_index(*args, **kwargs)
        bikes_screen = ValidObject.bikes_screen(self._screen())

        if app_config('bike', 'title') == self.current_slide.item['title']:
            bikes_screen.ids['title'].text = self.title_active()
        else:
            self.char_btn_disabled('character_wrap_power')
            self.char_btn_disabled('character_wrap_speed')
            self.char_btn_disabled('character_wrap_acceleration')
            self.char_btn_disabled('character_wrap_agility')

        color = self.define_color('bike')
        bikes_screen.ids['title'].color = color

        bike_model = get_bike_by_title(self.current_slide.item['title'])
        self.change_prop_title('character_wrap_price', str(bike_model.price),
                               color)
        self.change_prop_title('character_wrap_power', str(bike_model.power),
                               color)
        self.change_prop_title('character_wrap_speed', str(bike_model.speed),
                               color)
        self.change_prop_title('character_wrap_acceleration',
                               str(bike_model.acceleration), color)
        self.change_prop_title('character_wrap_agility',
                               str(bike_model.agility), color)
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    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))
Ejemplo n.º 8
0
    def on_go_mountains(self, dt):
        # print('GoBackgroundMockDispatcher:on_go_mountains => ', self.road and self.road.state)
        if self.road is None and self.parent.__class__.__name__ == 'Scene' and len(
                self.parent.children) > 0:
            self.road = ValidObject.road(
                GetObject.get_child(self.parent, 'Road'))

        if self.bike is None:
            self.bike = GetObject(road=self.road).bike

        if self.road.has_finished() or (self.road.state in (
                State.ON_RELAX_STOP, State.ON_WAIT_MOVE,
                State.ON_WAIT_STOP)) or self.bike.get_collisions('Rock'):
            self.go_mountains_stop()
            return False

        else:
            if self.is_repeat_texture:
                print('+ GoBackgroundMockDispatcher:on_go_mountains')
                uvpos_x = self.texture.uvpos[0] + (self.bike.speed *
                                                   dt) / 100.0
                self.texture.uvpos = uvpos_x, self.texture.uvpos[1]

                repeat_texture(self.texture)
                redraw_texture(self, 'texture')
                return True
            return False
Ejemplo n.º 9
0
    def map_text(self):
        if not self.road:
            self.road = ValidObject.road(self.scene.children[1])

        res = [
            self.format_map_elem(e, not bool(i))
            for i, e in enumerate(self.road.level.map)
        ]
        return ', '.join([e for e in res])
Ejemplo n.º 10
0
    def change_character_wrap(character_wrap, value, color=UColor.hex(UColor.WHITE)):
        if type(value) is int:
            progress_bar = ValidObject.progress_bar(character_wrap.children[0].children[0])
            character_wrap.value = value
            character_wrap.max = progress_bar.max = value

        if character_wrap.has_value:
            character_wrap.title = character_wrap.format_number()
        else:
            character_wrap.title = character_wrap.format_string()

        RightPanelBtn.prop_buttons_show(character_wrap)
        RightPanelBtn.change_color_labels_right_panel(character_wrap, color)
Ejemplo n.º 11
0
    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
Ejemplo n.º 12
0
    def _collision(self, bike):
        bike.speed = 0
        bike.power = 0
        bike.acceleration = 0
        bike.collected_currency = 0
        bike.finish_dt = time.time()
        bike.anim_collision()
        self.draw_collision_rectangle(bike)

        # show finish information
        road = ValidObject.road(GetObject.get_child(bike.parent, 'Road'))
        curtain = Curtain(road=road, font_size=FS.H1.value)
        curtain.text = curtain.collision_text_rock()
        curtain.add_to_game_screen()
Ejemplo n.º 13
0
    def test_map_buy_success(self):
        self.set_app()
        _map = get_map_by_title('Default')

        menu_screen = ValidObject.menu_screen(self.sm.get_screen('menu'))
        self.assertEqual(
            menu_screen.get_label_by_text('No map').text, 'No map')

        self.assertEqual(_map.title, 'Default')
        self.assertTrue(LevelOne.buy(_map))
        self.assertEqual(_map.title, Cache.get('map', 'title'))
        self.assertEqual(_map.level, Cache.get('map', 'level'))
        self.assertEqual(_map.map, Cache.get('map', 'map'))
        self.assertEqual(_map.total_way, Cache.get('map', 'total_way'))
        self.assertEqual(RM - int(_map.price), Cache.get('bike', 'rm'))
Ejemplo n.º 14
0
    def test_bike_buy_success(self):
        self.set_app()
        _bike = get_bike_by_title('Default')

        menu_screen = ValidObject.menu_screen(self.sm.get_screen('menu'))
        self.assertEqual(
            menu_screen.get_label_by_text('No bike').text, 'No bike')

        self.assertEqual(_bike.title, 'Default')
        self.assertTrue(Bike.buy(_bike))

        self.assertEqual(_bike.title, Cache.get('bike', 'title'))
        self.assertEqual(_bike.power, Cache.get('bike', 'power'))
        self.assertEqual(_bike.speed, Cache.get('bike', 'speed'))
        self.assertEqual(_bike.acceleration, Cache.get('bike', 'acceleration'))
        self.assertEqual(_bike.agility, Cache.get('bike', 'agility'))
        self.assertEqual(RM - int(_bike.price), Cache.get('bike', 'rm'))
Ejemplo n.º 15
0
    def on_index(self, *args, **kwargs):
        super(MapMenuCarousel, self).on_index(*args, **kwargs)
        maps_screen = ValidObject.maps_screen(self._screen())

        if app_config('map', 'title') == self.current_slide.item['title']:
            maps_screen.ids['title'].text = self.title_active()

        map_model = get_map_by_title(self.current_slide.item['title'])
        color = self.define_color('map')
        maps_screen.ids['title'].color = color

        self.change_prop_title('character_wrap_price', map_model.price, color)
        self.change_prop_title('character_wrap_record', '*dev', color)
        self.change_prop_title('character_wrap_level', map_model.level, color)
        self.change_prop_title('character_wrap_map', map_model.map, color)
        self.change_prop_title('character_wrap_total_way', map_model.total_way,
                               color)
Ejemplo n.º 16
0
 def bike(self):
     if hasattr(self.road, 'bike') and self.road.bike:
         return self.road.bike
     elif hasattr(self.road, 'parent') and self.road.parent and len(
             self.road.parent.children) > 0:
         return ValidObject.bike(self.get_child(self.road.parent, 'Bike'))
Ejemplo n.º 17
0
    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
Ejemplo n.º 18
0
 def get_road(self):
     return self.parent and ValidObject.road(
         GetObject.get_child(self.parent, 'Road'))
Ejemplo n.º 19
0
 def get_bike(self):
     if not self.bike:
         screen = ValidObject.screen(self.parent)
         self.bike = ValidObject.bike(screen.ids['bike'])
     return self.bike
Ejemplo n.º 20
0
 def background(self):
     if self.road.parent:
         return ValidObject.background(
             self.get_child(self.road.parent, 'Background'))
Ejemplo n.º 21
0
 def get_road(self) -> Optional[Widget]:
     return self.parent and ValidObject.road(
         GetObject.get_child(self.parent, 'Road'))
Ejemplo n.º 22
0
 def scene(self):
     if hasattr(self.road, 'parent') and self.road.parent:
         return ValidObject.scene(self.road.parent)
Ejemplo n.º 23
0
 def char_btn_disabled(self, sid: str):
     bikes_screen = ValidObject.bikes_screen(self._screen())
     box_layout = bikes_screen.ids[sid].children[1]
     btn = box_layout.children[0]
     btn.disabled = True
     btn.opacity = 0.2
Ejemplo n.º 24
0
 def get_bike(self):
     return ValidObject.bike(GetObject.get_child(self.parent, 'Bike'))
Ejemplo n.º 25
0
 def road(self):
     try:
         road = self._road if self._road else StatusBar.get_road()
         return ValidObject.road(road)
     except AttributeError:
         return None
Ejemplo n.º 26
0
 def set_title(self, value):
     if self.parent:
         screen = ValidObject.bikes_screen(self._screen())
         screen.ids['title'].text = value