From ab557f5404f225d4ae748b43482b28bd2ea3a62a Mon Sep 17 00:00:00 2001 From: anzhou5 <42353804+anzhou5@users.noreply.github.com> Date: Sat, 4 Sep 2021 13:36:09 -0700 Subject: [PATCH] Added game and wall jump functionality --- custom.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/custom.ts b/custom.ts index 0cca90b..7ba4e7c 100644 --- a/custom.ts +++ b/custom.ts @@ -6,6 +6,11 @@ enum Choice { } namespace sprites { + + /** + * Allow your sprite to jump and come back to the ground + * before jumping again + */ //% block="make $thisSprite=variables_get(mySprite) gravity jump" export function gravity_jump(thisSprite: Sprite) { if (thisSprite.isHittingTile(CollisionDirection.Bottom)) { @@ -13,7 +18,21 @@ namespace sprites { } } + /** + * Direct sprite to automatically jump only when hitting + * a wall to the right or left + */ + //% block="make $thisSprite=variables_get(mySprite) hurdle side wall" + export function wall_jump(thisSprite: Sprite) { + if (thisSprite.isHittingTile(CollisionDirection.Left) || thisSprite.isHittingTile(CollisionDirection.Right)) { + sprites.gravity_jump(thisSprite) + } + } + /** + * Set a profile pic and name for your hero in the + * upper-left hand corner of the screen + */ //% block="add corner profile for $choice" export function add_profile(choice: Choice) { if (choice == Choice.xialing) { @@ -21,7 +40,7 @@ namespace sprites { profilelife.setName("Xialing") } else { - profilelife.setProfileImage(assets.image`Shang - Chi profile`) + profilelife.setProfileImage(assets.image`Shang-Chi profile`) profilelife.setName("Shang-Chi") } } @@ -54,4 +73,11 @@ namespace animation { export function loopFrames2(sprite: Sprite, frames: Image[], frameInterval: number, rule: number) { characterAnimations.loopFrames(sprite, frames, frameInterval, rule); } +} + +namespace game { + //% block="display level number $num" + export function level_num(num: number) { + game.splash("Level ", num) + } } \ No newline at end of file