Assignment 3

Concept:

I wanted to apply my classroom knowledge, encompassing classes, functions, and arrays, to develop an engaging interactive game. Through this process, I successfully created an addictive game. The game incorporates two classes: one for displaying the person and another for handling the moving balls. Initially, I conducted trials with balls originating from the same point, following similar paths. After receiving feedback from friends, I recognized the need for a more dynamic experience. Subsequently, I modified the code to generate balls from random points across the canvas, each with its unique trajectory. For controls, I implemented basic key functions using left, right, up, and down arrows to navigate the human across the canvas. Additionally, I incorporated arrays to introduce a new ball each time the person reaches the designated area. To enhance clarity and transform the game into a point-based system, I added a visual display of the current ball count in the top left corner. This addition encourages players to strive for higher scores, further enhancing engagement.

Highlighted Code:

//for loop which creates more balls if the human hits ball and decrements ball count
 for (let j = 0; j < ballArr.length; j++) {
   ballArr[j].display();
   ballArr[j].bounce();
   
   //if distace betwee human and ball is less than 30, move to orignal position
   let d = dist(Human.getX(), Human.getY(), ballArr[j].getX(), ballArr[j].getY());
   
   if (d < 30) {
     Human.origin();
     ballArr.splice(j, 1);
     j--;
     ballCount--; 
   }
 }

Creating this code proved to be a substantial time investment. I focused on implementing the splice and push functions within arrays to dynamically generate more balls each time the person reached the “continue” area. Through numerous iterations and referencing online examples, I was able to achieve the desired outcome, resulting in the final product I had envisioned.

Code Link: https://editor.p5js.org/Nasar/sketches/JieIBPrML

Reflections:

I take pride in the progress I’ve made, in integrating classes and arrays into my game. This endeavor significantly enhanced my understanding of these fundamental concepts. Looking ahead, I envision improving the game’s visuals and crafting a more refined character design beyond the current tree-like representation. Additionally, I aim to streamline code logic for more efficient and concise outcomes. With continued learning, I anticipate greater proficiency in envisioning diverse scenarios and seamlessly implementing them into my games. This iterative process continues to sharpen my coding acumen and creativity.

Leave a Reply