mirror of
https://github.com/thilo-behnke/wasm-pong.git
synced 2026-07-12 19:19:16 +00:00
wip - acceleration needed for ball?
This commit is contained in:
@@ -123,7 +123,7 @@ impl Field {
|
||||
continue;
|
||||
}
|
||||
if *obj_mut.vel() == Vector::zero() {
|
||||
obj_mut.vel_mut().add(&Vector::new(-200., 0.))
|
||||
obj_mut.vel_mut().add(&Vector::new(-300., 0.))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,6 +128,26 @@ pub mod geom {
|
||||
let distance = self.x.powi(2) + self.y.powi(2);
|
||||
return (distance as f64).sqrt();
|
||||
}
|
||||
|
||||
pub fn multiply(&mut self, other: &Vector) {
|
||||
self.x = self.x * other.x;
|
||||
self.y = self.y * other.y;
|
||||
}
|
||||
|
||||
pub fn max(&mut self, other: &Vector) {
|
||||
self.x = self.x.max(other.x);
|
||||
self.y = self.y.max(other.y);
|
||||
}
|
||||
|
||||
pub fn min(&mut self, other: &Vector) {
|
||||
self.x = self.x.min(other.x);
|
||||
self.y = self.y.min(other.y);
|
||||
}
|
||||
|
||||
pub fn abs(&mut self) {
|
||||
self.x = self.x.abs();
|
||||
self.y = self.y.abs();
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Vector {
|
||||
|
||||
@@ -16,9 +16,20 @@ pub mod pong_collisions {
|
||||
ball.vel_mut().reflect(&player.orientation());
|
||||
// use vel of player obj
|
||||
if *player.vel() != Vector::zero() {
|
||||
let mut adjusted = player.vel().clone();
|
||||
adjusted.scalar_multiplication(0.3);
|
||||
ball.vel_mut().add(&adjusted);
|
||||
let mut collision_effect = player.vel().clone();
|
||||
collision_effect.scalar_multiplication(0.3);
|
||||
|
||||
let mut ball_vel = ball.vel().clone();
|
||||
ball_vel.add(&collision_effect);
|
||||
|
||||
let mut vel_ball_orientation = ball_vel.clone();
|
||||
vel_ball_orientation.normalize();
|
||||
|
||||
ball_vel.abs();
|
||||
ball_vel.min(&Vector::new(1000., 1000.));
|
||||
ball_vel.multiply(&vel_ball_orientation);
|
||||
|
||||
*ball.vel_mut() = ball_vel
|
||||
}
|
||||
// move out of collision
|
||||
let mut b_to_a = ball.pos().clone();
|
||||
|
||||
Reference in New Issue
Block a user