Beispiel #1
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
Beispiel #2
0
    def on_landing(self, dt):
        print('on_landing')
        # todo: only as temp solution fix speed loading page
        if self.road.state != State.ON_JUMP_MOVE:

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

            if self.bike.is_in_sky():
                self.bike.on_collision_currency()

                self.bike.acceleration = dt * self.road.gravity
                self.bike.y -= self.bike.acceleration * self.bike.max_power / 4

                self.bike.set_power(self.bike.power + self.bike.acceleration)

                # todo: need to move into start method
                # remove all animation (need to call one time)
                if self.road.state == State.ON_LANDING_START:
                    self.bike.anim_landing()

                self.road.set_state(State.ON_LANDING_MOVE)
                self.set_distances()
                return True

            else:
                self.bike.y = self.road.line_points[-1]
                self.landing_stop()
                return False
Beispiel #3
0
    def set_app(self):
        BaseGameScreenGUITest.setdefaults_config()

        self.screen = GameScreen(name='game')
        self.render(self.screen)

        self.road = self.screen.ids['road']
        self.bike = self.screen.ids['bike']
        self.road.bike = self.bike

        self.road.init_app_config()
        self.bike.init_app_config()

        curtain = GetObject(self.road).curtain
        curtain.text = ''

        # default value
        self.bike.x = 800
        self.road.set_state(State.ON_LANDING_START)

        self.bike.y = self.road.line_points[-1]
        self.bike.speed = 0
        self.bike.max_speed = 20
        self.bike.power = 0
        self.bike.max_power = 300
Beispiel #4
0
    def do_start_timer(self) -> Union[str, None]:
        self.text = str(self.stop)
        self.draw_background(0.7)

        if self.stop == 0:
            scene = GetObject(self.road).scene
            scene.remove_widget(self)
            return

        return self.text
Beispiel #5
0
class GoBackgroundDispatcher(BaseDispatcher):
    is_repeat_texture = BooleanProperty(False)
    texture = ObjectProperty()
    parent = ObjectProperty()

    @classmethod
    def start_states_list(cls):
        return (
            State.ON_GO_START,
            State.ON_GO_MOVE,
            State.ON_RELAX_START,
            State.ON_RELAX_MOVE,
            State.ON_RELAX_STOP,
        )

    @classmethod
    def stop_states_list(cls):
        return GoDispatcher.stop_states_list()

    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

    def go_mountains_start(self):
        if self.is_repeat_texture and self.road.state in GoBackgroundDispatcher.start_states_list(
        ):
            Clock.schedule_interval(self.on_go_mountains, SECOND_GAME)

    def go_mountains_stop(self):
        print('GoBackgroundMockDispatcher:go_mountains_stop')
        if self.road and self.road.state in GoBackgroundDispatcher.stop_states_list(
        ):
            # Clock.unschedule(self.on_go_mountains)
            if hasattr(self.on_go_mountains, 'cancel'):
                self.on_go_mountains.cancel()
Beispiel #6
0
    def start_timer(self, dt):
        curtain = self.parent.ids['curtain']
        if curtain:
            if curtain.text == '3':
                curtain.draw_background()
            elif curtain.text == '2':
                curtain.draw_background(0.5)
            elif curtain.text == '1':
                curtain.draw_background(0.4)
                curtain.text = ''
                self.remove_widget(curtain)

                bike = GetObject(self.parent.ids['road']).bike
                bike.start_dt = time.time()
                return False

            curtain.stop -= 1
            curtain.text = str(curtain.stop)
Beispiel #7
0
    def on_release(self):
        print('BTN: on_release')
        if not self.bike and not self.road:
            self.set_objects()

        curtain = GetObject(self.road).curtain
        if curtain.text == '':
            self.button_state_style()
            self._road_manage_events(is_release=True)
Beispiel #8
0
 def set_bike(self, bike: Optional[Bike] = None) -> None:
     if bike is not None:
         self.bike = bike
     if self.bike is None:
         WarnTrySetBikeFromLayoutWarn(self)
         self.bike = GetObject(road=self).bike
     if self.bike is None:
         ErrBikeIsNotConfig(self)
     else:
         InfoBikeInstalledFor(self)
