Advertisement
Guest User

Game Object 2d

a guest
Sep 6th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Game2D2Object {
  2.   constructor(options) {    
  3.     this.sx = options.sx || 0
  4.     this.sy = options.sy || 0
  5.     this.vx = options.vx || 0
  6.     this.vy = options.vy || 0
  7.     this.ax = options.ax || 0
  8.     this.ay = options.ay || 0
  9.  
  10.     this.as = options.as || 0
  11.     this.av = options.av || 0
  12.     this.aa = options.aa || 0
  13.  
  14.     this.radius = options.radius || 0
  15.     this.mass = options.mass || 0
  16.   }
  17.  
  18.   simulatePhysics(dt) {
  19.     const dt2 = dt / 2
  20.     const ax = this.ax
  21.     const ay = this.ay
  22.     const aa = this.aa
  23.    
  24.     this.sx += (this.vx + ax * dt2) * dt
  25.     this.sy += (this.vy + ay * dt2) * dt
  26.     this.vx += ax * dt
  27.     this.vy += ay * dt
  28.  
  29.     this.as += (this.av + aa * dt2) * dt
  30.     this.av += aa * dt
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement