File tree Expand file tree Collapse file tree 10 files changed +146
-213
lines changed
src/org/openpatch/scratch Expand file tree Collapse file tree 10 files changed +146
-213
lines changed Original file line number Diff line number Diff line change 11import org .openpatch .scratch .Stage ;
22
33public class BouncyHedgehogStage extends Stage {
4-
5- public BouncyHedgehogStage () {
6- this .addBackdrop ("playground" , "playground.jpg" );
7- this .add (new HedgehogSprite ());
8- this .add (new TrampolineSprite ());
9- }
104
11- public static void main (String [] args ) {
12- new BouncyHedgehogStage ();
13- }
5+ public BouncyHedgehogStage () {
6+ this .addBackdrop ("playground" , "playground.jpg" );
7+ this .add (new HedgehogSprite ());
8+ this .add (new TrampolineSprite ());
9+ }
10+
11+ public static void main (String [] args ) {
12+ new BouncyHedgehogStage ();
13+ }
1414}
Original file line number Diff line number Diff line change 33
44public class HedgehogSprite extends Sprite {
55
6- public HedgehogSprite () {
7- this .addCostume ("hedgehog" , "hedgehog.png" );
6+ public HedgehogSprite () {
7+ this .addCostume ("hedgehog" , "hedgehog.png" );
88
9- this .pointInDirection (15 );
10- this .setPosition (-180 , 140 );
11- }
9+ this .pointInDirection (15 );
10+ this .setPosition (-180 , 140 );
11+ }
1212
13- public void run () {
14- if (this .getY () > -120 ) {
15- this .move (1 );
16- this .ifOnEdgeBounce ();
13+ public void run () {
14+ if (this .getY () > -120 ) {
15+ this .move (1 );
16+ this .ifOnEdgeBounce ();
1717
18- if (this .isTouchingSprite (TrampolineSprite .class )) {
19- this .pointInDirection (Random .random (-45 , 45 ));
20- }
21- } else {
22- this .say ("Ouch!" , 2000 );
23- }
18+ if (this .isTouchingSprite (TrampolineSprite .class )) {
19+ this .pointInDirection (Random .random (-45 , 45 ));
20+ }
21+ } else {
22+ this .say ("Ouch!" , 2000 );
2423 }
24+ }
2525}
Original file line number Diff line number Diff line change 22import org .openpatch .scratch .Sprite ;
33
44public class TrampolineSprite extends Sprite {
5- public TrampolineSprite () {
6- this .addCostume ("trampoline" , "trampoline.png" );
7- this .setPosition (0 , -120 );
8- }
5+ public TrampolineSprite () {
6+ this .addCostume ("trampoline" , "trampoline.png" );
7+ this .setPosition (0 , -120 );
8+ }
99
10- public void whenKeyPressed (int keyCode ) {
11- if (keyCode == KeyCode .VK_LEFT ) {
12- this .changeX (-10 );
13- } else if (keyCode == KeyCode .VK_RIGHT ) {
14- this .changeX (10 );
15- }
10+ public void whenKeyPressed (int keyCode ) {
11+ if (keyCode == KeyCode .VK_LEFT ) {
12+ this .changeX (-10 );
13+ } else if (keyCode == KeyCode .VK_RIGHT ) {
14+ this .changeX (10 );
1615 }
16+ }
1717}
Original file line number Diff line number Diff line change 11import org .openpatch .scratch .Stage ;
22
33public class BouncyHedgehogStage extends Stage {
4-
5- public BouncyHedgehogStage () {
6- this .addBackdrop ("playground" , "playground.jpg" );
7- }
4+
5+ public BouncyHedgehogStage () {
6+ this .addBackdrop ("playground" , "playground.jpg" );
7+ }
88}
Original file line number Diff line number Diff line change 22
33public class HedgehogSprite extends Sprite {
44
5- public HedgehogSprite () {
6- this .addCostume ("hedgehog" , "hedgehog.png" );
7- }
8-
5+ public HedgehogSprite () {
6+ this .addCostume ("hedgehog" , "hedgehog.png" );
7+ }
98}
Original file line number Diff line number Diff line change 11import org .openpatch .scratch .Sprite ;
22
33public class TrampolineSprite extends Sprite {
4- public TrampolineSprite () {
5- this .addCostume ("trampoline" , "trampoline.png" );
6- }
4+ public TrampolineSprite () {
5+ this .addCostume ("trampoline" , "trampoline.png" );
6+ }
77}
Original file line number Diff line number Diff line change @@ -17,4 +17,4 @@ public void whenKeyPressed(int keyCode) {
1717 public void run () {
1818 this .move (2 );
1919 }
20- }
20+ }
Original file line number Diff line number Diff line change 1+ import java .awt .event .*;
12import org .openpatch .scratch .KeyCode ;
23import org .openpatch .scratch .Sprite ;
34import org .openpatch .scratch .Stage ;
45import org .openpatch .scratch .extensions .recorder .*;
5- import java .awt .event .*;
66
77public class SpriteWhenKeyPressed {
88
You can’t perform that action at this time.
0 commit comments