Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Game2D2Object {
- constructor(options) {
- this.sx = options.sx || 0
- this.sy = options.sy || 0
- this.vx = options.vx || 0
- this.vy = options.vy || 0
- this.ax = options.ax || 0
- this.ay = options.ay || 0
- this.as = options.as || 0
- this.av = options.av || 0
- this.aa = options.aa || 0
- this.radius = options.radius || 0
- this.mass = options.mass || 0
- }
- simulatePhysics(dt) {
- const dt2 = dt / 2
- const ax = this.ax
- const ay = this.ay
- const aa = this.aa
- this.sx += (this.vx + ax * dt2) * dt
- this.sy += (this.vy + ay * dt2) * dt
- this.vx += ax * dt
- this.vy += ay * dt
- this.as += (this.av + aa * dt2) * dt
- this.av += aa * dt
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement