@@ -35,6 +35,39 @@ namespace events {
3535
3636//% color=#FF4D88 icon="\uf443" block="Characters"
3737namespace characters {
38+ //% block="create $image | which is $type | moving left: $left | moving right: $right"
39+ //% image.shadow="screen_image_picker"
40+ //% type.shadow="MovingItemType.Nice"
41+ //% left.shadow="animation_editor"
42+ //% right.shadow="animation_editor"
43+ export function createAnimatedMovingItem ( image = img `` , type : MovingItemType , left = [ img `` ] , right = [ img `` ] ) {
44+ let kind = SpriteKind . Food
45+
46+ if ( type == MovingItemType . Bad ) {
47+ kind = SpriteKind . Enemy
48+ }
49+
50+ let x = randint ( - 50 , 50 )
51+ let sprite = sprites . createProjectileFromSide ( image , x , randint ( - 50 , 50 ) )
52+ sprite . setKind ( kind )
53+
54+ if ( x < 0 ) {
55+ animation . runImageAnimation (
56+ sprite ,
57+ left ,
58+ 200 ,
59+ true
60+ )
61+ } else {
62+ animation . runImageAnimation (
63+ sprite ,
64+ right ,
65+ 200 ,
66+ true
67+ )
68+ }
69+ }
70+
3871 //% block="create $image | which is $type"
3972 //% image.shadow="screen_image_picker"
4073 //% type.shadow="MovingItemType.Nice"
@@ -53,6 +86,40 @@ namespace characters {
5386 player = sprites . create ( image , SpriteKind . Player ) ;
5487 player . setStayInScreen ( true ) ;
5588 }
89+
90+ //% block="Create animated player $image | moving left: $left | moving right: $right"
91+ //% image.shadow="screen_image_picker"
92+ //% left.shadow="animation_editor"
93+ //% right.shadow="animation_editor"
94+ export function createAnimatedPlayer ( image = img `` , left = [ img `` ] , right = [ img `` ] ) {
95+ player = sprites . create ( image , SpriteKind . Player ) ;
96+ player . setStayInScreen ( true ) ;
97+ controller . player1 . onButtonEvent ( ControllerButton . Left , ControllerButtonEvent . Pressed , function ( ) {
98+ animation . runImageAnimation (
99+ player ,
100+ left ,
101+ 200 ,
102+ true
103+ )
104+ } ) ;
105+
106+ controller . player1 . onButtonEvent ( ControllerButton . Right , ControllerButtonEvent . Pressed , function ( ) {
107+ animation . runImageAnimation (
108+ player ,
109+ right ,
110+ 200 ,
111+ true
112+ )
113+ } ) ;
114+
115+ controller . player1 . onButtonEvent ( ControllerButton . Left , ControllerButtonEvent . Released , function ( ) {
116+ animation . stopAnimation ( animation . AnimationTypes . All , player )
117+ } )
118+
119+ controller . player1 . onButtonEvent ( ControllerButton . Right , ControllerButtonEvent . Released , function ( ) {
120+ animation . stopAnimation ( animation . AnimationTypes . All , player )
121+ } )
122+ }
56123}
57124
58125//% color=#006400 icon="\uf11b" block="Controller"
0 commit comments