Hands-Free Switch

Blow to connect

 

 

 

 

 

 

 

For this project, it took me a while to come up with an idea as we use our hands so often, every idea I imagined included hands in some way. Finally I decided to build something which would work when blowed on.

I began by making a simple circuit which would light up the LED, without a switch. I just used a resister, wires and the LED light. Then I detached one of the wires and added another wire in order to attach them both to alligator clips which would link to my project.

I ended up making a circuit which would light up the LED when two pieces of aluminium foil would touch (complete the circuit) through blowing from one side. The two pieces of foil are taped onto a piece of card and attached by alligator clips to the circuit.

In the future, if I was to recreate this concept along with code, I could incorporate sound each time the pieces of foil touch.

 

Week 8 – Stand up

It is good to stand up once in a while especially since I spend so much of my time, sitting in front of the computer. The switch turns on when I stand up and my leg makes contact with the table.

I have taped aluminum foil to the table and to my thigh and they are connected with alligator clips.

If I could program it, I would add a timer that caused the LED to start blinking after a certain time period and only stop blinking after the LED has been on for another period of time.

Hope you like it!

This is the schema but instead of using a switch, I used aluminum foil and connected them with alligator clips.

Week 9a Digital Input and Output

const int ledPin = 2;
const int buttonPin = 3;
unsigned long timer = 0;
bool onOff = LOW;
byte prevButtonState = LOW;
bool blinking = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  // read the button pin
  // store that in a local variable
  byte buttonState  = digitalRead(buttonPin);

  // print out the state of the button stored in the variable
  Serial.println(buttonState);

  // check to see if the button is pressed and last time it wasn't
  // only do something if that is the case
  if (buttonState == HIGH && prevButtonState == LOW) {
    // change blinking to not blinking
    blinking = !blinking;
  }

  // record the current button state for use next time through loop
  prevButtonState = buttonState;

  // if blinkkng is true, do the blinking stuff
  if (blinking == true) {
    // check to see if the current time (millis) is greater than the timer we recorded
    if (millis() > timer) {
      // flip the boolean
      onOff = !onOff;
      // record a new time to check against
      timer = millis() + 250;
      // turn the led on and off
      digitalWrite(ledPin, onOff);
    }
    / otherwise turn the LED off
  } else {
    digitalWrite(ledPin, LOW);
  }
}

 

Unusual Switch

Blow-torch

The circuit itself is very simplistic, in that only the components essential to the LED lighting up are present. For the switch I used a piece of paper and copper tape. I tightly stuck copper tape on the paper such that it would bend the paper. So as long as the paper stayed bent, it would remain in contact with the green jumper wire, thereby lighting up the LED. To turn off the LED, I can blow on the paper from above to straighten the paper, thereby disconnecting the circuit. The circuit does not have a resistor because when it was connected, the LED would not light up brightly, likely due to too high resistance in the circuit.

Close up of the switch
The circuit in action

Midterm Final

My Game:

Concept/ Inspiration:
My idea for the midterm came from the movie “Cloudy with a Chance of Meatballs” where the sky rains food and people keep eating what falls from the sky. Therefore, my main concept for the game is that food (Meatballs) fall from the sky and the character has to eat it. If the player eats all five meatballs, they win. If the player misses two meatballs, they lose.

Process and Challenges:
I have made a class for meatballs in order to have multiple meatballs falling at once.When the player misses two meatballs, he loses the game. Therefore, the screen changes to one that says “You Lost!”. when you click the mouse, you are brought back to the original page. However, one of the challenges I have faced and still do not know the answer to is that when the game is “restarted” everything is scattered and not like the game actually was at the beginning. Therefore, you have to click play again in order to restart the game. I am guessing it is because the game is actually still going and I need to do something to make every aspect of the game restart not just bring the screen back to the “Home” screen.

Midterm Assignment

“Shoot the Balloons”

Game:

Concept
My game is a classic carnival game, where the player has to shoot as many balloons as they can in a given time. I put the time as 45 seconds but realized it was low and changed to 120 seconds.

Implementation
I created a balloon class for the balloons. Initialized an array and added 4×6 balloons (for loop) in it. Then used the run function to display them at their positions. For the shooting part, I had a distance variable that calculated the distance from the click to the position of the balloon, and if it’s in a certain range the balloon pops. For popping, I simply pop the balloon object from the array. I added burst sound effect when it pops and shoots effect when the mouse is pressed anywhere else. Also, added a timer and score display. In the end, there’s a game over screen with a score and instructions to restart.

Challenges
There were two main challenges. I wanted to have random colors of balloons. I was using a sprite sheet with 6 colors of balloons. However, shooting a balloon displayed, made the whole screen disappear. That was because when I was adding balloons in my array, it was basically the whole sheet and not one balloon and popping that means removing the whole screen? So, I changed my image with only one balloon.
Another challenge was restarting the game or having multiple screens. My code was in a certain fashion that it was difficult to implement the screens one after the other- it led to crashing/overlapping of screens. The restarting the game was difficult as well-later I figured out that simply used keypressed() to restart.

Reflection
Overall, it was a fun game to implement, and learned several techniques of typical games. While some things were challenging as mentioned above, I am glad I am done with it! yay

