File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ import eu.barkmin.processing.scratch.* ;
2
+
3
+ ScratchStage stage;
4
+ Hero h, m;
5
+
6
+ void setup () {
7
+ size (800 , 800 );
8
+ ScratchStage . init(this , true );
9
+ stage = ScratchStage . getInstance();
10
+ h = new Hero ();
11
+ m = new MovableHero ();
12
+ }
13
+
14
+ void draw () {
15
+ h. draw();
16
+ m. draw();
17
+ }
18
+
19
+ class MovableHero extends Hero {
20
+ void draw () {
21
+ super . draw();
22
+ if (isKeyPressed(65 )) {
23
+ this . turnLeft(1 );
24
+ }
25
+ if (isKeyPressed(68 )) {
26
+ this . turnRight(1 );
27
+ }
28
+ if (isKeyPressed(87 )) {
29
+ this . move(1 );
30
+ }
31
+ if (isKeyPressed(83 )) {
32
+ this . move(- 1 );
33
+ }
34
+ if (isTouchingSprite(h)) {
35
+ println (" Ui a hero" );
36
+ } else {
37
+ println (" No hero :(" );
38
+ }
39
+ }
40
+ }
41
+
42
+ class Hero extends ScratchSprite {
43
+ Hero () {
44
+ super (" hero" , " sprites/hero.png" );
45
+ this . addCostume(" hero2" , " sprites/hero2.png" );
46
+ this . setSize(50 );
47
+ this . setRotation(45 );
48
+ this . move(280 );
49
+ }
50
+
51
+ void draw () {
52
+ super . draw();
53
+ if (isTouchingMousePointer()) {
54
+ this . switchCostume(" hero2" );
55
+ } else {
56
+ this . switchCostume(" hero" );
57
+ }
58
+ }
59
+ }
You can’t perform that action at this time.
0 commit comments