class PongBall(Widget):
    velocity_x = kv.NumericProperty(0)
    velocity_y = kv.NumericProperty(0)
    velocity = kv.ReferenceListProperty(velocity_x, velocity_y)

    def move(self):
        self.pos = Vector(*self.velocity) + self.pos
class ScatterImage(Scatter):
    source = Properties.StringProperty()
    anim_delay = Properties.NumericProperty()
    saveOnDBEvent = Properties.ObjectProperty()
    imagenId = Properties.NumericProperty()

    def on_pos(self, instance, value):
        try:
            self.saveOnDBEvent.cancel()
        except:
            logging.info('Gifs: No previous event')

        self.saveOnDBEvent = Clock.schedule_once(self.saveOnDB, 5)

    def bringToFront(self):
        parent = self.parent
        children = parent.children
        childOnTop = children[0]

        if (self != childOnTop):
            parent.remove_widget(self)
            parent.add_widget(self)

    def saveOnDB(self, dt):
        gifToSave = Gifs(
            _id=self.imagenId,
            source=self.source,
            posX=self.pos[0],
            posY=self.pos[1],
            scale=self.scale,
            rotation=self.rotation,
            delay=self.anim_delay)
        gifToSave.save()

        logging.info('DB: Updated gif with id: ' + str(self.imagenId))
Exemple #3
0
class ShmupApp(App):
    screen_manager = kp.ObjectProperty(None)
    highscore = kp.NumericProperty(0)
    game_over_msg = kp.StringProperty("")
    score = kp.NumericProperty(0)
    
    def build(self):
        # self.game = Game()
        # Clock.schedule_interval(self.game.update, 1.0/FPS)
        # return self.game
        self.screen_manager = MetaGame()
        return self.screen_manager

    def new_game(self):
        if self.screen_manager.game_screen.game.over:
            self.screen_manager.game_screen.game.new()
        self.screen_manager.current = "game_screen"
        Clock.schedule_interval(self.screen_manager.game_screen.game.update, 1.0/FPS)

    def update_score(self):
        self.score = self.screen_manager.game_screen.game.score
        self.highscore = max(self.highscore, self.score)

    def quit_game(self):
        self.update_score()
        self.screen_manager.game_screen.game.quit_game()
        self.screen_manager.current = "game_over_screen"
Exemple #4
0
class StatusBar(GridLayout):
    connection = properties.StringProperty("")
    mission = properties.StringProperty("None")
    speed = properties.NumericProperty(0)
    direction = properties.NumericProperty(0)

    def get_dir(self):
        return self.direction
Exemple #5
0
class ball(Widget):
    kivy.lang.Builder.load_file("/home/mmohdbilal/KIVY /KIVY-2/style.kv")
    velocity_x = properties.NumericProperty(0)
    velocity_y = properties.NumericProperty(0)
    velocity = properties.ReferenceListProperty(velocity_x, velocity_y)

    def move(self):
        self.pos = Vector(*self.velocity) + self.pos
Exemple #6
0
class Tile(Widget):
    tile = kp.ListProperty([0, 0])
    mapx = kp.NumericProperty()
    mapy = kp.NumericProperty()
    def __init__(self, **kwargs):
        super().__init__()
        # print("\nTile", kwargs, type(self))
        # tilex=col, tiley=row
        self.tile = [kwargs.get("tilex", 0), kwargs.get("tiley", 0)]

    def on_tile(self, *args):
        # print("on_tile", args, self.tile)
        self.mapx = self.tile[0] * GAME.get("tilesize")
        self.mapy = self.tile[1] * GAME.get("tilesize")
class GifConfig(ButtonBehavior, AsyncImage):
    imagenId = Properties.NumericProperty()
    pinned = Properties.BooleanProperty()
    delay = Properties.NumericProperty()

    def pinGif(self):

        self.pinned = not self.pinned

        gif = dbWrapper.findGifById(self.imagenId)
        gif.pinned = self.pinned
        gif.posX = 10
        gif.posY = 10
        gif.save()
