Midterm Project Update

The game is about fighting COVID-19 by the use of your fighting tools [handwash, facemask, and faceshield] the COVID-19 cells will fall from the top of the screen and if you shoot them, you get points but the number of fighting tools decrease. If the cells reaches the bottom of the screen the number of cases go up. The objective of the game is to keep the number of cases as low as possible.

For the midterm project the progress so far has been planning the game on paper. As seen below. As of right now on processing the code consists of a game class file and a main file.

The game class file will encapsulate all the game state and will be responsible for displaying the game stats and and updating them. The game class attributes are:

  1. points
  2. cases
  3. handwash
  4. masks
  5. shields
  6. state
  7. fightTool
  8. time
  9. And the icons

The game class methods are:

  1. increment points
  2. reduce points
  3. increment cases
  4. increment masks
  5. decrement masks
  6. increment shields
  7. decrement shields
  8. increment handwash
  9. decrement handwash
  10. change state
  11. update time
  12. drawGameStats

The icons for use in the game were downloaded from flaticon as seen below

 

class Game {
  // attributes
  int points = 0;
  int cases = 0;
  int handwash = 20;
  int masks = 14;
  int shields = 6;
  int state = 0; // 0->shooting 1-> buying -1 -> gameOver
  int fightingTool = 0; // 0-handwash, 1-mask, 2-shield
  int time = 120;
  PImage maskImg = loadImage("mask.png");
  PImage handwashImg = loadImage("handwash.png");
  PImage shieldImg = loadImage("shield.png");
  int timeDisplay = 0;


  //methods
  void incrementPoints() {
    if (fightingTool == 0) {
      points += 1;
    } else if (fightingTool == 1) {
      points += 3;
    } else if (fightingTool == 2) {
      points += 5;
    }
  }
  void reducePoints(int fightingTool) {
    if (state==1) {
      if (fightingTool == 1) {
      }
    }
  }
  void incrementCases() {
    cases+=1;
  }

  void incrementMasks() {
    masks+=1;
  }

  void decrementMasks() {
    masks-=1;
  }

  void incrementShields() {
    shields+=1;
  }

  void decrementShields() {
    shields-=1;
  }

  void incrementHandwash() {
    handwash+=1;
  }

  void decrementHandwash() {
    handwash-=1;
  }

  void changeState() {
    if (state==0) {
      state=1;
    } else if (state==1) {
      state=0;
    }
  }
  void updateTime() {
    if (time==0) {
      state=-1;
    }
    if (frameCount%60==0 && state!=-1) {
      time-=1;
      if (timeDisplay==0) {
        timeDisplay = 1;
      } else if (timeDisplay==1) {
        timeDisplay=0;
      }
    }
  }

  void drawGameStats() {
    color(0, 0, 0);
    imageMode(CENTER);

    // draw mask
    image(maskImg, 70, 30, 30, 30);
    text(masks+" x", 25, 30);

    //draw handwash
    image(handwashImg, 150, 30, 30, 30);
    text(handwash+" x", 110, 30);

    // draw faceshield
    image(shieldImg, 230, 30, 30, 30);
    text(shields+" x", 190, 30);

    //display time
    pushStyle();
    textSize(30);
    if (timeDisplay==1) {
      fill(0, 0, 0);
      text(time, width-100, height-30);
    } else if (timeDisplay==0) {
      fill(255, 255, 0);
      text(time, width-100, height-30);
    }
    popStyle();

    // game mode
    pushStyle();
    int rectWidth = 100;
    int rectHeight = 30;
    int cornerRadius = 10;
    noFill();
    rect(width/2-rectWidth/2, 20, rectWidth, rectHeight, cornerRadius, cornerRadius, cornerRadius, cornerRadius);
    if (state==0) {
      pushStyle();
      textAlign(CENTER);
      textSize(25);
      fill(255, 0, 0);
      text("FIGHT", width/2, 45);
      popStyle();
    }

    popStyle();
    
    //display points
    pushStyle();
    fill(0,0,0);
    textSize(25);
    text(points+" points", width-300,45);
    text(cases+" cases", width-150,45);
    popStyle();
  }
}

 

Leave a Reply