Skip to content

Commit

Permalink
Merge pull request #1 from Turbo87/loops
Browse files Browse the repository at this point in the history
Simplify loops
  • Loading branch information
t-sauer authored May 2, 2017
2 parents 54f2f6c + e63ad7c commit 9c8b8e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/ui/components/glimmeroids-app/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,20 @@ export default class Glimmeroids extends Component {
}

updateObjects(items: Entity[], group: 'asteroids' | 'ship' | 'particles' | 'bullets') {
let index = 0;
for (let item of items) {
for (let i = 0; i < items.length; i++) {
let item = items[i];
if (item.delete) {
this[group].splice(index, 1);
this[group].splice(i, 1);
} else {
items[index].render(this.state);
item.render(this.state);
}
index++;
}
}

checkCollisionsWith(items1: Entity[], items2: Entity[]) {
let a = items1.length - 1;
let b;
for (a; a > -1; --a) {
b = items2.length - 1;
for (b; b > -1; --b) {
let item1 = items1[a];
for (let a = 0; a < items1.length; a++) {
let item1 = items1[a];
for (let b = 0; b < items2.length; b++) {
let item2 = items2[b];
if (this.checkCollision(item1, item2)) {
item1.destroy();
Expand Down
1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"no-empty": false,
"only-arrow-functions": [false],
"no-shadowed-variable": false,
"prefer-for-of": false,
"prefer-const": false,
"object-literal-key-quotes": [true, "as-needed"],
"member-access": [true, "no-public"]
Expand Down

0 comments on commit 9c8b8e3

Please sign in to comment.