Exemple #8
0
class Resource(Widget):
    current = kp.NumericProperty(0)
    per_s = kp.NumericProperty(0)
    _type = kp.StringProperty()

    def __init__(self, _type, **kwargs):
        super().__init__(**kwargs)
        self._type = _type.lower()
        self.current = RESOURCES.get("INIT").get(_type)
        self.per_s = RESOURCES.get("PRODUCTION").get(_type)
        self.icon = RESOURCES.get("ICON").get(_type)
        self.ratio = RESOURCES.get("RATIO")

    def calc_next_level(self):
        return self.per_s * self.ratio
Exemple #9
0
class AppMenuTextItem(ToggleButton, AbstractMenuItem):
    label = kp.ObjectProperty(None)
    text = kp.StringProperty('')
    font_size = kp.NumericProperty(14)
    color = kp.ListProperty([1, 1, 1, 1])

    def on_release(self):
        submenu = self.get_submenu()

        if self.state == 'down':
            root = self._root_parent
            submenu.bounding_box_widget = root.bounding_box if root.bounding_box else root.parent

            submenu.bind(visible=self.on_visible)
            submenu.show(self.x, self.y - 1)

            for sibling in self.siblings:
                if sibling.get_submenu() is not None:
                    sibling.state = 'normal'
                    sibling.get_submenu().hide()

            self.parent._setup_hover_timer()
        else:
            self.parent._cancel_hover_timer()
            submenu.hide()

    def on_visible(self, *args):
        submenu = self.get_submenu()
        if self.width > submenu.get_max_width():
            submenu.width = self.width

    def _check_submenu(self):
        super(AppMenuTextItem, self)._check_submenu()
        self.disabled = (self.get_submenu() is None)
Exemple #10
0
class Timer(Widget):
    """Used to dynamically display the current time elapsed on the screen."""

    # initializes a timer with 0 seconds.
    timeText = props.NumericProperty(0)

    def __init__(self, **kwargs):
        super(Timer, self).__init__(**kwargs)

    # need dt to relate update of time to frames per second
    def update_time(self, dt):
        """Updates the time elapsed."""
        self.timeText += 1 * dt

    def reset_time(self):
        """Resets the time elapsed."""
        self.stop_time()
        self.timeText = 0
        self.start_time()

    def start_time(self):
        """Begins a clock interval running at 60 FPS calling update_time"""
        Clock.schedule_interval(self.update_time, 1.0 / 60.0)

    def stop_time(self):
        """Stops time."""
        Clock.unschedule(self.update_time)
Exemple #11
0
class Unit(EventDispatcher):
    n = kp.NumericProperty(0)
    n_str = kp.StringProperty("0")
    icon = kp.StringProperty()

    def __init__(self, **kwargs):
        super().__init__()
        self.name = kwargs.get("name").upper()
        self.settings = UNITS.get(self.name)
        self.name = self.name.lower()
        self.icon = self.settings.get("ICON")
        self._type = self.settings.get("TYPE", "general")
        self.requirements = self.settings.get("REQUIREMENTS")
        self.population = self.requirements.get("POPULATION")
        self.unlock = self.requirements.get("UNLOCK")
        self.atk = self.settings.get("ATK")
        self.defence = self.settings.get("DEFENCE")
        self.speed = self.settings.get("SPEED")
        self.capacity = self.settings.get("CAPACITY")
        self.special_abilities = self.settings.get("SPECIAL_ABILITIES")

    def __repr__(self):
        return "Unit(name=%s)" % self.name

    def on_n(self, *args):
        self.n_str = str(self.n)

    def recruit(self, n):
        n = int(n)
        app = App.get_running_app()
        # check if can recruit:
        if app.wood.current >= self.requirements.get("WOOD") * n:
            app.wood.current -= self.requirements.get("WOOD") * n
            self.n += n
Exemple #12
0
class IconLabel(HoverInfoBehavior, Label):
    icon = prop.StringProperty('')
    icon_size = prop.NumericProperty(16)

    def __init__(self, **k):
        super(IconLabel, self).__init__(**k)
        self.markup=True
