pxt-arcade 1.12.13 → 1.12.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/built/common-sim.d.ts +6 -0
- package/built/common-sim.js +15 -2
- package/built/sim.js +108 -26
- package/built/target-strings.json +2 -2
- package/built/target.js +274 -194
- package/built/target.json +274 -194
- package/built/targetlight.json +5 -5
- package/built/theme.json +5 -5
- package/docs/skillmap/educator-info/adventure-info.md +87 -0
- package/docs/static/hero-gallery/multiplayer-banner.png +0 -0
- package/docs/test/skillmap/adventure/adventure1.md +493 -0
- package/docs/test/skillmap/adventure/adventure2.md +279 -0
- package/docs/test/skillmap/adventure/adventure3.md +208 -0
- package/docs/test/skillmap/adventure/adventure4.md +1773 -0
- package/docs/test/skillmap/adventure.md +85 -0
- package/docs/test/skillmap/story/story1.md +15 -10
- package/docs/test/skillmap/story/story2.md +2 -1
- package/docs/test/tutorials/collect-clovers.md +1044 -0
- package/docs/test/tutorials/hawk.md +172 -75
- package/docs/test/tutorials/time-flies.md +346 -0
- package/package.json +4 -4
- package/pxtarget.json +5 -5
- package/targetconfig.json +57 -3
package/built/targetlight.json
CHANGED
|
@@ -508,11 +508,11 @@
|
|
|
508
508
|
}
|
|
509
509
|
],
|
|
510
510
|
"versions": {
|
|
511
|
-
"branch": "v1.12.
|
|
512
|
-
"tag": "v1.12.
|
|
513
|
-
"commits": "https://github.com/microsoft/pxt-arcade/commits/
|
|
514
|
-
"target": "1.12.
|
|
515
|
-
"pxt": "8.5.
|
|
511
|
+
"branch": "v1.12.16",
|
|
512
|
+
"tag": "v1.12.16",
|
|
513
|
+
"commits": "https://github.com/microsoft/pxt-arcade/commits/a8fdd30c00f5c318c3693aff3079dcffe3af2cdb",
|
|
514
|
+
"target": "1.12.16",
|
|
515
|
+
"pxt": "8.5.22"
|
|
516
516
|
},
|
|
517
517
|
"blocksprj": {
|
|
518
518
|
"id": "blocksprj",
|
package/built/theme.json
CHANGED
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"hasAudio": true,
|
|
57
57
|
"allowPackageExtensions": true,
|
|
58
58
|
"homeScreenHero": {
|
|
59
|
-
"imageUrl": "/static/hero-gallery/
|
|
60
|
-
"name": "
|
|
61
|
-
"url": "https://
|
|
62
|
-
"buttonLabel": "
|
|
63
|
-
"description": "
|
|
59
|
+
"imageUrl": "/static/hero-gallery/multiplayer-banner.png",
|
|
60
|
+
"name": "Multiplayer Games!",
|
|
61
|
+
"url": "https://arcade.makecode.com/--multiplayer",
|
|
62
|
+
"buttonLabel": "Try Now",
|
|
63
|
+
"description": "Multiplayer Games!",
|
|
64
64
|
"cardType": "link"
|
|
65
65
|
},
|
|
66
66
|
"homeScreenHeroGallery": "/hero-banner",
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Whack-the-Mole
|
|
2
|
+
|
|
3
|
+
**A page for Educators & Parents**
|
|
4
|
+
|
|
5
|
+
The **Whack-the-Mole** skillmap introduces simple game design and computer science concepts through a fun, relatable carnival interface.
|
|
6
|
+
|
|
7
|
+
In this set of activities, students will create a simple mole-chasing game with MakeCode Arcade. This map is intended for students who are new to MakeCode with little or no previous coding experience.
|
|
8
|
+
|
|
9
|
+
Designed for students between the ages of 8 & 13, this experience contains a total of 3 tutorials (approximating 45 minutes of instruction). At the end of the learning path, students receive a certificate of completion and a badge.
|
|
10
|
+
|
|
11
|
+
| | Minutes* | Key Concepts |
|
|
12
|
+
| --------------- | -------- | ------------ |
|
|
13
|
+
| Mole Hunt |18 | sprites, events, timer |
|
|
14
|
+
| Hammer Time |12 | sprites, overlaps, events |
|
|
15
|
+
| Get Animated |15 | sound, text, animations |
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
\* Minutes are approximate, based on time to follow instructions as written. Providing extra time for creativity and debugging is encouraged.
|
|
19
|
+
|
|
20
|
+
### Objectives
|
|
21
|
+
|
|
22
|
+
After completing Whack-the-Mole, students will have gained exposure to all the elements they need to successfully create their own Whack-the-Mole game using MakeCode Arcade, including:
|
|
23
|
+
|
|
24
|
+
#### Computer Science Concepts
|
|
25
|
+
|
|
26
|
+
- Sequencing and algorithms
|
|
27
|
+
- Events
|
|
28
|
+
- User input
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
#### Game Design Concepts
|
|
32
|
+
|
|
33
|
+
- Sprites
|
|
34
|
+
- Design, Sounds, and Effects
|
|
35
|
+
- Collision / overlap
|
|
36
|
+
- Countdown timers
|
|
37
|
+
- Game Score
|
|
38
|
+
- Win/Loss Criteria
|
|
39
|
+
- Animation
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
#### 1. Mole Hunt
|
|
44
|
+
|
|
45
|
+
| Activity | Mole Hunt (18 min) |
|
|
46
|
+
|---|---|
|
|
47
|
+
|  | Learn to use MakeCode Arcade and add a moving character sprite to your project. |
|
|
48
|
+
| Blocks used | ``[scene.setBackgroundImage(img`.`)]`` <br/> ``[let mySprite = sprites.create(img`.`, SpriteKind.Enemy)]`` <br/> ``[game.onUpdateInterval(1000, function () {}]``|
|
|
49
|
+
| Solution option | [Mole Hunt Project](https://makecode.com/_4WPAes5LMe9z) |
|
|
50
|
+
|
|
51
|
+
#### 2. Hammer Time
|
|
52
|
+
|
|
53
|
+
| Activity | Hammer Time (12 min) |
|
|
54
|
+
|---|---|
|
|
55
|
+
|  | Add a rubber hammer to tag the mole and earn points! |
|
|
56
|
+
| Blocks used | ``[let mySprite = sprites.create(img`.`, SpriteKind.Player)]`` <br/> ``[sprites.move_to_random_hole_on_grid(mySprite)]`` <br/> ``[controller.move_only_onscreen_with_arrows(myHammer, speeds.Fast)]`` <br/> ``[sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function (sprite, otherSprite) {})]`` <br/> ``[info.startCountdownGame(20, winTypes.Score, effects.confetti)]`` <br/> ``[info.changeScoreBy(1)]`` <br/> ``[sprites.move_to_random_hole_on_grid(mySprite)]`` |
|
|
57
|
+
| Solution option | [Hammer Time Project](https://makecode.com/_3kzWrvbA51PL) |
|
|
58
|
+
|
|
59
|
+
#### 3. Get Animated
|
|
60
|
+
|
|
61
|
+
| Activity | Get Animated (15 min) |
|
|
62
|
+
|---|---|
|
|
63
|
+
|  | Add sound and animation to polish your game! |
|
|
64
|
+
| Blocks used | ``[music.knock.play()]`` <br/> ``[animation.runImageAnimationHammer(myHammer,[img`.`],100,false)]`` <br/>``[scene.add_label_to("Whack-the-Mole", areas.Bottom)]`` |
|
|
65
|
+
| Solution option | [Get Animated Project](https://makecode.com/_PCKW94TVLMpA) |
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
##### Game Mod Ideas
|
|
74
|
+
|
|
75
|
+
After students complete Whack-the-Mole they can head back to the skillmap and click "SAVE TO MY PROJECTS", which will open the game in a window with a full-featured toolbox. Here are some modifications they can try:
|
|
76
|
+
|
|
77
|
+
- Change the mole to a different character. Try a monster, an alien, or a star!
|
|
78
|
+
- Animate your character each time it's tagged by the rubber hammer.
|
|
79
|
+
- Add background music.
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### What's Next?
|
|
83
|
+
|
|
84
|
+
After completing Whack-the-Mole, students can move on to the following activities:
|
|
85
|
+
|
|
86
|
+
* [Burstin' Balloons](https://arcade.makecode.com/--skillmap#docs:/skillmap/balloon)
|
|
87
|
+
* [Space Explorer](https://arcade.makecode.com/--skillmap#docs:/skillmap/space)
|
|
Binary file
|
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
# Dungeons & Dragons: Honor Among Thieves - Your Adventure
|
|
2
|
+
### @explicitHints true
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## {Intro @showdialog}
|
|
6
|
+
|
|
7
|
+
This activity will show you how to make your own text-based adventure inspired by the movie Dungeons & Dragons: Honor Among Thieves
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## {Step 2}
|
|
14
|
+
|
|
15
|
+
**Let's get rolling!**<br/>
|
|
16
|
+
|
|
17
|
+
First, we'll code a 20-sided die that we'll call a **d20**.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
- :tree: From the ``||scene:Scene||`` category in the toolbox,
|
|
22
|
+
grab
|
|
23
|
+
|
|
24
|
+
```block
|
|
25
|
+
scene.setBackgroundImage(img`.`)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
and drag it into the ``||loops(noclick):on start||`` container that's already in the workspace.
|
|
29
|
+
|
|
30
|
+
~hint Click here to see how 🕵🏽
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+
hint~
|
|
36
|
+
|
|
37
|
+
- :mouse pointer: Click **Next** to move on to the next step.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
#### ~ tutorialhint
|
|
43
|
+
|
|
44
|
+
```blocks
|
|
45
|
+
//@highlight
|
|
46
|
+
scene.setBackgroundImage(img`.`)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## {Step 3}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
- :paint brush: Click the empty grey square inside
|
|
55
|
+
|
|
56
|
+
```block
|
|
57
|
+
scene.setBackgroundImage(img`.`)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
to open the **image editor**. <br/><br/>
|
|
61
|
+
You can draw your own background or choose one from the **Gallery**.
|
|
62
|
+

|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
~hint Click here to see how 🕵🏽
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+

|
|
70
|
+
hint~
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
#### ~ tutorialhint
|
|
74
|
+
|
|
75
|
+
```blocks
|
|
76
|
+
//@highlight
|
|
77
|
+
scene.setBackgroundImage(storySprites.halloween)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## {Step 4}
|
|
85
|
+
|
|
86
|
+
**Look at your card.**
|
|
87
|
+
|
|
88
|
+
- :binoculars: Take a look at the game window. <br/><br/>
|
|
89
|
+
Do you see the background you chose?
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## {Step 5}
|
|
95
|
+
|
|
96
|
+
**Add a heartfelt greeting**<br/>
|
|
97
|
+
💛 💛 💛
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
- :ticket: From the ``||carnival:Carnival||`` category, drag
|
|
102
|
+
|
|
103
|
+
```block
|
|
104
|
+
carnival.addLabelTo("You Are Awesome", carnival.Areas.Top)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
into **the end** of the ``||loops(noclick):on start||`` container that's already in the workspace.
|
|
108
|
+
|
|
109
|
+
- :mouse pointer: Change the message to whatever you would like.
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
~hint Click here to see how 🕵🏽
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+

|
|
117
|
+
hint~
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
#### ~ tutorialhint
|
|
122
|
+
|
|
123
|
+
```blocks
|
|
124
|
+
scene.setBackgroundImage(storySprites.halloween)
|
|
125
|
+
//@highlight
|
|
126
|
+
carnival.addLabelTo("You Are Awesome", carnival.Areas.Top)
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
## {Step 6}
|
|
134
|
+
|
|
135
|
+
**Time for pizzazz**<br/>
|
|
136
|
+
🎉🎉🎉
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
- :tree: Open the ``||scene:Scene||`` category and drag
|
|
141
|
+
|
|
142
|
+
```block
|
|
143
|
+
effects.confetti.startScreenEffect()
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
into **the end** of the ``||loops(noclick):on start||`` container that's already in the workspace.
|
|
147
|
+
|
|
148
|
+
- :mouse pointer: Change the effect to whatever you would like.
|
|
149
|
+
|
|
150
|
+
~hint Click here to see how 🕵🏽
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+

|
|
155
|
+
hint~
|
|
156
|
+
|
|
157
|
+
#### ~ tutorialhint
|
|
158
|
+
|
|
159
|
+
```blocks
|
|
160
|
+
scene.setBackgroundImage(storySprites.halloween)
|
|
161
|
+
carnival.addLabelTo("You Are Awesome", carnival.Areas.Top)
|
|
162
|
+
//@highlight
|
|
163
|
+
effects.confetti.startScreenEffect()
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
## {Step 7}
|
|
171
|
+
|
|
172
|
+
**Look at your creation!**
|
|
173
|
+
|
|
174
|
+
- :binoculars: Take a look at the game window. Does the card look the way you want it to? <br/><br/>
|
|
175
|
+
Feel free to change it until you are happy with it.
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
## {Step 8}
|
|
182
|
+
|
|
183
|
+
**Let's add a personal note**<br/>
|
|
184
|
+
🎵 🎵 🎵
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
- :headphones: From the ``||music:Music||`` category, drag
|
|
189
|
+
|
|
190
|
+
```block
|
|
191
|
+
music.startSong(``, false)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
into **the end** of the ``||loops(noclick):on start||`` container that's already in the workspace.
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
- :mouse pointer: **Click the empty rectangle** to open the music editor.<br/><br/>
|
|
198
|
+
You can write your own song or switch to **My Assets** to pick one
|
|
199
|
+
that we've written for you.
|
|
200
|
+
|
|
201
|
+
~hint Click here to see how 🕵🏽
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+

|
|
206
|
+
hint~
|
|
207
|
+
|
|
208
|
+
#### ~ tutorialhint
|
|
209
|
+
|
|
210
|
+
```blocks
|
|
211
|
+
scene.setBackgroundImage(storySprites.halloween)
|
|
212
|
+
carnival.addLabelTo("You Are Awesome", carnival.Areas.Top)
|
|
213
|
+
effects.confetti.startScreenEffect()
|
|
214
|
+
music.startSong(assets.song`birthday`, false)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
## {Step 9}
|
|
221
|
+
|
|
222
|
+
**Celebrate your work!**
|
|
223
|
+
|
|
224
|
+
- :binoculars: Take a look at your finished card in the game window.<br/><br/>
|
|
225
|
+
Feel free to go back and make changes until you are happy with it.
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
## {Finish}
|
|
230
|
+
|
|
231
|
+
**Congratulations, you've finished your greeting card!**<br/>
|
|
232
|
+
🥳 🥳 🥳
|
|
233
|
+
|
|
234
|
+
Click **Done** to return to the main skillmap page where you can keep going to make an even more detailed card.
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
```blockconfig.global
|
|
238
|
+
carnival.addLabelTo("You Are Awesome", carnival.Areas.Top)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
```package
|
|
244
|
+
carnival=github:microsoft/arcade-tutorial-extensions/carnival/
|
|
245
|
+
dd=github:kiki-lee/dnd-sprite-pack
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
```template
|
|
252
|
+
|
|
253
|
+
function rollDie () {
|
|
254
|
+
loggr.addToTextlog(loggr.rollTextForLog(roll))
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
```ghost
|
|
264
|
+
function enounter1 () {
|
|
265
|
+
loggr.addImageToTextLog(assets.image`dd.gelatenousCube`)
|
|
266
|
+
loggr.addToTextlog("You quickly turn the corner and are startled by a gelatinous cube in your path")
|
|
267
|
+
loggr.addToTextlog("Press (A) to roll and see what happens next!")
|
|
268
|
+
rollOnButton(1, 20)
|
|
269
|
+
if (roll == 20) {
|
|
270
|
+
loggr.addToTextlog("A nat-20! You see the cube and dodge it with plenty of time to carry-on with your mission...and you find $10 and a cheeseburger on the floor while doing it.")
|
|
271
|
+
info.changeLifeBy(1)
|
|
272
|
+
info.changeScoreBy(10)
|
|
273
|
+
} else if (roll == 1) {
|
|
274
|
+
loggr.addToTextlog("A nat-1! This is bad. By the time you see the cube, you're already fully inside of it.")
|
|
275
|
+
loggr.addToTextlog("You've had sunburns before, but this is a whole other level.")
|
|
276
|
+
loggr.addToTextlog("The world slowly fades away.")
|
|
277
|
+
info.changeLifeBy(0 - info.life())
|
|
278
|
+
} else if (roll >= 10) {
|
|
279
|
+
loggr.addToTextlog("Your roll was high enough to help you dodge the cube.")
|
|
280
|
+
loggr.addToTextlog("Phew! That was a close one!")
|
|
281
|
+
} else {
|
|
282
|
+
loggr.addToTextlog("That roll was too low to escape unharmed.")
|
|
283
|
+
loggr.addToTextlog("You don't see the cube in time and it slowly starts absorbing your arm.")
|
|
284
|
+
loggr.addToTextlog("The pain is intense, but you're able to pull away and run to freedom.")
|
|
285
|
+
loggr.addToTextlog("Phew! That was a close one!")
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function rollOnButton (lo: number, hi: number) {
|
|
289
|
+
while (!(controller.A.isPressed())) {
|
|
290
|
+
pause(25)
|
|
291
|
+
}
|
|
292
|
+
roll = randint(lo, hi)
|
|
293
|
+
loggr.addToTextlog(loggr.multiTextForLog("You roll " + roll + "!"))
|
|
294
|
+
return roll
|
|
295
|
+
}
|
|
296
|
+
info.onLifeZero(function () {
|
|
297
|
+
game.over(false)
|
|
298
|
+
})
|
|
299
|
+
function enounter2 () {
|
|
300
|
+
loggr.addImageToTextLog(img`
|
|
301
|
+
. . . . . c c c c c c c . . . .
|
|
302
|
+
. . . . c 6 7 7 7 7 7 6 c . . .
|
|
303
|
+
. . . c 7 c 6 6 6 6 c 7 6 c . .
|
|
304
|
+
. . c 6 7 6 f 6 6 f 6 7 7 c . .
|
|
305
|
+
. . c 7 7 7 7 7 7 7 7 7 7 c . .
|
|
306
|
+
. . f 7 8 1 f f 1 6 7 7 7 f . .
|
|
307
|
+
. . f 6 f 1 f f 1 f 7 7 7 f . .
|
|
308
|
+
. . . f f 2 2 2 2 f 7 7 6 f . .
|
|
309
|
+
. . c c f 2 2 2 2 7 7 6 f c . .
|
|
310
|
+
. c 7 7 7 7 7 7 7 7 c c 7 7 c .
|
|
311
|
+
c 7 1 1 1 7 7 7 7 f c 6 7 7 7 c
|
|
312
|
+
f 1 1 1 1 1 7 6 f c c 6 6 6 c c
|
|
313
|
+
f 1 1 1 1 1 1 6 6 c 6 6 6 c . .
|
|
314
|
+
f 6 1 1 1 1 1 6 6 6 6 6 6 c . .
|
|
315
|
+
. f 6 1 1 1 1 1 6 6 6 6 c . . .
|
|
316
|
+
. . f f c c c c c c c c . . . .
|
|
317
|
+
`)
|
|
318
|
+
loggr.addToTextlog("A snake slithers into your path")
|
|
319
|
+
}
|
|
320
|
+
music.setVolume(20)
|
|
321
|
+
info.setLife(20)
|
|
322
|
+
enounter1()
|
|
323
|
+
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
```customts
|
|
327
|
+
|
|
328
|
+
music.setVolume(20);
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
//% color=#888888 icon="\uf036"
|
|
332
|
+
//% block="Text Log"
|
|
333
|
+
namespace loggr {
|
|
334
|
+
|
|
335
|
+
let stateStack: TextLogState[];
|
|
336
|
+
const padding = 5;
|
|
337
|
+
const pauseTime = 1500;
|
|
338
|
+
|
|
339
|
+
class LogEntry {
|
|
340
|
+
constructor(public isTextEntry: boolean) {
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
class TextEntry extends LogEntry {
|
|
345
|
+
text: sprites.RenderText;
|
|
346
|
+
|
|
347
|
+
constructor(text: string) {
|
|
348
|
+
super(true);
|
|
349
|
+
this.text = new sprites.RenderText(text, screen.width - (padding << 1));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
class ImageEntry extends LogEntry {
|
|
354
|
+
constructor(public image: Image) {
|
|
355
|
+
super(false);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
class SpriteEntry extends LogEntry {
|
|
360
|
+
constructor(public sprite: Sprite) {
|
|
361
|
+
super(false);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
class TextLogState {
|
|
366
|
+
log: LogEntry[];
|
|
367
|
+
printIndex: number
|
|
368
|
+
finishedPrinting: boolean;
|
|
369
|
+
printingTimer = 0;
|
|
370
|
+
|
|
371
|
+
constructor() {
|
|
372
|
+
this.log = [];
|
|
373
|
+
|
|
374
|
+
scene.createRenderable(10, () => this.draw())
|
|
375
|
+
this.printIndex = 0;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
draw() {
|
|
379
|
+
let top = screen.height - padding;
|
|
380
|
+
|
|
381
|
+
this.printIndex++
|
|
382
|
+
for (let i = 0; i < this.log.length; i++) {
|
|
383
|
+
const entry = this.log[this.log.length - 1 - i]
|
|
384
|
+
|
|
385
|
+
if (entry.isTextEntry) {
|
|
386
|
+
const text = (entry as TextEntry).text;
|
|
387
|
+
|
|
388
|
+
if (i === 0) {
|
|
389
|
+
top -= text.calculatePartialHeight(0, this.printIndex);
|
|
390
|
+
text.drawPartial(screen, padding, top, 7, this.printIndex);
|
|
391
|
+
|
|
392
|
+
if (!this.finishedPrinting) {
|
|
393
|
+
if (this.printIndex > text.printableCharacters()) {
|
|
394
|
+
if (this.printingTimer <= 0) {
|
|
395
|
+
this.printingTimer = pauseTime
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
this.printingTimer -= game.eventContext().deltaTimeMillis
|
|
399
|
+
|
|
400
|
+
if (this.printingTimer <= 0) {
|
|
401
|
+
this.finishedPrinting = true;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
top -= text.height + padding;
|
|
409
|
+
|
|
410
|
+
if (top + text.height < 0) {
|
|
411
|
+
this.log = this.log.slice(this.log.length - 1 - i);
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
text.draw(screen, padding, top, 11, 0);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
const image = (entry as ImageEntry).image;
|
|
419
|
+
top -= image.height + padding
|
|
420
|
+
screen.drawTransparentImage(image, padding, top);
|
|
421
|
+
|
|
422
|
+
if (i === 0 && !this.finishedPrinting) {
|
|
423
|
+
this.printingTimer -= game.eventContext().deltaTimeMillis
|
|
424
|
+
|
|
425
|
+
if (this.printingTimer <= 0) {
|
|
426
|
+
this.finishedPrinting = true;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
appendToLog(text: string) {
|
|
434
|
+
this.log.push(new TextEntry(text));
|
|
435
|
+
this.printIndex = 0;
|
|
436
|
+
this.finishedPrinting = false;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
appendImageToLog(image: Image) {
|
|
440
|
+
this.log.push(new ImageEntry(image));
|
|
441
|
+
this.printIndex = 0;
|
|
442
|
+
this.finishedPrinting = false;
|
|
443
|
+
this.printingTimer = pauseTime
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function init() {
|
|
448
|
+
if (stateStack) return;
|
|
449
|
+
|
|
450
|
+
stateStack = [new TextLogState()]
|
|
451
|
+
|
|
452
|
+
game.addScenePushHandler(() => {
|
|
453
|
+
stateStack.push(new TextLogState())
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
game.addScenePopHandler(() => {
|
|
457
|
+
stateStack.pop();
|
|
458
|
+
if (!stateStack.length) stateStack.push(new TextLogState());
|
|
459
|
+
})
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function state() {
|
|
463
|
+
init();
|
|
464
|
+
return stateStack[stateStack.length - 1];
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
//% blockId=dnd_add_to_text_log
|
|
468
|
+
//% block="add $text to text log"
|
|
469
|
+
export function addToTextlog(text: string) {
|
|
470
|
+
state().appendToLog(text)
|
|
471
|
+
pauseUntil(() => state().finishedPrinting)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
//% blockId=dnd_add_image_to_text_log
|
|
475
|
+
//% block="add $image to text log"
|
|
476
|
+
//% image.shadow=screen_image_picker
|
|
477
|
+
export function addImageToTextLog(image: Image) {
|
|
478
|
+
state().appendImageToLog(image)
|
|
479
|
+
pauseUntil(() => state().finishedPrinting)
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
//% color=#AAAAAA
|
|
483
|
+
//% blockId=log_roll
|
|
484
|
+
//% block="“You rolled $rolled !”"
|
|
485
|
+
//% inlineInputMode=inline
|
|
486
|
+
export function rollTextForLog(rolled:number):string {
|
|
487
|
+
return ("You rolled " + rolled.toString() + "!");
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
```
|