diff --git a/blockstile.ts b/blockstile.ts index fb041ae..02b81d8 100644 --- a/blockstile.ts +++ b/blockstile.ts @@ -37,10 +37,10 @@ namespace TileWorld { * @param index * @param img */ - //% blockId=TWsetsprite block="set sprite %index=colorindexpicker to %img=tile_image_picker" + //% blockId=TWsetsprite block="set sprite %index=colorindexpicker to %img=tile_image_picker with $kind=spritekind" //% group="Tiles" - export function addTileSprite(code: number, image: Image) { - myWorld.addTileSprites(code, image) + export function addTileSprite(code: number, image: Image, kind: number) { + myWorld.addTileSprites(code, image, kind) } /** * Set the player @@ -53,18 +53,8 @@ namespace TileWorld { bindToController(player) scene.cameraFollowSprite(player) } - /** - * Make a set of values and return the value representing the set - */ - //% group="Tiles" - //% blockId=TWmakeset block="make set from %code %code2|| %code3 %code4" - //% inlineInputMode=inline - export function makeSet(code: number, code2: number, code3: number = 0xff, code4: number = 0xff) { - return myWorld.makeGroup(code, code2, code3, code4) - } // notifications - //% group="Events" /** * Act on a sprite that is resting on a tile diff --git a/main.ts b/main.ts index ec28d21..c4da386 100644 --- a/main.ts +++ b/main.ts @@ -190,23 +190,22 @@ let world = new tw.TileWorld() world.setMap(levels.level1) world.setBackgroundTile(codes.Space) +// names for sets + +namespace SpriteKind { + export let Rock = SpriteKind.create() +} + world.addTiles(codes.StrongWall, art.Wall) world.addTiles(codes.Wall, art.Wall) world.addTiles(codes.Space, art.Space) world.addTiles(codes.Dirt, art.Dirt) -world.addTileSprites(codes.Boulder, art.Boulder) -world.addTileSprites(codes.Diamond, art.Diamond) -world.addTileSprites(codes.Enemy, art.Enemy) +world.addTileSprites(codes.Boulder, art.Boulder, SpriteKind.Rock) +world.addTileSprites(codes.Diamond, art.Diamond, SpriteKind.Rock) +world.addTileSprites(codes.Enemy, art.Enemy, SpriteKind.Enemy) world.addTileSprites(codes.Player, art.Player, SpriteKind.Player) -// names for sets - -namespace SpriteKind { - export let Wall = world.makeGroup(codes.Wall, codes.StrongWall) - export let Rock = world.makeGroup(codes.Boulder, codes.Diamond) -} - scene.cameraFollowSprite(world.getSprite(codes.Player)) tw.bindToController(world.getSprite(codes.Player)) @@ -244,7 +243,8 @@ world.onTileArrived(SpriteKind.Player, (tile) => { world.onTileArrived(SpriteKind.Player, (tile, dir) => { world.isNotOneOf(dir, TileDir.None) tile.hasNo(codes.Boulder, dir) - tile.hasNo(SpriteKind.Wall, dir) + tile.hasNo(codes.Wall, dir) + tile.hasNo(codes.StrongWall, dir) tile.moveOne(dir) }) @@ -272,17 +272,17 @@ world.onTileStationary(SpriteKind.Rock, (tile) => { // rock falls to right world.onTileStationary(SpriteKind.Rock, (tile) => { - tile.has(SpriteKind.Rock, TileDir.Down) tile.has(codes.Space, TileDir.Right) tile.has(codes.Space, TileDir.Right, TileDir.Down) + tile.has(SpriteKind.Rock, TileDir.Down) tile.moveOne(TileDir.Right) }) // rock falls to left world.onTileStationary(SpriteKind.Rock, (tile) => { - tile.has(SpriteKind.Rock, TileDir.Down) tile.has(codes.Space, TileDir.Left) tile.has(codes.Space, TileDir.Left, TileDir.Down) + tile.has(SpriteKind.Rock, TileDir.Down) tile.moveOne(TileDir.Left) }) diff --git a/tileworld.ts b/tileworld.ts index e6e6a96..f939364 100644 --- a/tileworld.ts +++ b/tileworld.ts @@ -50,7 +50,8 @@ namespace TileWorld { } // conditions - // block + //% blockId=TWhas block="%this(sprite) has %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) { this.parent.check(this.parent.containsAt(code, this, dir, dir2, dir3)) } @@ -322,6 +323,7 @@ namespace TileWorld { scene.setTile(code, art); this.sprites[code] = [] this.spriteCodes.push(code); + this.codeToKind[code] = kind; for (let value of tiles) { let tileSprite = new TileSprite(this, code, art, kind) this.sprites[code].push(tileSprite) @@ -342,22 +344,6 @@ namespace TileWorld { } } - makeGroup(code: number, code2: number, code3: number = 0xff, code4: number = 0xff) { - let kind = SpriteKind.create() - this.codeToKind[code] = kind; - this.codeToKind[code2] = kind; - this.setKind(code, kind); this.setKind(code2, kind) - if (code3 != 0xff) { - this.codeToKind[code3] = kind; - this.setKind(code3, kind); - } - if (code4 != 0xff) { - this.codeToKind[code4] = kind; - this.setKind(code4, kind); - } - return kind; - } - onTileStationary(kind: number, h: (ts: TileSprite) => void) { if (!this.stationaryHandlers[kind]) { this.stationaryHandlers[kind] = []