visit
Well, I just knew the basics and I knew as well that I wanted to learn to code, no matter what, as I explained here.
After some time trying to learn it by myself, I figured out that would be better for me to sign up for a coding bootcamp in my hometown.For those who just want to play the game and are not interested on the story on how it was made, !And oh boy! Coding almost every single day, with LABS (homework) to do, teachers available to reach for whenever I need some help or guidance and a group of other students that are in the same situation as me has really made a difference on my learning pace. But I'm not here to tell you -if you're learning how to code- that you must sign up for one of these, everyone has different oppinions about them. I'm here to explain what I was able to made after the first module, just learning HTML, CSS and Javascript.
The final project of the module was a game that we had to develop on 2 weeks. We had complete freedom on how to do it, the one and only rule was not to use any framework.
Here, in Spain, when you have to get your driving license, you must pass a medical test. This test is kind of boring, just evaluating how well you see and hear, but it had as well one thing that made it very enjoyable: a little coordination video game.The player is represented by 2 dots (one for each hand) that move only in horizontal. It consists on two little roads viewed from above which sudden turns to the right or left, with the purpose of making it a challenge to maintain both dots in the middle of the road.The game state will consist on just 3 screens:
On Github, I started for the first time to use branches. Having a branch means creating like a "clone" of all your code files, and that allows you to change it and test it without worrying too much about messing up. Once you have something that works, you can "merge" this test branch/es with your main code (usually called the "master").
I decided to call my game 'Coordinator 2000' in a retro reference and I started to code.
<canvas id="coordinator" width="1200" height="600"></canvas>
let canvas = document.getElementById('coordinator');
let ctx = canvas.getContext('2d');
let game = new Game(ctx);
_drawPlayer(player) {
this.ctx.fillStyle = player.color;
this.ctx.fillRect(player.x, player.y, player.width, player.height);
};
I first thought that I should create 2 lines to define the road and then move them in some way, until other student from my class told me that maybe would be easier to just create an array of little rectangles of the same color, one on top of each other to make the road.
Then, moving the road to draw the turns would be as easy as adding or subtracting the X position when adding new rectangles on the array.I ran into a little problem, as the array was getting bigger and bigger the browser started to show signs of underperformance, almost freezing at some point, so I just added a function that was deleting the rectangles from the array as soon as those stepped out of the canvas:_deletePath(array) {
for (let i = 0; i < array.length; i++) {
if (array[0].y >= this.canvasHeight) {
array.shift();
}
}
}
_generateTurnsR() {
let lastItem = this.rightPathArray[this.rightPathArray.length - 1];
if (this.frames >= 0 && this.frames < 160) { // turn right
this._generatePathR(lastItem.x += 1);
} else if (this.frames > 155 && this.frames < 220) { // turn left
this._generatePathR(lastItem.x -= 1);
} else if (this.frames > 215 && this.frames < 420) { // straight
this._generatePathR(lastItem.x);
Adding a frames counter on the 'update method' allowed me to place turns every few seconds, just adding or subtracting the X position of the little rectangles.
During those 2 weeks, there was some days that I was extremely frustrated, as I coudn't figure out how to do things. Luckily, I had Alex, a teacher assistant available, that sometimes helped me pointing to the right direction.At the end, there's still some bugs (if you notice playing the game, when the left dot steps out of the road, the border doesn't become red, as the right one does), some bad practices (the timer is a GIF image, instead of code, because I didn't have time left to do it properly) and the code, after being refactored by me a few times, is still sloppy and full of don't-know-how-to's (for example, I did all the CSS as quickly as possible, without taking into account screen sizes or responsiveness).
Still, is the first "thing" created by me coding all the lines, one by one. In the past, I created a few webpages, but all of them where using Wordpress and the sensation is not the same. This is a thousand times more exciting!And now... yes! you can play it ! :)