def get_unselected_eff(self): def _unselected_fn(spr: cocosnode.CocosNode): spr.scale = self.orig_scale spr.position = self.orig_pos self.orig_scale = self.orig_pos = None return actions.CallFuncS(_unselected_fn)
def policies2action(policy_list): action_list = [] for policy_start_fn, policy_step_fn in policy_list: if policy_start_fn is None: return actions.Driver() if policy_step_fn is None: action = actions.CallFuncS(policy_start_fn) else: action = IntervalPolicy(policy_start_fn, policy_step_fn) action_list.append(action) return functools.reduce(operator.or_, action_list) | actions.Driver()
def on_key_press(self, k, modifiers): if (k in g.keyBindings): hitbox = self.hitBoxes[g.keyBindings.index(k)] hitbox.do( ac.ScaleTo(spriteScale * 1.2, 0.05) + ac.ScaleTo(spriteScale, 0.1)) keySprite = self.keyIndicators[g.keyBindings.index(k)] if (keySprite): self.keyIndicators[g.keyBindings.index(k)] = {} action = (ac.FadeOut(2.25)) + ac.CallFuncS(self.remove_child) keySprite.do(action)
def jump(self): jumpheight = 200 jumpwidth = 90 jumptime = .4 if self.isjump == False: self.isjump = True if self.ismoveleft == True: self.do( actions.MoveBy((-jumpwidth, jumpheight), jumptime) + actions.MoveBy((-jumpwidth, -jumpheight), jumptime) + actions.CallFuncS(Player.markjumpfinished)) elif self.ismoveright == True: self.do( actions.MoveBy((jumpwidth, jumpheight), jumptime) + actions.MoveBy((jumpwidth, -jumpheight), jumptime) + actions.CallFuncS(Player.markjumpfinished)) else: self.do( actions.MoveBy((0, jumpheight), jumptime) + actions.MoveBy((0, -jumpheight), jumptime) + actions.CallFuncS(Player.markjumpfinished))
def get_selected_eff(self): def _selected_fn(spr: cocosnode.CocosNode): self.orig_scale = spr.scale self.orig_pos = spr.position spr.scale *= 2 y_ratio = spr.y / get_height() if y_ratio < 0.5: spr.y = min(y_ratio + 0.13, 0.5) * get_height() else: spr.y = max(y_ratio - 0.13, 0.5) * get_height() if self.move_to_top: set_z(spr, z='top') return actions.CallFuncS(_selected_fn)
def on_key_press (self, k, modifiers): if (k in g.keyBindings): self.s.timeLastKeyPress = time.time() children = self.boxes[g.keyBindings.index(k)] if(children): bestOne = min([abs(child.y - g.hitBoxHeight) for child in children]) bestChild = [child for child in children if abs(child.y - g.hitBoxHeight) == bestOne][0] #yuck if(bestChild): if(bestOne < 8.5): children.remove(bestChild) action = (ac.MoveTo((bestChild.x, g.hitBoxHeight)) | ac.FadeOut(0.25) | ac.ScaleBy(1.75, 0.25) ) + ac.CallFuncS(self.remove_child) bestChild.do(action) self.s.currentSpeed += 2.5 self.sounds[g.keyBindings.index(k)].play() # Play right now elif (bestOne < 20): children.remove(bestChild) action = (ac.FadeOut(0.25)) + ac.CallFuncS(self.remove_child) bestChild.do(action) self.s.currentSpeed += 1 self.missSounds[g.keyBindings.index(k)].play() # Play right now else: #apply penalty! (to stop spamming) self.s.currentSpeed -= 5
def remove_myself_action(): """Return the action that remove its target from its parent.""" def _remove_myself(self): self.parent.remove(self) return actions.CallFuncS(_remove_myself)
def set_color_action(color): return actions.CallFuncS( lambda label: setattr(label.element, 'color', color))
def __init__(self, note: BaseNote): def p(state: BaseNote.NoteState): res = copy.copy(state) res.pos *= settings.size res.speed *= settings.size return res states = list(map(p, sorted(note.states, key=lambda e: e.sec))) dis = 0 img = 'click.png' if isinstance(note, Drag): img = 'drag.png' elif isinstance(note, Flick): img = 'flick.png' elif isinstance(note, Hold): img = 'hold.png' sec = note.tap_sec length = 0 for i in states: if i.sec <= note.tap_sec: continue length += i.speed * (i.sec - sec) sec = i.sec length += states[-1].speed * (note.end_sec - sec) dis += length // 2 sec = note.tap_sec for i in states[::-1]: if i.sec > note.tap_sec: break note.show_sec = min( note.show_sec, sec - (settings.size * 2 - abs(dis) + (length if isinstance(note, Hold) else 0)) / abs(i.speed) ) dis += (sec - i.sec) * i.speed sec = i.sec note.show_sec = min( note.show_sec, sec - (settings.size * 2 - abs(dis) + (length if isinstance(note, Hold) else 0)) / abs(states[0].speed) ) dis += sec * states[0].speed super().__init__(img, (states[0].pos, dis)) if isinstance(note, Hold): self.scale_y = length / self.image.height action = cac.Hide() sec = 0 speed = states[0].speed for i in states: if i.sec > note.tap_sec: break dis -= (i.sec - sec) * speed act = cac.MoveTo((i.pos, dis), i.sec - sec) if sec <= note.show_sec < i.sec: act |= cac.Delay(note.show_sec - sec) + cac.Show() action += act sec = i.sec speed = i.speed act = cac.MoveTo((states[-1].pos, length // 2 if isinstance(note, Hold) else 0), note.tap_sec - sec) if sec <= note.show_sec < note.tap_sec: act |= cac.Delay(note.show_sec - sec) + cac.Show() action += act action += cac.CallFunc(play_sound) if isinstance(note, Hold): class Qwq(cac.IntervalAction): def init(self, length, duration): self._length = length self.duration = duration def start(self): self._cur = self.target.scale_y def update(self, t): from random import randint if randint(0, 6) < 3: self.target.parent.add(NoteExplode((self.target.x, 0))) self.target.scale_y = (self._cur - self._length) * (1 - t) + self._length nowlen = length // 2 sec = note.tap_sec for i in states: if i.sec <= note.tap_sec: continue nowlen -= (i.sec - sec) * i.speed action += cac.MoveTo((states[-1].pos, nowlen // 2), i.sec - sec) | \ Qwq(nowlen / self.image.height, i.sec - sec) sec = i.sec action += cac.MoveTo((states[-1].pos, 0), note.end_sec - sec) | \ Qwq(0, note.end_sec - sec) def explode(e: NoteSprite): e.kill() e.parent.add(NoteExplode((e.x, e.y))) score() action += cac.CallFuncS(explode) self.do(action)
def __init__(self, pos): super().__init__('explode.png', pos) self.do(cac.ScaleBy(1.3, 0.1) + cac.Delay(0.05) + cac.FadeOut(0.05) + cac.CallFuncS(lambda e: e.kill()))