MCPcopy Create free account
hub / github.com/Logicalshift/flo_draw / update

Method update

draw/examples/bounce.rs:37–52  ·  view source on GitHub ↗

Moves this ball on one frame

(&mut self)

Source from the content-addressed store, hash-verified

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///

Callers 1

mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected