These are chat archives for Azurasky1/DragonArena

13th
Jul 2016
Billy B.
@Azurasky1
Jul 13 2016 10:52
should have something for u today
i'm not used to seeing organized code so spending fair amount of time going back and forth between files
Andrea Sonny
@andreasonny83
Jul 13 2016 10:53
Great
:)
Billy B.
@Azurasky1
Jul 13 2016 11:04
quick q
the game object that is passed through a bunch of different functions
what are you looking to hold in it? the players, enemies & projectile objects?
Andrea Sonny
@andreasonny83
Jul 13 2016 11:05
well, that is the main object for the game containing all the information about the game
that will be used for communicate with the server side
it contains the avatar, the player information, the board information and all the variabless used by the game
Billy B.
@Azurasky1
Jul 13 2016 11:06
ok
can you tell me a little more about this too?
Andrea Sonny
@andreasonny83
Jul 13 2016 11:06
let me know if the code looks clear to you
sure, what you want to know?
Billy B.
@Azurasky1
Jul 13 2016 11:07
App.prototype.boardReady = function() {
    _log('Preparing the player...');

    var player = Math.floor((Math.random() * 8));
    var playersInfo = [{
      width: 128,
      height: 208
    }, {
      width: 128,
      height: 192
    }, {
      width: 128,
      height: 192
    }, {
      width: 128,
      height: 192
    }, {
      width: 192,
      height: 192
    }, {
      width: 128,
      height: 192
    }, {
      width: 128,
      height: 192
    }, {
      width: 128,
      height: 192
    }];
each time you ready the board, you're just readying a random player?
Andrea Sonny
@andreasonny83
Jul 13 2016 11:08
right, that is where I stored the sprite information for the different avatars
Billy B.
@Azurasky1
Jul 13 2016 11:09
ultimately the different images will have to be associated with their in-game class
Andrea Sonny
@andreasonny83
Jul 13 2016 11:09
because the images you sent me the links for, they have different sizes, I had to store those informations somewhere
Billy B.
@Azurasky1
Jul 13 2016 11:09
yeah
Andrea Sonny
@andreasonny83
Jul 13 2016 11:10
those are just the different images sizes for the differnt players inside the images/players folder
Billy B.
@Azurasky1
Jul 13 2016 11:10
i was mostly curious about this var player = Math.floor((Math.random() * 8));
Andrea Sonny
@andreasonny83
Jul 13 2016 11:11
that generates a random number between 1 and 8 to pick a random avatar for the player
Billy B.
@Azurasky1
Jul 13 2016 11:11
yeah i understand how it works
Andrea Sonny
@andreasonny83
Jul 13 2016 11:11
in the future, if you want, we can let the player chose the avatar
Billy B.
@Azurasky1
Jul 13 2016 11:11
right ok
Andrea Sonny
@andreasonny83
Jul 13 2016 11:12
so, the app.js file contains just the global logic for the game in order to stay slim and easy to read
then, everyhting else is inside its relative module
Billy B.
@Azurasky1
Jul 13 2016 11:13
i like modules
where did you learn to code like this
Andrea Sonny
@andreasonny83
Jul 13 2016 11:13
I kept the old javascript files for you renaming with an old so you can reused the code you wrote for the collision detection etc
hm, nowhere in particular
there are really a millions of different approach you can use in javascript, that is the good and bad part about JS
Billy B.
@Azurasky1
Jul 13 2016 11:14
i thought it possible that corporate culture had pushed their conventions on you :p
you work for sony right
Andrea Sonny
@andreasonny83
Jul 13 2016 11:15
not any more. I worked for them for 2 years as a full stack developer, now I’m more interested in the frontend so I’m working for a british telecommunication company working with Angular
if you want to understand better the Module pattern, here is a good article: https://toddmotto.com/mastering-the-module-pattern/
Billy B.
@Azurasky1
Jul 13 2016 11:16
that's funny i'm interested in backend more than frontend
Andrea Sonny
@andreasonny83
Jul 13 2016 11:16
Billy B.
@Azurasky1
Jul 13 2016 11:17
cool stuff, bookmarked
Andrea Sonny
@andreasonny83
Jul 13 2016 11:17
start with the todmotto one first
he always write great articles and I think he recently got a job at twitter
Billy B.
@Azurasky1
Jul 13 2016 11:18
good for him
sort of i think they are still in the red lol
Andrea Sonny
@andreasonny83
Jul 13 2016 11:19
yes, I know him in person as he’s living in London. he’s really great and inspiring
Billy B.
@Azurasky1
Jul 13 2016 11:20
i don't know any people like that so i take my inspiration from zuckerberg, wozniak, and all of the other entrepreneurs who have the courage to pursue their idea
the social network is one of my favorite movies :p
Andrea Sonny
@andreasonny83
Jul 13 2016 11:33
so, you should probably start looking inside keyboard.js and re-enable the logic for moving the player around the board
Billy B.
@Azurasky1
Jul 13 2016 11:33
yeah... my biggest problem right now is figuring out where to start...
Andrea Sonny
@andreasonny83
Jul 13 2016 11:33
inside Keyboard.prototype.keyDwn
start with moving the player
the direction already changes
you need to edit the _game.player object to set a different value for the position
_game.player.pos as x and y
just give that a try and you’ll soon figure out what to do
I need to include in the readme a map for the game object as it’s going to grow fast
and it’s better to keep track of all the properties insde that game object
Billy B.
@Azurasky1
Jul 13 2016 11:42
would you know why even after i pull from develop, my files are not being updated locally?
Andrea Sonny
@andreasonny83
Jul 13 2016 11:55
are you on develop now?
Billy B.
@Azurasky1
Jul 13 2016 11:56
i created a new branch, entitled newMovement
Andrea Sonny
@andreasonny83
Jul 13 2016 11:56
ok
can you push it?
Billy B.
@Azurasky1
Jul 13 2016 11:57
what should i type?
push to origin?
Andrea Sonny
@andreasonny83
Jul 13 2016 11:57
try just git push
Billy B.
@Azurasky1
Jul 13 2016 11:57
fatal: The current branch newMovement has no upstream branch.
Andrea Sonny
@andreasonny83
Jul 13 2016 11:58
so try git push origin
Billy B.
@Azurasky1
Jul 13 2016 11:58
got the same error there
Andrea Sonny
@andreasonny83
Jul 13 2016 11:59
ok then
git add .
git commit -am “test commit”
git push
Billy B.
@Azurasky1
Jul 13 2016 12:00
success
pull it now?
Andrea Sonny
@andreasonny83
Jul 13 2016 12:03
No, now your branch is pushed to git
What u want to do with it?
Billy B.
@Azurasky1
Jul 13 2016 12:04
i want the files in the repository to appear within my dragonarena directory on my machine
the modules folder on mine doesn't have the old js files
i want to see them side-by-side in atom
Andrea Sonny
@andreasonny83
Jul 13 2016 12:05
Ok, so try git merge develop
Billy B.
@Azurasky1
Jul 13 2016 12:06
it says that it's up to date
that makes no sense!
by this point i may just have to make another directory and clone everything
Billy B.
@Azurasky1
Jul 13 2016 12:36
if (!!_game.player.name) { this.startGame(); }
how come you included the double exclamation mark
Andrea Sonny
@andreasonny83
Jul 13 2016 12:58
Ah that's a trick
Billy B.
@Azurasky1
Jul 13 2016 12:59
stackoverflow says it's to ensure a boolean type but doesn't say what the point of that is
Andrea Sonny
@andreasonny83
Jul 13 2016 18:08
hey man, I’m back
! and !! return a boolan value back
so, if you have a string and you want to make sure that its value is set you can write this:
var myString = ‘val’;
if (typeof myString !== ‘undefined’ && myString !== ‘’) {
  console.log(‘myString is not defined’);
}
you can have the same result using a shortcut:
var myString = ‘val’;
if (!myString) {
  console.log(‘myString is not defined’);
}
but, if you want to do something only when myString is set to a value, then you need to negate that !myString again, so the result is !!myString
Andrea Sonny
@andreasonny83
Jul 13 2016 18:13
var myString = ‘val’;
if(!!myString) {
  console.log(‘myString is:’, myString);
}
because !!myString returns true instead of ‘val'
there is also a side effect using this syntax however
sometimes an empty string could be a possible value and using !! return false, so you need to be careful about that
also, if your variable is a number, sometimes 0 is a valid number and, again !!0 returns false. If you have a function that returns the sum of 2 numbers for example, 0 should be a alid value
Andrea Sonny
@andreasonny83
Jul 13 2016 18:19
// Bad practice
function sum(a, b) {
  if (!a || !b) {
    return;
  }

  return a + b;
}

var c = 10 + 0; // c = 0;
function sum(a, b) {
  if ((!a && a !== 0) || (!b && b !== 0)) {
    return;
  }

  return a + b;
}

var c = 10 + 0; // c = 10;
again:
function sum(a, b) {
  if (typeof a !== ‘undefined' || type of b !== ‘undefined) {
    return;
  }

  return a + b;
}

var c = 10 + 0; // c = 10;
so, the first example is a bad practice
your newMovement branch is wrong man
Andrea Sonny
@andreasonny83
Jul 13 2016 18:27
I fixed that. Make sure you switch back develop first then delete your local newMovement, then checkout newMovement again
git checkout develop
git branch -df newMovement
git checkout newMovement
git pull
seems you’re still confused about Git. Can you consider installing SourceTree and use the cool UI instead of the terminal?
Billy B.
@Azurasky1
Jul 13 2016 21:01
ok i'll do that thx sonny
i'll compile all my questions for u when u wake up tomorrow