Midterm Final Assignment – CITY RUN

Inspiration:
So at first I wanted to create something similar to the game Crossy Road, but overtime my game started to look like the 2D version of Subway Surfers and I decided to go with it because I really liked how my game was turning out. My game is called City Run and has a retro, mafia theme.

Process:
I began my first iteration of my project with letting my character move forward, but I found it was impractical as the character would go off screen so I removed the upward direction. I later decided to use the up button as a Jump button as sometimes the 3 lanes would all be blocked at the same time. I was also trying to think of a way to entice players to keep playing my game so I decided to scrap my original idea of my game being time based to just being score based with a high score tracker that would incentivize the players to want to beat it.

Reflection:
Overall, I feel that my confidence with p5.js has been lifted drastically after this assignment. I have a better grasp of the language and I feel like I learnt a lot and can finally manipulate the language in order to create something I want. Previously it was a lot harder to create what I envisioned in my head due to my skill level. I really enjoyed this assignment and I hope you enjoy my game!

Midterm – Fishing Simulator

Inspiration

In elementary school I played a lot of Club Penguin. In the club penguin world, there was a mini game based on fishing, and I’d always play because it was the quickest way to receive in-game money. Unfortunately Club Penguin has shut down now, so I made my version of the game to fill the void.  Welcome to Fishing Simulator!

Game Implementation

  1. I started by creating the fish class, and scolpted my game around it. I wanted to make them as random as possible, so each fish is given its own spawning location and speed. And each have their own boundaries, which after reaching, they will return back to their spawn location to start their journey again, until the user has caught them. The more fish the user catches, the higher their score is. I set the cap at 15 fishes, but this can be easily changed by varying the for loop containing the instantiation in the setup function. To my dissapointment, there was a lack of fish sprites online, so a png had to suffice.
  2. I chose backgrounds that I thought fit the theme of the game, and incorporated a lively outdoor-sy game music.
  3. Next I made the fishing line class. It was simple as it only constituants are a line and an arc shape. This is coupled with the catchFish() function to complete foundational game mechanics. In this function splice() is used to delete the fish objects that had been caught, by coming in contact with the fishing hook. At first I coded the fishing line to move according to mouseX and mouseY, but this made the game too easy, so I only allowed user to control the fishing line’s vertical movement. This way, users’ need to assess timings as well.
  4.  Subsequently, I created the Boot class. This didn’t take long as it had similar movement properties to the Fish class. The only difference is that if the user catches a boot, the game is over. This is checked by the catchBoot() function.
  5. With all this, the user is finally able to play the game with all the essential components incorporated. There are specific sound effects that play if the user catches any of the objects.
  6. Finally, I integrated the start and restart screens and their corresponding buttons. With these, the user doesn’t have to rerun the code everytime he/she wants to play again.

Midterm Final

As soon as we were introduced to the midterm assignment – i.e. make a game, I immediately knew that I wanted to make a game that involved a cat (I absolutely love cats). So I decided to make a game with the premise: “Oh no, my cat escaped into my brother’s room! Help me find him quick before my brother comes back from the bathroom!!” I would put a 1-2 minute timer, depending on how many items are in the space/how difficult it is to complete with trial and error.

The biggest struggle was trying to find an easy to understand code template for drag and drop an item within the canvas – once I figured that out with the help of the professor into making it a class, I was able to design the game how I wanted to. I tried making it look as much like a bedroom (with plausible decorations/furniture).

A discussion that I had with Jack when trying to get to instruct the game such that if the user clicks on the cat and it is not under any furniture/decoration, then change the screen to the winning screen. However, the drag and drop mechanism works like so:

There is a hidden small box where each item is placed onto and whenever the mouse hovers over this box, it switches from arrow cursor to hand cursor making it easy for the user to know when it is draggable. Each item has its own dimensions so only at the center of each item can it be dragged.

If I wanted the winning screen to only appear when the cat is not behind anything then it needs to not overlap with the box – considering that the box is small, this would not be feasible. In order for this idea to work, then the box would need to very specifically cover each item with all its curves, and have a specific box for each specific item since each item has their own dimensions. One small flaw of the game is that after the cat is clicked, even if it is behind an item, it would immediately change to the winning screen – so if the user were just clicking on random objects and not even dragging then they could win the game.

Nonetheless, after figuring out the main game screen and how to toggle between modes/screens (i.e. the instructions, actual game, winning the game and losing the game screens), I had to focus on how to integrate sound into the project. I needed to ask Jack for help in figuring out how to make my audio play only once, which led to making a hasPlayed variable. This variable and the timer is then reset every time the player returns to the main instructions screen.

It was important to me to have a timer on the screen – 1. to add suspense and stress 2. it is a fairly easy game, so I made the timer be 10 seconds. I had to figure out how to make the timer not flash as the countdown continued – but with a bit of changing a few variables here and there it all worked out.

Overall I am very proud and cannot believe I just made an entire game!! I cannot believe I kept at it and tried to understand each line of code one by one in order to make what I envisioned in my head happen. I’ve learnt so much and want to make more!

*sounds don’t work while embedded!*

Here it is: