pxt-common-packages 12.3.1 → 12.3.2

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.
@@ -4,8 +4,8 @@
4
4
  //% block="Browser Events"
5
5
  namespace browserEvents {
6
6
  export enum Event {
7
- PointerDown = 6857,
8
- PointerUp = 6858,
7
+ PointerDown = 6858,
8
+ PointerUp = 6857,
9
9
  PointerMove = 6859,
10
10
  PointerLeave = 6860,
11
11
  PointerEnter = 6861,
@@ -19,8 +19,8 @@ namespace browserEvents {
19
19
 
20
20
  export enum MouseButtonId {
21
21
  Left = 1,
22
- Right = 2,
23
- Wheel = 3,
22
+ Right = 3,
23
+ Wheel = 2,
24
24
  Back = 4,
25
25
  Forward = 5
26
26
  }
@@ -12,7 +12,7 @@ An overlap with a sprite of a different or the same kind is detected. If you wan
12
12
 
13
13
  When an overlap is detected the sprite of the first kind is given to you in the **sprite** parameter of **handler**. The sprite for the second kind is in **otherSprite**.
14
14
 
15
- An overlap of two sprites is dectected when the first non-transparent pixel in the image of the first sprite overlaps the first non-transparent pixel of the second sprite. If a sprite has it's ``ghost`` flag set, any overlap with another sprite won't be noticed. Also, an overlap occurs even when the values of **Z** for the sprites are different.
15
+ An overlap of two sprites is detected when the first non-transparent pixel in the image of the first sprite overlaps the first non-transparent pixel of the second sprite. If a sprite has it's ``ghost`` flag set, any overlap with another sprite won't be noticed. Also, an overlap occurs even when the values of **Z** for the sprites are different.
16
16
 
17
17
  ## Parameters
18
18
 
@@ -24,95 +24,22 @@ An overlap of two sprites is dectected when the first non-transparent pixel in t
24
24
 
25
25
  ## Example #example
26
26
 
27
- ### Ghost bumper #ex1
28
-
29
- Create a ``Ghost`` sprite that is blasted by green balls. Let the balls go through the sprite until it's ``kind`` is changed to ``Mortal`` by pressing the **A** button. When the ``Ghost`` sprite is changed to ``Mortal``, any contact with the balls is detected in ``||sprites:on overlaps||``. Make the balls push the ``Mortal`` sprite off the screen.
27
+ Create a ``Ghost`` sprite that is blasted by yellow balls. Let the balls go through the sprite until it's ghost status is removed by pressing the **A** button. When the ``Ghost`` sprite is exposed, any contact with the balls is detected in ``||sprites:on overlap||``. Make the balls push the ``Ghost`` sprite off the screen.
30
28
 
31
29
  ```blocks
32
- namespace SpriteKind {
33
- export const Mortal = SpriteKind.create()
34
- export const Ghost = SpriteKind.create()
35
- export const Ball = SpriteKind.create()
36
- }
37
- let ghost: Sprite = null
38
- let projectile: Sprite = null
39
- ghost = sprites.create(img`
40
- . . . . . . d d d d d . . . . .
41
- . . . d d d d 1 1 1 d d d . . .
42
- . . d d 1 1 1 1 1 1 1 1 d d . .
43
- . . d 1 1 1 1 1 1 1 1 1 1 d . .
44
- . . d 1 1 1 1 1 1 1 1 1 1 d d .
45
- . d d 1 1 1 f 1 1 1 f 1 1 1 d .
46
- . d 1 1 1 1 1 1 1 1 1 1 1 1 d d
47
- . d 1 1 1 1 1 1 1 1 1 1 1 1 1 d
48
- . d 1 1 1 1 1 1 1 1 1 1 1 1 1 d
49
- d d 1 1 1 1 1 1 f f 1 1 1 1 1 d
50
- d 1 1 1 1 1 1 1 f f 1 1 1 1 1 d
51
- d 1 1 1 1 1 1 1 1 1 1 1 1 1 1 d
52
- d 1 1 1 1 1 1 1 d 1 1 1 1 1 1 d
53
- d 1 d d d 1 1 d d d d 1 d 1 1 d
54
- d d d . d d d d . . d d d d d d
55
- d d . . . d d . . . . d . . d d
56
- `, SpriteKind.Ghost)
57
- ghost.x = 40
58
- ghost.setFlag(SpriteFlag.AutoDestroy, true)
59
- game.onUpdateInterval(400, function () {
60
- projectile = sprites.createProjectile(img`
61
- . . 7 7 7 7 . .
62
- . 7 7 7 7 7 7 .
63
- 7 7 7 7 7 7 7 7
64
- 7 7 7 7 7 7 7 7
65
- 7 7 7 7 7 7 7 7
66
- 7 7 7 7 7 7 7 7
67
- . 7 7 7 7 7 7 .
68
- . . 7 7 7 7 . .
69
- `, -400, 0, SpriteKind.Ball)
70
- projectile.z = -1
71
- })
72
- sprites.onOverlap(SpriteKind.Mortal, SpriteKind.Ball, function (sprite, otherSprite) {
73
- sprite.say("Ouch!", 200)
74
- otherSprite.vx = otherSprite.vx * -1
75
- otherSprite.vy = Math.randomRange(-100, 100)
76
- sprite.x += -1
77
- })
78
30
  controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
79
- ghost.setKind(SpriteKind.Mortal)
31
+ ghost.setFlag(SpriteFlag.Ghost, false)
80
32
  })
81
- sprites.onDestroyed(SpriteKind.Mortal, function (sprite) {
82
- game.over()
33
+ sprites.onOverlap(SpriteKind.Player, SpriteKind.Projectile, function (sprite, otherSprite) {
34
+ otherSprite.setVelocity(-50, 50)
35
+ sprite.sayText("Ouch!", 200, false)
36
+ sprite.setPosition(sprite.x + 2, sprite.y + 2)
37
+ })
38
+ sprites.onDestroyed(SpriteKind.Player, function (sprite) {
39
+ game.gameOver(false)
83
40
  })
84
- ```
85
-
86
- ## Ghosting mode #ex2
87
-
88
- Use the **A** to blast a green ball at a ``Ghost`` sprite. Set the flag for the sprite to ``Ghost``. In the ``||sprites:on overlaps||`` block, try to detect the contact of the ball with the ghost. When button **B** is pressed, switch the value of the ``ghost`` flag and see if the ball hits the ghost sprite.
89
-
90
- ```blocks
91
- namespace SpriteKind {
92
- export const Mortal = SpriteKind.create()
93
- export const Ghost = SpriteKind.create()
94
- export const Ball = SpriteKind.create()
95
- }
96
41
  let projectile: Sprite = null
97
42
  let ghost: Sprite = null
98
- let mySprite = sprites.create(img`
99
- . . . . . . . . . . . . . . . .
100
- . . . . . . . . . . . . . . . .
101
- . . . . . . . . . . . . . . . .
102
- . . . . . . . . . . . . . . . .
103
- . . . . . . . . . . . . . . . .
104
- . . . . . . . . . . . . . . . .
105
- . . . . . . . . . . . . . . . .
106
- . . . . . . . . . . . . . . . .
107
- . . . . . . . . . . . . . . . .
108
- . . . . . . . . . . . . . . . .
109
- . . . . . . . . . . . . . . . .
110
- . . . . . . . . . . . . . . . .
111
- . . . . . . . . . . . . . . . .
112
- . . . . . . . . . . . . . . . .
113
- . . . . . . . . . . . . . . . .
114
- . . . . . . . . . . . . . . . .
115
- `, SpriteKind.Ball)
116
43
  ghost = sprites.create(img`
117
44
  . . . . . . d d d d d . . . . .
118
45
  . . . d d d d 1 1 1 d d d . . .
@@ -130,33 +57,29 @@ ghost = sprites.create(img`
130
57
  d 1 d d d 1 1 d d d d 1 d 1 1 d
131
58
  d d d . d d d d . . d d d d d d
132
59
  d d . . . d d . . . . d . . d d
133
- `, SpriteKind.Ghost)
134
- ghost.x = 40
60
+ `, SpriteKind.Player)
61
+ ghost.setPosition(60, 60)
135
62
  ghost.setFlag(SpriteFlag.AutoDestroy, true)
136
- game.onUpdateInterval(400, function () {
137
- projectile = sprites.createProjectile(img`
138
- . . 7 7 7 7 . .
139
- . 7 7 7 7 7 7 .
140
- 7 7 7 7 7 7 7 7
141
- 7 7 7 7 7 7 7 7
142
- 7 7 7 7 7 7 7 7
143
- 7 7 7 7 7 7 7 7
144
- . 7 7 7 7 7 7 .
145
- . . 7 7 7 7 . .
146
- `, -400, 0, SpriteKind.Ball)
147
- projectile.z = -1
148
- })
149
- controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
150
- ghost.setKind(SpriteKind.Mortal)
151
- })
152
- sprites.onDestroyed(SpriteKind.Mortal, function (sprite) {
153
- game.over(false)
154
- })
155
- sprites.onOverlap(SpriteKind.Mortal, SpriteKind.Ball, function (sprite, otherSprite) {
156
- sprite.say("Ouch!", 200)
157
- otherSprite.vx = otherSprite.vx * -1
158
- otherSprite.vy = Math.randomRange(-100, 100)
159
- sprite.x += -1
63
+ ghost.setFlag(SpriteFlag.Ghost, true)
64
+ game.onUpdateInterval(1000, function () {
65
+ projectile = sprites.createProjectileFromSide(img`
66
+ . . . . . . . . . . . . . . . .
67
+ . . . . . . . . . . . . . . . .
68
+ . . . . . . . . . . . . . . . .
69
+ . . . . . . . . . . . . . . . .
70
+ . . . . . . . . . . . . . . . .
71
+ . . . . . . . 5 5 . . . . . . .
72
+ . . . . . . 5 5 5 5 . . . . . .
73
+ . . . . . 5 5 5 5 5 5 . . . . .
74
+ . . . . . 5 5 5 5 5 5 . . . . .
75
+ . . . . . . 5 5 5 5 . . . . . .
76
+ . . . . . . . 5 5 . . . . . . .
77
+ . . . . . . . . . . . . . . . .
78
+ . . . . . . . . . . . . . . . .
79
+ . . . . . . . . . . . . . . . .
80
+ . . . . . . . . . . . . . . . .
81
+ . . . . . . . . . . . . . . . .
82
+ `, 50, 50)
160
83
  })
161
84
  ```
162
85
 
@@ -42,28 +42,53 @@ f e e e e e f f f f f e e e e f
42
42
  smiley.say("Hello!")
43
43
  ```
44
44
 
45
- ### Bounce message
45
+ ### Yellow message
46
46
 
47
- Send a sprite toward a barrier. When it contacts the barrier, have it bounce back to its starting position and briefly show the `"Bounce!"` caption.
47
+ Make a square yellow sprite in the middle of the screen. Send a moving person sprite around the screen. When the person sprite crosses the yellow square, make the person say "Yellow!".
48
48
 
49
49
  ```blocks
50
- let greenBoxGo: Sprite = null
51
- let barrier: Sprite = null
52
- let shield: Image = null
53
- let greenBox: Image = null
54
- greenBox = image.create(32, 32)
55
- greenBox.fill(7)
56
- shield = image.create(4, 64)
57
- shield.fill(10)
58
- barrier = sprites.createObstacle(shield)
59
- barrier.x = scene.screenWidth() - 4
60
- greenBoxGo = sprites.create(greenBox)
61
- greenBoxGo.x = 16
62
- greenBoxGo.ax = 80
63
- greenBoxGo.onCollision(CollisionDirection.Right, function (wall) {
64
- greenBoxGo.x = 16
65
- greenBoxGo.say("Bounce!", 400)
50
+ sprites.onOverlap(SpriteKind.Player, SpriteKind.Player, function (sprite, otherSprite) {
51
+ sprite.sayText("Yellow!", 100, false)
66
52
  })
53
+ scene.setBackgroundColor(13)
54
+ let box = sprites.create(img`
55
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
56
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
57
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
58
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
59
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
60
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
61
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
62
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
63
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
64
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
65
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
66
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
67
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
68
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
69
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
70
+ 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
71
+ `, SpriteKind.Player)
72
+ let person = sprites.create(img`
73
+ . . . . . . f f f f . . . . . .
74
+ . . . . f f f 2 2 f f f . . . .
75
+ . . . f f f 2 2 2 2 f f f . . .
76
+ . . f f f e e e e e e f f f . .
77
+ . . f f e 2 2 2 2 2 2 e e f . .
78
+ . . f e 2 f f f f f f 2 e f . .
79
+ . . f f f f e e e e f f f f . .
80
+ . f f e f b f 4 4 f b f e f f .
81
+ . f e e 4 1 f d d f 1 4 e e f .
82
+ . . f e e d d d d d d e e f . .
83
+ . . . f e e 4 4 4 4 e e f . . .
84
+ . . e 4 f 2 2 2 2 2 2 f 4 e . .
85
+ . . 4 d f 2 2 2 2 2 2 f d 4 . .
86
+ . . 4 4 f 4 4 5 5 4 4 f 4 4 . .
87
+ . . . . . f f f f f f . . . . .
88
+ . . . . . f f . . f f . . . . .
89
+ `, SpriteKind.Player)
90
+ person.setBounceOnWall(true)
91
+ person.setVelocity(50, 50)
67
92
  ```
68
93
 
69
94
  ## #seealso
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pxt-common-packages",
3
- "version": "12.3.1",
3
+ "version": "12.3.2",
4
4
  "description": "Microsoft MakeCode (PXT) common packages",
5
5
  "keywords": [
6
6
  "MakeCode",