Note that there is a trap:
In Physics, actions A,V,P are done simultaneously, not one after the other. So, P is updated with old V, for instance
5
Expression 6: "F" left parenthesis, "p" , "v" , right parenthesis equals "G"Fp,v=G
6
Expression 7: "C" left parenthesis, "p" , "v" , right parenthesis equals left parenthesis, left brace, abs left parenthesis, "p" . "x" plus "v" . "x" times "d" Subscript, "t" , Baseline , right parenthesis greater than 8 : negative "v" . "x" , "v" . "x" , right brace , left brace, abs left parenthesis, "p" . "y" plus "v" . "y" times "d" Subscript, "t" , Baseline , right parenthesis greater than 6 : negative "v" . "y" , "v" . "y" , right brace , right parenthesisCp,v=absp.x+v.x·dt>8:−v.x,v.x,absp.y+v.y·dt>6:−v.y,v.y
7
Note that it is a naïve scheme: it looses energy, and collision may fail.