Last active
November 28, 2016 15:48
-
-
Save raduGaspar/94b42a1d36448242d60b15898aa7709e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Scene, DisplayObject } from '../../engine'; | |
import Rock from './Rock'; | |
import RockModel from '../models/RockModel'; | |
export default class RockField extends DisplayObject { | |
constructor(model, amount=10) { | |
super(); | |
this.model = model; | |
this.amount = amount; | |
this.rocks = []; | |
} | |
generateRocks() { | |
const { amount, rocks } = this; | |
for (let i = 0; i < amount; i++) { | |
const rockModel = new RockModel(); | |
const rock = new Rock(rockModel); | |
rocks.push(rock); | |
} | |
this.add(rocks); | |
} | |
update() { | |
// render all children | |
super.update(); | |
const { rocks, model } = this; | |
if (!rocks.length) { | |
this.generateRocks(); | |
} | |
for (let i=0; i < rocks.length; i++) { | |
// move rocks based on model velocity | |
rocks[i].model.x -= model.vx; | |
rocks[i].model.y -= model.vy; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment