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

Commit

Permalink
conditions all done
Browse files Browse the repository at this point in the history
  • Loading branch information
tballmsft committed Sep 23, 2019
1 parent cbd6d2c commit 99e58da
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
12 changes: 6 additions & 6 deletions blockstile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,29 @@ namespace TileWorld {
* @param body code to execute
*/
//% group="Events" color="#444488"
//% blockId=TWontilestationary block="on $sprite of kind $kind=spritekind at rest"
//% blockId=TWontilestationary block="on $tile of kind $kind=spritekind at rest"
//% blockAllowMultiple=1 draggableParameters="reporter"
export function onTileStationary(kind: number, h: (sprite: TileSprite) => void) {
export function onTileStationary(kind: number, h: (tile: 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"
//% blockId=TWontilearrived block="on $tile of kind $kind=spritekind arrived"
//% blockAllowMultiple=1 draggableParameters="reporter"
export function onTileArrived(kind: number, h: (sprite: TileSprite, direction: TileDir) => void) {
export function onTileArrived(kind: number, h: (tile: 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"
//% blockId=TWontiletransition block="on $tile of kind $kind=spritekind transition"
//% blockAllowMultiple=1 draggableParameters="reporter"
export function onTileTransition(kind: number, h: (sprite: TileSprite, col: number, row: number) => void) {
export function onTileTransition(kind: number, h: (tile: TileSprite, col: number, row: number) => void) {
myWorld.onTileTransition(kind, h)
}

Expand Down
30 changes: 15 additions & 15 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,47 +242,47 @@ world.onTileArrived(SpriteKind.Player, (tile) => {

world.onTileArrived(SpriteKind.Player, (tile, dir) => {
world.isNotOneOf(dir, TileDir.None)
tile.hasNo(codes.Boulder, dir)
tile.hasNo(codes.Wall, dir)
tile.hasNo(codes.StrongWall, dir)
tile.hasNoCode(codes.Boulder, dir)
tile.hasNoCode(codes.Wall, dir)
tile.hasNoCode(codes.StrongWall, dir)
tile.moveOne(dir)
})

world.onTileArrived(SpriteKind.Player, (tile, dir) => {
world.isOneOf(dir, TileDir.Left, TileDir.Right)
tile.has(codes.Space, dir, dir)
tile.has(codes.Boulder, dir)
tile.hasCode(codes.Space, dir, dir)
tile.hasCode(codes.Boulder, dir)
tile.get(codes.Boulder, dir).moveOne(dir)
tile.moveOne(dir)
})

// if the player is moving into a tile with a diamond, eat it
world.onTileTransition(SpriteKind.Player, (tile) => {
tile.has(codes.Diamond)
tile.hasCode(codes.Diamond)
tile.get(codes.Diamond).remove()
})

// rock logic

// rock starts falling if there is a space below it
world.onTileStationary(SpriteKind.Rock, (tile) => {
tile.has(codes.Space, TileDir.Down)
tile.hasCode(codes.Space, TileDir.Down)
tile.moveOne(TileDir.Down)
})

// rock falls to right
world.onTileStationary(SpriteKind.Rock, (tile) => {
tile.has(codes.Space, TileDir.Right)
tile.has(codes.Space, TileDir.Right, TileDir.Down)
tile.has(SpriteKind.Rock, TileDir.Down)
tile.hasCode(codes.Space, TileDir.Right)
tile.hasCode(codes.Space, TileDir.Right, TileDir.Down)
tile.hasKind(SpriteKind.Rock, TileDir.Down)
tile.moveOne(TileDir.Right)
})

// rock falls to left
world.onTileStationary(SpriteKind.Rock, (tile) => {
tile.has(codes.Space, TileDir.Left)
tile.has(codes.Space, TileDir.Left, TileDir.Down)
tile.has(SpriteKind.Rock, TileDir.Down)
tile.hasCode(codes.Space, TileDir.Left)
tile.hasCode(codes.Space, TileDir.Left, TileDir.Down)
tile.hasKind(SpriteKind.Rock, TileDir.Down)
tile.moveOne(TileDir.Left)
})

Expand All @@ -294,13 +294,13 @@ world.onTileArrived(SpriteKind.Rock, (tile, dir) => {

world.onTileArrived(SpriteKind.Rock, (tile, dir) => {
world.isOneOf(dir, TileDir.Down);
tile.has(SpriteKind.Rock, TileDir.Down)
tile.hasKind(SpriteKind.Rock, TileDir.Down)
tile.deadStop();
})

world.onTileArrived(SpriteKind.Rock, (tile, dir) => {
world.isNotOneOf(dir, TileDir.Down);
tile.has(codes.Space, TileDir.Down)
tile.hasCode(codes.Space, TileDir.Down)
tile.deadStop();
tile.moveOne(TileDir.Down)
})
Expand Down
24 changes: 18 additions & 6 deletions tileworld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,28 @@ namespace TileWorld {
}
// conditions

//% blockId=TWhas block="%this(sprite) has %code=colorindexpicker at %dir || %dir2 %dir3"
//% blockId=TWhascode block="does %this(tile) have code %code=colorindexpicker at %dir || %dir2 %dir3"
//% group="Conditions" color="#448844" inlineInputMode=inline
has(code: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
hasCode(code: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
this.parent.check(this.parent.containsAt(code, this, dir, dir2, dir3))
}
// block
hasNo(code: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
//% blockId=TWhaskind block="does %this(tile) have kind $kind=spritekind at %dir || %dir2 %dir3"
//% group="Conditions" color="#448844" inlineInputMode=inline
hasKind(kind: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
this.parent.check(this.parent.containsAt(kind, this, dir, dir2, dir3))
}
//% blockId=TWhasnocode block="%this(tile) has no code %code=colorindexpicker at %dir || %dir2 %dir3"
//% group="Conditions" color="#448844" inlineInputMode=inline
hasNoCode(code: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
this.parent.check(!this.parent.containsAt(code, this, dir, dir2, dir3))
}
// block
//% blockId=TWhasnokind block="%this(tile) has no kind $kind=spritekind at %dir || %dir2 %dir3"
//% group="Conditions" color="#448844" inlineInputMode=inline
hasNoKind(kind: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
this.parent.check(!this.parent.containsAt(kind, this, dir, dir2, dir3))
}
//% blockId=TWhasmultiple block="does %this(tile) have multiple $code=colorindexpicker at %dir || %dir2 %dir3"
//% group="Conditions" color="#448844" inlineInputMode=inline
hasMultiple(code: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
this.parent.check(this.parent.hasMultiple(code, this, dir, dir2, dir3))
}
Expand All @@ -70,7 +82,7 @@ namespace TileWorld {
get(code: number, dir: TileDir = TileDir.None, dir2: TileDir = TileDir.None, dir3: TileDir = TileDir.None) {
return this.parent.getSprite(code, this, dir, dir2, dir3)
}
//% blockId=TWsettilecode block="set tile at %this(sprite) to %code=colorindexpicker"
//% blockId=TWsettilecode block="set code at %this(tile) to %code=colorindexpicker"
//% group="Actions" color="#88CC44"
setCode(code: number) {
this.parent.setCode(this, code)
Expand Down

0 comments on commit 99e58da

Please sign in to comment.