wip - boundaries

This commit is contained in:
Thilo Behnke
2022-04-17 00:36:00 +02:00
parent 54d81ddaad
commit 1b7dbc768d

View File

@@ -106,10 +106,18 @@ impl Field {
let mut player_obj = &mut player.obj;
match input.input {
InputType::UP => {
player_obj.y += 5
let out_of_bounds = player_obj.y + 5 + (player_obj.shape & 255 / 2) > self.height;
if !out_of_bounds {
player_obj.y += 5
}
},
InputType::DOWN => {
player_obj.y -= 5
let out_of_bounds = player_obj.y - 5 - (player_obj.shape & 255 / 2) < 0;
if !out_of_bounds {
player_obj.y -= 5
} else {
log!("out of bounds: {:?}", player_obj)
}
},
};
}