// === Create Custom Tiles === namespace myTiles { // Define a basic grass tile (only declared once) export const grassTile = image.ofBuffer(hex` 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 10101010101010101010101010101010 `) // Define a basic sand tile (only declared once) export const sandTile = image.ofBuffer(hex` 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 `) } // === Set Background === scene.setBackgroundColor(9) // Set the background to blue for sky // === Create Tilemap === // Define the map using tile indices, use grass and sand tiles directly tiles.setTilemap(tiles.createTilemap( hex` 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 1111111111111111 1111111111111111 1111111111111111 1111111111111111 0000000000000000 0000000000000000 0000000000000000 0000000000000000 `, [myTiles.grassTile, myTiles.sandTile], // Use tile images directly 16, // Width (16 tiles horizontally) 16 // Height (16 tiles vertically) )) // === Create Invisible Camera Follower Sprite === let cameraFollower = sprites.create(img` . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . `, SpriteKind.Player) cameraFollower.setFlag(SpriteFlag.Invisible, true) cameraFollower.setPosition(30, 30) // Start in the center of the screen // === Camera Follow the Invisible Sprite === scene.cameraFollowSprite(cameraFollower) // === Control Movement for Camera === game.onUpdate(function () { if (controller.left.isPressed()) { cameraFollower.x -= 2 // Move the camera to the left } if (controller.right.isPressed()) { cameraFollower.x += 2 // Move the camera to the right } if (controller.up.isPressed()) { cameraFollower.y -= 2 // Move the camera up } if (controller.down.isPressed()) { cameraFollower.y += 2 // Move the camera down } })