pittore 0.2.4

Simple toolkit for 2D visualization based on wgpu.
Documentation
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
#![allow(unused)]

//! This is a WIP breakout game example.

use pittore::prelude::*;

struct App {
    paddle: Paddle,
    bricks: Vec<Brick>,
    ball: Ball,
}

impl App {
    pub fn new() -> Self {
        let mut bricks = Vec::new();
        let size = vec2(60.0, 20.0);
        let offset = size + Vec2::splat(10.0);
        let column = 10;
        let row = 6;

        for j in 0..row {
            for i in 0..column {
                bricks.push(Brick {
                    pos: vec2(i as f32, j as f32) * offset,
                    size,
                    destroyed: false,
                });
            }
        }

        App {
            paddle: Paddle {
                pos: vec2(320.0, 40.0),
                size: vec2(40.0, 10.0),
            },
            bricks,
            ball: Ball {
                pos: vec2(320.0, 60.0),
                vel: vec2(2.0, 10.0),
                radius: 8.0,
            },
        }
    }
}

struct Paddle {
    pos: Vec2,
    size: Vec2,
}

struct Brick {
    pos: Vec2,
    size: Vec2,
    destroyed: bool,
}

struct Ball {
    pos: Vec2,
    vel: Vec2,
    radius: f32,
}

impl PittoreApp for App {
    fn update(&mut self, c: &mut Context) {
        let mut x = self.paddle.pos.x;
        if c.key_pressed(KeyCode::ArrowLeft) {
            x -= 20.0;
        }
        if c.key_pressed(KeyCode::ArrowRight) {
            x += 20.0;
        }
        self.paddle.pos.x = x.clamp(self.paddle.size.x, 640.0 - self.paddle.size.x);

        self.ball.pos += self.ball.vel;

        // let mut rects = vec![Object {
        //     position: self.paddle.pos,
        //     scale: self.paddle.size,
        //     ..Default::default()
        // }];

        // for brick in &self.bricks {
        //     if !brick.destroyed {
        //         rects.push(Object {
        //             position: brick.pos,
        //             scale: brick.size,
        //             ..Default::default()
        //         });
        //     }
        // }

        // c.draw_rects(rects);

        // let ball = &self.ball;
        // c.draw_circles(vec![Object {
        //     position: ball.pos,
        //     scale: Vec2::splat(ball.radius),
        //     ..Default::default()
        // }]);

        // let screen_size = c.render_state.surface_size;
        // if let Some(position) = c.cursor_position() {
        //     let position = vec2(
        //         position.x as f32,
        //         screen_size.height as f32 - position.y as f32,
        //     );
        //     c.draw_circles(vec![shapes::Object {
        //         position,
        //         scale: Vec2::splat(64.0),
        //         ..Default::default()
        //     }]);
        // }
    }
}

fn main() {
    pittore::run("pittore", App::new());
}