Modified ReadMe and pressing space again resets also the velocity (might be restored in the futur )

This commit is contained in:
2022-05-17 13:35:16 +02:00
parent 33befbc561
commit 1b3337c993
2 changed files with 32 additions and 20 deletions
+22 -13
View File
@@ -44,27 +44,35 @@ impl Game{
}
}
pub fn up(&mut self){
self.main_ball.velocity.y -= BALL_SPEED as i32;
if self.main_ball.velocity.y < -MAX_SPEED as i32{
self.main_ball.velocity.y = -MAX_SPEED as i32;
}
if !self.ball_released{
self.main_ball.velocity.y -= BALL_SPEED as i32;
if self.main_ball.velocity.y < -MAX_SPEED as i32{
self.main_ball.velocity.y = -MAX_SPEED as i32;
}
}
}
pub fn down(&mut self){
self.main_ball.velocity.y += BALL_SPEED as i32;
if self.main_ball.velocity.y > MAX_SPEED as i32{
self.main_ball.velocity.y = MAX_SPEED as i32;
if !self.ball_released{
self.main_ball.velocity.y += BALL_SPEED as i32;
if self.main_ball.velocity.y > MAX_SPEED as i32{
self.main_ball.velocity.y = MAX_SPEED as i32;
}
}
}
pub fn left(&mut self){
self.main_ball.velocity.x -= BALL_SPEED as i32;
if self.main_ball.velocity.x < -MAX_SPEED as i32{
self.main_ball.velocity.x = -MAX_SPEED as i32;
if !self.ball_released{
self.main_ball.velocity.x -= BALL_SPEED as i32;
if self.main_ball.velocity.x < -MAX_SPEED as i32{
self.main_ball.velocity.x = -MAX_SPEED as i32;
}
}
}
pub fn right(&mut self){
self.main_ball.velocity.x += BALL_SPEED as i32;
if self.main_ball.velocity.y > MAX_SPEED as i32{
self.main_ball.velocity.y = MAX_SPEED as i32;
if !self.ball_released{
self.main_ball.velocity.x += BALL_SPEED as i32;
if self.main_ball.velocity.y > MAX_SPEED as i32{
self.main_ball.velocity.y = MAX_SPEED as i32;
}
}
}
pub fn toggle_debug(&mut self){
@@ -72,6 +80,7 @@ impl Game{
}
pub fn release(&mut self){
if self.ball_released{
self.main_ball.velocity = Point::new(0,0);
self.main_ball.shape.set_x(DEFAULT_START_BALL_LOCATION_X);
self.main_ball.shape.set_y(DEFAULT_START_BALL_LOCATION_Y);
}