Skip to content

Commit 4ed0aa2

Browse files
author
Mike Barkmin
committed
Add sensing example
1 parent d362205 commit 4ed0aa2

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

examples/Sensing/Sensing.pde

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
}

examples/Sensing/sprites/hero.png

55.6 KB
Loading

examples/Sensing/sprites/hero2.png

94.9 KB
Loading

0 commit comments

Comments
 (0)