Beispiel #9
0
    def go_start(self):
        print('go_start')
        curtain = GetObject(self.road).curtain

        # todo: It was fixed for tests. It was checked by logs
        if State.ON_WAIT_MOVE in self.road.last_states:
            if hasattr(self.road.on_wait, 'cancel'):
                self.road.on_wait.cancel()

        if curtain.text == '' and not self.bike.is_in_sky() and self.road.state in GoDispatcher.start_states_list():
            Clock.schedule_interval(self.on_go, SECOND_GAME)
            self.road.set_state(State.ON_GO_START)
            self.bike.anim_go()
Beispiel #10
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()
Beispiel #11
0
 def get_road(self) -> Optional[Widget]:
     return self.parent and ValidObject.road(
         GetObject.get_child(self.parent, 'Road'))
Beispiel #12
0
 def get_road(self):
     return self.parent and ValidObject.road(
         GetObject.get_child(self.parent, 'Road'))
Beispiel #13
0
 def get_bike(self):
     return ValidObject.bike(GetObject.get_child(self.parent, 'Bike'))
Beispiel #14
0
 def add_to_game_screen(self, screen=None, scene=None) -> None:
     self.draw_background()
     screen = screen or GetObject(self.road).screen
     scene = scene or GetObject(self.road).scene
     screen.ids[self.sid] = self
     scene.add_widget(self)
Beispiel #15
0
 def collision_text_rock(self) -> str:
     bike = GetObject(self.road).bike
     return 'Collision to {}.\nPress on "Restart Game"\n{:.2f}'.format(
         bike.__class__.__name__,
         bike.finish_dt - bike.start_dt)
Beispiel #16
0
class LandingDispatcher(BaseDispatcher):
    def __init__(self, **kwargs):
        self.register_event_type(State.EVENT_ON_LANDING)
        super(LandingDispatcher, self).__init__(**kwargs)

    @classmethod
    def start_states_list(cls):
        return (State.NONE, State.ON_WAIT_START, State.ON_JUMP_MOVE,
                State.ON_JUMP_STOP)

    @classmethod
    def stop_states_list(cls):
        return State.ON_LANDING_START, State.ON_LANDING_MOVE, State.ON_LANDING_STOP

    def landing_start(self):
        print('landing_start')
        if self.road.state in LandingDispatcher.start_states_list():
            Clock.schedule_interval(self.on_landing, SECOND_GAME)
            self.road.set_state(State.ON_LANDING_START)
            # todo: trouble with access to element
            self.bike and self.bike.anim_landing()

    def landing_stop(self):
        print('landing_stop')
        if self.road.state in LandingDispatcher.stop_states_list():
            # Clock.unschedule(self.on_landing)
            if hasattr(self.on_landing, 'cancel'):
                self.on_landing.cancel()

            self.road.set_state(State.ON_LANDING_STOP)

            self.bike.speed -= self.bike.max_speed / 200

            # check road state after loop and apply needed event
            # e.g. pass managing elements to other events
            if self.bike.speed <= 0:
                self.road.wait_start()
            else:
                self.road.relax_start()

    def on_landing(self, dt):
        print('on_landing')
        # todo: only as temp solution fix speed loading page
        if self.road.state != State.ON_JUMP_MOVE:

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

            if self.bike.is_in_sky():
                self.bike.on_collision_currency()

                self.bike.acceleration = dt * self.road.gravity
                self.bike.y -= self.bike.acceleration * self.bike.max_power / 4

                self.bike.set_power(self.bike.power + self.bike.acceleration)

                # todo: need to move into start method
                # remove all animation (need to call one time)
                if self.road.state == State.ON_LANDING_START:
                    self.bike.anim_landing()

                self.road.set_state(State.ON_LANDING_MOVE)
                self.set_distances()
                return True

            else:
                self.bike.y = self.road.line_points[-1]
                self.landing_stop()
                return False
Beispiel #17
0
 def get_tools(self) -> Widget:
     return GetObject(road=self.get_road()).tools
Beispiel #18
0
 def get_bike(self) -> Widget:
     return GetObject(road=self.get_road()).bike
Beispiel #19
0
 def get_background(self) -> Widget:
     return GetObject(road=self).background
Beispiel #20
0
 def get_road(self) -> Widget:
     _road = self.parent and GetObject.get_child(self.parent.parent, 'Road')
     return GetObject(road=_road).road
Beispiel #21
0
 def change_rm(screens, value):
     for s in screens:
         GetObject.get_child(s, 'RMLayout').ids['panel_rm'].text = "{}: {}".format(Currency.units, value)
         return