This repository has been archived by the owner on Nov 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blockstile.ts
110 lines (105 loc) · 3.92 KB
/
blockstile.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
//% weight=1000 color="#442255" icon="\uf45c"
//% groups='["Tiles", "Events", "Conditions", "Actions"]'
//% blockGap=8
namespace TileWorld {
let myWorld = new TileWorld();
/**
* Set the map for placing tiles in the scene
* @param map
*/
//% blockId=TWsettilemap block="set tile map to %map=tilemap_image_picker"
//% group="Tiles"
export function setTileMap(map: Image) {
myWorld.setMap(map)
}
/**
* Set the background tile for sprites
* @param color
*/
//% group="Tiles"
//% blockId=TWsetbackgroundtile block="set background tile to %color=colorindexpicker"
export function setBackgroundTile(code: number) {
myWorld.setBackgroundTile(code)
}
/**
* Set an image as a tile at the given index. Tiles should be a 16x16 image
* @param index
* @param img
*/
//% blockId=TWsettile block="set tile %index=colorindexpicker to %img=tile_image_picker"
//% group="Tiles"
export function setTile(code: number, image: Image) {
myWorld.addTiles(code, image)
}
/**
* Set an image as a sprite at the given index. Sprites should be a 16x16 image
* @param index
* @param img
*/
//% blockId=TWsetsprite block="set sprite %index=colorindexpicker to %img=tile_image_picker with $kind=spritekind"
//% group="Tiles"
export function addTileSprite(code: number, image: Image, kind: number) {
myWorld.addTileSprites(code, image, kind)
}
/**
* Set the player
* @param color
*/
//% group="Tiles"
//% blockId=TWsetplayer block="set player to %color=colorindexpicker"
export function setPlayer(code: number) {
let player = myWorld.getSprite(code)
bindToController(player)
scene.cameraFollowSprite(player)
}
// notifications
/**
* Act on a sprite that is resting on a tile
* @param body code to execute
*/
//% group="Events" color="#444488"
//% blockId=TWontilestationary block="on $sprite of kind $kind=spritekind at rest"
//% blockAllowMultiple=1 draggableParameters="reporter"
export function onTileStationary(kind: number, h: (sprite: TileSprite) => void) {
myWorld.onTileStationary(kind, h);
}
/**
* Act on a sprite that has moved to center of tile
* @param body code to execute
*/
//% group="Events" color="#444488"
//% blockId=TWontilearrived block="on $sprite of kind $kind=spritekind arrived"
//% blockAllowMultiple=1 draggableParameters="reporter"
export function onTileArrived(kind: number, h: (sprite: TileSprite, direction: TileDir) => void) {
myWorld.onTileArrived(kind, h)
}
/**
* Act on a sprite that has just moved into new tile
* @param body code to execute
*/
//% group="Events" color="#444488"
//% blockId=TWontiletransition block="on $sprite of kind $kind=spritekind transition"
//% blockAllowMultiple=1 draggableParameters="reporter"
export function onTileTransition(kind: number, h: (sprite: TileSprite, col: number, row: number) => void) {
myWorld.onTileTransition(kind, h)
}
// checks
/**
* Check if a direction is one of several values.
*/
//% group="Conditions" color="#448844"
//% blockId=TWisoneof block="is %dir=variables_get(direction) one of %c1 %c2 || %c3"
//% inlineInputMode=inline direction.shadow=tiledir
export function isOneOf(dir: number, c1: TileDir, c2: TileDir = 0xff, c3: TileDir = 0xff) {
myWorld.isOneOf(dir, c1, c2, c3)
}
/**
* Check if a direction is not one of several values.
*/
//% group="Conditions" color="#448844"
//% blockId=TWisnotoneof block="is %dir=variables_get(direction) not one of %c1 %c2 || %c3"
//% inlineInputMode=inline direction.shadow=tiledir
export function isNotOneOf(dir: number, c1: TileDir, c2: TileDir = 0xff, c3: TileDir = 0xff) {
myWorld.isNotOneOf(dir, c1, c2, c3)
}
}