JS13K Games 2019 Day 29

First of all, I need to give a shout out to my friend jedulz for helping me get Shield Bearer to be drawn on the HTML5 Canvas!  I was having trouble getting the height and width to be correct until he sent me this pull request to fix drawing to the Canvas.  Now that I can see what is going on, I can start solving some of the issues I'm currently having with my game.  I changed the Bearer from being drawn by strokes, to just a filled rectangle so I could see it better.  I'm hoping I can get some sprites going before the deadline.

The first issue I sent out to tackle was that the Bearer would get stuck traveling to the left of the screen.  Jedulz suggested to me that it might be caused by moveLeft, moveRight, stopLeft, and stopRight functions.  I didn't like using them in the first place, because they kept messing with the dx.  So, I stepped back and ask myself this question: what are the keyup and keydown events trying to tell my game?  The original answer was to tell the game to move the Bearer left or right, but what if I took another step back?  Eventually, I came up with this idea of the KeyTracker class.  KeyTrack is a simple object that just holds variables to tell the software what state the keys are in.  The game no longer simply responds to when I press a button on the keyboard: the eventListeners now just change the state of my "soft" and simplified keyboard.  Now, whenever the update() function is called for the Bearer, it looks at the keyboard state and then makes a decision on what value dx should hold.  It also allowed me to just change the keyboard state without having to worry about tracking whether the Bearer was moving or not; meaning, update() would handle changing the value of dx, and not the eventListeners.

You might be wondering why I said that it was a "soft" and simplified keyboard.  Well, it is "soft" because the program now only looks at the values of the KeyTracker object.  It is simplified because I don't need to track all the keys: I can tie multiple keys to the same variable in KeyTracker.  Using this list of key codes, I was able to set the eventListeners for keyup and keydown to include WASD keys.  However, I tied left arrow and a, and right arrow and d to the same variables in KeyTracker.  This is so the player can choose to either use WASD or the arrow keys to move the Bearer around.  This also prevents the player from moving at double speed, since the eventListener no longer changes the dx value.  The variables in KeyTracker are boolean, so double keyup or double keydown events have no affect on it.

My next issue was how could the Bearer reach my robot spiders?  The Bearer could only reach about halfway up the screen.  What would happen if spiders started spawning and only crawled down to less than half the screen?  It's getting too close to the deadline to get my platforms working, so what should I do?  I came up with the next best idea: the classic double jump!  So, whenever the player presses the up arrow or W key, the game calls the Bearer's jump function.  The jump function then checks to see if the Bearer has any available jumps; if so, then it deducts an available jump and jumps by setting dy to -20 wherever it is at on the screen.  If the Bearer no longer has available jumps, then the it ignores the player pressing the up arrow or w.  When the Bearer lands, its available jumps are refilled to whatever is set as its max allowed jumps.

The last issue I tackled today was the fact that my Shield Bearer has no Shield!  So, I made the Shield class for all the properties related to the shield.  I looked up color codes for the fillStyle so I could pick a color for the shield.  I picked lightgray.  Now, I decided that the shield should just spawn somewhere off screen and then "snap" it to the Bearer object during the next update.  The update should happen 60 times a second, so the player shouldn't be waiting long for the shield.  Then, when the Shield's update function is called, it figures out its x and y coordinates based on the position of the Bearer and which direction the Bearer is facing.  I even made the Shield a bit taller than the Bearer.  I think it makes the shield look better, and protects the Bearer better from angled shots.  Those shots will be implemented once I get the spiders implemented.

Okay, it's past midnight!  Time to close the blog!  Next time, I'll try implementing the Backscatter Buster!  I also want the shield to "drop" whenever the Bearer fires the Backscatter Buster.  I'll also need to implement a health bar of some kind, too!  I want those Backscatter Buster shots to also be dangerous to the Bearer, as well.

Comments

Popular posts from this blog

Game Off 2019 Day 4

Hacktoberfest 2019 Day 8

Metroidvania Month 7 Day 6