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
85 lines (80 loc) · 2.76 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
//% 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"
//% group="Tiles"
export function addTileSprite(code: number, image: Image) {
myWorld.addTileSprites(code, image)
}
/**
* 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
//% group="Events"
export function onTileStationary(code: number, h: (ts: TileSprite) => void) {
myWorld.onTileStationary(code, h);
}
export function onTileArrived(code: number, h: (ts: TileSprite, d: Dir) => void) {
myWorld.onTileArrived(code, h)
}
export function onTileTransition(code: number, h: (ts: TileSprite, col: number, row: number) => void) {
myWorld.onTileTransition(code, h)
}
// checks
export function makeGroup(code: number, code2: number, code3: number = 0xff, code4: number = 0xff) {
return myWorld.makeGroup(code, code2, code3, code4)
}
export function isOneOf(d: Dir, c1: Dir, c2: Dir = 0xff, c3: Dir = 0xff) {
myWorld.isOneOf(d, c1, c2, c3)
}
export function isNotOneOf(d: Dir, c1: Dir, c2: Dir = 0xff, c3: Dir = 0xff) {
myWorld.isNotOneOf(d, c1, c2, c3)
}
// actions
export function setTileCode(ts: TileSprite, code: number) {
myWorld.setCode(ts, code)
}
}