Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Andrea Sonny
    @andreasonny83
    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);
    Andrea Sonny
    @andreasonny83
    ok, you need firat to create the enemy object
    Billy B.
    @Azurasky1
      Enemy.prototype.draw = function () {
        _game.cv.drawImage(
          _game.enemy.avatar.src,
    Andrea Sonny
    @andreasonny83
    _game.enemy = {}; after _game = game;
    Billy B.
    @Azurasky1
    but i already define app.game.enemy within ready() in app.js
    Andrea Sonny
    @andreasonny83
    app.game.enemy = {}; ?
    Billy B.
    @Azurasky1
      function ready() {
        window.removeEventListener('load', ready, false);
    
        // Create an instance of the app
        app = new App();
    
        // Make sure the game Object is empty before starting a new game
        app.game = {
          fps: fps
        };
    
        app.game.player = {};
        app.game.enemy = {};
        app.game.bodies = [];
    
        // Initialize modules
        app.modules.Overlays.init(app.el.overlays, app.game);
    
        // Start the welcome screen once the app is loaded
        app.modules.Overlays.startWelcome();
      }
    
      window.addEventListener('load', re
    Andrea Sonny
    @andreasonny83
    hm