100 Days of Code - Day 2

Written by Josh Fabean

02. September 2016

Great, it’s day two of 100 days of code. Guess what!? I sort of already failed… I got to work at 7:30am and left at 11:40pm. In that time I was able to get 45 minutes throughout the day where I worked on this code. I’m going to count it because I’ll make it up tomorrow and I coded the whole time and taught classes on how to code from 6pm-11pm so you cannot be too made at me.

So today my commit is first my updated log file and the actual code I wrote.

Here is a list of what I accomplished:

  • Removed screen wiggle when pressing the down arrow
  • Made my gulp server actually work
    • This involves moving around the file structure a bit
  • Moved health indicator to the right of the screen
  • You can now fly off one side of the screen and appear on the other side

The screen wiggle was a simple e.preventDefault() which was so simple it made me wonder why I didn’t realize that was the issue with previous canvas projects I’ve made. The flying off the screen is pretty simple but much cooler than a preventDefault(). Below is sample code of what I do when someone is pressing the down arrow.

if (38 in keysDown) { // Player holding up
  if (10 <= player.ship.y) {
    player.ship.y += -(player.ship.speed.y);
    // going to check if they've hit the top, if they have, put them on the bottom
  if (player.ship.y <= 0) {
    player.ship.y = c.height;
  }
}

The only part of that code that is new is the if player.ship.y <= 0 we make their new y be the height of the element which is the bottom. It’s a pretty simple concept and took me a couple of minutes to come up with how I would do this and get it down. It’s only an addition because someone from work complained they couldn’t go off the screen and I realized that’d be a cool idea.

Like I said, today was a lighter day tomorrow I plan on trying to get something bigger done so we’ll see what happens.

Here is my code in CodePen as it currently stands, you can use the arrow keys to play with it.

See the Pen 100DaysOfCode day 2 by Josh Fabean (@fabean) on CodePen.

:wq