Skip to content

Instantly share code, notes, and snippets.

@ajweeks
Last active January 31, 2016 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajweeks/c341ca3d1fc155d04d0f to your computer and use it in GitHub Desktop.
Save ajweeks/c341ca3d1fc155d04d0f to your computer and use it in GitHub Desktop.
Devember Twenty-Sixth

Devember Day 26

I'm considering splitting the TM495 code base into separate files, mostly because Atom starts lagging a bit with files larger than a few hundred lines. That by the way is quite stupid, since handling files is a pretty basic functionality that every text editor should be able to do without any problem whatsoever, almost regardless of their size. It isn't always laggy, but once in a while it slows down for some reason. For the most part, I really love Atom, it loads quick and does a good job most of the time. I use an Atom plugin to compile my typescript code, which works really well also. The reason I am hesitant to separate things into multiple files, is that I've heard that each load a webpage makes slows it down, and loading all your code in one file is faster than loading several files containing the same code. I could copy and paste the compiled javascript into a single file whenever I update TM495 on my website, but that would be quite a pain.

Another reason to split up some of the code into separate files would be simply ease of editing. I use 'ctrl-f' quite a bit just to find classes and methods, whereas having a file which contains only specific funtionalities might be a bit nicer to work with. It would be a helpful (and quite basic) feature for a compiler to merge all of the .ts files into one .js file, maybe the one I'm using right now even does that. I'll look into that the next chance I get.

I didn't start coding until rather late tonight, and I didn't really have a big drive to start either. But I did will myself to get around an hour done, thanks entirely to Devember. I'm quite glad I decided to join in this year as I've gotten a lot more development done as a direct result of it, and therefore (hopefully) improved more than I would've otherwise.

Tonight I improved the camera movement algorithm, from this:

var deltaY = playerY - Main.renderer.camera.position.y;
if (deltaY > 8) {
    Main.renderer.camera.position.y = playerY - 8;
} else if (deltaY < 3) {
    Main.renderer.camera.position.y = playerY - 3;
}

To this:

var deltaY = playerY - Main.renderer.camera.position.y - 7;
var speedY = (deltaY/3.0 * this.cameraAcceleration.y) * deltaTime;
Main.renderer.camera.position.y += speedY;

In the old code, I only update the camera's position if the player is near either the top or the bottom of the screen, creating a "dead-zone" area in the middle. Also, the camera either updates, or it doesn't - with no in between. This creates a slightly jerky feel.

In the newer version, I adjust the camera's acceleration amount based on how far the player is from the camera. I do this by multiplying the difference of the player's position and the camera's position by an acceleration constant (0.022, as of now). This means that the camera's position will always update, unless it is directly "on top" of the player. This also removes that "dead-zone" area, which is actually a good thing I think. I will probably tweak some values over time, but I really like how such a simple calculation can work so nicely.

It's funny how sometimes I see the game start to get slightly choppy, and I think to myself "That is why you can't make a game in TypeScript", or something along those lines. But then I realize that I'm still outputting some debug info into the console, and once I remove that line, everything goes back to being buttery-smooth. Which is great of course, because no one likes a low fps game. We'll see how long that quickness lasts though, with the addition of more and more features.

Anyway, after making that small change I added the ability to upgrade your axe once you have gathered enough wood. Right now, you just press 'b' when you have 15 wood, your steel axe gets upgraded to a shiny gold one (I should definitely think of a better word for in-game currency than wood, maybe logs?) The axe then spins around and plays a little achievement sound. Eventually I will likely have some sort of store overlay where you can purchase upgrades and such.

It may not sound like I did much tonight, and really I didn't. But I got more done than I thought I would an hour and a half ago. I haven't uploaded the previous few days worth of devember entries, but I'll try to get out either tomorrow or the next day to an internet source and see if I can upload them then. Peace!

Previous Entry | All Entries | Next Entry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment