1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#![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());
}