class ScatterColoredLabel(Scatter):
    background_color = Properties.ListProperty((0, 0, 0, 1))
    visible = Properties.BooleanProperty()
    saveOnDBEvent = Properties.ObjectProperty()
    noteId = Properties.NumericProperty()
    text = Properties.StringProperty()

    def on_pos(self, instance, value):
        try:
            self.saveOnDBEvent.cancel()
        except:
            logging.info('Notes: No previous event')
        self.saveOnDBEvent = Clock.schedule_once(self.saveOnDB, 5)

    def saveOnDB(self, dt):
        noteToSave = Notes(
            _id=self.noteId,
            pinned=self.visible,
            text=self.text,
            posX=self.pos[0],
            posY=self.pos[1],
            scale=self.scale,
            rotation=self.rotation,
            rgb=[
                self.background_color[0]*255,
                self.background_color[1]*255,
                self.background_color[2]*255,
                self.background_color[3],
            ],

        )
        noteToSave.save()

        logging.info('DB: Updated note with id: ' + str(self.noteId))
Exemple #14
0
class Warehouse(Building):
    max_capacity = kp.NumericProperty()
    time_to_full = kp.DictProperty({"wood": "", "clay": "", "iron": ""})
    time_when_its_full = kp.DictProperty({"wood": "", "clay": "", "iron": ""})

    def __init__(self):
        self.settings = BUILDINGS.get("WAREHOUSE")
        super().__init__()
        self.capacity0 = self.settings.get("CAPACITY_INIT")
        self.capacity_ratio = self.settings.get("CAPACITY_RATIO")
        self.max_capacity = self.calc_capacity(self.level)
        self.bind(level=self.on_level)
        Clock.schedule_interval(self.calc_when_is_full, .1)

    def calc_capacity(self, level):
        return self.capacity0 * self.capacity_ratio**(level - 1)

    def on_level(self, *args):
        self.max_capacity = self.calc_capacity(self.level)

    def calc_when_is_full(self, *args):
        self.app = App.get_running_app()
        for resource in self.app.resources:
            resource_until_full = self.max_capacity - resource.current
            resource_until_full = max(resource_until_full, 0)
            seconds_to_full = resource_until_full / resource.per_s
            self.time_to_full[resource._type] = str(
                datetime.timedelta(seconds=int(seconds_to_full)))
            self.time_when_its_full[resource._type] =\
                datetime.datetime.fromtimestamp(time.time() + seconds_to_full).strftime('%H:%M:%S')
Exemple #15
0
class InfoDayConfig(Screen):
    colorHora = Properties.ListProperty([1, 1, 1, 1])
    formatoHora = Properties.ListProperty(["24h", False])

    colorFecha = Properties.ListProperty([1, 1, 1, 1])
    formatoFecha = Properties.StringProperty("dd/mm")

    colorTemp = Properties.ListProperty([1, 1, 1, 1])
    formatoTemp = Properties.StringProperty("metric")

    formatoClima = Properties.NumericProperty(2)

    c_id = Properties.StringProperty('6361046')
    activeInter = Properties.BooleanProperty(True)

    colorInter = Properties.ListProperty([1, 1, 1, 1])

    def __init__(self, **kwargs):
        super(InfoDayConfig, self).__init__(**kwargs)
        self.pos_hint = {'center_y': 0.5, 'center_x': 0.5}
        self.getAllInter()

    def saveConfig(self):
        #guardar las configs
        if self.ids.textinput.text == "":
            self.c_id = self.ids.textinput.hint_text
        else:
            self.c_id = self.ids.textinput.text
        dbWrapper.saveHora("hora", self.formatoHora, self.colorHora)
        dbWrapper.saveFecha("fecha", self.formatoFecha, self.colorFecha)
        dbWrapper.saveTemp("temp", self.formatoTemp, self.colorTemp, self.c_id)
        dbWrapper.saveClima("weather", self.formatoClima, self.c_id)
        dbWrapper.saveInfoState(self.activeInter)
        dbWrapper.saveInternationalConfig("inter", self.colorInter)

    def getAllInter(self):
        datos = dbWrapper.getAllInterByMonth(str(strftime('%m')))

        for j in datos:
            layout = BoxLayout(orientation='horizontal',
                               size_hint_y=None,
                               height=20,
                               padding=[-40, 0, 0, 0])
            layout.add_widget(Texto(text=str(j.dia)))
            layout.add_widget(
                Texto(text=str(j.info if len(j.info) < 25 else '...' +
                               j.info[10:35] + '...')))
            self.ids.todos.add_widget(layout)

    def pressedBack(self, widget):
        anim = Animation(pos_hint={"center_x": .5, "y": -.03}, duration=.1)
        anim += Animation(pos_hint={"center_x": .5, "y": 0}, duration=.1)
        anim.bind(on_complete=partial(self.goToMenuScreen))
        anim.start(widget)

    def goToMenuScreen(self, widget, selected):
        self.saveConfig()
        App.get_running_app().root.transition = FadeTransition(duration=.3)
        App.get_running_app().root.current = "menu"
Exemple #16
0
class LoadingModalView(ModalView):
    time = P.NumericProperty(0)

    def on_open(self):
        Clock.schedule_interval(self.update_time, 0)

    def update_time(self, dt):
        self.time += dt
Exemple #17
0
class GameApp(App):
    ball_size = kp.NumericProperty(BALL_SIZE * Window.width)

    def build(self):
        self.width = Window.width
        self.height = Window.height
        self.game = Game()
        Clock.schedule_interval(self.game.update, 1.0 / FPS)
        return self.game
Exemple #18
0
class Game(Screen):
    joystick_x = GAME.get("joystick", {}).get("x", 0.8)
    joystick_y = GAME.get("joystick", {}).get("y", 0.2)
    joystick_size = GAME.get("joystick", {}).get("size", 150)

    is_colliding = kp.BooleanProperty(False)

    # turn:
    last_magnitude = kp.NumericProperty(0)
    is_turn = kp.BooleanProperty(False)

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def update(self, dt):
        # print("update", self.joystick.angle)
        self.player.update(dt)

        delta_magnitude = self.joystick.magnitude - self.last_magnitude
        if abs(delta_magnitude) == 1:
            self.is_turn = 1
        else:
            self.is_turn = 0
        self.last_magnitude = self.joystick.magnitude
        # print("delta_magnitude", delta_magnitude)

        signal = -1 if abs(self.joystick.angle) > 90 else 1

        if self.is_turn:
            self.player.x += signal * self.player.agility / 5
        else:
            delta = self.player.agility * self.joystick.magnitude * dt
            self.player.x += signal * delta

        # Borders:
        self.player.right = min(self.player.right, Window.width)
        self.player.x = max(self.player.x, 0)

        # update cars:
        self.car.y -= self.player.speed * dt
        if self.car.top <= 0:
            self.car.y = Window.height
            self.car.center_x = random.randint(0, Window.width)

        # collisions:
        if self.player.collide_widget(self.car):
            if not self.is_colliding:
                print("collide")
                self.is_colliding = True
                self.player.hull -= self.player.speed / 50
                if self.player.hull <= 0:
                    print("GAME OVER")
                    self.player.new()
                    self.car.y = Window.height
                self.player.speed *= 0.5
        else:
            self.is_colliding = False
Exemple #19
0
class GameApp(App):
    width = kp.NumericProperty(Window.width)
    height = kp.NumericProperty(Window.height)

    def on_start(self):
        from kivy.base import EventLoop
        EventLoop.window.bind(on_keyboard=self.hook_keyboard)

    def hook_keyboard(self, window, key, *largs):
        if key == 27:
            print("back")
            # do what you want, return True for stopping the propagation
            if self.meta_game.current == "store_screen":
                self.meta_game.current = "menu_screen"
                return True

    def build(self):
        self.meta_game = MetaGame()
        return self.meta_game
class PongPaddle(Widget):
    score = kv.NumericProperty(0)

    def bounce_ball(self, ball):
        if self.collide_widget(ball):
            vx, vy = ball.velocity
            offset = (ball.center_y - self.center_y) / (self.height / 2)
            bounced = Vector(-1 * vx, vy)
            vel = bounced * 1.1
            ball.velocity = vel.x, vel.y + offset
