For my project I created a game to raise awareness towards mask wearing so the person is trying to move through covid particles to reach the mask. And basically gets saved if he does so without colliding with a covid body. If you reach the mask, the words, “You were saved show up” while if you collide with a cover particle it says, “You’ve been infected, happy recovery!”
If I had more time I would have implemented multiple levels where the speed of the covid particles begin to vary making it more difficult and instead of a generic score the levels would be how many months you have gone without being infected. Thus, again endorsing mask wearing as a norm.
Instructions use your mouse and YOU DO NOT WANT TO GET COVID SO STAY AWAY FROM THOSE NASTY RED THINGS!!
//Aadya Bhartia
//Section A
/* The objective of the game is for the user to reach the mask and to
avoid the covid particles! Once you reach the mask you win the game and if you
bang into a particle you lose. The purpose of the game is to encourage mask wearing
*/
var mask;//parameter for object creation
var rad = 40; // for size of covid particle
//person
var personX;
var personY;
//array to store covid symbols
var covidX = [];
var covidY = [];
var dx = [];
var dy = [];
//variables to store images
var covid;
var person;
var maskImg;
function preload(){
//preloading images
covid = loadImage("https://i.imgur.com/uT2allv.png");
person = loadImage("https://i.imgur.com/uVjRV7S.png");
maskImg = loadImage("https://i.imgur.com/1olzsvy.png");
}
function setup() {
createCanvas(500, 500);
background(220);
//storing covid particles random x and position as well as speed
for(var i = 0; i<15; i++){
covidX[i] = random(width);
covidY[i] = random(height);
dx[i] = random(-5,5);
dy[i] = random(-5,5);
}
mask = makeMask();
//text formatting
frameRate(10);
textAlign(CENTER);
textFont('New Roman');
textStyle(BOLD);
}
function draw() {
//constraining mouse within canvas
var x = constrain(mouseX, 0, width-10);
var y = constrain(mouseY, 0, height-10);
background(220);
//displaying mask and checking if person has touched maks
mask.show();
mask.check();
for(var i = 0; i<10; i++){
fill(0);
image(covid, covidX[i], covidY[i], rad, rad);
covidX[i] += dx[i];
covidY[i] += dy[i];
//to bounce covid particles off the sides
if(covidX[i] >= (width) || covidX[i] <= 0){
dx[i] = -1*dx[i];
}
if(covidY[i] >= (height) || covidY[i] <= 0){
dy[i] = -1*dy[i];
}
//when person bangs into covid particle
if(covidY[i]> y-15 & covidY[i]< y+15 ){
if(covidX[i]> x-15 && covidX[i]< x+15 ){
finishGame();
}
}
}
//person
fill(255,0,0);
//displaying mouse as person
image(person,x, y, 60,100);
}
//displaying mask
function maskDisplay(){
image(maskImg, this.x, this.y, 60,60);
}
//game won if person reaches the maks
function achieved(){
var d = dist(mouseX, mouseY, this.x, this.y);
if(d<20){
wonGame();
}
}
//constructor
function makeMask(){
var m = {x : random(30, width-30),
y : random(30, height-30),
show : maskDisplay, check : achieved}
return m;
}
//message for when game has been lost
function finishGame(){
fill("black");
textSize(30);
text("You've been infected, happy recovery!", width/2, height/2);
noLoop();
}
//message for when game has been won
function wonGame(){
fill("black");
textSize(40);
text("YOU WERE SAVED!!!", width/2, height/2);
noLoop();
}