A new Digger
I really liked the original digger code because in one way it was simple. I didn't have any fancy factorisation of functionality. I didn't use an object oriented anything. But I must admit for the limited functionality I felt the code was a bit long. So I tried to improve by factorising it it but I must admit I'm not very satisfied. I created a class to hold the digger and enemy positions and direction but it didn't feel like an improvement.
But I had an idea that I could hold all the information in a array and create a function to to generate the next frame, it's kind of low level and old skool but also it would be possible to accelerate it with a shader. So the function could look at a grid of 9 pixels and based on that decide the next value for the middle pixel.
I also was a bit unsatisfied with the frame rate or something was happening I wondered whether the canvas was a too big so I found a way that worked so that the canvas could be created whatever size you wanted and scaled using html.
function windowResized() {
if ( windowWidth / windowHeight < canvasWidth / canvasHeight )
canvas.elt.style.transform = 'scale( ' + windowWidth / canvasWidth + ')';
else
canvas.elt.style.transform = 'scale( ' + windowHeight / canvasHeight + ')';
loadPixels( );
}
So in this version I actually do some DOM manipulation and add a style to the canvas element to scale it up. This way you can even have a canvas that's 1x1 pixel? Actually I didn't try that but anyway you can have a smaller canvas and that should be faster. I honestly don't know what was going on with the timing... but it became really noticeable with the sound...
Anyway I think I'll develop this idea a but before moving on...
Subscribe to my newsletter
Read articles from Alexis Farmer directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by