-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.ts
132 lines (115 loc) · 4 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
namespace storyboard {
function bootMicrosoftLogo(done: () => void) {
const TARGET_POSITION_KEY = "target_position"
const text = "Microsoft";
const f = image.doubledFont(image.font8);
const bg = 0x6;
const tc = 0x1;
const colorOffset = 2;
const Logo = SpriteKind.create();
const Overlay = SpriteKind.create();
const Text = SpriteKind.create();
scene.setBackgroundColor(bg);
const logoColors = [
0xF25022, // red
0x7FBA00, // green
0x00A4EF, // blue
0xFFB900, // orange
0x737373 // gray
];
palette.setColors(color.createBuffer(logoColors), colorOffset);
pause(300);
const textSprite = sprites.create(
image.create(text.length() * f.charWidth, f.charHeight),
Text
);
textSprite.image.print(text, 0, 0, tc, f);
textSprite.x += 10;
textSprite.z = -1;
textSprite.setFlag(SpriteFlag.Ghost, true);
const overlaySprite = sprites.create(textSprite.image.clone(), Overlay);
overlaySprite.image.replace(tc, bg);
overlaySprite.x = textSprite.x;
overlaySprite.z = -1;
const makeLogoRectangle = (c: number) => {
const i = image.create(8, 8);
i.fill(c);
return i;
}
const logoSprites: Sprite[] = [];
for (let i = 0; i < 4; ++i) {
const s = sprites.create(makeLogoRectangle(i + colorOffset), Logo);
const yDiff = s.width >> 1;
s.y += i < 2 ? -(yDiff + 1) : yDiff;
s.x += (i % 2) * (s.height + 1) + (screen.width >> 1);
s.data[TARGET_POSITION_KEY] = textSprite.left - 3 - (((i + 1) % 2) * 9);
logoSprites.push(s);
}
// overlap to clear overlay
sprites.onOverlap(Logo, Overlay, (s: Sprite, os: Sprite) => {
os.image.fillRect(
s.left - os.left,
s.top - os.top,
s.width + 20, // make sure everything behind this is handled
s.height + 1, // draw mid
0
);
});
// overlap to clear text
sprites.onOverlap(Logo, Text, (s: Sprite, os: Sprite) => {
os.image.fillRect(
0,
0,
s.right - os.left, // make sure everything behind this is handled
os.height,
0
);
});
let allSpritesInPosition = false;
game.onUpdate(() => {
allSpritesInPosition = logoSprites
.map(s => {
const targetPosition = s.data[TARGET_POSITION_KEY];
if (s.right < targetPosition) {
s.ax = 0;
s.vx = 0;
s.right = targetPosition;
}
return s.right <= targetPosition;
})
.every(b => b);
});
logoSprites[2].vx = -50;
logoSprites[2].ax = -1500;
pause(20);
logoSprites[0].vx = -50;
logoSprites[0].ax = -1500;
pause(20);
logoSprites[3].vx = -50;
logoSprites[3].ax = -1500;
pause(20);
logoSprites[1].vx = -50;
logoSprites[1].ax = -1500;
pause(20);
pauseUntil(() => allSpritesInPosition);
overlaySprite.destroy();
pause(1000);
logoSprites.forEach(s => s.ax = 500);
textSprite.ax = -500;
textSprite.setFlag(SpriteFlag.Ghost, false);
pauseUntil(() => logoSprites[3].left >= screen.width >> 1);
logoSprites.forEach(s => {
s.ax = 0
s.vx = 0
});
pause(750);
logoSprites.forEach(s => s.destroy());
pause(250);
done();
}
/**
* Microsoft boot sequence
*/
//% block="Microsoft" fixedInstance whenUsed
export const microsoftBootSequence = new BootSequence(bootMicrosoftLogo, 0x737373);
}