(Updated Blog Post)
For this homework we had to use Object Orientated Programming (OOP) to create some sort of animation or simulation. The OOP syntax in javascript was completely new to me so this homework was more complicated than the previous ones. I chose to create another game but this time with no involvement of any balls.
Initially, I started working on a boat racing game but after a while I got in to a lot of issues that I was not able to solve so I decided to comment all the pieces of code that involved a second boat in the game and left only one boat. The issues I ran in to look very simple so I am not sure if it is actually simple and I can’t just do it for some reason or the issues are actually hard. One of the issues was changing the position of the second boat created. I didn’t want to use the random function because it is a poor option as the two boats can still be on top of each other or rather very close to each other (for example, to overlap). I thought of using for loops and increment the value of the y axis for every object I instantiate but for some reason both the web editor and the desktop editor crashed when I did so.
After spending some time to work on those issues I decided to rather think of another game that involves boats. I thought of using the same boat game but with only one boat and creating rocks in the river that act as obstacles facing the boat. If the boat, hits any of the rocks, the user loses but if the user makes it to the finish line he wins.
I faced another issue that perplexed me. I am not able to implement the if statement that decides whether the boat has collided with a rock or not. I cannot get it to work for some reason. I think it is a very simple issue but for some reason I cannot get it to work. I know why my if statement does not and I know that it is completely wrong but I cannot think of anyway else to check if the boat collided with a rock. I though of using trigonometry and measure the distance between the rock and the boat and if the distance is equal to the distance of the radius of the rock and the width/2 of the boat then a collision must have occurred I could not get that to work too. I left this issue open and I saved my code in github as “The boat game (Not fully completed)”.
Also, I have a bug in the code which at first I was concerned about and thought I had to fix but then I realized that it can actually be a part of the game. If the boat moves towards the green land on each side of the river it should stop. However, the boat stops completely from moving on the x axis because I assigned vy to be 0 in the code in the situation where the boat hits the land’s edge. The boat can still move to the front though, so I decided to leave it this way to make the game even harder.
Everything else in the code is running smoothly and perfectly. I hope I can figure out how to detect if a collision occurs between the boat and a rock by tomorrow morning. Otherwise, I will be reaching out to Daniel for help with this issue.
(UPDATE) Finally, I was able to solve the issues I had with game. After Thursday’s class things became clearer and I was able to solve the issue using the dist() function to detect if there were any collision between the boat and any of the rocks.