Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 additions & 29 deletions desktop/ox-desktop/src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Scene {
Self::Loading => ox(p, frame, 2.).into_any_element(),
_ => {
let variant = scene::thinking_variant(seed, uptime());
cabinet(p, self, variant, frame, false).into_any_element()
cabinet(p, self, variant, frame, None).into_any_element()
}
}
}
Expand All @@ -50,6 +50,7 @@ pub struct Runner {
left: Option<u8>,
tick: Option<Task<()>>,
bonus_frames: u8,
bonus_kind: u8,
}

impl EventEmitter<Finished> for Runner {}
Expand All @@ -63,6 +64,7 @@ impl Runner {
left: scene.one_shot(),
tick: None,
bonus_frames: 0,
bonus_kind: scene::BONUS_KINDS - 1,
}
}

Expand Down Expand Up @@ -105,7 +107,7 @@ impl Render for Runner {
let sprite = if !p.motion {
self.scene.still(p, self.seed)
} else if self.bonus_frames > 0 {
cabinet(p, self.scene, 0, self.frame, true).into_any_element()
cabinet(p, self.scene, 0, self.frame, Some(self.bonus_kind)).into_any_element()
} else {
self.scene.sprite_for(p, self.seed, self.frame)
};
Expand All @@ -117,6 +119,7 @@ impl Render for Runner {
.cursor_pointer()
.child(sprite)
.on_click(cx.listener(|s, _, _, cx| {
s.bonus_kind = (s.bonus_kind + 1) % scene::BONUS_KINDS;
s.bonus_frames = 16;
cx.notify();
}))
Expand All @@ -126,7 +129,13 @@ impl Render for Runner {
}

// Low-resolution sprites share the terminal palette and one eight-frame clock.
fn cabinet(p: Palette, scene: Scene, variant: u8, frame: u8, bonus: bool) -> impl IntoElement {
fn cabinet(
p: Palette,
scene: Scene,
variant: u8,
frame: u8,
bonus: Option<u8>,
) -> impl IntoElement {
canvas(
|_, _, _| (),
move |bounds, _, window, _| {
Expand All @@ -137,31 +146,7 @@ fn cabinet(p: Palette, scene: Scene, variant: u8, frame: u8, bonus: bool) -> imp
rgb(color),
));
};
if bonus {
// The easter egg: a saucer hovers in and drops a shot.
let beat = i32::from(frame);
let lift = i32::from((2..6).contains(&frame));
rect(8, 1 + lift, 4, 1, p.fg);
rect(6, 2 + lift, 8, 2, p.accent);
rect(3, 4 + lift, 14, 2, p.fg);
rect(5, 6 + lift, 10, 1, p.accent);
for i in 0..3 {
rect(
6 + i * 3,
5 + lift,
1,
1,
if (beat / 2) % 3 == i {
p.warning
} else {
p.line
},
);
}
rect(7 + beat % 6, 8, 1, 2, p.warning);
return;
}
scene::draw(scene, variant, frame, &mut |x, y, w, h, ink| {
let mut paint = |x: i32, y: i32, w: i32, h: i32, ink: Ink| {
let color = match ink {
Ink::Fg => p.fg,
Ink::Accent => p.accent,
Expand All @@ -173,7 +158,12 @@ fn cabinet(p: Palette, scene: Scene, variant: u8, frame: u8, bonus: bool) -> imp
Ink::Panel => p.panel,
};
rect(x, y, w, h, color);
});
};
if let Some(kind) = bonus {
scene::draw_bonus(kind, frame, &mut paint);
return;
}
scene::draw(scene, variant, frame, &mut paint);
},
)
.w(px(scene::GRID.0 as f32 * 2.))
Expand Down
Loading
Loading