pxt-common-packages 12.2.10 → 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.
|
@@ -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
|
|
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
|
-
|
|
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.
|
|
31
|
+
ghost.setFlag(SpriteFlag.Ghost, false)
|
|
80
32
|
})
|
|
81
|
-
sprites.
|
|
82
|
-
|
|
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.
|
|
134
|
-
ghost.
|
|
60
|
+
`, SpriteKind.Player)
|
|
61
|
+
ghost.setPosition(60, 60)
|
|
135
62
|
ghost.setFlag(SpriteFlag.AutoDestroy, true)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
.
|
|
145
|
-
. .
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
###
|
|
45
|
+
### Yellow message
|
|
46
46
|
|
|
47
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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
|