Bug Fixing Space Invaders

Owen Abbott
2 min readOct 7, 2020

--

Just starting on the game today. I created the component tree on Sunday and put that together. Somehow, today is Tuesday. No idea where Monday went.

Somebody is on the roof again and it’s keeping me up. I live on the third floor of an apartment building and there’s no apartment above, but there’s loud noises above me, it sounds like they’re bowling up there. It’s a rule of apartment living that the people upstairs are always. Now I’m living on the top floor of an apartment building, and it turns out that rule stays as true as it ever was. So here I am, awake.

So I’m coding. Here’s the problem that I am currently working on: I’m making a space invaders clone, and I’m trying to get the player ‘tank’ to move left and right. Earlier I struggled with getting ‘onKeyDown’ to work on one of my divs, and eventually I moved on from the problem. I managed to get the function to work using an input tag as a temporary workaround.

So long as the user clicks on the input tag in the top left corner, everything works fine. The blue ‘tank’ at the bottom fo the screen moves left when I press the left key, right when I press the right key, and shoots an asterisk when I press spacebar.

There was one small issue that was bugging me, though. When I press left or right, the tank will move in that direction, but there’s a small delay at first. I figure I can use the same sort of ‘setInterval’ function that moves the asterisk and call that on keydown, then clear the interval on keyup.

Tomorrow I’ll work on getting space aliens to exist and collide with the asterisk shot from the player tank. If I’m feeling ambitious, I’ll get said aliens to move left, down, right.

--

--

No responses yet