Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

Commit

Permalink
add player API back
Browse files Browse the repository at this point in the history
  • Loading branch information
tballmsft committed Sep 24, 2019
1 parent 13c0be5 commit 3b2b846
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
19 changes: 15 additions & 4 deletions blockstile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ namespace TileWorld {
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

/**
Expand All @@ -56,7 +67,7 @@ namespace TileWorld {
myWorld.onTileStationary(kind, h);
}
/**
* Act on a sprite that has moved to center of tile
* Sprite is at center of tile and received request to move
* @param body code to execute
*/
//% group="Events" color="#444488"
Expand All @@ -66,13 +77,13 @@ namespace TileWorld {
myWorld.onTileArrived(kind, h)
}
/**
* Act on a sprite that has just moved into new tile
* Sprite has just move into (entered) a tile
* @param body code to execute
*/
//% group="Events" color="#444488"
//% blockId=TWontiletransition block="enter $tile of kind $kind=spritekind"
//% blockAllowMultiple=1 draggableParameters="reporter"
export function onTileTransition(kind: number, h: (tile: TileSprite, col: number, row: number) => void) {
export function onTileTransition(kind: number, h: (tile: TileSprite) => void) {
myWorld.onTileTransition(kind, h)
}

Expand Down
2 changes: 2 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


/*
// Rules of the game:
Expand Down
2 changes: 1 addition & 1 deletion pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
],
"testFiles": [],
"public": false,
"installedVersion": "workspace:61b7f103-b0d4-4907-c2e8-9edc8ab9a6b9",
"installedVersion": "workspace:8fa74bb4-4622-48be-98e5-0a7f5d98f336",
"preferredEditor": "tsprj"
}
5 changes: 0 additions & 5 deletions tileworld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,6 @@ namespace TileWorld {
if (code == pixel) this.tileMap.setPixel(x, y, this.backgroundTile)
}
}
// TODO: check for multiple player sprites
if (kind == SpriteKind.Player) {
bindToController(this.sprites[code][0])
scene.cameraFollowSprite(this.sprites[code][0])
}
}

private setKind(code: number, kind: number) {
Expand Down

0 comments on commit 3b2b846

Please sign in to comment.