Modified ReadMe and pressing space again resets also the velocity (might be restored in the futur )
This commit is contained in:
17
ReadMe.md
17
ReadMe.md
@@ -1,6 +1,7 @@
|
||||
# test_sdl
|
||||
# Rusty Golfy
|
||||
|
||||
It is just a playground for me to test SDL2 features
|
||||
A little game inspired by "Messing with sdl2" where I tested some mechanics.
|
||||
The point is to have a Golf Game where you can shoot a ball against walls to get to a hole
|
||||
|
||||
## Run it
|
||||
|
||||
@@ -18,14 +19,16 @@ cargo run --release
|
||||
|
||||
## Controls
|
||||
|
||||
W,A,S,D and Arrow Keys are for moving around the ball.
|
||||
W,A,S,D and Arrow Keys are for modifying the shot direction and force
|
||||
|
||||
Left Click teleports the ball to the cursors location.
|
||||
[DEBUG] Left Click teleports the ball to the cursors location.
|
||||
|
||||
Right Click cancels any velocity of the ball.
|
||||
[DEBUG] Right Click cancels any velocity of the ball.
|
||||
|
||||
Tab toggles a debug mode where you can see the actual vector applied to the ball wich is render as a cube to see its hitbox (maybe even more in the futur)
|
||||
|
||||
Spacebar doubles the acceleration (to use with moderation)
|
||||
Spacebar releases the ball and when preseed back, resets the position and velocity of the ball
|
||||
|
||||
Bonus: Maintain the left click and moving(s) key(s) at the same time and it will store some momentum wich you can use when you release the click. Enjoy :)
|
||||
## How to play
|
||||
|
||||
You can use your arrows keys or W,A,S,D to setup the launching angle and force and then press Space to release the ball and see it boucing around
|
||||
35
src/main.rs
35
src/main.rs
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user