1extern crate jp;
2
3fn main() {
4 let mut pos_x = 75.0;
5 let mut pos_y = 75.0;
6 jp::create_window("Test", 150, 150)
7 .draw(move |mut g, c| {
8 g.rectangle(
9 c.state()
10 .fill([1.0, 1.0, 1.0, 1.0]),
11 c.width(),
12 c.height()
13 );
14 g.rectangle(
15 c.state()
16 .translate(pos_x, pos_y)
17 .fill([1.0, 0.0, 0.0, 1.0]),
18 50.0, 50.0);
19 let speed = c.dt * 40.0;
20 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Left)) {
21 pos_x -= speed;
22 }
23 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Right)) {
24 pos_x += speed;
25 }
26 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Up)) {
27 pos_y -= speed;
28 }
29 if c.is_pressed(jp::input::Button::Keyboard(jp::input::Key::Down)) {
30 pos_y += speed;
31 }
32 })
33 .run();
34}