Skip to content

Instantly share code, notes, and snippets.

@ajweeks
Last active January 31, 2016 15:55
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/d221b76f6241f318ed7e to your computer and use it in GitHub Desktop.
Save ajweeks/d221b76f6241f318ed7e to your computer and use it in GitHub Desktop.
Devember Thirtieth

Devember Day 30

I added another improvement to the game's realism today, by requiring the player to face trees to chop them down. This can be done by a simple check of which direction the player is facing and to which direction the tree is.

I then disabled buttons, which required a bit of a rework of how I handled button clicks. The need for this feature arose while I was thinking about adding a save/load feature. I will likely have a "Resume Game" button in the main menu, along with a "New Game" button. If you don't have any previous saves, then the "resume game" button should be disabled. It's not the prettiest thing ever but here's what I'm using at the moment:

function buttonClick(button: string, event: MouseEvent, callback: () => void) {
    if (get(button).className === 'button enabled' && clickType(event)===ClickType.LMB) {
        callback.call(this);
    }
}

and then in the HTML:

<div class="button" id="buttonid" onclick="buttonClick('gameBackButton', event, function() { Main.sm.enterPreviousState(); })">Button Name</div>

I basically just pass in an anonymous function to be called if the left mouse button was clicked and the button isn't disabled.

Then, with that out of the way, I began to implement the ability to save the game. I've dealt with saving games before with Mirrors, using the document's localStorage item. I actually spent a while just looking though the Mirror's .ts file, initially to see how I dealt with saves, but I kept looking around just to see how different it was from code I type today. It was quite interesting to see actually. There weren't too many differences, the biggest one I saw was my bracketing style. I saw many single line if statements which didn't use an explicit block, which is something that I never do today. There was also a few occurrences of getting a variable more than one time, which today I would've used a temporary variable for.

I love it when I implement a feature sort of half-knowngly why, and at some point later realize that that feature will help me add a new feature I want more seamlessly. Today, I thought of another thing which I brainstormed a while ago, but had forgotten until now. I would like the game to load with a little animation, or video, describing the situation the player is in. Nothing long, just a way of setting the mood for the player. If you've played the first version of Spelunky, then you know what kind of thing I mean. A few days ago I added a loading state, mostly because I wanted to prevent an exception from occurring when the game tried rendering a texture before it was loaded.

But now, I'll be able to use the loading state to show this intro video thing. Anyways, that's it for now, see you in the next (and final) entry, tomorrow!

Previous Entry | All Entries | Next Entry

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