Moves this ball on one frame
(&mut self)
| 35 | /// Moves this ball on one frame |
| 36 | /// |
| 37 | pub fn update(&mut self) { |
| 38 | // Collide with the edges of the screen |
| 39 | if self.x+self.dx+self.radius > 1000.0 && self.dx > 0.0 { self.dx = -self.dx; } |
| 40 | if self.y+self.dy+self.radius > 1000.0 && self.dy > 0.0 { self.dy = -self.dy; } |
| 41 | if self.x+self.dx-self.radius < 0.0 && self.dx < 0.0 { self.dx = -self.dx; } |
| 42 | if self.y+self.dy-self.radius < 0.0 && self.dy < 0.0 { self.dy = -self.dy; } |
| 43 | |
| 44 | // Gravity |
| 45 | if self.y >= self.radius { |
| 46 | self.dy -= 0.2; |
| 47 | } |
| 48 | |
| 49 | // Move this ball in whatever direction it's going |
| 50 | self.x += self.dx; |
| 51 | self.y += self.dy; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /// |