Skip to content

Commit af615b7

Browse files
committed
Introduce basic intro menu logic
1 parent 68333c5 commit af615b7

File tree

5 files changed

+247
-73
lines changed

5 files changed

+247
-73
lines changed

Cargo.lock

Lines changed: 162 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/input.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,41 @@ pub struct Input {
66
pub p1_down_pressed: bool,
77
pub p2_up_pressed: bool,
88
pub p2_down_pressed: bool,
9+
pub enter_pressed: bool,
910
}
1011

1112
impl Input {
1213
pub fn new() -> Self {
1314
Default::default()
1415
}
1516

16-
pub fn update(&mut self, input: KeyboardInput) -> bool {
17+
pub fn update(&mut self, input: KeyboardInput) {
1718
let pressed = input.state == KeyboardKeyState::Pressed;
1819
match input.key {
1920
KeyboardKey::Up => {
2021
self.p2_up_pressed = pressed;
21-
true
2222
}
2323
KeyboardKey::Down => {
2424
self.p2_down_pressed = pressed;
25-
true
2625
}
2726
KeyboardKey::W => {
2827
self.p1_up_pressed = pressed;
29-
true
3028
}
3129
KeyboardKey::S => {
3230
self.p1_down_pressed = pressed;
33-
true
3431
}
35-
_ => false,
32+
KeyboardKey::Return => {
33+
self.enter_pressed = pressed;
34+
}
35+
_ => (),
3636
}
3737
}
38+
39+
pub fn ui_up_pressed(&self) -> bool {
40+
self.p1_up_pressed || self.p2_up_pressed
41+
}
42+
43+
pub fn ui_down_pressed(&self) -> bool {
44+
self.p1_down_pressed || self.p2_down_pressed
45+
}
3846
}

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ mod ball;
44
mod input;
55
mod player;
66
mod pong_game;
7+
mod state;
8+
mod system;
9+
mod text;
10+
mod util;
711
use pong_game::PongGame;
812

913
fn main() {

src/player.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ use dynamo_lib::geometry::quad::Quad;
33

44
pub struct Player {
55
pub quad: Quad,
6+
pub score: u32,
7+
pub visible: bool,
68
}
79

810
impl Player {
911
pub fn new(position: cgmath::Vector2<f32>, size: cgmath::Vector2<f32>) -> Player {
1012
Player {
1113
quad: Quad::new(position, size),
14+
score: 0,
15+
visible: false,
1216
}
1317
}
1418

@@ -20,6 +24,11 @@ impl Player {
2024
self.quad.size
2125
}
2226

27+
pub fn update_y_position(&mut self, position: f32) {
28+
let position = (self.position().x, position);
29+
self.update_position(position.into());
30+
}
31+
2332
pub fn update_position(&mut self, position: cgmath::Vector2<f32>) {
2433
self.quad = Quad::new(position, self.quad.size);
2534
}

0 commit comments

Comments
 (0)