/* * public void Move(double dt) * { * x += (float)(vx * dt); * y += (float)(vy * dt); * alpha += (float)(omega * dt); * if (vx < 0) { * if (x < radius) { * x = radius * 2 - x; * vx = -vx; * } * } else if (x >= U.WX - radius) { * x = (U.WX - radius) * 2 - x; * vx = -vx; * } * if (vy < 0) { * if (y < radius) { * y = radius * 2 - y; * vy = -vy; * } * } else if (y >= U.WY - radius) { * y = (U.WY - radius) * 2 - y; * vy = -vy; * } * } */ public void MakeMove(double starttime, double endtime, List <Rib> ribs) { Rib r = new Rib(this, endtime, starttime); r.Clip(ribs); ribs.Add(r); }
public void Clip(List <Rib> ribs) { var radius = sprite.Radius; bool hit = false; double poshit = 0.0; if (speed.X < 0) { if (pos1.X < radius) { hit = true; poshit = radius; } } else if (pos1.X > U.WX - radius) { hit = true; poshit = U.WX - radius; } if (hit) { // clipped by X double thit = (poshit - pos0.X) / speed.X; Rib next = Split(thit); next.setSpeed(new Vec(-speed.X, speed.Y)); next.Clip(ribs); ribs.Add(next); hit = false; } if (speed.Y < 0) { if (pos1.Y < radius) { hit = true; poshit = radius; } } else if (pos1.Y > U.WY - radius) { hit = true; poshit = U.WY - radius; } if (hit) { double thit = (poshit - pos0.Y) / speed.Y; Rib next = Split(thit); next.setSpeed(new Vec(speed.X, -speed.Y)); next.Clip(ribs); ribs.Add(next); hit = false; } }