def update_velocity(self, dt): if self.is_manual: return velocity = self.velocity t_velocity = self.terminal_velocity next_ = self.near_next_notch() pull_back_velocity = self.pull_back_velocity if pull_back_velocity < abs(velocity) < t_velocity and next_: duration = abs((next_ - self.scroll) / self.velocity) anim = Animation( scroll=next_, duration=duration, ) self._anim = anim anim.on_complete = self._coasted_to_stop anim.start(self) return if abs(velocity) < pull_back_velocity and not self.on_notch(): anim = Animation( scroll=self.nearest_notch(), duration=self.pull_duration, t="in_out_circ", ) self._anim = anim anim.on_complete = self._coasted_to_stop anim.start(self) else: self.velocity -= self.velocity * self.friction self.apply_distance(self.velocity * dt) self.trigger_velocity_update()
def remove(self): # remove current tile and bring in a new one column = self.parent window = column.parent.get_parent_window() fall_out = Animation(size=self.size,pos=(self.x, -125), \ t='out_bounce', d = 1.5) dest_tile = column.children[len(column.children)-column.missing_tiles] destination = (self.x, dest_tile.y) fall_in = Animation(pos=destination, t='out_bounce', d = 1) # track animations completing for new and old tiles # Note: old tiles are being tracked, but don't currently # figure into cleanup rules Tile.anims_to_complete += 1 Tile.tiles_being_removed += 1 new_tile = Tile(dest_tile.number) new_tile.x = self.x new_tile.y = window.height + 100 new_tile.intended_pos = destination # assign followup events to animations fall_out.on_complete = self.remove_complete fall_in.on_complete = new_tile.add_complete # count down number of tiles to assign destinations for column.missing_tiles -= 1 return fall_out, self, fall_in, new_tile
class FadeScreen(Screen): def __init__(self, **kwargs): super(FadeScreen, self).__init__(**kwargs) self.opacity = 0 self.inAndOut = Animation(opacity = 1, duration = 2.5) + Animation( opacity = 0, duration = 2.5) self.In = Animation(opacity = 1, duration = 2.) self.Out = Animation(opacity = 0, duration = 2.) self.trigSplashFade = Clock.create_trigger(self.splashFade) self.refocus = Clock.create_trigger(self.refocus_text) self.trigFadeIn = Clock.create_trigger(self.fadeIn) self.dc = 0 #double check self.string = '' #this string is used to switch between screens def splashFade(self, dt): """ This does what the name says, it fades in to the current screen and fades out """ if not self.opacity: self.inAndOut.start(self) self.inAndOut.on_complete(Clock.schedule_interval(self.splashTransit, 1/60)) def fadeIn(self, dt): if not self.opacity: self.In.start(self) def fadeOut(self, screen): self.string = screen if self.opacity: self.Out.start(self) self.Out.on_complete(Clock.schedule_interval(self.regTransit, 1/60)) def regTransit(self, dt): if not self.opacity: self.manager.current = self.string return False def splashTransit(self, dt): """ this allows the fade method to not only fade in, but also fade out and go to the next screen after animation is complete """ if self.opacity or self.dc: #here is where the dc comes in handy self.dc = 1 if not self.opacity: self.manager.current = 'title' self.dc = 0 return False def refocus_text(self, dt): self.usr.focus = True self.usr.text = '' self.usr.readonly = False
def die(self): if self.dead: return self.dead=True a=Animation(opacity=0,ay=50,duration=.5,t="out_quad") a.on_complete=lambda a:[self.parent.kill(self),setattr(self.tile,"block",Air())] a.start(self)
def display_img(dt): def mask_txt(dt): self.family_text.opacity = 0 anim = Animation(opacity=1, d=1) anim.on_complete = mask_txt anim.start(self.img_square)
def attack(self, widget): if not self.collardog: self.dog.source = 'images/screenshot_troupeau_chien_morts.png' self.wolf.wolf.source = 'images/loup_repu.png' self.wolf.rotation -= 180 anim = Animation(x=310, y=-300, t='in_out_sine', d=3) anim.on_complete=self.killWolf anim.start(self.wolf)
def appear(self): search = _Board.footer.search animation = Animation(pos=(search.x, search.y), t='out_bounce', d = 1.5) animation.on_complete = self.appear_complete search.pos = search.x, _Board.height + 200 animation.start(search) self.appeared = 1
def on_release(self): if self.apertado: anim = Animation(size=(self.width, 70), duration=0.2) anim.start(self) self.remove_widget(self.contentDate) self.contentTitle.bold = False self.apertado = False else: self.contentTitle.size_hint_y = None self.contentTitle.heigth = 70 anim = Animation(size=(self.width, self.contentTitle.heigth + self.contentDate.texture_size[1]), duration=0.1) anim.start(self) anim.on_complete(self.add_widget(self.contentDate)) self.contentTitle.bold = True self.apertado = True
def anim_scale(item, scale, on_progress=None, on_complete=None): Animation.stop_all(item) anim = Animation(scale=scale, duration=.2) if on_progress != None: anim.on_progress = on_progress if on_complete: anim.on_complete = on_complete anim.start(item)
def talpa(self, *args): talpa = Talpa() talpa.bind(on_press=self.talpa_colpita) self.add_widget(talpa) animazione = Animation(size_hint=(self.dimansione_talpa, self.dimansione_talpa), duration=self.durata_talpa, transition="out_elastic") animazione.on_complete = self.talpa_mancata animazione.start(talpa)
def out_of_map_handler(self, entity): # Should be more static method. gm = self.game_map # Mapborder falls off. # can_collide_wall and can_fly are both used to determine behaviour. if 0 > entity.right or entity.x > gm.right or \ 0 > entity.top or entity.y > gm.top: if not entity.components['Physics'].can_fly: # If entity can fall off, death animations. dmg = DamageInfo(self, 1337, 'absolute') """if entity.name in self.players: # Temporary solution as there is no proper game over, only regain hp on death, prevents crashing. entity.receive_damage(dmg) entity.center = gm.center entity.velocity = Vector(0, 0) # Remove displacement sliding.""" if True: def death(entity): entity.receive_damage(dmg) if not entity.falling:#entity.name not in self.players: entity.original_size = entity.size[:] # Disgusting workaround temp. entity.original_v_multiplier = entity.velocity_multiplier fall = Animation(size=(1,1), step=1/60, duration=1) entity.velocity_multiplier = 0 if entity.name in self.players: def rebirth(entity): # Temp. entity.size = entity.original_size[:] #entity.size = original_size entity.velocity_multiplier = entity.original_v_multiplier entity.receive_damage(dmg) fall.on_complete = rebirth else: fall.on_complete = death fall.start(entity) entity.falling = True else: # Insta kills player to avoid their attributes permanently changing upon game restart. death(entity) # Removes entities that fly too far away. elif (not -500 < entity.x < gm.right + 500) or (not -500 < entity.y < gm.top + 500): self.remove_widget(entity)
def on_press(self): img = self.ids['main_img'] label = self.ids['main_label'] Animation.stop_all(img) anim = Animation(color=self.color) anim_label = Animation(opacity=1,duration=0.05) anim.start(img) anim_label.start(label) anim.on_complete = self.launch_expo
def gen_ob_slang(self): self.ids.test.source = 'sun3334.png' anim = Animation(angle=360, duration=0.5) anim += Animation(angle=360, duration=0.5) anim.start(self) anim.on_progress = self.empty anim.on_complete = self.eliteeng_slova self.ubrat() self.which_sound()
def reset_all(self): for part in dir(self): p = getattr(self, part) if hasattr(p, "angle"): Animation(angle=0, duration=1 / 3).start(p) self.flipped = False anm = Animation(xy=(0, 0), duration=1 / 3) anm.on_complete = self.on_reset_done anm.start(self.oposition)
def hop(self,tile): last=True self.parent.active=None self.parent.state="anim" self.tile.block = Air() self.parent.highlighted = [] d=distance(self.tile.pos,tile.pos) m=d/150 t=.5+.1*m i=0 z=None Animation(center_x=tile.center_x,center_y=tile.center_y+tile.blockheight,duration=t).start(self) a=Animation(ay=50+50*m,duration=t*.5,t="out_quad") b=Animation(ay=0,duration=t*.5,t="in_quad") t = "self" if not isinstance(tile.block,Air): l=lambda a: [self.hit(tile.block,self.damage), self.hop(random.choice(tile.adjacenttiles)) ] b.on_complete=l last=False z=-sum(tile.block.gpos) i=1 a.on_complete=lambda a:self.zefresh(z=z,i=i,t=t) f=a+b def dolast(_): self.parent.state="ready" if last: self.tile=tile self.tile.block=self f.on_complete=dolast f.start(self)
def talpa(self, *args): talpa = Talpa() talpa.bind(on_press=self.talpa_colpita) self.add_widget(talpa) animazione = Animation(size_hint=(self.dimansione_talpa, self.dimansione_talpa), duration=self.durata_talpa, transition="out_elastic") animazione.on_complete = self.talpa_mancata animazione.start(talpa)
def init_anims(dt): Animation.stop_all(self.dynamic_sentence) if self.dynamic_sentence.width > 1400: anim = Animation(x=-self.dynamic_sentence.width - 30, d=duration) anim.start(self.dynamic_sentence) def callback(dt): self.dynamic_sentence.x = 30 anim.on_complete = callback
def animfunc(self, *args): """Если текстовое поле за пределами границы окна программы то есть `self.txtinpt.x >= 350`. """ if self.flot_txt.x >= Window.width: self.add_widget(self.flot_txt) with self.canvas.before: Color(rgba=(0, 0, 0, 0.3)) Rectangle(size=self.parent.children[1].size, pos=(self.x, self.y)) Animation(x=dp(10), t='linear', d=0.3).start(self.flot_txt) else: anim = Animation(x=Window.width, t='linear', d=0.3) anim.start(self.flot_txt) anim.on_complete = self.animation_compl
def center_on(self, val, animate=True): Animation.stop_all(self) center_index = self.index_of(val) half_length = self.line_length / 2. / self.scale index_0 = center_index - half_length index_1 = center_index + half_length if animate: anim = Animation(index_0=index_0, index_1=index_1, duration=self.center_duration) anim.on_complete = lambda *args: self._centered() anim.start(self) else: self.index_0 = index_0 self.index_1 = index_1 self._centered()
def center_on(self, val, animate=True): Animation.stop_all(self) center_index = self.index_of(val) half_length = self.line_length / 2. / self.scale index_0 = center_index - half_length index_1 = center_index + half_length if animate: anim = Animation(index_0=index_0, index_1=index_1, duration=self.center_duration) anim.on_complete = lambda *args: self._centered() anim.start(self) else: self.index_0 = index_0 self.index_1 = index_1 self._centered()
def fall(tiles, i): # handle tiles falling after tiles below have been removed tile = tiles[i] column = tile.parent # assign destination for falling tiles prev_tile = tiles[i-tile.parent.missing_tiles] tile.next_number = prev_tile.number Tile.anims_to_complete += 1 destination = (prev_tile.x, prev_tile.y) animation = Animation(pos=destination, t='out_bounce', d = 1) # assign function to handle animation completion animation.on_complete = tile.fall_complete tile.intended_pos = destination # start the animation animation.start(tile)
def move(self, dir_x, dir_y): if self.moving: return dir_x = int(dir_x) dir_y = int(dir_y) for board_x, board_y in all_cells(dir_x > 0, dir_y > 0): tile = self.b[board_x][board_y] if not tile: continue x, y = board_x, board_y while self.can_move(x + dir_x, y + dir_y): self.b[x][y] = None x += dir_x y += dir_y self.b[x][y] = tile if self.can_combine(x + dir_x, y + dir_y, tile.number): self.b[x][y] = None x += dir_x y += dir_y self.remove_widget(self.b[x][y]) self.b[x][y] = tile tile.number *= 2 if tile.number == 2048: print('You Win The Game!!!') tile.update_colors() if x == board_x and y == board_y: continue anim = Animation(pos=self.cell_pos(x, y), duration=0.25, transition='linear') if not self.moving: anim.on_complete = self.new_tile self.moving = True anim.start(tile)
def move(self, dir_x, dir_y): if self.moving: return dir_x = int(dir_x) dir_y = int(dir_y) for board_x, board_y in all_cells(dir_x > 0, dir_y > 0): tile = self.b[board_x][board_y] if not tile: continue x, y = board_x, board_y while self.can_move(x + dir_x, y + dir_y): self.b[x][y] = None x += dir_x y += dir_y self.b[x][y] = tile if self.can_combine(x + dir_x, y + dir_y, tile.number): self.b[x][y] = None x += dir_x y += dir_y self.remove_widget(self.b[x][y]) self.b[x][y] = tile tile.number *= 2 if (tile.number == 2048): print('You win the game') tile.update_colors() if x == board_x and y == board_y: continue # nothing has happened anim = Animation( pos=self.cell_pos(x, y), duration=0.25, transition='linear' ) if not self.moving: anim.on_complete = self.new_tile self.moving = True anim.start(tile)
def check_position(self,f): if f in self.universe and (f.x <0.1*Window.width or f.x>0.9*Window.width or f.y<0.05*Window.height or f.y>0.90*Window.height): self.universe.remove(f) self.game.remove_widget(f) return 1 for e in self.universe: if e == f: continue if f.collide_widget(e): b = self.transmute(e.text,f.text) if b: pop = ElementPop( text="%s + %s = %s" % (e.text,f.text,b), center=Window.center, app=self) self.sound_find.play() self.universe.remove(e) self.universe.remove(f) self.game.remove_widget(e) self.game.remove_widget(f) self.add_element_to_universe(b) if b not in self.elements_found: self.elements_found.append(b) output = open(self.data_path + 'savegame', 'wb') pickle.dump(self.elements_found, output) output.close() self.update_elements_menu(b) #animation pop.scale = pop.scale*0.2 self.game.add_widget(pop) A = Animation( scale = 1.0, transition = 'out_sine', duration = 1.0 ) A.on_complete = partial(self.deletePop,pop) A.start(pop) return 1
def on_midi(self, msg): self.ear.hear(msg) if not self.ear.heard_count() >= 1: return heard = self.ear.retrieve() print("Heard", heard) for neighbor in self.map.neighbors(self.pc_loc): if notes_match(heard, self.map.node_label(neighbor).container()): prev_loc = self.pc_loc self.pc_loc = neighbor anim = Animation( center=(self.pc_loc.x, self.pc_loc.y), duration=0.5, transition=AnimationTransition.in_out_quad ) anim.on_complete = self.resetNavigationWidgets if self.overlay: anim.on_start = partial(self.reveal_map_areas, self.pc_loc) print(self.map.wall_between_nodes(prev_loc, self.pc_loc)) anim.start(self.features.pcWidget)
def close_content_container(self, d=.2, close_parent=False): def remove(dt): if self.content_container != None: if close_parent == True: self.open() if hasattr(self.content_container, 'joint') and self.content_container.joint != None: self.space().remove(self.content_container.joint) self.content_container.joint = None # self.app.root_images.remove_widget(self.content_container) self.app.root_content_layout.remove_widget(self.content_container) self.content_container = None if self.content_container != None: anim = Animation(scale=.2, d=d) anim.on_complete = remove anim.start(self.content_container) anim2 = Animation(y=52, d=d) # anim = Animation(y=y0 - 80, d=d) anim2.start(self.close_button)
def __init__(self, **kwargs): super(WolfAttack, self).__init__(**kwargs) self.dog = Dog() self.add_widget(self.dog) self.wolf = Wolf() self.wolf.pos = (0, -300) self.wolf.rotation += 90 self.add_widget(self.wolf) self.collarZone = ObjectZone(source='images/drop_zone_UNVALID.png', pos=(50, 700), size=(300, 150), size_hint=(None, None), idx_zone=1) self.collarZone.bind(object_id=self.checkDropZone) self.add_widget(self.collarZone) self.info = Image(source='images/TXT_COLLIER.png', size_hint=(None, None), size=(300, 150)) self.info.pos = (500, 200) self.add_widget(self.info) anim = Animation(x=310, y=-300,t='in_elastic', d=12) anim.on_complete = self.startAttack anim.start(self.wolf)
def shift_camera(self, final_pos=None, final_scale=None): if self.in_motion: return if final_pos is None: final_pos = self.gameworld.camera.camera_pos if final_scale is None: final_scale = self.gameworld.camera.camera_scale def motion_start(_): self.in_motion = True def motion_complete(_): self.in_motion = False self.gameworld.terrain.tile_trigger() self.gameworld.buildings.tile_trigger() anim = Animation(camera_pos=final_pos, camera_scale=final_scale, duration=0.15, t='out_sine') anim.on_start = motion_start anim.on_complete = motion_complete anim.start(self.gameworld.camera)
def move(self, dir_x, dir_y): dir_x = int(dir_x) dir_y = int(dir_y) has_on_complete = False for board_x, board_y in all_cells(dir_x > 0, dir_y > 0): tile = self.b[board_x][board_y] if not tile: continue x, y = board_x, board_y while self.can_move(x + dir_x, y + dir_y): self.b[x][y] = None x += dir_x y += dir_y self.b[x][y] = tile if self.can_combine(x + dir_x, y + dir_y, tile.number): self.b[x][y] = None x += dir_x y += dir_y self.remove_widget(self.b[x][y]) self.b[x][y] = tile tile.number *= 2 if (tile.number == 2048): print('You win the game') # TODO tile.update_colors() if x == board_x and y == board_y: continue # nothing has happened anim = Animation(pos=self.cell_pos(x, y), duration=0.25, transition='linear') if not has_on_complete: anim.on_complete = self.new_tile has_on_complete = True anim.start(tile)
def fade_in_label(self, *args): self.welcome.color = (1, .4, 0, 0) anim = Animation(color=(1, .4, 0, 1), duration=2) anim.start(self.welcome) anim.on_complete(self.show_wait_message())
def animate_on_push(self, instance): anim = Animation(size_hint=[.75, .07], duration=.2) anim.start(instance) anim.on_complete( Clock.schedule_once(partial(self.selection, instance), .2))
def animate_opacity(self, *args): opacity_ = 0 if self.label.opacity == 1 else 1 anim2 = Animation(opacity = opacity_, duration = 1.5, t = 'in_out_cubic') anim2.on_complete = self.choose_word anim2.start(self.label)
def go_to_angle(self, a, d = .5): Animation.stop_all(self) anim = Animation(global_angle = a, duration= d, t='linear') anim.on_complete = self.filter_items anim.start(self)
def on_touch_up(self, touch): """Base kivy method inherited from Button. This method is called on all buttons at once, so we need to return True for only the *originally* touched button. Note: We are not currently passing this up to super(), but we could consider doing so. Args: touch: A kivy motion event Returns: True if for *originally* touched button, False otherwise. """ if touch.is_touch or touch.button == 'left': if touch.grab_current is self: word = _Board.complete # clear word complete text _Board.complete = '_ _ _' # release grab touch.ungrab(self) # only check word if on playArea if _Board._dictionary.lookup(word) and \ _Board.collide_point(touch.x, touch.y) \ and _Board._highlighted: # add bubble points indicator bubble = _Board.footer.bubble # get the last element added to highlighted last = next(reversed(_Board._highlighted)) bubble.pos = last.pos bubble.text = _Board.header.word_complete.bubble.text[:] bubble.score = int(_Board.value) score_board = _Board.header.lheader.score timer = _Board.game_timer move_bubble = Animation(pos=(timer.x + 30, timer.y - 20), \ t='in_expo', d = 0.7) move_bubble += Animation(pos=(score_board.x + 50, score_board.y), \ t='in_out_elastic', d = 0.3) move_bubble.on_progress = self.mid_bubble move_bubble.on_complete = self.done_bubble move_bubble.start(bubble) # mark score bubble as in-progress bubble.working = 1 affected_columns = set() # find columns with tiles to remove for tile in _Board._highlighted: affected_columns.add(tile.parent) Tile.replace_tiles(set(_Board._highlighted), affected_columns) _Board._highlighted.clear() else: #clear word complete point bubble _Board.value = 0 # clear highlight for tile in _Board._highlighted: tile.background_color = [1,1,1,1] # clear highlighted list _Board._highlighted.clear() return True return False
class Player(): def __init__(self): self.health = playerhealth self.money = 0 self.gems = 0 self.upgPathSelectLvl = 5 self.abilities = list() self.wavenum = 0 self.gameover = False self.towerSelected = None self.tbbox = None self.layout = None self.wavestart = 999 self.next_wave = False self.pausetime = 0 self.state = "Start" self.restart = False self.score = 0 self.newMoveList = False self.wavetime = None self.wavetimeInt = None self.myDispatcher = EventDispatcher.EventDisp() self.analytics = Analytics.Analytics() self.store = DictStore('settings.txt') if self.store.exists('audio'): self.soundOn = self.store.get('audio')['soundOn'] self.musicOn = self.store.get('audio')['musicOn'] else: self.soundOn = True self.musicOn = True def setResources(self): if Map.mapvar.difficulty == 'easy': self.money = 2000 self.gems = 5 self.myDispatcher.Money = str(self.money) self.myDispatcher.Gems = str(self.gems) elif Map.mapvar.difficulty == 'medium': self.money = 1000 self.gems = 4 self.myDispatcher.Money = str(self.money) self.myDispatcher.Gems = str(self.gems) else: self.money = 300 self.gems = 3 self.myDispatcher.Money = str(self.money) self.myDispatcher.Gems = str(self.gems) self.myDispatcher.Score = str(self.score) self.myDispatcher.Timer = str(self.wavetimeInt) self.myDispatcher.Health = str(self.health) def setupCoinAnim(self): self.coinAnimating = False self.coinanim = Animation(pos=(__main__.ids.coinimage.x, __main__.ids.coinimage.y+20), duration=.1) + \ Animation(pos=(__main__.ids.coinimage.x, __main__.ids.coinimage.y), duration=.1) self.coinanim.on_complete(self.toggleCoinAnim) def toggleCoinAnim(self): self.coinAnimating = False def die(self): '''Set gameover to True to reset the game''' self.gameover = True def genWaveList(self): self.waveList, self.waveTypeList = Wavegen.wavegen() # [{'wavenum': 1, 'setnum': 1, 'enemytype': 'b', 'enemymods': []}, dict repeats] self.wavetime = Map.mapvar.waveseconds self.wavetimeInt = int(Map.mapvar.waveseconds) def storeSettings(self): self.store.put('audio', soundOn=self.soundOn,musicOn=self.musicOn) self.store.put('gameplay', difficulty = Map.mapvar.difficulty, numpaths = Map.mapvar.numpaths, waveorder = Map.mapvar.waveOrder)
def complete(self, widget: Widget): Animation.on_complete(self.anim, widget)
def go_to_angle(self, a, d=.5): Animation.stop_all(self) anim = Animation(global_angle=a, duration=d, t='linear') anim.on_complete = self.filter_items anim.start(self)
def fade(self, duration): anim = Animation(background_color=[1, 1, 1, 0], duration=duration // 1.2) anim.on_complete(self.dismiss) anim.start(self) del self
def on_press(self): img = self.ids['main_img'] Animation.stop_all(img) anim = Animation(color=self.color, d=.2) anim.start(img) anim.on_complete = self.launch_expo
def stage_2(self, callback): a = Animation(font_size=1, duration=0.5) a &= Animation(opacity=0, duration=0.5) a.on_complete = callback a.start(self) self.alive = False
def startAttack(self, widget): self.remove_widget(self.collarZone) anim = Animation(x=310, y=300,t='in_out_circ', d=3) anim.on_complete = self.attack anim.start(self.wolf)
def on_pre_enter(self): anim = Animation(progress=1000, duration=3) anim.on_start = self.__prepare anim.on_complete = self.__start anim.start(self)