diff --git a/__init__.py b/__init__.py index c0de47e394e76093648e280047b590977f9c0248..9f9ec9e746287b5873d19a8d3c711dc20b7171e5 100644 --- a/__init__.py +++ b/__init__.py @@ -28,6 +28,7 @@ class PetalHero(Application): self.blm = None self.fiba_sound = None self.select = select.SelectView(self.app) + self.after_score = False #self.blm_extra = bl00mbox.Channel("Petal Hero Extra") #self.blm_extra.background_mute_override = True diff --git a/difficulty.py b/difficulty.py index 5c17b66d47eee945123684dd1791024a5975de64..5bd26c4594710e1307bf0ec8dc0a31caddc51fd1 100644 --- a/difficulty.py +++ b/difficulty.py @@ -99,7 +99,7 @@ class DifficultyView(BaseView): """ def think(self, ins: InputState, delta_ms: int) -> None: - self.input.think(ins, delta_ms) + super().think(ins, delta_ms) self._sc.think(ins, delta_ms) media.think(delta_ms) self.flower.think(delta_ms) diff --git a/score.py b/score.py new file mode 100644 index 0000000000000000000000000000000000000000..2d8d5abbeee3070885bfc641fa0c2ed0b7db3388 --- /dev/null +++ b/score.py @@ -0,0 +1,133 @@ +from st3m.input import InputController +from st3m.ui.view import BaseView, ViewManager, ViewTransitionSwipeLeft, ViewTransitionSwipeRight +from st3m.application import Application, ApplicationContext +from st3m.ui.interactions import ScrollController +import st3m.run +import media +import math +import random +import sys_display + +if __name__ == '__main__': + import sys + sys.path.append('/flash/apps/PetalHero') + +import flower +import loading +import utils +import midireader + +class ScoreView(BaseView): + def __init__(self, app, data, streak): + super().__init__() + self.app = app + self.data = data + self.flower = flower.Flower(0) + self.time = 0 + self.streak = streak + self.played = False + if not self.data: + self.accuracy = 0.42 + else: + events = data.track.getAllEvents() + self.accuracy = len(set(filter(lambda x: isinstance(x, midireader.Note) and x.played, events))) / len(events) + self.stars = int(5.0 * (self.accuracy + 0.05)) + + def draw(self, ctx: Context) -> None: + + #utils.background(ctx) + ctx.gray(0) + ctx.rectangle(-120, -120, 240, 240) + ctx.fill() + + ctx.save() + ctx.translate(-90, 1) + ctx.scale(0.325, 0.325) + for i in range(5): + if i < self.stars: + utils.fire_gradient(ctx) + else: + ctx.gray(0.15) + self.flower.draw(ctx) + ctx.translate(45 / 0.325, 0) + ctx.restore() + + ctx.save() + + offset = 0 + + ctx.font = "Camp Font 3" + ctx.text_align = ctx.CENTER + ctx.text_baseline = ctx.MIDDLE + + ctx.move_to(0, 0) + + ctx.restore() + + """ + ctx.rectangle(-120, 65, 240, 55) + ctx.fill() + """ + utils.fire_gradient(ctx) + + ctx.font = "Camp Font 1" + ctx.font_size = 38 + ctx.text_align = ctx.CENTER + ctx.text_baseline = ctx.MIDDLE + ctx.move_to (0, -78) + ctx.text("SONG") + ctx.move_to (0, -42) + ctx.text("COMPLETE") + + ctx.gray(1.0) + ctx.font = "Camp Font 3" + ctx.font_size = 18 + ctx.move_to (0,37) + ctx.text(f"Accuracy: {int(self.accuracy * 100)}%") + ctx.move_to(0,58) + ctx.text(f"Longest streak: {self.streak}") + + ctx.font = "Camp Font 3" + ctx.font_size = 16 + ctx.text_align = ctx.CENTER + ctx.text_baseline = ctx.MIDDLE + ctx.gray(0.5) + ctx.move_to(0, 84 - math.sin(self.time * 4) * 2) + ctx.text("Press the button...") + + def think(self, ins: InputState, delta_ms: int) -> None: + super().think(ins, delta_ms) + media.think(delta_ms) + self.time += delta_ms / 1000 + + if self.time > 1.5 and not self.played: + self.played = True + taunt = None + if self.accuracy == 0: + taunt = "jurgen1" + elif self.accuracy >= 0.99: + taunt = "myhero" + elif self.stars in [0, 1]: + taunt = random.choice(["jurgen2", "jurgen3", "jurgen4", "jurgen5"]) + elif self.stars == 5: + taunt = random.choice(["perfect1", "perfect2", "perfect3"]) + if self.app and taunt: + media.load(self.app.path + "/sounds/" + taunt + ".mp3") + + if self.input.buttons.app.middle.pressed: + self.vm.pop(ViewTransitionSwipeRight()) + + def on_enter(self, vm: Optional[ViewManager]) -> None: + super().on_enter(vm) + if self.app: + self.app.after_score = True + + def on_exit(self): + sys_display.set_mode(0) + super().on_exit() + if self.app: + utils.play_go(self.app) + +if __name__ == '__main__': + view = ScoreView(None, None, 420) + st3m.run.run_view(view) diff --git a/select.py b/select.py index 1da87d3ed807f4e56ca005bf25ebf12f817161a0..ac33ff4abef82211fd3f15a17a280c7015512ced 100644 --- a/select.py +++ b/select.py @@ -218,6 +218,9 @@ class SelectView(BaseView): def on_enter(self, vm: Optional[ViewManager]) -> None: super().on_enter(vm) + if self.app and self.app.after_score: + self.play() + self.app.after_score = False def play(self): if self.songs: diff --git a/song.py b/song.py index 1d5981d955b14967b7d79ce423e2c8974909518f..a47cc7875f1b848e5e2752cf7ab8c4889456b2bb 100644 --- a/song.py +++ b/song.py @@ -18,6 +18,7 @@ import midi import midireader import utils import flower +import score AUDIO_DELAY = -70 VIDEO_DELAY = 30 - AUDIO_DELAY @@ -54,6 +55,7 @@ class SongView(BaseView): self.longeststreak = 0 self.exiting = False self.led_override = [0] * 5 + self.laststreak = -1 self.good = 0.0 self.bad = 0.0 @@ -230,9 +232,13 @@ class SongView(BaseView): else: self.successive_sames = 0 + #if self.input.buttons.app.middle.pressed: + # self.successive_sames = 1000 + if self.successive_sames > 250 and not self.finished: self.finished = True - self.vm.pop() + media.stop() + self.vm.replace(score.ScoreView(self.app, self.data, self.longeststreak)) if self.input.buttons.os.middle.pressed: self.vm.pop(ViewTransitionSwipeRight()) @@ -287,12 +293,11 @@ class SongView(BaseView): self.miss = 1.0 if event.played and event.time + event.length - lateMargin > self.time: p = 4 if event.number == 0 else event.number - 1 - if not ins.captouch.petals[p*2].pressed: + if not ins.captouch.petals[p*2].pressed and not event.missed: event.missed = True - self.streak = 0 - if not self.started or self.exiting: + if self.exiting: return leds.set_all_rgb(0, 0, 0) @@ -316,7 +321,9 @@ class SongView(BaseView): if not event.played: event.played = True self.led_override[petal] = 100 - self.streak += 1 + if event.time > self.laststreak: + self.streak += 1 + self.laststreak = event.time self.petals[petal] = event self.good = 1.0 diff --git a/sounds/jurgen1.mp3 b/sounds/jurgen1.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..2f1180ee38c34875b39b48736ea465f8082eaf61 Binary files /dev/null and b/sounds/jurgen1.mp3 differ diff --git a/sounds/jurgen2.mp3 b/sounds/jurgen2.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..1b1c9fba77912b24d63dd0c7a0c0edbef401c7f7 Binary files /dev/null and b/sounds/jurgen2.mp3 differ diff --git a/sounds/jurgen3.mp3 b/sounds/jurgen3.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..2f995a9e32ceddfedc7333bd70a1889b98e1c651 Binary files /dev/null and b/sounds/jurgen3.mp3 differ diff --git a/sounds/jurgen4.mp3 b/sounds/jurgen4.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..3eb4455cdfd1dff7f0463b094bfc79f789e96a19 Binary files /dev/null and b/sounds/jurgen4.mp3 differ diff --git a/sounds/jurgen5.mp3 b/sounds/jurgen5.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..dfcb0418aa63536444d1e849ebb10d49030ac9e0 Binary files /dev/null and b/sounds/jurgen5.mp3 differ diff --git a/sounds/myhero.mp3 b/sounds/myhero.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..634293af182be7e434634d05164ab2ca8ff43612 Binary files /dev/null and b/sounds/myhero.mp3 differ diff --git a/sounds/perfect1.mp3 b/sounds/perfect1.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..c46626cc887daf5e2d4e9e66fe89a6f0f563522f Binary files /dev/null and b/sounds/perfect1.mp3 differ diff --git a/sounds/perfect2.mp3 b/sounds/perfect2.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..886aac9e072916374fe617f7812fbcc36ae8fd0c Binary files /dev/null and b/sounds/perfect2.mp3 differ diff --git a/sounds/perfect3.mp3 b/sounds/perfect3.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..514dae9f9cc65c11ac63fe07ad8e4bf7b3fd6bab Binary files /dev/null and b/sounds/perfect3.mp3 differ