Skip to content

Commit 3242fb3

Browse files
committed
add simple example wip
1 parent 266bddc commit 3242fb3

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package studio.programkode.jgdk.examples;
2+
3+
import studio.programkode.jgdk.API;
4+
import studio.programkode.jgdk.Launcher;
5+
import studio.programkode.jgdk.Plugin;
6+
7+
import java.awt.event.KeyEvent;
8+
9+
10+
public class MovingRectangle extends Plugin
11+
{
12+
static void main() {
13+
Launcher.createWindow(640, 480, new MovingRectangle());
14+
}
15+
16+
private boolean moveRight = false;
17+
private int x = 0;
18+
19+
public void setup(API.Setup canvas) {
20+
canvas.onKeyPressed(event -> {
21+
if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
22+
this.moveRight = true;
23+
}
24+
});
25+
26+
canvas.onKeyReleased(event -> {
27+
if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
28+
this.moveRight = false;
29+
}
30+
});
31+
}
32+
33+
@Override
34+
public void update(API.Update canvas) {
35+
if (this.moveRight) {
36+
this.x += (int) (100*canvas.getDelta());
37+
}
38+
}
39+
40+
@Override
41+
public void draw(API canvas) {
42+
canvas.drawRectangle(this.x, 0, 50, 50);
43+
}
44+
}

0 commit comments

Comments
 (0)