collisions with objects
This commit is contained in:
parent
ba26cbe9dd
commit
d6db37ca93
4
game/dist/project-constants.json
vendored
4
game/dist/project-constants.json
vendored
@ -18,8 +18,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"player": {
|
"player": {
|
||||||
"max_velocity": 30,
|
"max_velocity": 3,
|
||||||
"acceleration": 20,
|
"acceleration": 2,
|
||||||
"deceleration": 1,
|
"deceleration": 1,
|
||||||
"start_size": 0.8
|
"start_size": 0.8
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,15 @@ impl PlayableScene {
|
|||||||
Color::GREEN,
|
Color::GREEN,
|
||||||
);
|
);
|
||||||
draw.draw_text(
|
draw.draw_text(
|
||||||
format!("player: ({}, {}) size: {} map: ({}, {})", self.player.position.x,self.player.position.y,self.player.size,self.world_map.get_map_size().x,self.world_map.get_map_size().y).as_str(),
|
format!(
|
||||||
|
"player: ({}, {}) size: {} map: ({}, {})",
|
||||||
|
self.player.position.x,
|
||||||
|
self.player.position.y,
|
||||||
|
self.player.size,
|
||||||
|
self.world_map.get_map_size().x,
|
||||||
|
self.world_map.get_map_size().y
|
||||||
|
)
|
||||||
|
.as_str(),
|
||||||
10,
|
10,
|
||||||
50,
|
50,
|
||||||
20,
|
20,
|
||||||
@ -266,18 +274,21 @@ impl PlayableScene {
|
|||||||
&& player.position.y - player_size <= i.position.y + i.size.y / 2.0
|
&& player.position.y - player_size <= i.position.y + i.size.y / 2.0
|
||||||
&& player.position.y + player_size >= i.position.y + i.size.x / 2.0
|
&& player.position.y + player_size >= i.position.y + i.size.x / 2.0
|
||||||
{
|
{
|
||||||
if player.velocity.x < 0.0 {
|
// if player.velocity.x < 0.0 {
|
||||||
player.position.x = i.position.x + i.size.x / 2.0 + player_size;
|
// player.position.x = i.position.x + i.size.x / 2.0 + player_size;
|
||||||
} else if player.velocity.x > 0.0 {
|
// } else if player.velocity.x > 0.0 {
|
||||||
player.position.x = i.position.x - i.size.x / 2.0 - player_size;
|
// player.position.x = i.position.x - i.size.x / 2.0 - player_size;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
player.position.x -= velocity_modifier.x;
|
||||||
player.velocity.x = 0.0;
|
player.velocity.x = 0.0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if player.position.x - player_size < 0.0 || player.position.x + player_size > self.world_map.get_map_size().x {
|
if player.position.x - player_size < 0.0
|
||||||
|
|| player.position.x + player_size > self.world_map.get_map_size().x
|
||||||
|
{
|
||||||
if player.velocity.x < 0.0 {
|
if player.velocity.x < 0.0 {
|
||||||
player.position.x = player_size;
|
player.position.x = player_size;
|
||||||
} else if player.velocity.x > 0.0 {
|
} else if player.velocity.x > 0.0 {
|
||||||
@ -296,15 +307,19 @@ impl PlayableScene {
|
|||||||
{
|
{
|
||||||
if player.velocity.y < 0.0 {
|
if player.velocity.y < 0.0 {
|
||||||
player.position.y = i.position.y + i.size.y / 2.0 + player_size;
|
player.position.y = i.position.y + i.size.y / 2.0 + player_size;
|
||||||
} else if player.velocity.x > 0.0 {
|
} else if player.velocity.y > 0.0 {
|
||||||
player.position.y = i.position.y - i.size.y / 2.0 - player_size;
|
player.position.y = i.position.y - i.size.y / 2.0 - player_size;
|
||||||
}
|
}
|
||||||
|
player.position.y -= velocity_modifier.y;
|
||||||
|
player.velocity.y = 0.0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if player.position.y + player_size > 0.0 || player.position.y - player_size < -self.world_map.get_map_size().y {
|
if player.position.y + player_size > 0.0
|
||||||
|
|| player.position.y - player_size < -self.world_map.get_map_size().y
|
||||||
|
{
|
||||||
if player.velocity.y > 0.0 {
|
if player.velocity.y > 0.0 {
|
||||||
player.position.y = -player_size;
|
player.position.y = -player_size;
|
||||||
} else if player.velocity.y < 0.0 {
|
} else if player.velocity.y < 0.0 {
|
||||||
|
Reference in New Issue
Block a user