CodingTrain / asteroids-advanced

24 stars 7 forks source link

Decoupled UI from World and made the world bigger #12

Closed MunWolf closed 7 years ago

MunWolf commented 7 years ago

The title says most of it.

Other small changes include making the camera follow the player, sadly this breaks the edge by making things suddenly disappear there, I put a bandaid on it by rendering the actual end of the world but this will be fixed in a follow up PR.

Also added a lifetime on the laser, it not being able to cross edges was in my opinion bad but having them persist endlessly until they hit something would make the game way too easy.

JonathanHHenson commented 7 years ago

This should fix the wrapping problem:

Entity.prototype.edges = function() {
  if (this.pos.x > world.halfwidth) {
    this.pos.x = this.pos.x % world.halfwidth - world.halfwidth;
  } else if (this.pos.x < -world.halfwidth) {
    this.pos.x = this.pos.x % world.halfwidth + world.halfwidth;
  }
  if (this.pos.y > world.halfheight) {
    this.pos.y = this.pos.y % world.halfwidth - world.halfheight;
  } else if (this.pos.y < -world.halfheight) {
    this.pos.y = this.pos.y % world.halfwidth + world.halfheight;
  }
}
JonathanHHenson commented 7 years ago

Now you just have to get rid of the border thingy and make the objects render on both sides.

MunWolf commented 7 years ago

Yeah its the rendering on both sides which I need to do, and I mean to do that in a second PR, I feel this one is already big enough.