Exemple #21
0
class GameApp(App):
    step_size = kp.NumericProperty(Window.height / N_OF_STEPS)
    debug = kp.BooleanProperty(DEBUG)

    def build(self):
        game = Game()
        game.frog = Player()
        game.new()
        game.add_widget(game.frog)
        Clock.schedule_interval(game.update, 1.0 / FPS)
        return game
class GifConfig2(BoxLayout):
    imagenId = Properties.NumericProperty()
    pinned = Properties.BooleanProperty()
    delay = Properties.NumericProperty()
    updateListFunction = Properties.ObjectProperty()
    source = Properties.StringProperty()

    def pinGif(self):

        self.pinned = not self.pinned

        gif = dbWrapper.findGifById(self.imagenId)
        gif.pinned = self.pinned
        gif.posX = 10
        gif.posY = 10
        gif.save()

    def deleteGif(self):
        dbWrapper.deleteGifById(self.imagenId)
        self.updateListFunction()
Exemple #23
0
class LinhaHomePage(BoxLayout):
    nome_group = kvProps.StringProperty('')
    idGrupo = kvProps.NumericProperty()

    def go_chat(self):
        db = BancoDadosGrupos()
        GrupoList = db.listarGruposPorId(self.idGrupo)
        App.get_running_app().registro_atual = GrupoList
        App.get_running_app().route.transition.direction = 'left'
        App.get_running_app().route.current = 'chat'

        global idGrupoChat
        idGrupoChat = self.idGrupo
Exemple #24
0
class ContextMenuText(ContextMenuItem):
    label = kp.ObjectProperty(None)
    submenu_postfix = kp.StringProperty(' ...')
    text = kp.StringProperty('')
    font_size = kp.NumericProperty(14)
    color = kp.ListProperty([1, 1, 1, 1])

    def __init__(self, *args, **kwargs):
        super(ContextMenuText, self).__init__(*args, **kwargs)

    @property
    def content_width(self):
        # keep little space for eventual arrow for submenus
        return self.label.texture_size[0] + 10
class Platform(Sprite):
    img1 = kp.StringProperty("imgs/ground_grass.png")
    img1_width = kp.NumericProperty(380)
    img1_height = kp.NumericProperty(94)
    img2 = kp.StringProperty("imgs/ground_grass_small.png")
    img2_width = kp.NumericProperty(201)
    img2_height = kp.NumericProperty(100)

    def __init__(self, x, y, w, h, game, **kwargs):
        self.groups = (game.all_sprites, game.platforms)
        super().__init__(**kwargs)
        width = w * Window.width
        width = min(width, self.img1_width)
        width = max(width, self.img2_width * 0.5)
        if width > self.img2_width:
            self.source = self.img1
            self.ratio = self.img1_height / self.img1_width
        else:
            self.source = self.img2
            self.ratio = self.img2_height / self.img2_width
        self.game = game
        self.add_to_groups(index=PLATFORM_LAYER)
        self.pos = (x * Window.width, y * Window.height)
        # self.size = (w * Window.width, h * Window.height)
        self.width = width
        self.height = width * self.ratio
        with self.canvas.before:
            Color(0, 1., 0, 0.8 * DEBUG)
            self.rect = Rectangle(size=self.size, pos=self.pos)

        if randrange(100) < POW_SPAWN_PCT:
            PowerUp(self)

        self.bind(pos=self.update_rect)

    def update_rect(self, *args):
        self.rect.pos = self.pos
Exemple #26
0
class app(Widget):

    pongball = properties.ObjectProperty(None)
    player = properties.ObjectProperty(None)
    opponent = properties.ObjectProperty(None)
    score = properties.NumericProperty(0)
    game = properties.ObjectProperty(None)

    def serve(self):
        self.game = "off"

    def on_touch_down(self, touch):
        if touch.x <= self.width and self.game == "off":
            self.pongball.velocity = Vector(0, 0)

    def on_touch_up(self, touch):
        if touch.x <= self.width and self.game == "off":
            self.pongball.velocity = Vector(10,
                                            0).rotate(random.randint(60, 300))
            self.game = "on"

    def update(self, dt):
        self.pongball.move()
        if (self.pongball.y <= 30) or (self.pongball.y >= self.height - 45):
            self.pongball.velocity_y *= -1

        if (self.pongball.x <= 0) or (self.pongball.x >= self.width - 25):
            self.score += 1
            self.pongball.velocity_x *= -1

        if (self.player.y <= 0):
            self.player.y += 20
        if (self.player.y >= self.height - 125):
            self.player.y -= 20

        if (self.opponent.y <= 0):
            self.opponent.y += 20
        if (self.opponent.y >= self.height - 125):
            self.opponent.y -= 20

        self.player.collision(self.pongball)
        self.opponent.collision(self.pongball)

    def on_touch_move(self, touch):
        if touch.x <= self.width / 4:
            self.player.center_y = touch.y

        if touch.x >= self.width - self.width / 4:
            self.opponent.center_y = touch.y
Exemple #27
0
class SearchNode(ButtonBehavior, HoverBehavior, MDBoxLayout):
    """Custom widget to populate recycleview"""

    cls_nome = prop.StringProperty() ## Node name
    codigo_ref = prop.StringProperty() ## Node reference rode
    legacyId = prop.NumericProperty() ## Node id to be searched
    search_frame = prop.ObjectProperty() ## Root widget reference

    def on_enter(self, *args):
        """Mouse over node, bg color becomes gray"""
        self.md_bg_color = [.8, .8, .8, .8]

    def on_leave(self, *args):
        """Mouse leaves node, bg color back to default"""
        self.md_bg_color = [1, 1, 1, 1]
Exemple #28
0
class MainWidget(BoxLayout):

    number = kv.NumericProperty()

    def __init__(self, **kwargs):
        super(MainWidget, self).__init__(**kwargs)

    def increment_time(self, interval):
        self.number += .1

    def start(self):
        Clock.unschedule(self.increment_time)
        Clock.schedule_interval(self.increment_time, .1)

    def stop(self):
        Clock.unschedule(self.increment_time)
Exemple #29
0
class LinhaSearch(BoxLayout):
    nome_group = kvProps.StringProperty('')
    idGrupo = kvProps.NumericProperty()

    def clique(self):
        db = BancoDadosGrupos()
        GrupoList = db.listarGruposPorId(self.idGrupo)
        App.get_running_app().registro_atual = GrupoList
        App.get_running_app().route.transition.direction = 'left'
        App.get_running_app().route.current = 'entrar'

        global idGrupoChat
        idGrupoChat = self.idGrupo

        global nome_sala
        nome_sala = self.nome_group
class DraggableColoredLabel(DragBehavior, Label):
    background_color = Properties.ListProperty((0, 0, 0, 1))
    visible = Properties.BooleanProperty()
    saveOnDBEvent = Properties.ObjectProperty()
    noteId = Properties.NumericProperty()

    def on_pos(self, instance, value):
        try:
            self.bringToFront()
            self.saveOnDBEvent.cancel()
        except:
            logging.info('Notes: No previous event')

        self.saveOnDBEvent = Clock.schedule_once(self.saveOnDB, 5)

    def bringToFront(self):
        parent = self.parent
        children = parent.children
        childOnTop = children[0]

        if (self != childOnTop):
            parent.remove_widget(self)
            parent.add_widget(self)

    def saveOnDB(self, dt):
        noteToSave = Notes(
            _id=self.noteId,
            pinned=self.visible,
            text=self.text,
            posX=self.pos[0],
            posY=self.pos[1],
            sizeX=self.size_hint[0],
            sizeY=self.size_hint[1],
            rgb=[
                self.background_color[0]*255,
                self.background_color[1]*255,
                self.background_color[2]*255,
                self.background_color[3],
            ],

        )
        noteToSave.save()

        logging.info('DB: Updated note with id: ' + str(self.noteId))