Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Billy B.
    @Azurasky1
    ok
    Andrea Sonny
    @andreasonny83
    you can create a javascript sandbox in where you can run simple tests
    Billy B.
    @Azurasky1
    i guess i might as well include bodies [] within game {}
    Andrea Sonny
    @andreasonny83
    just create a new sandbox.js file and then you can run from your terminal with: node sandbox.js
    Billy B.
    @Azurasky1
    awesome
    i'll do that
    Andrea Sonny
    @andreasonny83
    write this code inside:
    var myVar = [];
    var _var = myVar;
    
    _var.push({
      player: {
        name: 'Joe'
      }
    });
    
    
    console.log(myVar);
    myVar will print what you put inside _var
    so, if you want to push objects inside your array, just use push and pass the object inside the brackets
    Billy B.
    @Azurasky1
    what is this
      modules.Projectiles = (function() {
        return {
          projectiles: [],
          new: function(cv, x, y, width, height, direction, speed) {
            this.projectiles.push(
              new Projectile(cv, x, y, width, height, direction, speed));
          },
    
          getActive: function() {
            return this.projectiles.length;
          },
    
          draw: function() {
            for (var i = 0; i < this.projectiles.length; i++) {
              this.projectiles[i].draw();
            }
          }
        };
    Andrea Sonny
    @andreasonny83
    is the projectile service
    Billy B.
    @Azurasky1
    i have never seen an iife used in that way
    var batman = (function () {
        var identity = "Bruce Wayne";
    
        return {
            fightCrime: function () {
                console.log("Cleaning up Gotham.");
            },
    
            goCivilian: function () {
                console.log("Attend social events as " + identity);
            }
        };
    })();
    Billy B.
    @Azurasky1
    so what data are we trying to keep private?
    Andrea Sonny
    @andreasonny83
    we return eveything
    Billy B.
    @Azurasky1
    is the information before "return" the private information? or is it just everything within the iife?
    that's what i thought
    Andrea Sonny
    @andreasonny83
    that is optional
    but we have the projectiles array in where we store all the projectiles active in the game
    and the new method just push a new projectile object inside that array
    in this way we don’t have a draw method inside each projectile
    we just store an array of projectiles ready to be drawed inside the canvas
    Billy B.
    @Azurasky1
    if we want to hide the array so no one can write to it shouldn't we move it to the line above return
    Andrea Sonny
    @andreasonny83
    correct
    Billy B.
    @Azurasky1
    ok
    Andrea Sonny
    @andreasonny83
    and getActive will become return projectiles.length; instead of return this.projectiles.length;
    because this is the object we’re returning
    you make that change
    and see what happen
    Billy B.
    @Azurasky1
    looks like i will need to remove this from everything in there
      modules.Projectiles = (function() {
        var projectiles = [];
        return {
          new: function(cv, x, y, width, height, direction, speed) {
            projectiles.push(
              new Projectile(cv, x, y, width, height, direction, speed));
          },
    
          getActive: function() {
            return projectiles.length;
          },
    
          draw: function() {
            for (var i = 0; i < projectiles.length; i++) {
              projectiles[i].draw();
            }
          }
        };
      })();
    how does that look
    Andrea Sonny
    @andreasonny83
    yes
    give that a try and see if that still works
    Billy B.
    @Azurasky1
    ok i changed a lot of stuff so haven't run anything yet
    i will get to it
    Andrea Sonny
    @andreasonny83
    that’s bad practice
    you should always verify after changing something
    Billy B.
    @Azurasky1
    i will have a lot of debugging to do lol
    Andrea Sonny
    @andreasonny83
    :)
    Billy B.
    @Azurasky1
    can't seem to get an .avatar property to stick to my new _game.enemy
    keeps just coming back null even when i explicitly assign it to something
    i'm too tired to figure this out cuz i've been up all night so i'll try again later
    Andrea Sonny
    @andreasonny83
    how did you assign that?
    Billy B.
    @Azurasky1
    well
    i
    i'll show you
      Enemy.prototype.init = function(game, avatar, enemyInfo) {
        _game = game;
    
        _game.enemy.avatar = new Image();
        _game.enemy.avatar.src = avatar;
        console.log(_game.enemy.avatar.src);