Skip to content

Commit c612d9f

Browse files
committed
paddle collision
1 parent 8ef078a commit c612d9f

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/game.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ impl Game {
151151

152152
let buttons = io::controller_buttons();
153153

154-
if buttons & io::Left != 0 && self.paddle.x > 1 {
154+
if buttons & io::LEFT != 0 && self.paddle.x > 1 {
155155
self.paddle.x -= 2;
156-
} else if buttons & io::Right != 0 {
156+
} else if buttons & io::RIGHT != 0 && self.paddle.x + self.paddle.width * 8 < 0xe0 {
157157
self.paddle.x += 2;
158158
}
159159

@@ -189,7 +189,7 @@ impl Game {
189189
let hit_bottom = dist_bottom < r;
190190

191191
if hit_left || hit_right {
192-
self.ball.dx = -self.ball.dx;
192+
// self.ball.dx = -self.ball.dx;
193193
}
194194
if hit_top || hit_bottom {
195195
self.ball.dy = -self.ball.dy;
@@ -214,16 +214,20 @@ impl Game {
214214
self.ball.dx = -self.ball.dx;
215215
apu::play_sfx(apu::Sfx::Lock);
216216
}
217-
if self.ball.y == 0 || self.ball.y + BALL_DIAMETER >= HEIGHT {
217+
if self.ball.y == 0 {
218218
self.ball.dy = -self.ball.dy;
219219
apu::play_sfx(apu::Sfx::Lock);
220220
}
221+
// paddle collision
222+
if self.ball.y + BALL_DIAMETER >= self.paddle.y {
223+
if self.ball.x > self.paddle.x && self.ball.x + BALL_DIAMETER < self.paddle.x + (self.paddle.width * 8) {
224+
self.ball.dy = -self.ball.dy;
225+
apu::play_sfx(apu::Sfx::Lock);
226+
} else {
227+
self.ball.dx = 0;
228+
self.ball.dy = 0;
229+
apu::play_sfx(apu::Sfx::Topout);
230+
}
231+
}
221232
}
222233
}
223-
224-
225-
// // Paddle collision
226-
// if self.ball.y >= self.paddle.y && self.ball.y <= self.paddle.y + self.paddle.height &&
227-
// self.ball.x >= self.paddle.x && self.ball.x <= self.paddle.x + self.paddle.width {
228-
// self.ball.dy = -self.ball.dy;
229-
// }

src/io.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ pub fn _set_chr_bank(bank: u8) {
1111
unsafe { *(0x8000 as *mut u8) = bank; }
1212
}
1313

14-
pub const Right: u8 = 0x01;
15-
pub const Left: u8 = 0x02;
16-
pub const Down: u8 = 0x04;
17-
pub const Up: u8 = 0x08;
18-
pub const Start: u8 = 0x10;
19-
pub const Select: u8 = 0x20;
14+
pub const RIGHT: u8 = 0x01;
15+
pub const LEFT: u8 = 0x02;
16+
pub const DOWN: u8 = 0x04;
17+
pub const UP: u8 = 0x08;
18+
pub const START: u8 = 0x10;
19+
pub const SELECT: u8 = 0x20;
2020
pub const B: u8 = 0x40;
2121
pub const A: u8 = 0x80;
2222

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![no_std]
22
#![feature(start)]
3-
#![allow(unused_imports)]
3+
#![allow(unused_imports, dead_code)]
44

55
mod apu;
66
mod io;

0 commit comments

Comments
 (0)