These are chat archives for Azurasky1/DragonArena

31st
Jul 2016
Billy B.
@Azurasky1
Jul 31 2016 08:10
ok i got a function to filter through the bodies and filter out the ones that are colliding
Andrea Sonny
@andreasonny83
Jul 31 2016 09:53
Great
What about the ones that go outside of the canvas?
Billy B.
@Azurasky1
Jul 31 2016 09:54
i can include that as well
got a question for you
Andrea Sonny
@andreasonny83
Jul 31 2016 09:55
Sure
Billy B.
@Azurasky1
Jul 31 2016 09:55
what motivates your choice to initialize the player and its with an init() function, rather than a constructor?
what motivates your choice to initialize the player and its properties with an init() function, rather than a constructor?
saves memory?
Andrea Sonny
@andreasonny83
Jul 31 2016 09:57
Because the constructor, in this case, creates an object inside the global module, it doesn't really create an instance of Player.
You can use var player1 = new Player() when you need to reuse that function constructor more than one time, but in this case Player is just an object literal
We will use that logic for creating the other players in the view because they will be more than one
Billy B.
@Azurasky1
Jul 31 2016 10:00
smart
im thinking the alternative is good if for some reason we wanted all players to inherit a prototype from something else
Andrea Sonny
@andreasonny83
Jul 31 2016 10:00
But we still need to depend from a big object in where storing all the game variables if we want the game to works in multi player mode
Yes, when you define a prototype to reuse accross different players, you save memory because they are all referring to the same funcion instead of creating a clone for each player
Billy B.
@Azurasky1
Jul 31 2016 10:07
we will probably have to approach it that way when we have more than one player
for example in the draw prototype for player, we approach approach it like this, adjusting the object player attached to the container _game
```
  _game.cv.drawImage(
      _game.player.avatar,
      _game.player.frame.width * _game.player.frame.current,
      _game.player.frame.direction * _game.player.frame.height,
      _game.player.frame.width, _game.player.frame.height,
       // centered on canvass
      _game.player.pos.x, _game.player.pos.y,
      // image size to draw
      _game.player.frame.width * _game.scaleFactor,
      _game.player.frame.height * _game.scaleFactor
    );
instead probably best to switch _game.player to this right
maybe there's something im missing
Andrea Sonny
@andreasonny83
Jul 31 2016 10:13
what’s wrong with that?
Billy B.
@Azurasky1
Jul 31 2016 10:14
well we're gonna have several players right
well
there technically is only one player per client
idk
Andrea Sonny
@andreasonny83
Jul 31 2016 10:14
as soon as we have more player we can simply wrap that drawImage logic inside a for loop to go through all the players
Billy B.
@Azurasky1
Jul 31 2016 10:14
ok
Andrea Sonny
@andreasonny83
Jul 31 2016 10:15
but we need to keep in mind that the game object will be stored inside the server side
so, all the information regarding the game need to be available inside that big object
in this way the server will collect all the informations from all the players all the time, recalculate the different positions, players health, projectiles, etc, and spread the game object back to all the players connected
so we’re going soon to move all the logic inside the server side and keep just the rendering logic inside the client
Billy B.
@Azurasky1
Jul 31 2016 10:36
can u show me where the object .player is added to the _game {} object
i'm having a rly hard time understanding this
if each variable name is unique, then how can we run something like the code above in a loop
say we have several players, they aren't all going to be named "player"
i don't understand how that code works
when u initialize player, ur adjusting the player object within the _game container, but i can't find where u are placing it inside the game container in the first place
it's really hard to write code for this when i don't understand the core concept
Andrea Sonny
@andreasonny83
Jul 31 2016 10:40
sure, give me a sec
Billy B.
@Azurasky1
Jul 31 2016 10:41
ok, so you initialize the player with init() and pass in app.game, which is at the time an empty object... then, you set _game = game, and proceed to adjust the properties, _game.player.health
but up until that point player doesn't exist
so how can u adjust health
the code works in browser so it must work somehow but i don't have a grasp on it at all
it is so frustrating :(
Andrea Sonny
@andreasonny83
Jul 31 2016 10:42
have a look at Overlays.prototype.init
_game.player = {};
Billy B.
@Azurasky1
Jul 31 2016 10:43
ok we have to move that
that doesn't even make any sense
Andrea Sonny
@andreasonny83
Jul 31 2016 10:43
yes
you’re right
that should be inside ap.js
Billy B.
@Azurasky1
Jul 31 2016 10:43
modules confuse me, i hope i get used to them soon
Andrea Sonny
@andreasonny83
Jul 31 2016 10:43
that goes inside function ready() {
after
app.game = {
fps: fps
};
you can put _game.player = {};
so once overlays.init is called, the player object already exists
something like this:
  function ready() {
    // clean the memory space removing the event listener
    // not required any more
    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 = {};

    // Initialize modules
    app.modules.Overlays.init(app.el.overlays, app.game);

    // Start the welcome screen once the app is loaded
    app.modules.Overlays.startWelcome();
  }
Billy B.
@Azurasky1
Jul 31 2016 10:45
i put in this app.player = {};
wait
Andrea Sonny
@andreasonny83
Jul 31 2016 10:45
should be app.game.player
Billy B.
@Azurasky1
Jul 31 2016 10:45
ya
Andrea Sonny
@andreasonny83
Jul 31 2016 10:46
and then we’ll have something like app.game.players = []; for all the other players in the game
it will be an array of objects
you can already add that after app.game.player = {}; if you want
Billy B.
@Azurasky1
Jul 31 2016 10:47
still i don't see how it is beneficial not to create everything as player objects
Andrea Sonny
@andreasonny83
Jul 31 2016 10:47
what do you mean?
Billy B.
@Azurasky1
Jul 31 2016 10:47
ur adding objects to the global object and giving them properties
Andrea Sonny
@andreasonny83
Jul 31 2016 10:47
yes
Billy B.
@Azurasky1
Jul 31 2016 10:47
instead of creating objects using a constructor
u can't use the prototypes
and the methods like the draw image one i posted above don't make sense
Andrea Sonny
@andreasonny83
Jul 31 2016 10:48
why not?
Billy B.
@Azurasky1
Jul 31 2016 10:49
because if u wanna call .drawImage on an object, say player, and you have more than one player
u can't call player.drawImage for both
Andrea Sonny
@andreasonny83
Jul 31 2016 10:49
what do you mean for: "instead of creating objects using a constructor”?
Billy B.
@Azurasky1
Jul 31 2016 10:49
the way i am used to creating objects is like this
u have a constructor function Player (name) { this.name = name};
that way, if i want to draw every single player, all i have to do is use the prototype
Player.prototype.drawImage = function () { this.drawImage(....) }
Andrea Sonny
@andreasonny83
Jul 31 2016 10:50
right
Billy B.
@Azurasky1
Jul 31 2016 10:50
the way u wrote
u are creating an object arbitrarily and then changing its values
it's not a child of the Player object type
it's just some random object
it can't use the methods
so when u want to draw several players, the code becomes very wonky and inefficient
Andrea Sonny
@andreasonny83
Jul 31 2016 10:51
which method?
Billy B.
@Azurasky1
Jul 31 2016 10:51
the methods attached to the Player prototype
Andrea Sonny
@andreasonny83
Jul 31 2016 10:51
you mean the Player.prototype.draw ?
Billy B.
@Azurasky1
Jul 31 2016 10:51
the code that you wrote here doesn't make sense: _game.cv.drawImage( _game.player.avatar, _game.player.frame.width * _game.player.frame.current, _game.player.frame.direction * _game.player.frame.height, _game.player.frame.width, _game.player.frame.height, // centered on canvass _game.player.pos.x, _game.player.pos.y, // image size to draw _game.player.frame.width * _game.scaleFactor, _game.player.frame.height * _game.scaleFactor );
 _game.cv.drawImage(
      _game.player.avatar,
      _game.player.frame.width * _game.player.frame.current,
      _game.player.frame.direction * _game.player.frame.height,
      _game.player.frame.width, _game.player.frame.height,
       // centered on canvass
      _game.player.pos.x, _game.player.pos.y,
      // image size to draw
      _game.player.frame.width * _game.scaleFactor,
      _game.player.frame.height * _game.scaleFactor
    );
we are going to have many players
that works when you have a single player object
Andrea Sonny
@andreasonny83
Jul 31 2016 10:52
right, that probably needs to be refactored
Billy B.
@Azurasky1
Jul 31 2016 10:52
creating all of these init() functions seems to be more trouble than it is worth
if anything, don't assign properties inside of init(), put them inside of the constructor, and then create an instance of Player() inside of init()
make sense?
Andrea Sonny
@andreasonny83
Jul 31 2016 10:53
it is confusing because at the moment we have everything inside the client side
Billy B.
@Azurasky1
Jul 31 2016 10:53
it is very confusing lol
i am spending a lot of time just trying to conform to this new format
Andrea Sonny
@andreasonny83
Jul 31 2016 10:53
but in the future, we’ll have the game object inside the server and all the “draw” logic inside the client
you’re right
this logic works fine for 1 player and without a server implementation
Billy B.
@Azurasky1
Jul 31 2016 10:54
that's generally not what i have in mind
Andrea Sonny
@andreasonny83
Jul 31 2016 10:54
we need new functions to handle the drawable part of the game, but still don’t know how
Billy B.
@Azurasky1
Jul 31 2016 10:55
writing code for one player when we will eventually have to change it to accomodate several is a waste of time
what exactly are we including inside of the game object
Andrea Sonny
@andreasonny83
Jul 31 2016 10:56
we need to store the varialbes only
Billy B.
@Azurasky1
Jul 31 2016 10:56
players, dragons, projectiles?
that's basically everything
Andrea Sonny
@andreasonny83
Jul 31 2016 10:56
like players names, health, positions, projectiles coordinates, etc
but all the functions need to be outside the object
what I did is partially wrong
as I told at the very beginnin, is difficult to start a project in the correct direction. that will need to be rewriten from scratch as we progress and discover new issues
Billy B.
@Azurasky1
Jul 31 2016 10:59
ya
Andrea Sonny
@andreasonny83
Jul 31 2016 10:59
we never defined a real architectural strategy for that so is really diffucult to consider everything when you start
we need the server working before proceeding with the client I guess
Billy B.
@Azurasky1
Jul 31 2016 10:59
the experience will be valuable
Andrea Sonny
@andreasonny83
Jul 31 2016 11:00
the server needs to store the game object and send that back to the client every frame to be rendered
Billy B.
@Azurasky1
Jul 31 2016 11:00
a lot of the concepts that i am working with now with this new modular format are giant leaps ahead of what i am used to
Andrea Sonny
@andreasonny83
Jul 31 2016 11:01
I learned a lot about the requestAnimationFrame as I never created an html game before
so yes, is not a wasting of time for sure
Billy B.
@Azurasky1
Jul 31 2016 11:01
i just like to understand why things are done the way they are
before this i had never used something like init()
Andrea Sonny
@andreasonny83
Jul 31 2016 11:02
I think the client will be really slim if we move part of the logic in the server side
and a lot more understandable and easy to read
Billy B.
@Azurasky1
Jul 31 2016 11:03
which part?
which part should we move?
Andrea Sonny
@andreasonny83
Jul 31 2016 11:03
so, if move the game object inside the server side now, would you be able to write the code for the client in a better way?
Billy B.
@Azurasky1
Jul 31 2016 11:03
we need collision detection and movement in the client right
no keep it as is
the last thing i need is something else to confuse me lol
Andrea Sonny
@andreasonny83
Jul 31 2016 11:04
well, in theory, the server should detect the collision nad the client render that
all the logic should go inside the server, the client should only render the game
no logic
this is foundamental in every web application
Billy B.
@Azurasky1
Jul 31 2016 11:05
so the server holds the game object and all of the logic
Andrea Sonny
@andreasonny83
Jul 31 2016 11:05
because of a security reason, you don’t want hackers to change the information in the client side and update the server database with them, right?
Billy B.
@Azurasky1
Jul 31 2016 11:06
and then we just send the clients whatever they may need at the time nearby players projectiles etc
events
right i see your point
Andrea Sonny
@andreasonny83
Jul 31 2016 11:07
the client will only send information about its player but, again, not the real coordinates. The server just needs to know if the player is still or moving and in which direction, or, if the player pressed the space key for triggering a projectile
then, the server can process all the information toghether and send back the players with all the coordinates updated to be rendered
so, in the client, we just need to render whatever the server sends back
but yu can see its complex to build something like that just in the 2 of us working a couple of hours per week and without working side by side
it takes time
Billy B.
@Azurasky1
Jul 31 2016 11:10
yea
at some point i would like to give skype a try
& during that time we could work simultaneously
Andrea Sonny
@andreasonny83
Jul 31 2016 11:11
not sure what to do now
we really need to move that logic inside the server side
also, we need a game id
because the server will have an array of games created by the different players
so app.game.player is not going to work any more
Billy B.
@Azurasky1
Jul 31 2016 11:12
before anything i want to get these last few changes committed
Andrea Sonny
@andreasonny83
Jul 31 2016 11:12
that will be app[game_id].players[my_player_name]
all the players will be stored inside the same players array
Billy B.
@Azurasky1
Jul 31 2016 11:33
i want to push newly created player and enemy objects into the bodies array
Andrea Sonny
@andreasonny83
Jul 31 2016 11:33
ook
Billy B.
@Azurasky1
Jul 31 2016 11:33
the way we have it now, the initialize function found within the player & enemy modules takes a parameter, the app.game object. a new variable _game is then set equal to the app.game object
now, the the new player object is attached to that local object container
i want all objects to be in the original app.game though, not this newly created container
how do i go about doing this and getting them in a bodies array
basically i can't access variables from inside app.js when i'm using the init() function inside of this module
Andrea Sonny
@andreasonny83
Jul 31 2016 11:35
are you creating a new module?
Billy B.
@Azurasky1
Jul 31 2016 11:35
no this is player.js
Player.prototype.init = function(game, avatar, playerInfo) {
    var colVariation = Math.floor(Math.random() * 9);
    var keys = Object.keys(modules.Utils.colors());

    _game = game;

    _game.player.health = 100;
    _game.player.avatar = new Image();
    _game.player.avatar.src = avatar;
    _game.player.ticks = 2;
    _game.player.tick = this.ticks;

    // Pick a random color to assign to the player
    _game.player.color = modules.Utils.colors()[
        keys[keys.length * Math.random() << 0]
      ][
        colVariation
      ];

    // place the player in a random place
    _game.player.pos = {
      x: Math.floor((Math.random() * 600) + 100) * _game.scaleFactor,
      y: Math.floor((Math.random() * 400) + 100) * _game.scaleFactor
    };

    _game.player.animation = {
      x: 0,
      y: 0
    };

    _game.player.frame = {
      current: 0,
      direction: Math.floor((Math.random() * 3)),
      total: playerInfo.frames,
      width: (playerInfo.width / playerInfo.frames),
      height: (playerInfo.height / playerInfo.frames)
    };

    _game.player.avatar.onload = function() {
      _log('Player ready');
      document.dispatchEvent(event);
    };
  };
you see how a local variable _game is assigned to the app.game object
Andrea Sonny
@andreasonny83
Jul 31 2016 11:36
so you can use _game
Billy B.
@Azurasky1
Jul 31 2016 11:36
no i can't
Andrea Sonny
@andreasonny83
Jul 31 2016 11:36
why
Billy B.
@Azurasky1
Jul 31 2016 11:37
because it's a local variable and i need to be able to access it elsewhere
Andrea Sonny
@andreasonny83
Jul 31 2016 11:37
it is pointing to the global one. that is copied by reference not by value
when you edit _game you edit app.game
is just because _game is shorter than app.game so I created a shorter nickname for that
Billy B.
@Azurasky1
Jul 31 2016 11:38
that is good to know
thank you
Andrea Sonny
@andreasonny83
Jul 31 2016 11:39
var obj = {};
var obj2 = obj;
obj2.player = ‘myPlayer’;

console.log(obj); // {player: ‘myPlayer’}
objects are always copied by reference in javascript
you can try by yourself
try to really clone an object in javascript. is really tricky
Billy B.
@Azurasky1
Jul 31 2016 11:41
i think that is one of the topics that was covered in the udemy course
by reference v.s. by value
Andrea Sonny
@andreasonny83
Jul 31 2016 11:41
yes
Billy B.
@Azurasky1
Jul 31 2016 11:41
goes to show how much i remembered... lol
i was thinking of going through it again and taking notes
Andrea Sonny
@andreasonny83
Jul 31 2016 11:41
but if you really want to create a copy of that object, is really not easy in javascript
this is what you need to write if you really want to clone an object to store in a different variable:
function cloneObject(obj) {
    var clone = {};
    for(var i in obj) {
        if(typeof(obj[i])=="object" && obj[i] != null)
            clone[i] = cloneObject(obj[i]);
        else
            clone[i] = obj[i];
    }
    return clone;
}
Billy B.
@Azurasky1
Jul 31 2016 11:43
jeez lol
Andrea Sonny
@andreasonny83
Jul 31 2016 11:43
not really 1 line of code
Billy B.
@Azurasky1
Jul 31 2016 11:44
so all i have to do to edit an object from another file is pass it in as a parameter to a function and create a local variable
Andrea Sonny
@andreasonny83
Jul 31 2016 11:44
yes
that is just passing over the address in where the object is stored
but, if you pass a variable instead of an object, then you will create a new variable
Billy B.
@Azurasky1
Jul 31 2016 11:46
does this count as an object
var bodies = [];
Andrea Sonny
@andreasonny83
Jul 31 2016 11:46
var a = 10;
var b = a;
b = 20;

console.log(a); // 10
yes, arrays are special kind of objects
Billy B.
@Azurasky1
Jul 31 2016 11:47
so it's by reference too?
Andrea Sonny
@andreasonny83
Jul 31 2016 11:47
yes
Billy B.
@Azurasky1
Jul 31 2016 11:48
ok
Andrea Sonny
@andreasonny83
Jul 31 2016 11:48
you can create a javascript sandbox in where you can run simple tests
Billy B.
@Azurasky1
Jul 31 2016 11:48
i guess i might as well include bodies [] within game {}
Andrea Sonny
@andreasonny83
Jul 31 2016 11:48
just create a new sandbox.js file and then you can run from your terminal with: node sandbox.js
Billy B.
@Azurasky1
Jul 31 2016 11:49
awesome
i'll do that
Andrea Sonny
@andreasonny83
Jul 31 2016 11:50
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
Jul 31 2016 12:13
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
Jul 31 2016 12:13
is the projectile service
Billy B.
@Azurasky1
Jul 31 2016 12:13
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
Jul 31 2016 12:17
so what data are we trying to keep private?
Andrea Sonny
@andreasonny83
Jul 31 2016 12:18
we return eveything
Billy B.
@Azurasky1
Jul 31 2016 12:18
is the information before "return" the private information? or is it just everything within the iife?
that's what i thought
Andrea Sonny
@andreasonny83
Jul 31 2016 12:18
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
Jul 31 2016 12:20
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
Jul 31 2016 12:20
correct
Billy B.
@Azurasky1
Jul 31 2016 12:21
ok
Andrea Sonny
@andreasonny83
Jul 31 2016 12:21
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
Jul 31 2016 12:23
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
Jul 31 2016 12:24
yes
give that a try and see if that still works
Billy B.
@Azurasky1
Jul 31 2016 12:27
ok i changed a lot of stuff so haven't run anything yet
i will get to it
Andrea Sonny
@andreasonny83
Jul 31 2016 12:27
that’s bad practice
you should always verify after changing something
Billy B.
@Azurasky1
Jul 31 2016 12:28
i will have a lot of debugging to do lol
Andrea Sonny
@andreasonny83
Jul 31 2016 12:28
:)
Billy B.
@Azurasky1
Jul 31 2016 13:07
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
Jul 31 2016 13:07
how did you assign that?
Billy B.
@Azurasky1
Jul 31 2016 13:08
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
Jul 31 2016 13:09
ok, you need firat to create the enemy object
Billy B.
@Azurasky1
Jul 31 2016 13:09
  Enemy.prototype.draw = function () {
    _game.cv.drawImage(
      _game.enemy.avatar.src,
Andrea Sonny
@andreasonny83
Jul 31 2016 13:09
_game.enemy = {}; after _game = game;
Billy B.
@Azurasky1
Jul 31 2016 13:10
but i already define app.game.enemy within ready() in app.js
Andrea Sonny
@andreasonny83
Jul 31 2016 13:10
app.game.enemy = {}; ?
Billy B.
@Azurasky1
Jul 31 2016 13:10
  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
Jul 31 2016 13:10
hm
what happen when you log game object inside Enemy.prototype.init?
Enemy.prototype.init = function(game, avatar, enemyInfo) {
    _game = game;

  console.log(_game);
can you see the enemy object in there?
Billy B.
@Azurasky1
Jul 31 2016 13:13
i just checked and yes
what is this error here 25enemy.js:29 Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap)'
Andrea Sonny
@andreasonny83
Jul 31 2016 13:14
something wrong inside your Enemy.prototype.draw function
Billy B.
@Azurasky1
Jul 31 2016 13:15
  Enemy.prototype.draw = function () {
    _game.cv.drawImage(
      _game.enemy.avatar,
      _game.enemy.frame.width * _game.enemy.frame.current,
      _game.enemy.frame.direction * _game.enemy.frame.height,
      _game.enemy.frame.width, _game.enemy.frame.height,
       // centered on canvass
      _game.enemy.pos.x, _game.enemy.pos.y,
      // image size to draw
      _game.enemy.frame.width * _game.scaleFactor,
      _game.enemy.frame.height * _game.scaleFactor
    );

    this.drawHealth();

  }
i explicitly assign .enemy.avatar to a new image, then i assign the src to a path
and when i try to draw it with that function, i get that error
Andrea Sonny
@andreasonny83
Jul 31 2016 13:17
show me where you assign _game.enemy.avatar
Billy B.
@Azurasky1
Jul 31 2016 13:18
Enemy.prototype.init = function(game, avatar, enemyInfo) {
    _game = game;
    console.log(_game);

    _game.enemy.avatar = new Image();
    _game.enemy.avatar.src = avatar;
    console.log(_game.enemy.avatar.src);

  _game.enemy.pos = {
      x: Math.floor((Math.random() * 600) + 100) * _game.scaleFactor,
      y: Math.floor((Math.random() * 400) + 100) * _game.scaleFactor
    };

    _game.enemy.animation = {
      x: 0,
      y: 0
    };

  _game.enemy.frame = {
      current: 0,
      direction: Math.floor((Math.random() * 3)),
      total: enemyInfo.frames,
      width: (enemyInfo.width / enemyInfo.frames),
      height: (enemyInfo.height / enemyInfo.frames)
    };

    _game.enemy.health = {
      total: 100,
      current: 100,
      percent: 100
    };

    _game.enemy.speed = .05;
    _game.enemy.avatar = null;
    _game.bodies.push(_game.enemy);

  }

  modules.Enemy = new Enemy();
  window.$modules = modules;
})(window.$modules || {});
Andrea Sonny
@andreasonny83
Jul 31 2016 13:19
and what is avatar ?
Billy B.
@Azurasky1
Jul 31 2016 13:19
the path
a string
Andrea Sonny
@andreasonny83
Jul 31 2016 13:19
is that correct?
Billy B.
@Azurasky1
Jul 31 2016 13:19
it's passed in when the function is called
same format as player
here is the app.js
    app.modules.Player.init(app.game,
      '/images/players/player_00' + player + '.png', {
        frames: 4,
        width: playersInfo[player - 1].width,
        height: playersInfo[player - 1].height
      });


  app.modules.Enemy.init(app.game,
    '/images/dragons/dragon.png', {
      frames: 10,
      width: (750 / 10),
      height: (560 / 8)

    });
Andrea Sonny
@andreasonny83
Jul 31 2016 13:21
so, does the dragon.png exists in that path?
Billy B.
@Azurasky1
Jul 31 2016 13:22
yes i checked
Andrea Sonny
@andreasonny83
Jul 31 2016 13:22
ok, so, inside your Enemy.prototype.draw = function () { function
console.log(_game.enemy);
what does it say?
can you see everything you need?
avatar, positions, frame, etc?
Billy B.
@Azurasky1
Jul 31 2016 13:24
it says that the avatar is null
all the other stuff is there
i can't really copy/paste because my console is being spammed by the uncaught typeerror
i don't rly get why the avatar is null because i clearly defined it within the init
Andrea Sonny
@andreasonny83
Jul 31 2016 13:26
weird
Billy B.
@Azurasky1
Jul 31 2016 13:30
i'm exhausted i'll figure it out later
ok
i made a pull request even though it isn't functional but everything is in the dragon branch
Andrea Sonny
@andreasonny83
Jul 31 2016 13:35
ok
Billy B.
@Azurasky1
Jul 31 2016 13:35
maybe you can take a look and figure out why it doesn't work
Andrea Sonny
@andreasonny83
Jul 31 2016 13:35
sure
Billy B.
@Azurasky1
Jul 31 2016 13:35
i'll catch u later it's nap time
take care :D