1use baba::prelude::*;
2
3fn main() -> baba::Result {
4 baba::run("Example", State::update)
5}
6
7struct State {
8 position: Vec2,
9 scale: Vec2,
10 angle: f32,
11 creature: TextureSlice,
12}
13
14impl Default for State {
15 fn default() -> Self {
16 Self {
17 position: vec2(800., 600.) / 2., scale: Vec2::splat(8.),
19 angle: 0.,
20 creature: Texture::load_with("examples/tiles.png", Origin::CENTER)
21 .slice(Rect::new(27, 9, 8, 8)),
22 }
23 }
24}
25
26impl State {
27 fn update(&mut self) {
28 gfx::clear(Color::from_rgb(0x2f, 0x28, 0x43));
29
30 if is_key_down(KeyCode::A) {
31 self.position.x -= 1.;
32 }
33 if is_key_down(KeyCode::D) {
34 self.position.x += 1.;
35 }
36 if is_key_down(KeyCode::W) {
37 self.position.y -= 1.;
38 }
39 if is_key_down(KeyCode::S) {
40 self.position.y += 1.;
41 }
42
43 if is_key_down(KeyCode::Q) {
44 self.angle = (self.angle - 0.04) % TAU;
45 }
46 if is_key_down(KeyCode::E) {
47 self.angle = (self.angle + 0.04) % TAU;
48 }
49
50 if is_key_down(KeyCode::J) {
51 self.scale /= 1.005;
52 }
53 if is_key_down(KeyCode::K) {
54 self.scale *= 1.005;
55 }
56
57 gfx::draw(&self.creature, (self.position, self.scale, self.angle));
58 }
59}